如果订单被取消或退款,我的付款模块需要向付款服务发送通知。我假设订单页面上的“取消”按钮(在管理后端)将取消订单,并且“贷项凭证”按钮(在创建发票后)将退还订单。
如何在这些事件上运行我的代码?我尝试在我的付款方式模型中使用cancel()方法,但代码没有运行。
答案 0 :(得分:2)
在Magento的付款处理阶段,没有触发任何可观察的事件。相反,您为要实现的任何网关定义一个类,然后定义Magento将自动调用的方法,因为订单会通过各种付款方式。
围绕基本抽象支付类查看支付处理期间将调用的各种方法。在您的班级中定义相同的方法,以便在您想要的任何时候挂钩到付款流程。
File: app/code/core/Mage/Payment/Model/Method/Abstract.php
class abstract class Mage_Payment_Model_Method_Abstract
{
/**
* Authorize
*
* @param Varien_Object $orderPayment
* @return Mage_Payment_Model_Abstract
*/
public function authorize(Varien_Object $payment, $amount)
...
/**
* Capture payment
*
* @param Varien_Object $orderPayment
* @return Mage_Payment_Model_Abstract
*/
public function capture(Varien_Object $payment, $amount)
...
/**
* Void payment
*
* @param Varien_Object $invoicePayment
* @return Mage_Payment_Model_Abstract
*/
public function void(Varien_Object $payment)
...
/**
* Refund money
*
* @param Varien_Object $invoicePayment
* @return Mage_Payment_Model_Abstract
*/
//public function refund(Varien_Object $payment, $amount)
public function refund(Varien_Object $payment, $amount)
...
/**
* Cancel payment (GoogleCheckout)
*
* @param Varien_Object $invoicePayment
* @return Mage_Payment_Model_Abstract
*/
public function cancel(Varien_Object $payment)
...
我没有做很多支付网关实施,但我猜测refund
是您想要的贷项凭证方法,而capture
是发票的方法。看起来cancel
方法是特定于Google Checkout的方法。使用一些日志记录功能在您的班级中定义所有五个,如果您想确切知道,请在开发系统上查看一些假订单。
答案 1 :(得分:2)
好像您的付款方式未使用交易或未创建授权交易ID。这是支付网关开发中常见的初学者错误。
要通过在线操作启用支付网关,您需要在付款方式中实施以下内容:
class MyBest_Payment_Model_Method extends Mage_Payment_Model_Method_Abstract
{
protected $_canAuthorize = true; // Set true, if you have authorization step.
protected $_canCapture = true; // Set true, if you payment method allows to perform capture transaction (usally only credit cards methods)
protected $_canRefund = true; // Set true, if online refunds are available
protected $_canVoid = true; // Set true, if you can cancel authorization via API online
public function authorize(Varien_Object $payment, $amount)
{
// ... You payment method authorization goes here ...
// Here goes retrieving or generation non-zero,
// non-null value as transaction ID.
$transactionId = $api->someCall();
// Setting tranasaction id to payment object
// It is improtant, if you want perform online actions
// in future with this order!
$payment->setTransactionId($transactionId);
// ... some other your actions ...
return $this;
}
public function void(Varien_Object $payment)
{
// ... some actions for sending cancel notification to your payment gateway
}
public function refund(Varien_Object $payment, $amount)
{
// ... some actions for performing an online refund ...
}
}
答案 2 :(得分:1)