Issues geting vars from cart to javascript, custom payment gateway (hosted chk)

  • Posts: 1
  • Thank you received: 0
7 years 1 month ago #265782

Hello, First of all, I introduce myself, my name is Alan and I live in Los Cabos, Mexico, I'm studying Systems Engineer degree and for the moment im struggling creating a basic e-shop for a project of mine, I've been reading all of documentation refering to payment gateways, spent hours searching in this forum and around the web, but I cant resolve this problem.

I have developed a payment gateway based on hikashop documentation and a piece of code that a bank institution gave to me but im facing issues passing by the values to a JSON object and then calling it to succesfully complete the checkout process. Joomla acepts and display the plugin, Hikashop recognizes the plugin and I can use it and everything goes well if I put values directly into the JSON object, but I just cant put these values with php.

If i do this inside payment.php it will display the values when i click the Finish button after checkout process

echo '<br/>merchant:'. $this->payment_params->identifier.'<br/>';
echo 'amount:' . $this->order->cart->full_total->prices[0]->price_value.'<br/>';
echo 'currency:'. 'USD'.'<br/>';
echo 'description:' . $this->order->cart->products[0]->order_product_name.'<br/>';
echo 'id:' . '1'.'<br/>';

As you can see in the pic I've uploaded i got the values from the cart but when I press "confirm pay "these values aren't loaded inside the script (JS) given to complete the checkout process, I would really appreciate your comments so I can resolve this issue, I uploaded the payment gateway files just in case, thanks in advance!

Attachments:

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

  • Posts: 81540
  • Thank you received: 13069
  • MODERATOR
7 years 1 month ago #265784

Hi,

You've quite a bit of problems in the plugin.

1. The function getPaymentDefaultValues is defined inside the function onAfterOrderConfirm.
First, that means that this getPaymentDefaultValues function won't be found by HikaShop. And second, having functions inside functions, while allowed by PHP is not a good practice.

2. In the function onAfterOrderConfirm, you initialize the $vars array with the data you need in your end file, however, you don't pass the $vars variable to end.
If you look at the example payment plugin we provide in the developer documentation, you can see that we do this:

$this->vars = $vars;
just before calling:
return $this->showPage('end');
so that $this->vars is then available in the end file.
That way, in your end file, you can replace for example:
merchant: "TEST1058409",
by:
merchant: "'.$this->vars['IDENTIFIER'].'",
and you'll get your data in your javascript.

3. You use addScript in both the onAfterOrderConfirm and the end file to add two different JS files. If you need only one, I would recommend having it only in the end file, and if you need both, then put both in the end file.

4. The code:
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
in the function onAfterOrderConfirm might not work as, depending on how you configure your HikaShop settings, the cart already be cleared from the user session. But you already have all the data of the order in $order anyway, so you don't need that.

5. All the code after the closing of the class plgHikashoppaymentevopayment should be removed as it doesn't do anything good.
All the code you put outside of the class definition in a Joomla plugin will run each time the plugins of that group are loaded by Joomla.
So you'll end having that code run in the backend, when the plugin is being configured, during the checkout, when the payment methods list is being displayed, or when the cart is being loaded, etc.
And you don't want that.

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

Time to create page: 0.055 seconds
Powered by Kunena Forum