我正在使用自定义付款模块,并且在收到来自我的自定义付款网关的失败的交易回复后,我想
使用“pending_payment”状态/状态保存订单,不发送任何订单电子邮件。
我不想创建任何发票/流程或发送任何发票电子邮件。
此外,我想将我的客户重定向到失败页面或可能是结帐/购物车页面,但顶部有一条消息说他们的付款详情错误,请再试一次。
一旦收到来自我的支付网关的“失败”回复,我就可以将订单保存到pending_payment状态并停止发送新订单电子邮件,但我无法阻止它开具发票n因此停止发票发送电子邮件。
我在自定义付款模块中的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;
}
Observer.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状态并停止发票并使用适当的消息重定向到购物车页面。
任何有关解决任何比特的帮助都将受到高度赞赏。感谢
答案 0 :(得分:0)
我找到了解决问题的部分方法。在付款交易失败时,我将付款状态设置为已取消并将pending_payment
设置为NULL
CcTransId
状态。
然后在我的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);
}
}
Observer.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'))
,但是工作。
关于如何完成最后一点的任何想法。 }
答案 1 :(得分:0)
付款失败后,我正在使用此功能成功重定向到购物车页面。
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/onepage/index/'))->sendResponse();