2014-02-15 21 views
0

我正在基於API的支付網關在magento中工作,當用戶直接從信用卡支付時,我通過在支付網關的捕獲方法中調用API特定功能。在自定義付款方式中標記爲捕獲方法中的待處理方式

當我爲支付網關啓用3D安全選項時,我需要將用戶重定向到第三方進行驗證,以便使用條件爲getOrderPlaceRedirectUrl

有條件我也可以保存有待處理狀態的訂單,但Magento會生成發票並標記爲已付款並將狀態更改爲處理。我需要從第三方獲得成功的身份驗證。

使用下面的代碼更新訂單狀態:

$order->setState(Mage_Sales_Model_Order::STATE_NEW, true); 
$order->save(); 

如果有人可以幫助我如何控制不生成發票捕獲方法將非常感激。

回答

0

嘗試將狀態設置爲掛起付款,如下所示;

$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, 
    'pending_payment', 
    '3D Secure Auth Now Taking Place')->save(); 

P.S. Magento附帶的PayPal模塊完全符合您的要求,因此請查看PayPal Standard模型和控制器以瞭解一些指標。

1

如果您在您的付款方式中使用capture(),並且您的capture()方法在不拋出異常的情況下返回,那麼Magento會假定捕獲已完成,「錢在您的口袋裏」,因此它會生成發票。如果您使用第三方支付網關,這並不好。

你可以做到以下幾點:在你的config.xml中

<config>  
    <default> 
     <payment> 
      <yourPaymentCode> 
       <order_status>pending_payment</order_status> 
       <payment_action>order</payment_action> 
       ... 

你* payment_action *設置爲爲了在您的付款方式設置的屬性和執行的命令()方法。 Snd集getOrderPlaceRedirectUrl,但你已經做到了。

class Your_Module_Model_PaymentMethod 
    extends Mage_Payment_Model_Method_Abstract 
{ 
    // set these attributes 
    protected $_code = 'yourPaymentCode'; 
    protected $_isGateway = true; 
    protected $_canCapture = false; 
    protected $_canAuthorize = false; 
    protected $_canOrder = true; 

    public function order(Varien_Object $payment, $amount) 
    { 
     // initialize your gateway transaction as needed 
     // $gateway is just an imaginary example of course 
     $gateway->init($amount, 
      $payment->getOrder()->getId(), 
      $returnUrl, 
      ...); 
     if($gateway->isSuccess()) { 
      // save transaction id 
      $payment->setTransactionId($gateway->getTransactionId()); 
     } else { 
      // this message will be shown to the customer 
      Mage::throwException($gateway->getErrorMessage()); 
     } 
     return $this; 
    } 

不知何故,網關必須迴應。在我的情況下,他們將客戶重定向到init()中給出的$ responseUrl,但他們警告說,用戶的瀏覽器在付款後但可能被重定向到我們的商店之前可能會崩潰:在這種情況下,背景,因此處理該URL不能依賴會話數據。我爲此做了一個控制器:

public function gatewayResponseAction() 
{ 
    // again the imaginary example $gateway 
    $order = Mage::getModel('sales/order')->load($gateway->getOrderId()); 
    $payment = $order->getPayment(); 
    $transaction = $payment->getTransaction($gateway->getTransactionId()); 

    if ($gateway->isSuccess()) 
    { 
     $payment->registerCaptureNotification($gateway->getAmount()); 
     $payment->save(); 
     $order->save(); 
     $this->_redirect('checkout/onepage/success'); 
    } 
    else 
    { 
     Mage::getSingleton('core/session') 
      ->addError($gateway->getErrorMessage()); 
     // set quote active again, and cancel order 
     // so the user can make a new order 
     $quote = Mage::getModel('sales/quote')->load($order->getQuoteId()); 
     $quote->setIsActive(true)->save(); 
     $order->cancel()->save(); 
     $this->_redirect('checkout/onepage'); 
    } 
}