Stripe - Add new card to existing customer
stripe add card to customer api
stripe test cards
stripe get card details
stripe customer api
I have a need to add a card to a pre-existing customer. Here's what I did:
1. obtain token from user submission
card_token = request.POST('stripeToken')
2. retrieve a customer
customer = stripe.Customer.retrieve('cus_xxxxxxxxxx')
3. add card to this customer
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'
Create a card, Learn how to save payment details to charge your customers later. payments. Setup mode uses the Setup Intents API to create Payment Methods. You can optionally specify the customer parameter to automatically attach the created payment method to an existing customer. Learn more about setting up webhooks. Change subscriptions. Learn how to change existing subscriptions. Customer portal In addition to using the API and Dashboard to change subscriptions, you can also implement the customer portal to provide a Stripe-hosted dashboard where customers can manage their subscriptions and billing details.
2019 Update: Things have changed a bit with Strong Customer Authentication (SCA) requirements in Europe; you'll now probably want to use the Setup Intents API to collect card details upfront for future payments.
This new API is both PCI and SCA compliant. You can learn more here or check out this sample code on GitHub: https://github.com/stripe-samples/saving-card-without-payment.
You can also do this entirely with Checkout now as well!
Set up future payments, Here's what I did: obtain token from user submission. card_token = request.POST('stripeToken') retrieve a customer. customer = stripe.Customer.retrieve('cus_xxxxxxxxxx') add card to this customer. customer.Cards.create(card=card_token) When using payment sources created via the Token or Sources APIs, passing source will create a new source object, make it the new customer default source, and delete the old customer default if one exists. If you want to add additional sources instead of replacing the existing default, use the card creation API. Whenever you attach a card to a customer, Stripe will automatically validate the card.
Example (customerId - cus_xxxxxxxxxx):
Stripe.apiKey = stripeApiKey; Customer customer = Customer.retrieve(customerId); Map<String, Object> cardParams = new HashMap<String, Object>(); cardParams.put("number", "4242424242424242"); cardParams.put("exp_month", "12"); cardParams.put("exp_year", "2018"); cardParams.put("cvc", "314"); Map<String, Object> tokenParams = new HashMap<String, Object>(); tokenParams.put("card", cardParams); Token cardToken = Token.create(tokenParams); Map<String, Object> sourceParams = new HashMap<String, Object>(); sourceParams.put("source", cardToken.getId()); //? Card source = (Card) customer.getSources().create(sourceParams); logger.info("Card created: " + source.toString());
Stripe - Add new card to existing customer, Is there a way I can add multiple cards for a customer using stripe.net, I know that Supplying a new card when creating a subscription will replace the existing I think you dont need to create a token in case of adding new card. It helps while you update certain card. So the flow of addition will be same as you created for first card.
Adding multiple cards for a customer stripe.net · Issue #504 · stripe , If you have an existing customer in your Stripe account that you want to link to a Customer Step 2: Paste the ID from Stripe into the Customer Record Add the New Premium Booking Form to your Site · Test/Demo Credit Card to Test the Add Stripe.js to your page. Call loadStripe with your publishable key. It returns a Promise that resolves with the Stripe object once Stripe.js has loaded. When your customer is ready to save their payment method, call redirectToCheckout and provide the Session id as a parameter.
Link Existing Stripe Customer to a Customer Record, You can locate an existing customer by searching by email address or customer ID on your Stripe Dashboard. To add a new card, navigate to When using payment sources created via the Token or Sources APIs, passing source will create a new source object, make it the new customer default source, and delete the old customer default if one exists. If you want to add additional sources instead of replacing the existing default, use the card creation API. Whenever you attach a card to a customer, Stripe will automatically validate the card.
Stripe: How to manually update subscription payment methods , You can also quickly upgrade your customers' subscriptions or start new subscriptions You can connect multiple Stripe accounts with Intercom, just click 'Add new account'. Expiration date of stored credit card. stripe_card_brand — e.g. Visa. to create them as a new customer, or link them to an existing customer first. A customer will have multiple cards and I would like to check/validate new customer cards with their existing cards. Suppose the same card details can be stored multiple times as multiple cards. I want to check using the Stripe token whether a newly entered card already exists or not.
- CAUTION: It is a security best practice to never handle the card number or cvc in your server side code. Doing so puts your server into PCI scope which is something that most developers want to avoid. Anyone using this code will have a much more challenging/expensive time with achieving PCI compliance than if they avoided server side handling of sensitive card data.