我正在使用 StripeEvent gem处理来自 Stripe 的网络 Hook 。
在我的 Rails 初始化程序中,我得到了这个:
StripeEvent.configure do |events|
events.subscribe 'invoice.payment_succeeded', PaymentSucceeded.new
events.subscribe 'invoice.payment_failed', PaymentFailed.new
end
我还有一个文件夹app/stripe_events
,我在其中保存如下类:
class PaymentFailed
def call(event)
StripeMailer.admin_payment_failed(event.data.object).deliver_now
end
end
问题是我时不时地收到这个错误:
ArgumentError (A copy of PaymentFailed has been removed from the module tree but is still active!)
我猜这是因为 app
中的所有内容都被 Rails 不断地重新加载,而初始化程序中的 StripeEvent.configure
位却没有?
如何预防?
感谢您的指点。
最佳答案
对于那些遇到这个问题的人,events.subscribe
的第二个参数可以是一个 lambda,它可以解决这个问题:
StripeEvent.configure do |config|
config.subscribe 'customer.subscription.created', ->(event) {
RecordStripeSubscription.new.call event
}
end
关于ruby-on-rails - 如何使用 StripeEvents/Webhooks 防止 ArgumentError(PaymentFailed 的副本已从 > 模块树中删除但仍处于事件状态!)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48640498/