2012-02-20 92 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 */ 

} 
相關問題