Skip to content
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

Merged
merged 6 commits into from Mar 15, 2021

Conversation

humitos
Copy link
Member

@humitos humitos commented Mar 10, 2021

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.

If we receive a webhook multiple times, we fetch the GoldUser already created
and update its fields.
@humitos humitos requested a review from a team March 10, 2021 16:49
Copy link
Contributor

@agjohnson agjohnson left a 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 👍 on being more defensive with the webhook.

@@ -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)
Copy link
Contributor

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.

Copy link
Member Author

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.

readthedocs/payments/forms.py Show resolved Hide resolved
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.
@humitos humitos requested review from agjohnson and a team March 15, 2021 10:30
@humitos humitos merged commit 16611d9 into master Mar 15, 2021
3 checks passed
@humitos humitos deleted the humitos/remove-old-payment-code branch March 15, 2021 17:47
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.

None yet

3 participants