Subscription not found because of email mismatch

Description of the issue

We had a complaint from a customer who got a subscription but was not added to the group.

TL;DR

If the email address for a user does (somehow?) not match their email address in Stripe, they do not get a subscription. Changing the email address in Stripe resolves the issue.

Investigation

Now we saw the following.

  • In the overview with all the subscriptions, it’s there

  • The user does have a payment in their profile

  • The user does NOT have a subscription in their profile!!!

  • In the database everything looks ok. I redacted the ID’s a bit since I don’t know how confidential Stripe ID’s are.
db0731=# select * from discourse_subscriptions_subscriptions where external_id='sub_1Lf285...9YA0';
-[ RECORD 1 ]-----------------------------
id          | 944
customer_id | 944
external_id | sub_1Lf285...9YA0
created_at  | 2022-09-06 13:47:57.074098
updated_at  | 2022-09-06 13:47:57.074098

db0731=# select * from discourse_subscriptions_customers where user_id=62443;
-[ RECORD 1 ]---------------------------
id          | 944
customer_id | cus_MN...sc
product_id  | prod_MH451u0JeKHoMv
user_id     | 62443
created_at  | 2022-09-06 13:47:57.057455
updated_at  | 2022-09-06 13:47:57.057455

The user ID matches the user in question.

In Stripe, the metadata matches, but the email address does not!

image

Changing the email address in Stripe so it matches the Discourse email address does resolve the issue. The subscription immediately appears in the profile of the user.

For some reason, the plugin reaches out to Stripe trying to find the subscriptions for this email address.

I do not understand why it works this way.

  • The meta data is there so why not match it on the metadata?
  • All the information is in the database already so why reach out to Stripe in the first place?

It’s not only an issue with the display, after all the user was not added to the group either.

2 Likes