2013-02-03 51 views
0

我對Magento中的自定義付款方式有幾乎完整的解決方案。我跟着[這] http://www.junaidbhura.com/how-to-make-a-custom-magento-payment-extension-for-an-external-gateway/優秀教程如何做到這一點,但我現在堅持認證問題。使用POST驗證重定向到第三方支付網關

我聯繫了網關,IT代表告訴我必須發佈正確的值到網關進行身份驗證。

TESTMODE用戶名:這些值也必須以XML格式發送###### TESTMODE密碼:###### TESTMODE MERCHANTID:##### TESTMODE TerminalID:#### # BIN = ###### 1

我創建了一個在的System.Xml我的網關模塊用正確的字段:

<?xml version="1.0"?> 
<config> 
    <sections> 
    <payment> 
     <groups> 
     <mygateway translate="label comment" module="mygateway"> 
      <label>My Module mygateway</label> 
      <frontend_type>text</frontend_type> 
      <sort_order>0</sort_order> 
      <show_in_default>1</show_in_default> 
      <show_in_website>1</show_in_website> 
      <show_in_store>1</show_in_store> 
      <fields> 
      <active translate="label"> 
       <label>Enabled</label> 
       <frontend_type>select</frontend_type> 
       <source_model>adminhtml/system_config_source_yesno</source_model> 
       <sort_order>10</sort_order> 
       <show_in_default>1</show_in_default> 
       <show_in_website>1</show_in_website> 
       <show_in_store>0</show_in_store> 
      </active> 
      <title translate="label"> 
       <label>My Module mygateway Paymentech</label> 
       <frontend_type>text</frontend_type> 
       <sort_order>20</sort_order> 
       <show_in_default>1</show_in_default> 
       <show_in_website>1</show_in_website> 
       <show_in_store>1</show_in_store> 
      </title> 
      <order_status translate="label"> 
       <label>New Order Status</label> 
       <frontend_type>select</frontend_type> 
       <source_model>adminhtml/system_config_source_order_status</source_model> 
       <sort_order>50</sort_order> 
       <show_in_default>1</show_in_default> 
       <show_in_website>1</show_in_website> 
       <show_in_store>0</show_in_store> 
      </order_status> 
      <allowspecific translate="label"> 
       <label>Payment Applicable From</label> 
       <frontend_type>select</frontend_type> 
       <sort_order>61</sort_order> 
       <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model> 
       <show_in_default>1</show_in_default> 
       <show_in_website>1</show_in_website> 
       <show_in_store>0</show_in_store> 
      </allowspecific> 
      <specificcountry translate="label"> 
       <label>Countries Payment Applicable From</label> 
       <frontend_type>multiselect</frontend_type> 
       <sort_order>70</sort_order> 
       <source_model>adminhtml/system_config_source_country</source_model> 
       <show_in_default>1</show_in_default> 
       <show_in_website>1</show_in_website> 
       <show_in_store>0</show_in_store> 
       <depends> 
       <allowspecific>1</allowspecific> 
       </depends> 
      </specificcountry> 
      <sort_order translate="label"> 
       <label>Sort Order</label> 
       <frontend_type>text</frontend_type> 
      </sort_order> 
      <sort_order>100</sort_order> 
      <show_in_default>1</show_in_default> 
      <show_in_website>1</show_in_website> 
      <show_in_store>0</show_in_store> 
      <test_apiusername translate="label"> 
          <label>Test Mode Username</label> 
          <frontend_type>text</frontend_type> 
          <sort_order>6</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </test_apiusername> 
         <test_apipassword translate="label"> 
          <label>Test Mode Password</label> 
          <frontend_type>obscure</frontend_type> 
          <backend_model>adminhtml/system_config_backend_encrypted</backend_model> 
          <sort_order>7</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </test_apipassword> 
         <test_MerchantID translate="label"> 
          <label>Test Mode MerchantID</label> 
          <frontend_type>text</frontend_type> 
          <sort_order>8</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </test_MerchantID> 
         <test_TerminalID translate="label"> 
          <label>Test Mode TerminalID</label> 
          <frontend_type>text</frontend_type> 
          <sort_order>9</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </test_TerminalID> 
         <test_BINNumber translate="label"> 
          <label>Test Mode BIN</label> 
          <frontend_type>text</frontend_type> 
          <sort_order>10</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </test_BINNumber> 
         <test_cgi_url> 
          <label>Test Mode Gateway URL</label> 
          <frontend_type>text</frontend_type> 
         <sort_order>11</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         <comment>Above values should be entered for Test account</comment> 
         </test_cgi_url> 
         <apiusername translate="label"> 
          <label><![CDATA[<strong>Production</strong>]]> Mode Username</label> 
          <frontend_type>text</frontend_type> 
          <sort_order>12</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </apiusername> 
         <apipassword translate="label"> 
          <label><![CDATA[<strong>Production</strong>]]> Mode Password</label> 
          <frontend_type>obscure</frontend_type> 
          <backend_model>adminhtml/system_config_backend_encrypted</backend_model> 
          <sort_order>13</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </apipassword> 
         <MerchantID translate="label"> 
          <label><![CDATA[<strong>Production</strong>]]> Mode MerchantID</label> 
          <frontend_type>text</frontend_type> 
         <sort_order>14</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </MerchantID> 
         <TerminalID translate="label"> 
          <label><![CDATA[<strong>Production</strong>]]> Mode TerminalID</label> 
          <frontend_type>text</frontend_type> 
         <sort_order>15</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </TerminalID> 
         <BINNumber translate="label"> 
          <label><![CDATA[<strong>Production</strong>]]> Mode BIN</label> 
          <frontend_type>text</frontend_type> 
         <sort_order>16</sort_order> 
          <show_in_default>1</show_in_default> 
          <show_in_website>1</show_in_website> 
          <show_in_store>1</show_in_store> 
         </BINNumber> 
      </fields> 
     </mygateway> 
     </groups> 
    </payment> 
    </sections> 
