Developer Feature Suggestion

  • Posts: 141
  • Thank you received: 3
  • Hikashop Business
2 years 6 months ago #335585

-- HikaShop version -- : 4.4.3
-- Joomla version -- : 3.10.1
-- PHP version -- : 7.4.23

I am writing a new payment plugin for a customer. On payment, the payment plugin uses onBeforeOrderCreate to contact their gateway and Authorize the payment amount, so that they can Capture the funds when they actually ship the order (as is required by U.S. law). This is working beautifully, but historically, they have needed to go to both their payment gateway's website (in order to capture the funds), AND to return to HikaShop to change the order's status from Created to Shipped.

They have finally moved to a gateway which provides a more robust API, so I am writing this payment plugin so that if they use HikaShop to change status from Created to Confirmed, the plugin will use its onBeforeOrderUpdate method to Capture the customer's funds in a single step, so that they can immediately change the status again Shipped. ('Shipped' being the term they use to mean 'Completed', since they also use HikaShop for orders which are picked up by the customer.)

The issue I have is that when onBeforeOrderCreate receives the Order object in its args, it contains a StdClass object for a new History record for the status modification, but no means to call the Order's 'creation' History record, which seemed like the logical space to store the gateway's Transaction ID and Token, both of which are needed to capture the funds.

I've worked out a query for the particular history record I need, but a helper method to call an Order's History records would be handy. Or a method within the History class to call specific records. Since these are primarily log records, there don't seem to be any search methods.

Are there any simpler ways than querying them directly from their DB?

Please Log in or Create an account to join the conversation.

  • Posts: 25994
  • Thank you received: 4004
  • MODERATOR
2 years 6 months ago #335598

Hello,

You have order_payment_params for that.
The order history is for admin log, not for storing plugin data.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 141
  • Thank you received: 3
  • Hikashop Business
2 years 6 months ago #335783

OK, I have modified the payment plugin to store the Transaction values in the order_payment_params field. ( I had some initial trouble with trying to store it as JSON, which would be my preference, but the Helper Class's hikashop_unserialize method was being called repeatedly behind the scenes, so that threw all sorts of errors. )

It appears there is no place in HikaShop's order interfaces for an administrator to view this data though. I fully expect that at some point, they'll need it. I don't see any back end templates that can be override to include it. ( I assume it was included in the data object, because it was definitely being unserialized, but I couldn't find it being displayed anywhere.)

Suggestions?

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13037
  • MODERATOR
2 years 6 months ago #335792

Hi,

The data in order_payment_params is serialized, but the structure of the data you add in there is up to your payment plugin. So HikaShop cannot display it as it doesn't know the format/structure of your data in there.
Also, payment plugins don't necessarily want the data stored there to be displayed.
If you want to display it, you need to have your plugin implement some kind of event.
The simplest is to implement onAfterOrderProductsListingDisplay(&$order, $type) in your plugin. In that function, just echo your HTML and it will appear below the products listing on the order in the backend, in the frontend for the customer and in the notification emails.
You can use $type or $_REQUEST to only display your HTML for some parts (for example if you don't want to display the data to the customer), or to display different things.

For example, for the MyParcel plugin available on our marketplace, we have this code:

public function onAfterOrderProductsListingDisplay(&$order, $type) {
		//skip if URL not yet known
		if(!empty($order->order_shipping_params->my_parcel['tracking_url'])) {
			$url = $order->order_shipping_params->my_parcel['tracking_url'];
		}
		if(empty($url))
			return;
		
		// skip on order details page in the backend
		$app = JFactory::getApplication();
		if(version_compare(JVERSION,'4.0','<'))
			$admin = $app->isAdmin();
		else
			$admin = $app->isClient('administrator');
		if($admin && @$_REQUEST['ctrl'] == 'order' && @$_REQUEST['task'] == 'show')
			return;

		// load the translations of the plugin
		$this->loadOptions();

		// display the tracking URL for the frontend and emails
		echo '<p class="hikashop_myparcel_tracking_information">'.JText::sprintf('YOU_CAN_ACCESS_THE_TRACKING_INFORMATION_HERE', $url).'</p>';
	}
which displays the tracking URL of the order if available and only for the emails and the frontend as the plugin uses another event to display the tracking URL to the admin on the orders listing.

Please Log in or Create an account to join the conversation.

  • Posts: 141
  • Thank you received: 3
  • Hikashop Business
2 years 6 months ago #335803

I'll give this a shot. Thanks.

A full explanation, for anyone following the thread:

My HikashopPayment plugin uses onBeforeOrderCreate to Authorize a customer's credit card payment, but the rules are that our customer should not collect those funds until the order is assembled and ready to be handed off to either customer pickup or to the shipper. To do that, we need to store two values given by the Gateway (Transaction ID and transaction Token). The funds will be captured by using onBeforeOrderUpdate to capture the funds when status is changed to Confirmed ( then to Shipped afterward as needed. )

The challenge is that between the purchase and the status change, the only information that connects the Hikashop Order with the Gateway's Transaction record is that data given back during purchase, which HikaShop keeps hidden for good reasons. Although it is possible to send a unique identifier to the Gateway for storage there, Hikashop's unique ID doesn't exist yet because the Order doesn't yet exist. If anything goes wrong during that period, our customer could not reliably identify which records to connect without asking us for direct database access. The only information they can actually see to match those records is the timestamps, which - coming from two different servers - might not be a perfect match.

To assist in this situation, I intend to use Nicolas' tips to add a read only display of the Transaction ID value to the Order's Admin interface, but NOT the Transaction Token. That should help keep it secure.

I also plan to add a flag value to indicate whether the funds for that order have been successfully collected funds, preferably on the Administrator's list view of Orders.

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.070 seconds
Powered by Kunena Forum