Skip to content

Commit b8ff656

Browse files
authored
Merge pull request #2015 from argos-ci/prevent-duplicate-update
fix(stripe): prevent duplicate update
2 parents 7b22f3c + b80b52a commit b8ff656

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

apps/backend/src/stripe/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,17 @@ export async function handleStripeEvent({
633633
return;
634634
}
635635
case "customer.updated": {
636-
const customer = data.object as Stripe.Customer;
637-
await updateSubscriptionsFromCustomer(customer.id);
636+
// Only update from customer if the "default_payment_method" changes,
637+
// for everything else we will get a "customer.subscription.updated".
638+
if (
639+
data.previous_attributes &&
640+
"invoice_settings" in data.previous_attributes &&
641+
data.previous_attributes.invoice_settings &&
642+
"default_payment_method" in data.previous_attributes.invoice_settings
643+
) {
644+
const customer = data.object as Stripe.Customer;
645+
await updateSubscriptionsFromCustomer(customer.id);
646+
}
638647
return;
639648
}
640649

0 commit comments

Comments
 (0)