0

我正在使用自定义支付模块,并且在收到来自自定义支付网关的失败交易响应后,我想

  • 使用“pending_payment”状态/状态保存订单,不要发送任何订单电子邮件。

  • 我不想创建任何发票/处理它或发送任何发票电子邮件。

  • 此外,我想将我的客户重定向到失败页面或结帐/购物车页面,但顶部有一条消息说他们的付款详细信息有误,请重试。

一旦我收到来自我的支付网关的“失败”响应,我就可以将订单保存到 pending_payment 状态并停止它发送新的订单电子邮件,但我无法阻止它开票 n 因此停止 d 发票电子邮件送出。

我在我的自定义支付模块中调用事件观察员,sales_order_place_after该模块为订单开具发票并在成功交易时发送发票电子邮件。

现在我不知道该文件是否也需要编辑(app/code/local/Mage/Paymentmodule/Model/Observer.php)或者只是我的 app/code/local/Mage/Paymentmodule/Model/PaymentMethod.php 就足够了。

PaymentMethod.php

      public function capture(Varien_Object $payment, $amount) 
      {
        $error = false;
    // check for payment
   if($amount > 0)
   {
    $payment->setAmount($amount);
    $order = $payment->getOrder();
    if($payment->getTxnNumber() == "")
    {
        $transaction = $this->_build($payment, self::TRANSACTION_PREAUTH);
            $authResponse = $this->_send($transaction);
        if($authResponse->getResponseCode() > 0 && $authResponse->getResponseCode() <= self::ERROR_CODE_LIMIT)
        {
            $payment->setCcApproval($authResponse->getReceiptId())
             ->setLastTransId($authResponse->getReceiptId())
             ->setCcTransId($authResponse->getTxnNumber())    ->setCcCidStatus($this->getCvdDescription($authResponse->getCvdResultCode()));    

        }
        else if($authResponse->getResponseCode() > self::ERROR_CODE_LIMIT && $authResponse->getResponseCode() < self::ERROR_CODE_UPPER_LIMIT)
        {
           $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, 'pending_payment', '', false)->save();
           $order->setCanSendNewEmailFlag(false);
           $order->setCanInvoiceFlag(false);
        }
        else
        {
           $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, 'pending_payment', '', false)->save();
           $order->setCanSendNewEmailFlag(false);
           $order->setCanInvoiceFlag(false);
        }
    }
    $check = $this->checkCvdResponse($authResponse->getCvdResultCode());
    if($check == true)
    {
        $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, 'pending_payment', '', false)->save();
        $order->setCanSendNewEmailFlag(false);
        $order->setCanInvoiceFlag(false);
    }
    else
    {
        $transaction_completion = $this->_build($payment, self::TRANSACTION_COMPLETION);
        $response = $this->_send($transaction_completion);  
        if($response->getResponseCode() > 0 && $response->getResponseCode() <= self::ERROR_CODE_LIMIT) 
        {
            $payment->setStatus(self::STATUS_SUCCESS);
            $payment->setCcApproval($response->getReceiptId())
             ->setLastTransId($response->getReferenceNum())
             ->setCcTransId($response->getTxnNumber())
             ->setCcAvsStatus($this->getAvsDescription($authResponse->getAvsResultCode()))
             ->setCcCidStatus($this->getCvdDescription($authResponse->getCvdResultCode())); 
        }    
        else if($response->getResponseCode() > self::ERROR_CODE_LIMIT && $response->getResponseCode() < self::ERROR_CODE_UPPER_LIMIT) 
        {
            $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, 'pending_payment', '', false)->save();
            $order->setCanSendNewEmailFlag(false);
            $order->setCanInvoiceFlag(false);
        } 
        else 
        {
           $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, 'pending_payment', '', false)                                       ->save();
           $order->setCanSendNewEmailFlag(false);
           $order->setCanInvoiceFlag(false);
        }
    }
} 
else
{
    $error = Mage::helper('paygate')->__('Invalid amount for authorization.');
}
if ($error !== false)
Mage::throwException($error);
    return $this;
 }

