我正在使用stripe_event gem为Stripe webhooks设置我的事件处理程序。我想发送一封电子邮件,通知客户他们的订阅是否未续订。一个这样的设置如下:
# config/initializers/stripe.rb
StripeEvent.setup do
subscribe 'customer.subscription.updated' do |event|
subscription = event.data.object
customer_id = subscription.customer
user = User.find_by_customer_id(customer_id)
UserMailer.delay.past_due_email(user) if subscription.status == 'past_due'
end
end
现在我的目标是在本地测试上面的事件处理程序(不依赖于ngrok或ultrahook等)。
在我的规范中,我构建了一个类型为"customer.subscription.updated"
的虚假Stripe webhook事件。它还包含对localhost:3000/stripe
的POST请求:
RestClient.post('localhost:3000/stripe', fake_webhook_event)
我在本地启动rails服务器并运行规范。服务器正在接收POST请求并且正在运行事件处理程序,但请求中包含的订阅对象的状态为active
而不是past_due
。其他属性(例如事件ID)与我编写的虚假webhook相同。很奇怪。
我有一种感觉我不应该将请求发送到开发服务器,但也许在其他地方?有什么建议?提前谢谢!
答案 0 :(得分:1)
享受使用这颗宝石 https://github.com/stripe-ruby-mock/stripe-ruby-mock
<块引用>特点