If this is your custom payment module, you have to create your own redirect url
(you can create one for all cases [success, error, cancel] and redirect upon status message returned):
1.Specify a menu callback and a function to catch the POST variables returned by your payment gateway
e.g for module name: uc_mypayment
/**
* Implementation of hook_menu().
*/
function uc_mypayment_menu() {
$items['cart/mypayment/complete'] = array(
'title' => 'Order complete',
'page callback' => 'uc_mypayment_complete',
'access callback' => 'uc_mypayment_completion_access',
'type' => MENU_CALLBACK,
'file' => 'uc_mypayment.pages.inc',
);
}
2.Then you have to implement the callback function which is the one that handles the returned variables:
function uc_mypayment_complete($cart_id = 0) {
$order_id = check_plain($_POST['Param1']);
$payment_status = check_plain($_POST['Result']);
$payment_amount = check_plain($_POST['Charge']);
$payment_currency = check_plain($_POST['Currency']);
$ErrorMessage = check_plain($_POST['ErrorMessage']);
...
}
tweak it according to your gateway protocol.
3.Depending on the status and message you get back, you may redirect to the corresponding status page (i.e success, error, cancel) e.g
//assuming you have saved your success, error and cancel Urls into the variables: uc_mypayment_success_return_url, uc_mypayment_error_return_url, uc_mypayment_cancel_return_url
switch ($payment_status) {
case 1: // successful transaction
$comment = t('MyPaymentGateway transaction ID: @PayId', array('@PayId' => $PayId));
uc_payment_enter($order->order_id, 'myPaymentGateway', $payment_amount, $order->uid, NULL, $comment);
uc_cart_complete_sale($order);
uc_order_comment_save($order->order_id, 0, t('Payment of @amount @currency submitted through myPaymentGateway.', array('@amount' => $price , '@currency' => $payment_currency)), 'order', 'payment_received');
uc_order_comment_save($order->order_id, 0, t('MyPaymentGateway reported a payment of @amount @currency', array('@amount' => $payment_amount , '@currency' => $payment_currency)));
drupal_set_message($debugmessage . t('Your payment was completed.'));
drupal_goto(variable_get('uc_mypayment_success_return_url', 'cart'));
break;
case 2: //error
$message = $debugmessage . t("Your payment failed with following error message: @Error", array('@Error' => $ErrorMessage));
uc_order_comment_save($order->order_id, 0, $message, 'admin');
drupal_set_message($message . t(' Please try again in a few moments.'));
drupal_goto(variable_get('uc_mypayment_error_return_url', 'cart'));
break;
case 3: //user cancelled
uc_order_comment_save($order->order_id, 0, t("The customer cancelled payment."), 'order', 'canceled' );
drupal_set_message($debugmessage .t('Your payment was cancelled. Please feel free to continue shopping or contact us for assistance.'));
unset($_SESSION['cart_order']);
drupal_goto(variable_get('uc_mypayment_cancel_return_url', 'cart'));
break;
}
Now you can just supply one url for all cases, in this example: cart/mypayment/complete