0

在本教程http://www.junaidbhura.com/how-to-make-a-custom-magento-payment-extension-for-an-external-的帮助下,我成功地为 magento 集成了一个自定义支付解决方案网关/

如果付款成功与否,我正处于通知网站的最后阶段。

我在下面有一个 PaymentController.php 文件,但不确定如何将其链接到支付网关通知。

支付网关通过 HTTP GET 请求向服务器提供通知,让您知道支付是被接受还是被拒绝。这是下面

http://www.websitedomain.co.uk/mygateway/payment/response?Operator=&SessionID=&Note=&Tariff=&Status=&Mobile=

我需要输入代码的支付控制器代码如下

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 = ''; // 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();
        }
    }
}

}

4

1 回答 1

0

如果付款已经过验证,您必须在 $validated = true; 此处输入您自己的条件。

因此,如果这是来自支付网关的响应,请使用响应中的变量 http://www.websitedomain.co.uk/mygateway/payment/response?Operator=&SessionID=&Note=&Tariff=&Status=&Mobile=

例如

if ( $_GET('Status') == 'Paid' ){
$validated = true;
}

您必须阅读有关其代码的信息的支付网关文档。例如,Status 变量的值可以是“Paid”、“Pending”、“Expired”或“1”、“2”、“3”。取决于网关。

于 2013-09-24T15:24:54.473 回答