成功付款后,ubercart的返回URL是多少?

时间:2012-03-23 00:25:00

标签: drupal ubercart

我的简单ubercart支付网关模块中有以下代码,可在结帐后将其重定向到我的商家付款表单:

  $data = array(
  'merchantId' => "1",  
  'amount' => $total,
  'orderRef' => $order->order_id,
  'currCode' => 608,
  'successUrl' => 'http://mydomain.com/cart/checkout/complete',
  'failUrl' => 'http://mydomain.com/Fail.html',
  'cancelUrl' => 'http://mydomain.com/Cancel.html',
  'payType' => 'N',
  'lang' => 'E',
  'pdesc' => t('You have !num_of_products products in your cart', array('!num_of_products' => count($order->products))),
);

$form['#action'] = 'https://test.mymerchantgateway.com/payment/pay.jsp';

在上面的代码中,我可以成功启动付款。问题在于如何返回我的网站并将订单标记为完整。经过一些研究,我添加了“http://mydomain.com/cart/checkout/complete”作为我网站的返回网址,但它没有用。

任何知道什么是正确的退货网址,以便在结帐后将超级卡订单标记为完整?

我正在使用drupal 6.0

1 个答案:

答案 0 :(得分:2)

如果这是您的自定义付款模块,则必须创建自己的重定向网址 (您可以为所有案例创建一个[成功,错误,取消]并在返回状态消息时重定向):

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