</config> 

我是一個不確定的執行POST值需要驗證到PaymentController.php

<?php 

class Myname_Mygateway_PaymentController extends Mage_Core_Controller_Front_Action { 
    // The redirect action is triggered when someone places an order 
    public function redirectAction() { 
     $this->loadLayout(); 
     $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','mygateway',array('template' => 'mygateway/redirect.phtml')); 
     $this->getLayout()->getBlock('content')->append($block); 
     $this->renderLayout(); 
    } 

    // The response action is triggered when your gateway sends back a response after processing the customer's payment 
    public function responseAction() { 
     if($this->getRequest()->isPost()) { 

      /* 
      /* Your gateway's code to make sure the reponse you 
      /* just got is from the gatway and not from some weirdo. 
      /* This generally has some checksum or other checks, 
      /* and is provided by the gateway. 
      /* For now, we assume that the gateway's response is valid 
      */ 

      $validated = true; 
      $orderId = '123'; // Generally sent by gateway 

      if($validated) { 
       // Payment was successful, so update the order's state, send order email and move to the success page 
       $order = Mage::getModel('sales/order'); 
       $order->loadByIncrementId($orderId); 
       $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Gateway has authorized the payment.'); 

       $order->sendNewOrderEmail(); 
       $order->setEmailSent(true); 

       $order->save(); 

       Mage::getSingleton('checkout/session')->unsQuoteId(); 

       Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=>true)); 
      } 
      else { 
       // There is a problem in the response we got 
       $this->cancelAction(); 
       Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true)); 
      } 
     } 
     else 
      Mage_Core_Controller_Varien_Action::_redirect(''); 
    } 

    // The cancel action is triggered when an order is to be cancelled 
    public function cancelAction() { 
     if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) { 
      $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId()); 
      if($order->getId()) { 
       // Flag the order as 'cancelled' and save it 
       $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Gateway has declined the payment.')->save(); 
      } 
     } 
    } 
} 

最後會被重定向即形式redirect.phtml

<?php 
// Retrieve order 
$_order = new Mage_Sales_Model_Order(); 
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); 
$_order->loadByIncrementId($orderId); 
?> 
<form name="mygatewayform" method="post" action="http://www.gateway.com/the_url_they_gave_me"> 
    <input type="hidden" name="orderid" value="<?php echo $orderId; ?>"> 
    <input type="hidden" name="grandtotal" value="<?php echo $_order->getBaseGrandTotal(); ?>"> 
