如何在ubercart中集成第三方商家支付网关

时间:2012-03-22 06:03:12

标签: drupal ubercart

我一直在寻找2天如何将我的商家支付网关整合到ubercart中。所以我决定在这里问一下。

我的商家提供以下代码作为示例:

<form name="payFormCcard" method="post" action=" https://test.MyMerchantGateway.com/ECN/eng/payment/payForm.jsp">
<input type="hidden" name="merchantId" value="1"> 
<input type="hidden" name="amount" value="3000.0" >
<input type="hidden" name="orderRef" value="000000000014">
<input type="hidden" name="currCode" value="608" >
<input type="hidden" name="successUrl" value="http://www.yourdomain.com/Success.html">
<input type="hidden" name="failUrl" value="http://www.yourdomain.com/Fail.html">
<input type="hidden" name="cancelUrl" value="http://www.yourdomain.com/Cancel.html">
<input type="hidden" name="payType" value="N">
<input type="hidden" name="lang" value="E">
<input type="submit" name="submit">
</form>

请注意,出于安全原因,我更改了上面的实际域名。

结帐后我想要的是将其重定向到https://test.MyMerchantGateway.com/ECN/eng/payment/payForm.jsp

1 个答案:

答案 0 :(得分:1)

您希望进行异地付款(在您的Drupal网站外部),因此在您的付款模块中,您需要编写一个重定向的付款方式:

function my_pay_gateway_uc_payment_method() {
  $methods[] = array(
    'id' => 'my_pay_credit',
    'name' => t('My Payment Gateway'),
    'title' => t('My Payment Gateway'),
    'desc' => t('Pay through my payment gateway'),
    'callback' => 'my_payment_method',
    'redirect' => 'my_payment_form',  // <-- Note the redirect callback provided
    'weight' => 1,
    'checkout' => TRUE,
  );
  return $methods;
}

然后,您应该向重定向回调添加代码,以构建一个位于提交订单按钮后面的表单,以重定向到您的支付网关,同时包含您需要的所有信息:

function my_payment_form($form, &$form_state, $order) {

  // Build the data to send to my payment gateway
  $data = array(
    'merchantId' => '1',
    'amount' => '3000.0',
    'orderRef' => '000000000014',
    'currCode' => '608',
    // You can fill in the rest...
  );

  // This code goes behind the final checkout button of the checkout pane
  foreach ($data as $name => $value) {
    if (!empty($value)) {
      $form[$name] = array('#type' => 'hidden', '#value' => $value);
    }
  }

  $form['#action'] = 'https://test.MyMerchantGateway.com/ECN/eng/payment/payForm.jsp';
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit Orders'),
  );
  return $form;
}

有关详细信息,请参阅http://nmc-codes.blogspot.ca/2012/07/how-to-create-custom-ubercart-payment.html

上的博文