2012-03-22 108 views
0

我一直在尋找2天的時間來關注如何將我的商家支付網關集成到ubercart中。所以我決定在這裏問一下。如何將第三方商戶支付網關集成到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

看起來像你想要做一個異地支付(外部您的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

+0

謝謝NMC。我已經成功地實現了你的代碼。關於$ form ['#action'] ='https://test.MyMerchantGateway.com/ECN/eng/payment/payForm.jsp';我添加了一些增值網址。例如:https://test.MyMerchantGateway.com?id = 111,name =「ex .......所有這些值都已經出現在評論頁面上了,我可以知道如何獲得這些值嗎?帖子:http://stackoverflow.com/questions/34348089/array-how-to-retrieve-value – peifa 2015-12-22 08:41:52