我對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集成手冊,網關無法提供幫助。
我會爲一些幫助非常感激,如果它不是太麻煩了......
是的,我想,客戶可以重定向到一個第三方網關輸入他們的信用卡資料,然後重新導向我們的網站。 – user1704524
我已經接受了這個答案...如果你有任何使用這種方法/模塊的經驗,你可以告訴我如何使用表單重定向,而不是:/template/payment/form/ccsave.phtml – user1704524