Discussions

Drupal commerce - what page/function should i call after an off site payment

I'm creating a module to integrate xpay - carta sì payments inside Drupal commerce. I don't have any documentation on xpay apart for the module developed for ubercart. Anyway i managed to code the part where the payment method is added and i succesfully dealt with going from my site to the bank page sending the correct data. I'm stuck with where to go after the payment is completed. When i send the data to the bank i set some url to call according to the outcome of the transaction

'RESULT_URL' => $site_url.'/cart/xpay/complete',
'NOTIFICATION_URL' => $site_url.'/cart/xpay/server',
'ERROR_URL' => $site_url.'/cart/xpay/error',
'ANNULMENT_URL' => $site_url.'/cart/xpay/error',

I've defined those menu_callbacks, but i'm not sure that Drupal Commerce works like this, maybe i should do something totally different like returning to $site_url.'/checkout/%order_id/payment'

Has anybody of you tackled something similar?

Posted: Mar 22, 2012

Comments

LoRaK on April 4, 2012

I've just started playing with drupal commerce two days ago, so my answer may not be complete, but here is how I'm doing it, based on the 'commerce_adyen' module.

In the callback(s) for the response url(s):

if the transaction was successful

commerce_payment_redirect_pane_next_page($order);
drupal_goto(commerce_checkout_order_uri($order));

if unsuccessful
commerce_payment_redirect_pane_previous_page($order);
drupal_goto(commerce_checkout_order_uri($order));

These will direct the user to either the Order complete page, or the page where they selected the payment method.

You might also want to update the transaction (load or create the apropriate transaction object before)

$transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
commerce_payment_transaction_save($transaction);