mwild
mwild

Reputation: 1655

Stripe - storing multiple sources on a user

I am trying to store multiple sources (cards) on a single user object.

Lets say I have a customer that already has one source stored.

With a new source token I then do the following

stripe.customers.update(customer, {source:call.request.source}, function(err, updatedCustomer){
     if(err){
         return console.log(err);
     }
     console.log(updatedCustomer.sources.data);     
})

When I do this, the customers existing source is lost and the new one is stored.

How can I store multiple sources on the same customer??

Upvotes: 2

Views: 271

Answers (2)

Rahul Sharma
Rahul Sharma

Reputation: 1431

This will work for you.

customer = Stripe::Customer.retrieve(stripe_customer_id)

customer.sources.create(stripeToken)

Stripe token is generated using stripe.js.

Upvotes: 0

mwild
mwild

Reputation: 1655

Using createSource rather than update done the trick.

stripe.customers.createSource(customer, {source:call.request.source}, function(err, updatedCustomer){
   if(err){
     return console.log(err);
   }
   console.log(updatedCustomer.sources.data);     
})

Upvotes: 2

Related Questions