integrallis / stripe_event

Stripe webhook integration for Rails applications.
https://rubygems.org/gems/stripe_event
MIT License
840 stars 107 forks source link

Using Background job #80

Closed peco8 closed 7 years ago

peco8 commented 7 years ago

First off, thanks for the nice library. I've been using stripe_event for test phase, and works pretty well.

Let's assume that

In this case, I feel I need to consider to using background job.

Best practices in stripe doc

If your webhook script performs complex logic, or makes network calls, it's possible the script >would timeout before Stripe sees its complete execution. For that reason, you may want to have >your webhook endpoint immediately acknowledge receipt by returning a 2xx HTTP status code, >and then perform the rest of its duties.

Here is my code, I've just wondered which part I should bundle and enqueue?

StripeEvent.event_retriever = lambda do |params|
  return nil if StripeWebhook.exists?(stripe_id: params[:id])
  StripeWebhook.create!(stripe_id: params[:id])

  return Stripe::Event.construct_from(params.deep_symbolize_keys) if Rails.env.test?

  return Stripe::Event.retrieve(params[:id])
end

StripeEvent.configure do |events|
  events.subscribe 'invoice.created', InvoiceCreated.new
  events.subscribe 'invoice.payment_succeeded', InvoicePaymentSucceeded.new
 ...
end
invisiblefunnel commented 7 years ago

Hi @peco8. This is a good question, but I would suggest posting this on Stack Overflow. Stack Overflow is designed for asking questions about how to use a language or library, and there are lots of people answering questions about Stripe integrations. Feel free to link to your question on SO from this issue so people can find it.

GitHub issues is best used for bug reports or discussions about specific changes to the library.

Thank you.

theblang commented 4 years ago

@peco8 ~Did you ever post this to Stack Overflow? I'm in the same situation: wanting to use a background job to asynchronously process the event.~

Scratch that, just found it!