call custom payment plugin even when total is 0

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
1 year 2 months ago #349453

-- HikaShop version -- : 4.7.1
-- Joomla version -- : 3.10.11
-- PHP version -- : 7.4.3
-- Browser(s) name and version -- : Chrome 90.0.4430.212

Hello,
we made a custom payment plugin, this plugin redirect to a servlet (java) for the payment logic.
if the cart has total amount = 0 (due to discounts or coupons) the plugin is not called at all.

Is it possible to make it always called even with a total amount = 0?

Thanks.

Regards,
Matteo

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

  • Posts: 4519
  • Thank you received: 612
  • MODERATOR
1 year 2 months ago #349456

Hello,

Sorry for this return, but we aren't sure to follow you, what do you mean by "the plugin is not called at all"
- Do you mean not display in while checkout process
OR
- The finish button isn't display ? Or nothing happen when you click it?
If it's a different idea, please be very specific in your answer, and in all case explain us why you need to pass by the payment server, whereas with a total of 0 no payment should be required.
=> Your elements will surely allow us to better understand your needs and therefore be more precise in our help.

Regards

Last edit: 1 year 2 months ago by Philip.

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
1 year 2 months ago #349472

Hello,
we made a custom payment plugin that is called when choosed as a payment method from the chekcout page.
this custom plugin redirect to a servlet (java app) because this app manage the payment environment and do other stuff after the payment is done.
if the total amount on checkout page is = 0 the finish button is dispayed, but if i click it, hikashop does not call out custom payment plugin, because the chkeout page with a total amout = 0 does not present any choose for the payment (yes, because the total is 0)

but we need to call out payment plugin anyway, because in the flow, even when the total is 0 we need to do stuff

is there a way to call our custom payment plugin even when no payment method is present for choice?

Thanks.

Regards,
Matteo

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
1 year 2 months ago #349474

Hi,

You should implement the onAfterOrderCreate(&$order, &$send_email) event in your plugin.
In it, check if the $order->order_full_price is set to 0. If it is, then you can call the function of your plugin redirecting to the servlet.

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
1 year 2 months ago #349492

Hi,
ok thank you!

i just implemented the onAfterOrderCreate and it is ok, but our "servlet url" to call is configured as a payment plugin parameter, and i usually retrive it with $this->payment_params->payment_url, but unfortunatelly in this case is empty, maybe because no payment method is selected (order_full_price = 0) ??

Usually we use onAfterOrderConfirm(&$order, &$methods, $method_id) and call parent::onAfterOrderConfirm($order, $methods, $method_id); // This is a mandatory line in order to initialize the attributes of the payment method

Is there a way i can simulate like if our custom payment plugin is selected when order_full_price = 0?

Thanks.

Regards,
Matteo

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
1 year 2 months ago #349493

Hi,

Yes. Like in the onPaymentNotification method of payment plugins, you can use the line:

$this->loadPaymentParams($order);
This will load $this->payment_params based on the payment method selected in the order.

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
1 year 2 months ago #349505

Hi,

the problem is that in the $order there is no payment method selected, that is because when order_full_price = 0 no payment method is presented as a choice in the checkout page.

Is there another way to load our custom payment plugin parameters?

Thanks.

Regards,
Matteo

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
1 year 2 months ago #349506

Hi,

You just need to set it:

$order->order_payment_method = 'XXX';
$order->order_payment_id = 'YYY';
$this->loadPaymentParams($order);

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
1 year 2 months ago #349517

Hi,

yes but, how am i supposed to know those data?
order_payment_method is a class, how can i reproduce it?

and how can i be sure what number is order_payment_id ?
we have a development environment, a staging and a production one, in every environment could be a different number.

Is there a way to do it?

Thanks.

Regards,
Matteo

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
1 year 2 months ago #349519

Hi,

suppose that i set a "default payment id" parameter somewhere in our component, is there a way to retrive "payment_method" class from payment_id ?

something like:

$order->order_payment_id = JComponentHelper::getParams('our_component')->get('default_payment_id');
$order->order_payment_method = hikashop->getPaymentClass($order->order_payment_id);
$this->loadPaymentParams($order);

Thanks.

Regards,
Matteo

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
1 year 2 months ago #349518

Hi,

order_payment_method needs to be the folder name of your payment plugin. Since this development is for a payment plugin you already know it and it won't change. You could actually use $this->name since you're implementing the onAfterOrderCreate in your payment plugin.
For order_payment_id, this will change for each different website. You could retrieve it from the database with a small MySQL query:

$db = JFactory::getDBO();
$query = 'SELECT payment_id FROM #__hikashop_payment WHERE payment_type = '.$db->Quote($this->name);
$db->setQuery($query);
$order->order_payment_id = $db->loadResult();

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
1 year 2 months ago #349526

Hi,

ok thank you i'll give it a try.

Meanwhile I notice a strange beaviour when full_price is > 0
onAfterOrderCreate() is called two times, the first one with $order->order_full_price = 0 and the second time with the right order
amount. Furthermore the first time the object $order is different from the second time $order, the first only have properties, the second have classes as well (bill,cap,cart, etc.)

A similar behaviour appends when full_price is = 0

It's expected? how can we know if we are in the right onAfterOrderCreate() call?

Thanks.

Regards,
Matteo

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

  • Posts: 81540
  • Thank you received: 13071
  • MODERATOR
1 year 2 months ago #349527

Hi,

It must be because you're using HikaMarket. In that case, HikaMarket will create a sub order for each vendor linked to the order.
That way, each vendor only see his sub order while the shop owner and the customer see the main order.
So you need to check $order->order_type == 'sale' in order to only take into account the main order, not the sub orders.

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

  • Posts: 50
  • Thank you received: 1
  • Hikamarket Multivendor Hikashop Business
1 year 2 months ago #349560

Hi,

you are precious! thank for your kind support, I managed to solve.

Thanks.

Regards,
Matteo

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

Time to create page: 0.069 seconds
Powered by Kunena Forum