Magento-我的订单被取消或退款时如何运行代码 [英] Magento - How can I run code when my order is canceled or refunded

查看:109
本文介绍了Magento-我的订单被取消或退款时如何运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果订单被取消或退款,我的付款模块需要将通知发送到付款服务.我假设订单页面(位于管理后端)中的取消"按钮将取消该订单,而贷项凭证"按钮(在创建发票后)将退还该订单.

My payment module is required to sent notifications to the payment service if an order is canceled or refunded. I assume that the "Cancel" button on the order page (in the administration backend) will cancel the order, and that the "Credit memo" button (after an invoice has been created) will refund the order.

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

How do I run my code on these events? I tried using the cancel() method in my payment method model, but the code did not run.

推荐答案

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

Seems like your payment method is not using transactions or does not create authorization transaction id. It is common beginner mistake in Payment gateways development.

要使您的付款网关能够执行在线操作,您需要在付款方式中实现以下类似内容:

To enable your payment gateway with online actions you need to implement something like this in your payment method:

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 ...
    }
}

这篇关于Magento-我的订单被取消或退款时如何运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