8000 feat(stripe): Update payment method in a job by julienbourdeau · Pull Request #3381 · getlago/lago-api · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 3 commits into from
Mar 26, 2025
Merged

Conversation

julienbourdeau
Copy link
Contributor
@julienbourdeau julienbourdeau commented Mar 26, 2025

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 😄

@julienbourdeau julienbourdeau self-assigned this Mar 26, 2025
@julienbourdeau julienbourdeau changed the title Feat/strip pm retry feat(stripe): Update payment method in a job Mar 26, 2025
@jdenquin
Copy link
Contributor

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 😄

With a job you can still have the payment not updated, it may be rare but it can still happen no?

@julienbourdeau
Copy link
Contributor Author
julienbourdeau commented Mar 26, 2025

@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.

Copy link
Contributor
@jdenquin jdenquin left a 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?

@julienbourdeau julienbourdeau merged commit fc587d7 into main Mar 26, 2025
6 checks passed
@julienbourdeau julienbourdeau deleted the feat/strip-pm-retry branch March 26, 2025 15:54
julienbourdeau added a commit that referenced this pull request Mar 27, 2025
## 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
jdenquin pushed a commit that referenced this pull request Mar 27, 2025
## 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 😄
jdenquin pushed a commit that referenced this pull request Mar 27, 2025
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0