Further action after successful payment

  • Posts: 2
  • Thank you received: 0
11 years 3 months ago #118759

-- HikaShop version -- : 2.2.0
-- Joomla version -- : 2.5.8
-- PHP version -- : 5.3.2

We are trying to ascertain the best method to call custom code after successful user payment.. The code needs to be called only when the order has successfully paid for. We are selling digital goods and need to setup the user's access via API once he has completed his payment.

As part of that, we also need to either modify the email that goes out to the customer or send another one with the access details.

We looked into the API and there are certain events mentioned like :

onAfterOrderConfirm(&$order,&$methods,$method_id)
onAfterOrderUpdate(&$order,&$send_email)

We are not sure if these are called after payment, the document seems to suggest that the orderConfirm method is actually used by the payment plugins to redirect to payment page.

Please advise as to the best approach to achieve this.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
11 years 3 months ago #118771

Hi,

You have to use both triggers.
Some plugins can check if the payment was made before creating the order and other, creates the order and some time after, the payment is made and the order validated.

In each trigger you have an access to the $order object.
You can access to the value " $order->order_status " in order to check if the order is "confirmed" or not.
To know if an order is being confirmed, you have to compare the order_status with the old order_status.

$config = hikashop_config();
$confirmed = $config->get('order_confirmed_status', 'confirmed');
if( !empty($order->order_status) && $order->order_status == $confirmed && (empty($order->old->order_status) || $order->order_status != $order->old->order_status) ) {
  // The order is being confirmed.
}
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: 2
  • Thank you received: 0
11 years 3 months ago #118815

Hi,

Thanks a lot for a quick and detailed reply. Really appreciate you taking the time out to answer our query.

Some confusion regarding where to put this code. Are we required to create a plugin under HikaShopPayment group extending the HikashopPaymentPlugin ? This is supposed to be a post processing code and not a payment gateway choice, and therefore does not seem correct to put it under HikashopPayment. Are we correct ? Not certain if the events would be triggered if we put it somewhere else.

Please advise.

Regards,

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
11 years 3 months ago #118835

Hi,

You have to use this code in an HikaShop plugin. No necessary a payment plugin, you can just create a classical JPlugin under the group "hikashop".
onAfterOrderConfirm is a special payment trigger which is call only for the selected payment method.
You can use onAfterOrderCreate and onAfterOrderUpdate in a classical hikashop plugin without any problem.

If you want to create your own payment plugin, using a structure based on HikashopPaymentPlugin will be useful because all the generic tasks for payments are already there (same thing for shipping plugins and HikashopShippingPlugin).

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.

Time to create page: 0.047 seconds
Powered by Kunena Forum