如果您在您的付款方式中使用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');
}
}