stripe-firebase-extensions icon indicating copy to clipboard operation
stripe-firebase-extensions copied to clipboard

Firestore-stripe-payments - Duplicate Customers

Open tlorenz34 opened this issue 3 years ago • 5 comments

Bug report

  • Extension name: [e.g. firestore-stripe-payments]

Describe the bug

Every time a customer creates an account within my chrome extension, then buys a subscription via Stripe Payment Links, two customers are created within the Stripe portal (I have confirmed with Stripe that this is an issue with the Firestore-Stripe-Payments extension as they checked on their side). When the customer's account is duplicated two times in Stripe, one of the accounts is blank except for the email field and the other is filled with the customer's name and payment information. The Stripe customer's name and Customer ID does not match with the one in Firestore AND Firestore doesn't even create a "Subscription" collection with the Customer's Document.

To Reproduce

  1. Download the Chrome Extension at https://theminutejournal.com/
  2. Create an account in the Minute Journal
  3. Click "Start Day" upon New Tab
  4. Buy a Stripe subscription (Monthly or Annually)
  5. Confirm payment success
  6. Close Chrome
  7. Reopen or create a new tab to use the Minute Journal
  8. Click "Start Day" (same as step 3)
  9. You will be brought to the pricing plans again Once you have done the steps above, I can confirm the duplicate customer within Stripe.

Expected behavior

Users should have a Subscription Collection within their Firestore Document that confirms they are a paying customer and should be able to access the Minute Journal's features. Furthermore, there should only be one Customer within Stripe created.

Screenshots

Duplicate Customers within Stripe: Screen Shot 2022-06-03 at 8 51 48 AM

How it should look or behave via Firestore: Screen Shot 2022-06-03 at 8 53 21 AM

How it looks currently via Firestore: Screen Shot 2022-06-03 at 8 53 08 AM

System information

  • macOS
  • Google Chrome

Additional context

THIS IS URGENT AS I AM LOSING PAYING CUSTOMERS!

tlorenz34 avatar Jun 03 '22 12:06 tlorenz34

I can confirm the failure. Two user accounts are created at almost the same timestamp. It has occurred very rarely so far. Nevertheless, the product cannot be released because the payment is not synchronised even though both user accounts have the same firebaseUID but different users. @tlorenz34 , have you made any progress on this?

Spitzbua avatar Jun 17 '22 12:06 Spitzbua

HI @tlorenz34 @Spitzbua.

Can you provide any logs from the extension function. This can be accessed through by:

  1. Navigate to the Extensions Dashboard
  2. Select the Stripe Payments Installation
  3. Choose Apis and resources
  4. Select the payments function logs

Additionally, could you confirm that you only have one instance of the extension installed to confirm this isn't an issue caused by multiple instances.

dackers86 avatar Jun 18 '22 20:06 dackers86

I had a look at the logs at the timestamp where the failure happened. The case popped up last week happened in February 2022 and there a no rows written in the logs. Perhaps they are deleted after some time. The only information that I have is from the customer portal. The canceled payment intent is synced but not the successfull one. The two customers with the same mail address are created in the same timestamp. stripe_customer_duplicates

Spitzbua avatar Jun 20 '22 09:06 Spitzbua

With Stripe allowing multiple customers with the same email address, could suggest this is created upon a new checkout session. Although this bug doesn't seem obvious in the extension.

If you navigate to both users and select Events and Logs, could you provide information on how each customer was created for debugging purposes?

https://dashboard.stripe.com/test/customers/{Stripe_Customer_ID}

dackers86 avatar Jun 20 '22 10:06 dackers86

Payment Links/Checkout will by default create a new Customer object if no customer parameter is provided on session creation:

If blank for Checkout Sessions in payment or subscription mode, Checkout will create a new Customer object based on information provided during the payment flow.

Based on the limited information above, I expect that your integration is creating multiple Checkout Session objects simultaneously.

jsteele-stripe avatar Jul 27 '22 16:07 jsteele-stripe

I had the same problem, every 1-3 out of 100 payments creates a duplicate account in Stripe and links the wrong Stripe customer to the Firestore user.

In the error cases, I create a user and then directly run a checkout session. However, the createCustomer event happens too closely to the checkout session createCheckoutSession. In most cases it works fine, but when createCustomer takes too long, createCheckoutSession also creates a customer. See below:

if (!customerRecord?.stripeId) {
        const { email, phoneNumber } = await admin
          .auth()
          .getUser(context.params.uid);
        customerRecord = await createCustomerRecord({
          uid: context.params.uid,
          email,
          phone: phoneNumber,
        });
    }

Based on the logs, I assume this was my problem. I'll either add a delay or wait for the Firestore update before creating the checkout session.

Suggestions:

  1. I assume account creation followed by checkout is a common behaviour for websites with subscriptions, and it would be good to communicate this edge case.
  2. In my case, I'd prefer createCheckoutSession to wait for the stripeId update, instead of creating a new customer. But this is probably not best for all use cases.

emilwallner avatar Dec 21 '22 19:12 emilwallner