【问题标题】:How to cancel orders using payment method in magento如何在magento中使用付款方式取消订单
【发布时间】:2012-03-10 22:48:11
【问题描述】:

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

Magento - How can I run code when my order is canceled or refunded

但每当我取消订单时,它既不会调用无效(仅在授权付款操作的情况下)也不会退款(在授权-捕获付款操作的情况下)。

当我使用 capture-refund 时,它说订单无法取消。

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

我不明白出了什么问题。

这里是代码。 这是付款方式模型

<?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>

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

【问题讨论】:

  • 这里有没有人可以帮助我......
  • 您找到解决方案了吗?我也有同样的问题!

标签: php zend-framework magento


【解决方案1】:

遗憾的是,我没有足够的“经验”来发表评论,所以我将把它作为答案发布。

您能否在取消之前验证订单是否处于正确状态?例如,一些订单是自动处理的,如软件下载。信用卡收费,产品分发都可以自动完成,那我怀疑它会让你取消。您能否确认订单仍处于待处理状态?

【讨论】:

  • 我正在尝试取消使用相同付款方式创建的订单。
  • 这没有意义。当然,它的付款方式相同,我们只讨论 1 个订单。你能进一步解释一下吗?
  • 当我下订单时,将调用授权方法...授权方法进行休息 api 调用并获得响应。作为回应,我从 Api 获得了唯一的参考 ID,我将其作为 transactionId 存储在 Magento 中。订单成功后,我去选择相同的订单并尝试取消。它显示订单取消成功,但 Void() 函数中的 API 调用没有发生。这就是我不明白的原因
  • 我想知道canVoid、canCancel等强制标志是什么
【解决方案2】:

您应该只能“取消”或“作废”尚未捕获的订单。即没有关联发票的订单。

如果您想退款捕获的订单,则应通过在发票上创建creditmemo来完成。

对于您的付款方式的 void 函数 未被调用的问题 - 您应该使用 X-Debug 设置像 Netbeans 这样的 IDE ,并在 Mage_Adminhtml_Sales_OrderController 中的 cancelActionvoidPaymentAction 函数的第一行放置一个断点。这样你就可以单步调试代码,看看问题出在哪里。

例如,到 void 的路径应该类似于...

Mage_Adminhtml_Sales_OrderController->voidPaymentAction:629
Mage_Sales_Model_Order_Payment->void:602
Mage_Sales_Model_Order_Payment->_void:1088
Package_Cashondelivery_Model_Createorder->void:

所以如果您不想使用适当的调试环境,请沿着该路径放置您的日志语句并检查所有条件是否有效以调用您的付款方式的 void 函数。

【讨论】:

    【解决方案3】:

    问题是 Magento 在您按下取消时确实不会调用 Void 或 Refund。当您按下 void 时,它会运行 void 方法,当您单击退款时,它会调用退款方法。猜猜看,当你按下取消键时,它实际上调用了取消方法。

    我同意,当您按下取消时,您实际上是想取消授权,但有单独的方法会很方便,以防您也想做其他事情。所以你可以这样做:

    /*
     * 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 */
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-29
      • 2015-01-19
      相关资源
      最近更新 更多