-
Notifications
You must be signed in to change notification settings - Fork 118
feat(stripe): Update payment method in a job #3381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
With a job you can still have the payment not updated, it may be rare but it can still happen no? |
@jdenquin At this point it shouldn't happen because the code right before enqueuing this job will already fail if the payment is not updated. And if that happens, we'll see it in the dead queue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we discuss about this one?
app/services/payment_providers/stripe/webhooks/payment_intent_succeeded_service.rb
Show resolved
Hide resolved
## Description See #3381 If the initial service updating the payment method (which might also create payment if not found doesn't return a payment), ignore the next job. What I got wrong initially is that I assumed if no payment was found in the end, the service was raising an error. It doesn't. https://github.com/getlago/lago-api/blob/953b92a96de74ab613479dd4db1d5e85977d9d47/app/services/invoices/payments/stripe_service.rb#L16-L28 https://github.com/getlago/lago-api/blob/953b92a96de74ab613479dd4db1d5e85977d9d47/app/services/payment_requests/payments/stripe_service.rb#L32-L42
## Description I was hesitant to make it async but it's better for retries. Note that `update_payment_status` might raise a not found error if the webhook arrived before the `payment._provider_payment_id` is updated in the DB, which will retry the HandleEventJob. So when `UpdatePaymentMethodDataJob` is dispatched, we're guaranteed that payment is updated... until the implementation of `update_payment_status` changes 😄
## Description See #3381 If the initial service updating the payment method (which might also create payment if not found doesn't return a payment), ignore the next job. What I got wrong initially is that I assumed if no payment was found in the end, the service was raising an error. It doesn't. https://github.com/getlago/lago-api/blob/953b92a96de74ab613479dd4db1d5e85977d9d47/app/services/invoices/payments/stripe_service.rb#L16-L28 https://github.com/getlago/lago-api/blob/953b92a96de74ab613479dd4db1d5e85977d9d47/app/services/payment_requests/payments/stripe_service.rb#L32-L42
Description
I was hesitant to make it async but it's better for retries.
Note that
update_payment_status
might raise a not found error if the webhook arrived before thepayment._provider_payment_id
is updated in the DB, which will retry the HandleEventJob.So when
UpdatePaymentMethodDataJob
is dispatched, we're guaranteed that payment is updated... until the implementation ofupdate_payment_status
changes 😄