Magento - 当我的订单取消或退款时如何运行代码
如果订单被取消或退款,我的支付模块需要向支付服务发送通知。我假设订单页面(在管理后端)上的“取消”按钮将取消订单,而“贷项通知单”按钮(创建发票后)将退还订单。
如何针对这些事件运行我的代码?我尝试在付款方式模型中使用 cancel() 方法,但代码未运行。
My payment module is required to sent notifications to the payment service if an order is canceled or refunded. I assume that the "Cancel" button on the order page (in the administration backend) will cancel the order, and that the "Credit memo" button (after an invoice has been created) will refund the order.
How do I run my code on these events? I tried using the cancel() method in my payment method model, but the code did not run.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的付款方式似乎未使用交易或未创建授权交易 ID。这是支付网关开发中常见的初学者错误。
要通过在线操作启用您的支付网关,您需要在支付方式中实现类似以下内容:
Seems like your payment method is not using transactions or does not create authorization transaction id. It is common beginner mistake in Payment gateways development.
To enable your payment gateway with online actions you need to implement something like this in your payment method:
在 Magento 的付款处理阶段不会触发任何可观察的事件。相反,您可以为要实现的任何网关定义一个类,然后定义 Magento 在订单通过各种付款方式时自动调用的方法。
查看基本抽象支付类以查看支付处理期间将调用的各种方法。在您的类中定义相同的方法,以便在您想要的任何时候连接到支付流程。
我没有做很多支付网关的实现,但我猜
refund
是您想要的贷项通知单方法,而capture
是用于发票的方法。看起来cancel
方法是 Google Checkout 特有的。使用一些日志记录功能在您的类中定义所有五个,如果您想确定的话,可以在您的开发系统上查看一些假订单。No observable events are fired during the Payment processing stage of Magento. Instead, you define a class for whatever gateway you're implementing, and then define methods that Magento will automatically call as an order makes it's way through the various payment methods.
Poke around the base abstract payment class to see the various methods that will be called during payment processing. Define the same methods in your class to hook into the payment process at whatever point you'd like.
I don't do a lot of Payment Gateway implementations, but I'm guessing that
refund
is the method you want for credit memos, andcapture
is the one for invoices. It looks like thecancel
method is something specific to Google Checkout. Define all five in your class with some logging functions and walk though some fake orders on your development system if you want to know for sure.Magento 的事件挂钩可能会有所帮助。可以在此处找到事件列表(我认为有点过时)。还有一篇关于 Magneto 事件如何工作的有用文章 这里。
此外,查看现有的付款扩展可能会很有用。如果 Google Checkout 因订单取消而调度类似的事件,我不会感到惊讶。扩展存储库将有很多付款方式可供查看。
祝你好运!
Magento has event hooks that might be helpful. A list of events (a bit outdated, I think) can be found here. And there is a useful article about how Magneto's events work here.
Also, looking at existing payment extensions could be useful. I would not be surprised if similar events are dispatched by Google Checkout for order cancellations. The Extension repository will have lots of payment methods to look at.
Good luck!