我有一个启动并运行的第三方支付网关,但我可以真正使用您的帮助将信息发送回magento并在付款完成后重定向到成功页面。
Magento在结帐流程中通过“下订单”(通过getOrderPlacedRedirectUrl
)重定向到我们的支付网关,并将订单提交到商店信息中心。我们的支付网关有一个可自定义的重定向网址,但当我尝试路由回magento的成功页面时,我收到403禁止错误。
我想将用户发回成功页面并更新订单状态/根据来自我的支付网关的响应参数从magento发送确认电子邮件。
我有PaymentConroller
个redirectAction
,responseAction
和cancelAction
方法(虽然我认为responseAction
不会被调用)。
额外信息:一旦选择作为付款方式(在“审核订单”步骤之前通过getCheckoutRedirecturl
),我也尝试过指向我的付款网关,就像PayPal Express一样,但我又一次在运行之后用403错误返回magento的问题。这将是我理想的设置,并在付款后下订单。这甚至可能吗?
基本上我的问题围绕着我的付款完成后回到magento和当前订单。
提前感谢您的帮助!
我的代码如下。
PaymentController(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";
}
}
?>
config(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>
system(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>
答案 0 :(得分:0)
在responseAction()函数(Paymentcontroller.php)中你有:
if($this->getRequest()->isPost()) {
...
}else{
Mage_Core_Controller_Varien_Action::_redirect('');
}
只有在控制器中发送POST数据时,第一个代码块才有效。你写了#34;我们的支付网关有一个可自定义的重定向网址...&#34;,你可能只是重定向回Magento,这意味着GET请求。所以你进入
Mage_Core_Controller_Varien_Action::_redirect('');
得到403服务器错误。
P.S。:将controllers / Paymentcontroller.php重命名为controllers / PaymentController.php