Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store stripe customer id in a database

Let's say a customer is returning to pay for a subscription after some time of not using the service. Once card information from a customer is POSTed from the client browser, does stripe.customers.create identify the card that has been used before? In such case, does customer object id returned has the same id as the one customer had before? I am asking this question because I am not sure if I should relate one customer ID per a user in my DB or multiple customer IDs per a user.

like image 860
sawa Avatar asked Oct 14 '16 09:10

sawa


2 Answers

If a customer come back to do some operation we can suppose that you have already all the informations about that.. So you have to handle if create or update a customer (card or subscription, etc.. )

This is the documentation about Stripe.create.Customer.

And it say:

Creates a new customer object.

Anyway, explains more about your situation. Is it into a site where the user is already logged-in? Or is it different?

like image 163
The Dude Avatar answered Oct 21 '22 12:10

The Dude


Yes Customer ID is a constant string in stripe. In your application, when you register your customer, make sure you through one call to stripe payment gateway to register there. stripe.customers.create() method should be invoke with customer object as parameter.
https://stripe.com/docs/api#create_customer

After creating user in stripe you can add card for that user from you api by throwing a call to this method of stripe stripe.customers.createSource({},{},cb)

here first parameter will be customer ID which is returned from stripe. second parameter will be token and third parameter will be a callback function if you are in (Node.js) environment.

Thanks

like image 1
Parit Avatar answered Oct 21 '22 13:10

Parit