</form> 
<script type="text/javascript"> 
document.mygatewayform.submit(); 
</script> 

我能夠運行一個測試順序,但網關只收到我的訂單由於IP記錄,這是不正確的格式。在發佈之前,我一直在搜索Magento論壇和Google近三週,但是我沒有找到解決方案。由於沒有Magento集成手冊,網關無法提供幫助。

我會爲一些幫助非常感激,如果它不是太麻煩了......

回答

1

,你下面是創建付款將重定向到一個第三方網關的指令。

The URL that the payment gateway needs to redirect to on your web site after processing the customer’s payment (based on the naming we’ve used in this example) should be: http://www.yourwebsite.com/mygateway/payment/response .

做你要完成的最好的辦法是遵循這一http://www.excellencemagentoblog.com/magento-create-custom-payment-method-api-based

另見

/app/code/core/Mage/Paygate/Model/Authorizenet.php

//create xml and send info to gateway 
private function callApi(Varien_Object $payment, $amount,$type){ 

    //call your authorize api here, incase of error throw exception. 
    //only example code written below to show flow of code 

    /* 
    $order = $payment->getOrder(); 
    $types = Mage::getSingleton('payment/config')->getCcTypes(); 
    if (isset($types[$payment->getCcType()])) { 
    $type = $types[$payment->getCcType()]; 
    } 
    $billingaddress = $order->getBillingAddress(); 
    $totals = number_format($amount, 2, '.', ''); 
    $orderId = $order->getIncrementId(); 
    $currencyDesc = $order->getBaseCurrencyCode(); 

    $url = $this->getConfigData('gateway_url'); 
    $fields = array(
      'api_username'=> $this->getConfigData('api_username'), 
      'api_password'=> $this->getConfigData('api_password'), 
      ...... 

      'customer_firstname'=> $billingaddress->getData('firstname'), 
      'customer_lastname'=> $billingaddress->getData('lastname'), 
      'customer_phone'=> $billingaddress->getData('telephone'), 
      'customer_email'=> $billingaddress->getData('email'), 
      'customer_ipaddress'=> $_SERVER['REMOTE_ADDR'], 
      'bill_firstname'=> $billingaddress->getData('firstname'), 
      'bill_lastname'=> $billingaddress->getData('lastname'), 
      'Bill_address1'=> $billingaddress->getData('street'), 
      'bill_city'=> $billingaddress->getData('city'), 
      'bill_country'=> $billingaddress->getData('country_id'), 
      'bill_state'=> $billingaddress->getData('region'), 
      'bill_zip'=> $billingaddress->getData('postcode'), 
      'customer_cc_expmo'=> $payment->getCcExpMonth(), 
      'customer_cc_expyr'=> $payment->getCcExpYear(), 
      'customer_cc_number'=> $payment->getCcNumber(), 
      'customer_cc_type'=> strtoupper($type), 
      'customer_cc_cvc'=> $payment->getCcCid(), 
      'merchant_ref_number'=> $order->getIncrementId(), 
      'currencydesc'=>$currencyDesc, 
      'amount'=>$totals 
    ); 

    $fields_string=""; 
    foreach($fields as $key=>$value) { 
    $fields_string .= $key.'='.$value.'&'; 
    } 
    $fields_string = substr($fields_string,0,-1); 
    //open connection 
    $ch = curl_init($url); 
    //set the url, number of POST vars, POST data 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_POST,1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1); 
    curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); // Timeout on connect (2 minutes) 
    //execute post 
    $result = curl_exec($ch); 
    curl_close($ch); 
    */ 

    return array('status'=>1,'transaction_id' => time() , 'fraud' => rand(0,1)); 
} 
+0

是的,我想,客戶可以重定向到一個第三方網關輸入他們的信用卡資料,然後重新導向我們的網站。 – user1704524

+0

我已經接受了這個答案...如果你有任何使用這種方法/模塊的經驗,你可以告訴我如何使用表單重定向,而不是:/template/payment/form/ccsave.phtml – user1704524

相關問題