如果这是您的自定义支付模块,您必须创建自己的重定向网址
(您可以为所有情况创建一个 [成功、错误、取消] 并在返回状态消息时重定向):
1.指定一个菜单回调和一个函数来捕获您的支付网关返回的 POST 变量
例如模块名称: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.然后你必须实现回调函数,它是处理返回变量的回调函数:
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']);
...
}
根据您的网关协议对其进行调整。
3.根据您返回的状态和消息,您可以重定向到相应的状态页面(即成功、错误、取消)例如
//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;
}
现在您可以只为所有情况提供一个网址,在本例中为:cart/mypayment/complete