2012-02-20 93 views
1

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

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

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

当我使用捕获退款时,它表示订单不能被取消。

当我使用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> 

任何人有任何想法,为什么发生这种情况以及如何解决。

+0

有没有人在这里谁可以帮助我... – naquiuddin 2012-02-21 14:11:28

+0

你找到了解决方案吗?我有完全相同的问题! – Ziagl 2013-09-20 10:18:08

回答

0

可悲的是我没有足够的“经验”来评论,所以我会将其作为回答发表。

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

+0

我试图取消通过相同付款方式创建的订单。 – naquiuddin 2012-02-21 04:57:16

+0

这没有意义。当然它的付款方式相同,我们只谈1个订单。你能进一步解释吗? – cr125rider 2012-02-22 14:52:35

+0

当我下订单时,授权方法被调用...授权方法使得休息API调用并获得响应。作为回应,我从Api中获得唯一的引用Id,并将其作为transactionId存储在Magento中。订单成功后,我去选择相同的顺序,并尝试取消。它显示顺序取消成功,但Void()函数中的API调用没有发生。这是我什么都喜欢canVoid,canCancel等强制性标志不明白其中的道理 – naquiuddin 2012-02-23 07:39:23

0

您应该只能够“取消”或“虚空”一个还没有被抓获秩序。即没有相关发票的订单。

如果你想退款拍摄的顺序,那么这应该是通过在发票创建贷记通知单完成。

对于付款方式的void函数的问题没有被调用 - 你应该建立类似Netbeans的一个IDE,使用X-调试,并把一个破发点中的cancelAction的第一线voidPaymentAction函数Mage_Adminhtml_Sales_OrderController。通过这种方式,您可以浏览代码并查看问题出在哪里。

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

Mage_Adminhtml_Sales_OrderController - >voidPaymentAction:629
Mage_Sales_Model_Order_Payment - >空隙:602
Mage_Sales_Model_Order_Payment - >_void:1088
Package_Cashondelivery_Model_Createorder - >空隙

所以,如果你不想要进入使用适当的调试环境,然后把你的日志报表沿该路径,并检查所有条件都有效打电话给你的付款方式的无效功能。

0

的问题是,Magento的确实不叫任何空隙,也不退票时按取消。当你按下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 */ 

} 
相关问题