我有一个已启动并正在运行的第三方支付网关,但我真的需要您的帮助才能将信息发送回 magento 并在支付完成后重定向到成功页面。
Magento 在结帐过程中“下订单”(通过 getOrderPlacedRedirectUrl
)重定向到我们的支付网关,并将订单提交到商店仪表板。我们的支付网关有一个可自定义的重定向 url,但是当我尝试路由回 magento 的成功页面时,我收到 403 禁止错误。
我想将用户发送回成功页面并根据我的支付网关的响应参数更新订单状态/从 magento 发送确认电子邮件。
我有一个带有 redirectAction
、responseAction
和 cancelAction
方法的 PaymentConroller
(虽然我不认为responseAction
被调用过)。
额外信息:我也试过在我的支付网关被选为支付方式后(在“查看订单”步骤之前通过 getCheckoutRedirecturl
)以与 PayPal Express 相同的方式定向到我的支付网关,但同样我遇到了 403 错误之后返回 magento 的问题。这将是我理想的设置并在付款后下订单。这可能吗?
本质上,我的问题围绕着在付款完成后返回 magento 和当前订单。
预先感谢您的帮助!
我的代码如下。
支付 Controller (controllers/Paymentcontroller.php
):
<?php
/**
* @method redirectAction()
* @method responseAction()
* @method cancelAction()
*/
class Knox_KnoxGateway_PaymentController extends Mage_Core_Controller_Front_Action {
public function redirectAction() {
$this->loadLayout();
$block = $this->getLayout()->createBlock('Mage_Core_Block_Template','KnoxGateway',array('template' => 'KnoxGateway/redirect.phtml'));
$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();
}
/**
* @var $validated is initialized to true
* @var $orderId is set to 'default', might make it a number
*/
public function responseAction() {
if($this->getRequest()->isPost()) {
$validated = true;
$orderId = 'default';
if($validated) {
$order = Mage::getModel('sales/order');
$order->loadByIncrementId($orderId);
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Knox 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 {
$this->cancelAction();
Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
}
}
else
Mage_Core_Controller_Varien_Action::_redirect('');
}
public function cancelAction() {
if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
if($order->getId()) {
$order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Knox has declined the payment.')->save();
}
}
}
}
标准(Models/Standard.php
):
<?php
class Knox_KnoxGateway_Model_Standard extends Mage_Payment_Model_Method_Abstract {
/**
* @var $_code defines the name of our plugin when we register to magento
*/
protected $_code = 'KnoxGateway';
/**
* @var $_isInitializeNeeded is set to true to declare we need
* to initialize while the order is in place
*/
protected $_isInitializeNeeded = true;
/**
* @var $_canUseInternal is set to true to declare that people can pay
* with knox from the admin pages
*/
protected $_canUseInternal = true;
/**
* @var $_canUseForMultishipping is set to false so that we don't try
* to send to multiple shipping addresses
*/
protected $_canUseForMultishipping = false;
/**
* @var $_canUseCheckout is set to true due to the fact that we want to
* be used like any other normal payment gateway
*/
protected $_canUseCheckout = true;
/**
* @return getOrderPlacedRedirectUrl simply returns a redirect to Knox
*/
public function getOrderPlaceRedirectUrl() {
$key = Mage::getStoreConfig('payment/KnoxGateway/api_key');
$grandTotal = Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal();//'11.50';
$reccur = "ot";
$callback = Mage::getStoreConfig('payment/KnoxGateway/callback_url');//"https://www.knoxpayments.com";//
$info = Mage::getStoreConfig('payment/KnoxGateway/info_request');
$invoice = Mage::getStoreConfig('payment/KnoxGateway/invoice_detail');
return "https://knoxpayments.com/pay?api_key=".$key."&amount=".$grandTotal."&redirect_url=".$callback."&recurring=".$reccur."&information_request=".$info."&invoice_detail=".$invoice."";
// "https://knoxpayments.com/newflow/?api_key='{$this->$API_KEY}'&api_password='{$this->$API_PASSWORD}'&amount='{$this->$DATA_AMOUNT}'&redirect_url='{$this->$CALLBACK_URL}'&recurring=ot&information_request='{$this->$INFO_REQUEST}'&invoice_detail='{$this->$INVOICE_DETAIL}'&user_request";
}
}
?>
配置(etc/config.xml
):
<?xml version="1.0"?>
<config>
<modules>
<Knox_KnoxGateway>
<version>0.1.0</version>
</Knox_KnoxGateway>
</modules>
<global>
<models>
<KnoxGateway>
<class>Knox_KnoxGateway_Model</class>
</KnoxGateway>
</models>
<helpers>
<KnoxGateway>
<class>Knox_KnoxGateway_Helper</class>
</KnoxGateway>
</helpers>
<blocks>
<KnoxGateway>
<class>Knox_KnoxGateway_Block</class>
</KnoxGateway>
</blocks>
</global>
<default>
<payment>
<KnoxGateway>
<model>KnoxGateway/standard</model>
<active>1</active>
<order_status>payment_review</order_status>
<title>Knox Gateway</title>
<payment_action>sale</payment_action>
<sort_order>1</sort_order>
</KnoxGateway>
</payment>
</default>
<frontend>
<routers>
<KnoxGateway>
<use>standard</use>
<args>
<module>Knox_KnoxGateway</module>
<frontName>KnoxGateway</frontName>
</args>
</KnoxGateway>
</routers>
</frontend>
</config>
系统(etc/system.xml):
<?xml version="1.0"?>
<config>
<sections>
<payment>
<groups>
<KnoxGateway translate="label comment" module="paygate">
<label>Knox Gateway</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>Title</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>
<callback_url translate="label">
<label>Knox Callback URL</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>
</callback_url>
<info_request translate="label">
<label>Information request</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>
</info_request>
<why_who translate="label">
<label>Why Who</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>
</why_who>
<invoice_detail translate="label">
<label>Invoice Detail</label>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<show_in_default>1</show_in_default>
</invoice_detail>
<api_key translate="label">
<label>Knox Api Key</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>
</api_key>
<api_password translate="label">
<label>Knox Api Password</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>
</api_password>
</fields>
</KnoxGateway>
</groups>
</payment>
</sections>
</config>
最佳答案
在 responseAction() 函数 (Paymentcontroller.php) 中你有:
if($this->getRequest()->isPost()) {
...
}else{
Mage_Core_Controller_Varien_Action::_redirect('');
}
只有当您在 Controller 中发送 POST 数据时,第一个代码块才会起作用。你写了“我们的支付网关有一个可定制的重定向 url...”,可能你只是重定向回 Magento,这意味着 GET 请求。所以你输入到
Mage_Core_Controller_Varien_Action::_redirect('');
并得到 403 服务器错误。
P.S.: 将 controllers/Paymentcontroller.php 重命名为 controllers/PaymentController.php
关于magento - 在第 3 方支付网关后需要帮助返回 Magento 和更新订单状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25085655/