Question

I am having an issue with the card token not saving against a customer using the Ruby Stripe integration and Stripe.js

We get what looks to be a valid card token from Stripe.js (e.g. tok_4VeYrrjJpCwGG6)

Then I am calling the following;

customer = Stripe::Customer.retrieve(customer_id) #customer_id is correct and valid
customer.card = stripeToken # e.g. the tok_ I gave as an example
customer.save

If I log out the result of customer.save I get something like;

{
    "id":"cus_4QR8ZuPUPlgA0G",
    "object":"customer",
    "created":1405685697,
    "livemode":false,
    "description":null,
    "email":"my_email",
    "delinquent":true,
    "metadata":{},
    "subscriptions": {
        "object":"list",
         "total_count":0,
         "has_more":false,
         "url":"/v1/customers/cus_4QR8ZuPUPlgA0G/subscriptions",
         "data":[],
         "count":0
    },
    "discount":null,
    "account_balance":0,
    "currency":"eur",
    "cards"{
         "object":"list",
         "total_count":0,
         "has_more":false,
         "url":"/v1/customers/cus_4QR8ZuPUPlgA0G/cards",
         "data":[],
         "count":0
     },
     "default_card":null,
     "subscription":null
} 

Everything is as I would expect bar the card hasn't been added.

Could anyone advise what I am possibly doing wrong here?

Was it helpful?

Solution

To add a new card to an already existing customer you have to make use of the create card API call. Please take a look at https://stripe.com/docs/api/ruby#create_card for details on how to go about this.

In your particular case, you can update the user with: customer = Stripe::Customer.retrieve(customer_id) customer.sources.create(:source => stripeToken)

Let me know if that helps solve your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top