I have a need to add a card to a pre-existing customer. Here's what I did:
card_token = request.POST('stripeToken')
customer = stripe.Customer.retrieve('cus_xxxxxxxxxx')
customer.Cards.create(card=card_token)
It is # 3 that I'm having trouble because it looks like the customer doesn't have method Cards, but I've seen people done it elsewhere.
How should I achieve this?
If you are on the 2015-02-18
API version or later then the cards
attribute has been changed to sources
as you can see in the changelog
The documentation on the Create Card API shows the following code now:
customer = stripe.Customer.retrieve('cus_xxxxxxxxxx')
customer.sources.create(card=card_token)
You can find your API version in the API keys settings in the dashboard and you can also use the Stripe-Version
header to force your API request to an older API version so that cards
still work as explained in the Versioning documentation:
stripe.api_version = '2015-01-26'