Duplicate Customers

396 views
Skip to first unread message

Jonathan Rivera

unread,
Apr 14, 2016, 4:51:47 PM4/14/16
to Stripe API Discussion
What's the best method to avoid duplicate customers being created using the Stripe API? Is there a parameter that can be sent to ensure it's a unique customer?

Currently my flow is:

1. Customer signs up
2. Website uses \Stripe\Customer::create();
3. Website creates the user account if a payment is successful

The problem I'm coming across is when there are technical difficulties like lost connection after the payment has been submitted, or if for some reason the page doesn't load the customers are hitting the back button and submitting the form again. There's not much I can do from a programming perspective unless I create user accounts before the payment is accepted. That would help stop this issue but would create a whole other issue altogether where user accounts are created if a payment is not made.

Any suggestions? Is there a better API call to use when creating a customer/charge?

Matthew Arkin

unread,
Apr 14, 2016, 6:17:39 PM4/14/16
to Jake K.
To handle the case where the connection is lost between your server and Stripe's server you'd want to implement idempotency key's this allows you to retry api calls and get the same response back from Stripe as the last time you sent the request with that key. 

For the cases where a customer resubmits a form again, you may want to check to see if the customer already exists in your database before retrying the charge / customer creation step, this could more be seen as how to do idempotency between your server and your client as opposed to Stripe.

Personally I like to actually reverse steps 2 and 3, I'll create a customer's account in my database first and then depending on if the charge goes through or not flag it as active or inactive.

Matt

--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Jonathan Rivera

unread,
Apr 14, 2016, 6:46:47 PM4/14/16
to api-d...@lists.stripe.com
Thanks Matt. I'm going to give idempotency a try! I missed that going through the docs to build our integration so thanks for pointing that out. The quick reading I did on it sounds like it will help alleviate the issue since most duplicate charges happen within a minute of each other during sign up.
--
Jonathan Rivera
i-4Web

Reply all
Reply to author
Forward
0 new messages