3

如果订单被取消或退款,我的支付模块需要向支付服务发送通知。我假设订单页面(在管理后端)上的“取消”按钮将取消订单,并且“信用备忘录”按钮(在创建发票后)将退还订单。

如何在这些事件上运行我的代码?我尝试在我的付款方式模型中使用 cancel() 方法,但代码没有运行。

4

3 回答 3

2

似乎您的付款方式未使用交易或未创建授权交易 ID。这是支付网关开发中常见的初学者错误。

要使用在线操作启用您的支付网关,您需要在您的支付方式中实现类似的内容:

class MyBest_Payment_Model_Method extends Mage_Payment_Model_Method_Abstract
{
    protected $_canAuthorize            = true; // Set true, if you have authorization step.
    protected $_canCapture              = true; // Set true, if you payment method allows to perform capture transaction (usally only credit cards methods)
    protected $_canRefund               = true; // Set true, if online refunds are available
    protected $_canVoid                 = true; // Set true, if you can cancel authorization via API online

    public function authorize(Varien_Object $payment, $amount)
    { 

        // ... You payment method authorization goes here ...
        // Here goes retrieving or generation non-zero, 
        // non-null value as transaction ID. 
        $transactionId = $api->someCall(); 
        // Setting tranasaction id to payment object
        // It is improtant, if you want perform online actions 
        // in future with this order!
        $payment->setTransactionId($transactionId); 

        // ... some other your actions ... 
        return $this;
    }

    public function void(Varien_Object $payment)
    {
        // ... some actions for sending cancel notification to your payment gateway
    }

    public function refund(Varien_Object $payment, $amount)
    {
        // ... some actions for performing an online refund ...
    }
}
于 2011-01-25T23:26:27.643 回答
2

在 Magento 的付款处理阶段不会触发任何可观察的事件。相反,您为要实现的任何网关定义一个类,然后定义 Magento 将自动调用的方法,因为订单使其通过各种支付方式。

查看基本的抽象支付类以查看在支付处理期间将调用的各种方法。在您的课程中定义相同的方法,以便在您想要的任何时间点连接到付款流程。

File: app/code/core/Mage/Payment/Model/Method/Abstract.php

class abstract class Mage_Payment_Model_Method_Abstract
{

    /**
     * Authorize
     *
     * @param   Varien_Object $orderPayment
     * @return  Mage_Payment_Model_Abstract
     */
    public function authorize(Varien_Object $payment, $amount)
    ...     
    /**
     * Capture payment
     *
     * @param   Varien_Object $orderPayment
     * @return  Mage_Payment_Model_Abstract
     */
    public function capture(Varien_Object $payment, $amount)    
    ... 

    /**
     * Void payment
     *
     * @param   Varien_Object $invoicePayment
     * @return  Mage_Payment_Model_Abstract
     */
    public function void(Varien_Object $payment)
    ...    

    /**
     * Refund money
     *
     * @param   Varien_Object $invoicePayment
     * @return  Mage_Payment_Model_Abstract
     */
    //public function refund(Varien_Object $payment, $amount)
    public function refund(Varien_Object $payment, $amount)
    ...


    /**
     * Cancel payment (GoogleCheckout)
     *
     * @param   Varien_Object $invoicePayment
     * @return  Mage_Payment_Model_Abstract
     */
    public function cancel(Varien_Object $payment)
    ...

我没有做很多支付网关的实现,但我猜这refund是你想要的贷项通知单的方法,capture也是发票的方法。看起来该cancel方法是特定于 Google Checkout 的。如果你想确定的话,用一些日志记录函数在你的类中定义所有五个,并通过你的开发系统上的一些假订单。

于 2011-01-25T22:21:55.340 回答
1

Magento 有可能有用的事件挂钩。可以在此处找到事件列表(我认为有点过时) 。还有一篇有用的文章,介绍 Magneto 的事件是如何工作

此外,查看现有的付款扩展可能很有用。如果 Google Checkout 发送类似事件以取消订单,我不会感到惊讶。扩展存储库将有很多支付方式可供查看。

祝你好运!

于 2011-01-25T20:44:38.283 回答