如何在Magento中使用付款方式取消订单 [英] How to cancel orders using payment method in magento

查看:49
本文介绍了如何在Magento中使用付款方式取消订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Magento创建一个开源扩展.它处于非常早期的阶段.我正在努力解决取消订单问题.我在这里找到了一些解决方案

I am creating an Open Source Extension for Magento. Its in very early stages. I am struggling with cancel orders problem. I found some solution here

Magento-如何订单取消或退款时我可以运行代码.

但是,每当我取消订单时,它都不会无效(仅在授权付款操作的情况下)或退款(在授权捕获付款操作的情况下).

But whenever I cancel an order it calls neither void (in case of only Authorize payment action) nor refund (in case of authorize-capture payment action).

当我使用捕获退款时,它说不能取消订单.

When I use capture-refund, It says the order cannot be cancelled.

当我使用authorize-void时,说订单已被取消.但是根本没有调用Void()函数.我在其中保留了一些Mage :: Log()函数.哪些未显示在日志文件中.

When I use authorize-void, It say's the order have been cancelled. But the Void() function wasn't called at all. I kept some Mage::Log() functions inside. Which are not shown in Log file.

我不明白怎么了.

这是代码.这是付款方式模型

Here is the code. This is payment method model

<?php 
class Package_Cashondelivery_Model_Createorder extends Mage_Payment_Model_Method_Abstract
{
    protected $_code = 'cashondelivery';
    protected $_canCapture = true;
    protected $_canUseCheckout = true;
    protected $_canFetchTransactionInfo     = true;
    protected $_isGateway                   = true;
    protected $_canUseInternal = true;
    protected $_canVoid    = true;
    protected $_canRefund = true;

    public function validate()
    {

        $paymentInfo = $this->getInfoInstance();
         if ($paymentInfo instanceof Mage_Sales_Model_Order_Payment) {
             $postCode = $paymentInfo->getOrder()->getBillingAddress()->getPostcode();

         } 
         else {
             $postCode = $paymentInfo->getQuote()->getBillingAddress()->getPostcode();
         }
         $res=Api->validatePostCode($postCode);
         $r = $res=='false'? FALSE : TRUE; 
         if (!$r) {
             Mage::throwException($this->_getHelper()->__('Sorry ! Service is not available in your area'));
         }
         return $this;
    }

    public function authorize(Varien_Object $payment, $amount)
    {
        -------------------------------
        -------------------------------
        -------------------------------
        #This is working fine
        $transactionId = Api->someCall();
        $payment->setTransactionId();
       ------------------------------- 
       -------------------------------
       -------------------------------
       -------------------------------
       -------------------------------
       -------------------------------
        return $this;
    }

    public function void(Varien_Object $payment)
    {
        if (!$this->canVoid($payment)) {
            Mage::throwException($this->_getHelper()->__('Void action is not available.'));
        }
        -------------------------------
        -------------------------------
        -------------------------------
        -------------------------------
        Mage::Log('Starting Void here....');
        $transactionId = $Payment->getTransactionId();
        Api->cancelOrder($transactionId);
        return $this;
        -------------------------------
        -------------------------------
        -------------------------------
    }
}
?>

这是配置文件.

<?xml version="1.0"?>
<config>
    <modules>
       <Package_Cashondelivery>
<!-- declare module's version information for database updates -->
          <version>0.1.0</version>
       </Package_Cashondelivery>
    </modules>
    <global>
<!-- declare model group for new module -->
        <models>
<!-- model group alias to be used in Mage::getModel('newmodule/...') -->
            <cashondelivery>
<!-- base class name for the model group -->
                <class>Package_Cashondelivery_Model</class>
            </cashondelivery>    
        </models>
        <helpers>
            <cashondelivery>
                <class>Package_Cashondelivery_Helper</class>
            </cashondelivery>
        </helpers> 
<!-- declare resource setup for new module -->
        <resources>
<!-- resource identifier -->
            <cashondelivery_setup>
<!-- specify that this resource is a setup resource and used for upgrades -->
                <setup>
<!-- which module to look for install/upgrade files in -->
                    <module>Package_Cashondelivery</module>
                </setup>
<!-- specify database connection for this resource -->
                <connection>
<!-- do not create new connection, use predefined core setup connection -->
                    <use>core_setup</use>
                </connection>
            </cashondelivery_setup>
            <cashondelivery_write>
                <connection>
                  <use>core_write</use>
                </connection>
            </cashondelivery_write>
            <cashondelivery_read>
               <connection>
                <use>core_read</use>
              </connection>
            </cashondelivery_read>
        </resources>
    </global>
<!-- declare default configuration values for this module -->
    <default>
        <payment>
            <cashondelivery>
                <active>1</active>
                <model>cashondelivery/createorder</model>
                <order_status>Processing</order_status>
                <payment_action>authorize</payment_action>
                <title>Cash On Delivery</title>
                <example_uri>services.example.com</example_uri>
            </cashondelivery>
         </payment>
    </default>
</config>

任何人都知道为什么会发生这种情况以及如何解决.

Anybody has any idea why this happens and how to resolve.

推荐答案

问题在于,当您按取消"时,Magento的确不会调用虚空"或退款".当您按void时,它将运行void方法,而当您单击退款时,它将调用退款方法.猜猜是什么,当您按取消"时,它实际上调用了取消"方法.

The problem is that Magento indeed does not call either Void, nor Refund when you press cancel. When you press void it runs the void method, and when you click on refund it calls the refund method. And guess what, when you press on cancel, it actually calls the cancel method.

我同意,当您按取消"时,您实际上想使授权无效,但是使用单独的方法很方便,以防万一您也想做其他事情.因此,您可以执行以下操作:

I agree that when you press cancel you actually want to void the authorization, but it comes handy to have separate methods just in case you would like to do something else too. So you could do something like this:

/*
 * Your class stuff
 */

public function cancel(Varien_Object $payment){

    // void the order if canceled
    $this->void($payment);

    return $this;
}

public function void(Varien_Object $payment){

    /* Whatever you call to void a payment in your gateway */

}

这篇关于如何在Magento中使用付款方式取消订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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