ruby-on-rails - 如何使用 StripeEvents/Webhooks 防止 ArgumentError(PaymentFailed 的副本已从 > 模块树中删除但仍处于事件状态!)?

标签 ruby-on-rails stripe-payments

我正在使用 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

参见 https://github.com/integrallis/stripe_event/issues/108 .

关于ruby-on-rails - 如何使用 StripeEvents/Webhooks 防止 ArgumentError(PaymentFailed 的副本已从 > 模块树中删除但仍处于事件状态!)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48640498/

相关文章:

android - 在 Stripe 付款上显示每小时价格而不是存款价格

android - 在 Stripe Android CardWidget 如何更改提示文本大小和提示文本?

reactjs - Stripe webhook checkout.session 项目到 Supabase

ruby-on-rails - 我如何在 Jbuilder 中使用 Rails 助手和 Gon gem?

ruby-on-rails - Rake任务: How to make task from another namespace prerequesite?

mysql - 我应该如何避免sql注入(inject)?

java - 如何在Stripe中更新客户默认的PaymentMethod?

ruby-on-rails - 如何在 Rails 上的 .yml 本地化文件中换行?

ruby-on-rails - 如何在 Rails 4 中使用 typeahead.js 作为 Bower 组件

php - Sylius/Payum/Stripe 配置错误 "boolean sandbox option must be set"