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
Stripe Checkout: handle duplicated wehbook #8002
Conversation
If we receive a webhook multiple times, we fetch the GoldUser already created and update its fields.
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.
It seemed the duplicate webhook thing was probably not going to be common, but
@@ -52,10 +52,6 @@ class GoldUser(models.Model): | |||
stripe_id = models.CharField(max_length=255) | |||
subscribed = models.BooleanField(default=False) | |||
|
|||
# TODO: these are managed completely by Stripe now; we could remove them | |||
last_4_card_digits = models.CharField(max_length=4, null=True, blank=True) | |||
business_vat_id = models.CharField(max_length=128, null=True, blank=True) |
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.
I assume we probably want to make sure that the users that did specify a VAT actually have this configured in Stripe on their subscription as well.
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.
Good point! I checked this with a small script:
users = []
for g in GoldUser.objects.exclude(business_vat_id__isnull=True).exclude(business_vat_id=''):
customer = stripe.Customer.retrieve(g.stripe_id)
stripe_vat = customer.tax_ids.data[0].value
if stripe_vat != g.business_vat_id:
subscriptions = stripe.Subscription.list(customer=g.stripe_id)
users.append((g.user.username, stripe_vat, g.business_vat_id, len(subscriptions.data)))
and I can say that all the users we have business_vat_id
for has the same tax id on Stripe.
We had this event registered but it wasn't added to the list of handled events.
We were returning `None` in some cases and that makes Django to return a 500.
Stripe checkout: handle events
If we receive a webhook multiple times, we fetch the GoldUser already created and update its fields.
This PR also removes some old and unused payment code.