Magento定制付款通知

时间:2013-07-09 08:15:20

标签: php magento magento-1.7 payment-gateway

我已成功整合了magento的自定义付款解决方案,并提供了本教程中的大量帮助http://www.junaidbhura.com/how-to-make-a-custom-magento-payment-extension-for-an-external-gateway/

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

我在下面有一个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();
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

你有一行$validated = true; 如果付款已经过验证,您必须输入自己的条件。

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

例如

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

您必须阅读有关其代码的信息的付款网关文档。例如,Status变量可以具有诸如“付费”,“待定”,“过期”或“1”,“2”,“3”之类的值。取决于网关。