dotty
dotty

Reputation: 41523

Should I be keeping both stripe_id and card_id in a database?

I'm new to stipe, and I'm just wondering if that I'm doing is a standard way of working with Stripe.

I have a very simple User model which I've added 2 new fields - stripe_id and card_id. When a user registers an API call to Stripe is made to generate a stripe_id. Then I ask for a credit card. I've used to basic stripe.js API to retrieve a card_id. I then store that card in the User model.

Is this safe to do this? I then card the user with their stripe_id and card_id.

I know that a user has more than one card, so eventually I'll move the cards a seperate table.

Upvotes: 0

Views: 508

Answers (1)

Muhammet
Muhammet

Reputation: 3308

If you want to use the card later again store the card_id.

This is an example of how you would retrieve card info later in PHP

$customer = \Stripe\Customer::retrieve({CUSTOMER_ID});
$card = $customer->sources->retrieve({CARD_ID});

So you need both stripe_id and card_id.


If you only store stripe_id you can still list customer's all cards' information:

Stripe\Customer::retrieve({CUSTOMER_ID})->sources->all(array(
  "object" => "card"
));

Upvotes: 2

Related Questions