观察者.php

   public function implementOrderStatus($event)
  {
    $order = $event->getEvent()->getOrder();    
    if ($this->_getPaymentMethod($order) == 'custompaymentmodule') 
    {
        if($order->getState() == 'pending_payment')
        {
          $order->setCanSendNewEmailFlag(false);
          $order->setCanInvoiceFlag(false);
        }
                 if ($order->canInvoice())

            $this->_processOrderStatus($order);
    }
    return $this;
}

任何想法我如何才能保存它pending_payment 状态并停止它形成发票并使用适当的消息重定向到购物车页面。

任何有关解决任何问题的帮助将不胜感激。谢谢

4

2 回答 2

0

我找到了解决问题的部分方法。在失败的付款交易中,pending_payment我没有在我的 PaymentMethod.php 中设置状态,而是将付款状态设置为已拒绝并设置CcTransId为 NULL

然后在我的 Observer.php 中使用此条件,我将使用pending_payment状态保存该订单。

这是修改后的代码

PaymentMethod.php

   if($payment->getTxnNumber() == "")
   {
      <!-- SOME CODE -->
      if($authResponse->getResponseCode() > 0 && $authResponse->getResponseCode() <= self::ERROR_CODE_LIMIT)
      {
        <!-- SUCCESSFUL TRANSACTION CODE   
      }
      else if($authResponse->getResponseCode() > self::ERROR_CODE_LIMIT && $authResponse->getResponseCode() < self::ERROR_CODE_UPPER_LIMIT)
      {
         $payment->setStatus(self::STATUS_DECLINED);
      }
      else
      {
         $payment->setStatus(self::STATUS_DECLINED);
      }
   }
   $check = $this->checkCvdResponse($authResponse->getCvdResultCode());
   if($check == true)
   {
       $payment->setStatus(self::STATUS_DECLINED);
       $payment->setCcTransId(NULL);  
   }
   else
   {
       $transaction_completion = $this->_build($payment, self::TRANSACTION_COMPLETION);
       $response = $this->_send($transaction_completion);  
       if($response->getResponseCode() > 0 && $response->getResponseCode() <= self::ERROR_CODE_LIMIT) 
       {
          <!-- SUCCESSFUL CAPTURE -->   
       }    
      else if($response->getResponseCode() > self::ERROR_CODE_LIMIT && $response->getResponseCode() < self::ERROR_CODE_UPPER_LIMIT) 
      {
         $payment->setStatus(self::STATUS_DECLINED);
         $payment->setCcTransId(NULL);  
      } 
      else 
      {
        $payment->setStatus(self::STATUS_DECLINED);
        $payment->setCcTransId(NULL);  
      }
}

观察者.php

    public function implementOrderStatus($event)
    {
      $order = $event->getEvent()->getOrder(); 
      if ($this->_getPaymentMethod($order) == 'custompaymentmodule') 
      {
     if($order->getPayment()->getCcTransId() == NULL)
     {
        $state = 'pending_payment';
    $status = 'pending_payment';
    $comment = 'Payment transaction failed due to incorrect AVS/CVD details.';
    $isNotified = false;
    $order->setState($state,$status,$comment,$isNotified)->save();
        $order->setCanSendNewEmailFlag(false);
         }
         else
         {
             <!-- SUCCESSFUL INVOICE CODE -->
         }
      }

我现在唯一剩下的就是将用户重定向到购物车页面,并在顶部显示错误消息。

但是,由于我需要在 Observer 文件中执行所有这些操作,因此我无法调用$this->_redirect()方法。尝试过Mage::app->getResponse->setRedirect(Mage::getUrl('checkout/cart'))但效果不佳。

关于如何完成这最后一点的任何想法。}

于 2012-05-22T12:16:20.480 回答
0

一旦付款失败,我正在使用它成功重定向到购物车页面。

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/onepage/index/'))->sendResponse();
于 2013-12-11T15:43:26.183 回答