【问题标题】:What is the return URL of ubercart after successful payment支付成功后ubercart的返回地址是什么
【发布时间】:2012-04-07 14:50:55
【问题描述】:

我的简单 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”作为我网站的返回网址,但它不起作用。

任何人知道什么是正确的返回 url 以便在结帐后将 ubercart 订单标记为完成?

我正在使用 drupal 6.0

【问题讨论】:

    标签: drupal ubercart


    【解决方案1】:

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

    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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-30
    • 2019-05-30
    • 2012-05-27
    • 2013-03-07
    • 1970-01-01
    • 2014-07-11
    • 2011-11-03
    • 2018-07-05
    相关资源
    最近更新 更多