Update payment details
Learn how to update the payment method used for future invoices.
Use the following steps to create a Checkout page that collects your customer’s payment details and returns a Payment Method. Then use the Stripe REST APIs to update the payment method used for future invoices.
1 Set up Stripe Server-side
First, you need a Stripe account. Register now.
Use our official libraries for access to the Stripe API from your application:
# Available as a gem gem install stripe# Available as a gem gem install stripe
# If you use bundler, you can add this line to your Gemfile gem 'stripe'# If you use bundler, you can add this line to your Gemfile gem 'stripe'
# Install through pip pip install --upgrade stripe# Install through pip pip install --upgrade stripe
# Or find the Stripe package on http://pypi.python.org/pypi/stripe/# Or find the Stripe package on http://pypi.python.org/pypi/stripe/
# Find the version you want to pin: # https://github.com/stripe/stripe-python/blob/master/CHANGELOG.md # Specify that version in your requirements.txt file stripe>=2.48.0,<3.0# Find the version you want to pin: # https://github.com/stripe/stripe-python/blob/master/CHANGELOG.md # Specify that version in your requirements.txt file stripe>=2.48.0,<3.0
# Install the PHP library via Composer composer require stripe/stripe-php# Install the PHP library via Composer composer require stripe/stripe-php
# Or download the source directly: https://github.com/stripe/stripe-php/releases# Or download the source directly: https://github.com/stripe/stripe-php/releases
/* For Gradle, add the following dependency to your build.gradle and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest */ implementation "com.stripe:stripe-java:{VERSION}"/* For Gradle, add the following dependency to your build.gradle and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest */ implementation "com.stripe:stripe-java:{VERSION}"
<!-- For Maven, add the following dependency to your POM and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest --> <dependency> <groupId>com.stripe</groupId> <artifactId>stripe-java</artifactId> <version>{VERSION}</version> </dependency><!-- For Maven, add the following dependency to your POM and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest --> <dependency> <groupId>com.stripe</groupId> <artifactId>stripe-java</artifactId> <version>{VERSION}</version> </dependency>
# For other environments, manually install the following JARs: # - The Stripe JAR from https://github.com/stripe/stripe-java/releases/latest # - Google Gson from https://github.com/google/gson# For other environments, manually install the following JARs: # - The Stripe JAR from https://github.com/stripe/stripe-java/releases/latest # - Google Gson from https://github.com/google/gson
# Install via npm npm install --save stripe# Install via npm npm install --save stripe
# Make sure your project is using Go Modules go mod init # Install stripe-go go get -u github.com/stripe/stripe-go/v72# Make sure your project is using Go Modules go mod init # Install stripe-go go get -u github.com/stripe/stripe-go/v72
// Then import the package import ( "github.com/stripe/stripe-go/v72" )// Then import the package import ( "github.com/stripe/stripe-go/v72" )
# Install via dotnet dotnet add package Stripe.net dotnet restore# Install via dotnet dotnet add package Stripe.net dotnet restore
# Or install via NuGet PM> Install-Package Stripe.net# Or install via NuGet PM> Install-Package Stripe.net
2 Create a Checkout Session Server-side
To create a setup mode Session, use the mode
parameter with a value of setup
when creating the Session. See the Checkout Session API
reference for a complete list of parameters
that you can use for Session creation.
Append the {CHECKOUT_SESSION_ID}
template variable to the success_url
to get access
to the Session ID after your customer successfully completes a Checkout Session.
Finally, use the
setup_intent_data.metadata
dictionary to pass your customer’s existing Stripe subscription_id
to the
Checkout Session. Note that there other ways to pass this data to your server,
but we’ll use metadata for this guide.
curl https://api.stripe.com/v1/checkout/sessions \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d "payment_method_types[]"=card \ -d mode=setup \ -d customer=cus_FOsk5sbh3ZQpAU \ -d "setup_intent_data[metadata][subscription_id]"=sub_8epEF0PuRhmltU \ -d success_url="https://example.com/success?session_id={CHECKOUT_SESSION_ID}" \ -d cancel_url="https://example.com/cancel"curl https://api.stripe.com/v1/checkout/sessions \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d "payment_method_types[]"=card \ -d mode=setup \ -d customer=cus_FOsk5sbh3ZQpAU \ -d "setup_intent_data[metadata][subscription_id]"=sub_8epEF0PuRhmltU \ -d success_url="https://example.com/success?session_id={CHECKOUT_SESSION_ID}" \ -d cancel_url="https://example.com/cancel"
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' session = Stripe::Checkout::Session.create( payment_method_types: ['card'], mode: 'setup', customer: 'cus_FOsk5sbh3ZQpAU', setup_intent_data: { metadata: { subscription_id: 'sub_8epEF0PuRhmltU', }, }, success_url: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}', cancel_url: 'https://example.com/cancel', )# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' session = Stripe::Checkout::Session.create( payment_method_types: ['card'], mode: 'setup', customer: 'cus_FOsk5sbh3ZQpAU', setup_intent_data: { metadata: { subscription_id: 'sub_8epEF0PuRhmltU', }, }, success_url: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}', cancel_url: 'https://example.com/cancel', )
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' session = stripe.checkout.Session.create( payment_method_types=['card'], mode='setup', customer='cus_FOsk5sbh3ZQpAU', setup_intent_data={ 'metadata': { 'subscription_id': 'sub_8epEF0PuRhmltU', }, }, success_url='https://example.com/success?session_id={CHECKOUT_SESSION_ID}', cancel_url='https://example.com/cancel', )# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' session = stripe.checkout.Session.create( payment_method_types=['card'], mode='setup', customer='cus_FOsk5sbh3ZQpAU', setup_intent_data={ 'metadata': { 'subscription_id': 'sub_8epEF0PuRhmltU', }, }, success_url='https://example.com/success?session_id={CHECKOUT_SESSION_ID}', cancel_url='https://example.com/cancel', )
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $session = \Stripe\Checkout\Session::create([ 'payment_method_types' => ['card'], 'mode' => 'setup', 'customer' => 'cus_FOsk5sbh3ZQpAU', 'setup_intent_data' => [ 'metadata' => [ 'customer_id' => 'cus_FOsk5sbh3ZQpAU', 'subscription_id' => 'sub_8epEF0PuRhmltU', ], ], 'success_url' => 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => 'https://example.com/cancel', ]);// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $session = \Stripe\Checkout\Session::create([ 'payment_method_types' => ['card'], 'mode' => 'setup', 'customer' => 'cus_FOsk5sbh3ZQpAU', 'setup_intent_data' => [ 'metadata' => [ 'customer_id' => 'cus_FOsk5sbh3ZQpAU', 'subscription_id' => 'sub_8epEF0PuRhmltU', ], ], 'success_url' => 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => 'https://example.com/cancel', ]);
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; SessionCreateParams params = SessionCreateParams.builder() .addPaymentMethodType(SessionCreateParams.PaymentMethodType.CARD) .setMode(SessionCreateParams.Mode.SETUP) .setCustomer("cus_FOsk5sbh3ZQpAU") .setSetupIntentData( SessionCreateParams.SetupIntentData.builder() .putMetadata("customer_id", "cus_FOsk5sbh3ZQpAU") .putMetadata("subscription_id", "sub_8epEF0PuRhmltU") .build()) .setSuccessUrl("https://example.com/success?session_id={CHECKOUT_SESSION_ID}") .setCancelUrl("https://example.com/cancel") .build(); Session session = Session.create(params);// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; SessionCreateParams params = SessionCreateParams.builder() .addPaymentMethodType(SessionCreateParams.PaymentMethodType.CARD) .setMode(SessionCreateParams.Mode.SETUP) .setCustomer("cus_FOsk5sbh3ZQpAU") .setSetupIntentData( SessionCreateParams.SetupIntentData.builder() .putMetadata("customer_id", "cus_FOsk5sbh3ZQpAU") .putMetadata("subscription_id", "sub_8epEF0PuRhmltU") .build()) .setSuccessUrl("https://example.com/success?session_id={CHECKOUT_SESSION_ID}") .setCancelUrl("https://example.com/cancel") .build(); Session session = Session.create(params);
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const session = await stripe.checkout.sessions.create({ payment_method_types: ['card'], mode: 'setup', customer: 'cus_FOsk5sbh3ZQpAU', setup_intent_data: { metadata: { customer_id: 'cus_FOsk5sbh3ZQpAU', subscription_id: 'sub_8epEF0PuRhmltU', }, }, success_url: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}', cancel_url: 'https://example.com/cancel', });// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const session = await stripe.checkout.sessions.create({ payment_method_types: ['card'], mode: 'setup', customer: 'cus_FOsk5sbh3ZQpAU', setup_intent_data: { metadata: { customer_id: 'cus_FOsk5sbh3ZQpAU', subscription_id: 'sub_8epEF0PuRhmltU', }, }, success_url: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}', cancel_url: 'https://example.com/cancel', });
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.CheckoutSessionParams{ PaymentMethodTypes: stripe.StringSlice([]string{ "card", }), Customer: stripe.String("cus_FOsk5sbh3ZQpAU"), SetupIntentData: &stripe.CheckoutSessionSetupIntentDataParams{ Params: stripe.Params{ Metadata: map[string]string { "customer_id": "cus_FOsk5sbh3ZQpAU", "subscription_id": "sub_8epEF0PuRhmltU", }, }, }, Mode: stripe.String(string(stripe.CheckoutSessionModeSetup)), SuccessURL: stripe.String("https://example.com/success?session_id={CHECKOUT_SESSION_ID}"), CancelURL: stripe.String("https://example.com/cancel"), } cs, _ := session.New(params)// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.CheckoutSessionParams{ PaymentMethodTypes: stripe.StringSlice([]string{ "card", }), Customer: stripe.String("cus_FOsk5sbh3ZQpAU"), SetupIntentData: &stripe.CheckoutSessionSetupIntentDataParams{ Params: stripe.Params{ Metadata: map[string]string { "customer_id": "cus_FOsk5sbh3ZQpAU", "subscription_id": "sub_8epEF0PuRhmltU", }, }, }, Mode: stripe.String(string(stripe.CheckoutSessionModeSetup)), SuccessURL: stripe.String("https://example.com/success?session_id={CHECKOUT_SESSION_ID}"), CancelURL: stripe.String("https://example.com/cancel"), } cs, _ := session.New(params)
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new SessionCreateOptions { PaymentMethodTypes = new List<string> { "card", }, Customer = "cus_FOsk5sbh3ZQpAU", SetupIntentData = new SessionSetupIntentDataOptions { Metadata = new Dictionary<string, string> { { "customer_id", "cus_FOsk5sbh3ZQpAU" }, { "subscription_id", "sub_8epEF0PuRhmltU" }, } }, Mode = "setup", SuccessUrl = "https://example.com/success?session_id={CHECKOUT_SESSION_ID}", CancelUrl = "https://example.com/cancel", }; var service = new SessionService(); var session = service.Create(options);// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new SessionCreateOptions { PaymentMethodTypes = new List<string> { "card", }, Customer = "cus_FOsk5sbh3ZQpAU", SetupIntentData = new SessionSetupIntentDataOptions { Metadata = new Dictionary<string, string> { { "customer_id", "cus_FOsk5sbh3ZQpAU" }, { "subscription_id", "sub_8epEF0PuRhmltU" }, } }, Mode = "setup", SuccessUrl = "https://example.com/success?session_id={CHECKOUT_SESSION_ID}", CancelUrl = "https://example.com/cancel", }; var service = new SessionService(); var session = service.Create(options);
3 Redirect to Checkout Client-side
Checkout relies on Stripe.js, Stripe’s foundational JavaScript library for building payment flows.
To get started, include the following script tag on your website—always load it directly from https://js.stripe.com. You can’t include it in a bundle or host it yourself. See Stripe samples for examples.
<script src="https://js.stripe.com/v3/"></script><script src="https://js.stripe.com/v3/"></script>
npm install @stripe/stripe-jsnpm install @stripe/stripe-js
Next, create an instance of the Stripe object by providing your publishable API key as the first parameter:
var stripe = Stripe('pk_test_TYooMQauvdEDq54NiTphI7jx');var stripe = Stripe('pk_test_TYooMQauvdEDq54NiTphI7jx');
import {loadStripe} from '@stripe/stripe-js'; const stripe = await loadStripe('pk_test_TYooMQauvdEDq54NiTphI7jx');import {loadStripe} from '@stripe/stripe-js'; const stripe = await loadStripe('pk_test_TYooMQauvdEDq54NiTphI7jx');
To use Checkout on your website, you must add a snippet of code that includes
the Session id
from the previous step. When your customer
is ready to save or update their payment method, call redirectToCheckout
and provide the Session id
as a parameter.
var checkoutButton = document.getElementById('checkout-button'); checkoutButton.addEventListener('click', function() { stripe.redirectToCheckout({ // Make the id field from the Checkout Session creation API response // available to this file, so you can provide it as argument here // instead of the {{CHECKOUT_SESSION_ID}} placeholder. sessionId: '{{CHECKOUT_SESSION_ID}}' }).then(function (result) { // If `redirectToCheckout` fails due to a browser or network // error, display the localized error message to your customer // using `result.error.message`. }); });var checkoutButton = document.getElementById('checkout-button'); checkoutButton.addEventListener('click', function() { stripe.redirectToCheckout({ // Make the id field from the Checkout Session creation API response // available to this file, so you can provide it as argument here // instead of the {{CHECKOUT_SESSION_ID}} placeholder. sessionId: '{{CHECKOUT_SESSION_ID}}' }).then(function (result) { // If `redirectToCheckout` fails due to a browser or network // error, display the localized error message to your customer // using `result.error.message`. }); });
const checkoutButton = document.getElementById('checkout-button'); checkoutButton.addEventListener('click', () => { stripe.redirectToCheckout({ // Make the id field from the Checkout Session creation API response // available to this file, so you can provide it as argument here // instead of the {{CHECKOUT_SESSION_ID}} placeholder. sessionId: '{{CHECKOUT_SESSION_ID}}' }) // If `redirectToCheckout` fails due to a browser or network // error, display the localized error message to your customer // using `error.message`. });const checkoutButton = document.getElementById('checkout-button'); checkoutButton.addEventListener('click', () => { stripe.redirectToCheckout({ // Make the id field from the Checkout Session creation API response // available to this file, so you can provide it as argument here // instead of the {{CHECKOUT_SESSION_ID}} placeholder. sessionId: '{{CHECKOUT_SESSION_ID}}' }) // If `redirectToCheckout` fails due to a browser or network // error, display the localized error message to your customer // using `error.message`. });
To get started, install the Stripe.js module. Always load Stripe.js directly from https://js.stripe.com. You can’t include it in a bundle or host it yourself.
npm install @stripe/stripe-jsnpm install @stripe/stripe-js
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 or update their payment method, call redirectToCheckout and provide the Session id
as a parameter.
import React from 'react'; import ReactDOM from 'react-dom'; import { loadStripe } from '@stripe/stripe-js'; // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('pk_test_TYooMQauvdEDq54NiTphI7jx'); function App() { const handleClick = async (event) => { // Call your backend to create the Checkout session. const { sessionId } = await fetchCheckoutSession(); // When the customer clicks on the button, redirect them to Checkout. const stripe = await stripePromise; const { error } = await stripe.redirectToCheckout({ sessionId, }); // If `redirectToCheckout` fails due to a browser or network // error, display the localized error message to your customer // using `error.message`. }; return ( <button role="link" onClick={handleClick}> Checkout </button> ); } ReactDOM.render(<App />, document.getElementById('root'));import React from 'react'; import ReactDOM from 'react-dom'; import { loadStripe } from '@stripe/stripe-js'; // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('pk_test_TYooMQauvdEDq54NiTphI7jx'); function App() { const handleClick = async (event) => { // Call your backend to create the Checkout session. const { sessionId } = await fetchCheckoutSession(); // When the customer clicks on the button, redirect them to Checkout. const stripe = await stripePromise; const { error } = await stripe.redirectToCheckout({ sessionId, }); // If `redirectToCheckout` fails due to a browser or network // error, display the localized error message to your customer // using `error.message`. }; return ( <button role="link" onClick={handleClick}> Checkout </button> ); } ReactDOM.render(<App />, document.getElementById('root'));
This code is typically invoked from an event handler that triggers in response to an action taken by your customer, such as clicking on a payment button.
4 Retrieve the Checkout Session Server-side
After a customer successfully completes their Checkout Session, you need to retrieve the Session object. There are two ways to do this:
- Asynchronously: Handle
checkout.session.completed
webhooks, which contain a Session object. Learn more about setting up webhooks. - Synchronously: Obtain the
sessionId
from the URL when a user redirects back to your site (appended to thesuccess_url
) and retrieve the Session object.
curl https://api.stripe.com/v1/checkout/sessions/cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:curl https://api.stripe.com/v1/checkout/sessions/cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' session = Stripe::Checkout::Session.retrieve('cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k')# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' session = Stripe::Checkout::Session.retrieve('cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k')
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' session = stripe.checkout.Session.retrieve('cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k')# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' session = stripe.checkout.Session.retrieve('cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k')
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $session = \Stripe\Checkout\Session::retrieve('cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k');// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $session = \Stripe\Checkout\Session::retrieve('cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k');
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Session session = Stripe.Session.retrieve("cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k");// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Session session = Stripe.Session.retrieve("cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k");
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const session = await stripe.checkout.sessions.retrieve('cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k');// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const session = await stripe.checkout.sessions.retrieve('cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k');
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" session, _ := session.Get("cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k", nil)// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" session, _ := session.Get("cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k", nil)
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var service = new SessionService(); var session = service.Get("cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k");// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var service = new SessionService(); var session = service.Get("cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k");
The right choice depends on your tolerance for dropoff, as customers may not
always reach the success_url
after a successful payment. It’s possible for them
close their browser tab before the redirect occurs. Handling webhooks
prevents your integration from being susceptible to this form of dropoff.
After you have retrieved the Session object, get the value of the setup_intent
key, which is the ID for the SetupIntent created during the Checkout Session. A
SetupIntent is an object used to set up the
customer’s bank account information for future payments.
Example checkout.session.completed
payload:
{ "id": "evt_1Ep24XHssDVaQm2PpwS19Yt0", "object": "event", "api_version": "2019-03-14", "created": 1561420781, "data": { "object": { "id": "cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k", "object": "checkout.session", "billing_address_collection": null, "cancel_url": "https://example.com/cancel", "client_reference_id": null, "customer": "cus_FOsk5sbh3ZQpAU", "customer_email": null, "display_items": [], "mode": "setup", "setup_intent": "seti_1EzVO3HssDVaQm2PJjXHmLlM", "submit_type": null, "subscription": null, "success_url": "https://example.com/success" } }, "livemode": false, "pending_webhooks": 1, "request": { "id": null, "idempotency_key": null }, "type": "checkout.session.completed" }{ "id": "evt_1Ep24XHssDVaQm2PpwS19Yt0", "object": "event", "api_version": "2019-03-14", "created": 1561420781, "data": { "object": { "id": "cs_test_MlZAaTXUMHjWZ7DcXjusJnDU4MxPalbtL5eYrmS2GKxqscDtpJq8QM0k", "object": "checkout.session", "billing_address_collection": null, "cancel_url": "https://example.com/cancel", "client_reference_id": null, "customer": "cus_FOsk5sbh3ZQpAU", "customer_email": null, "display_items": [], "mode": "setup", "setup_intent": "seti_1EzVO3HssDVaQm2PJjXHmLlM", "submit_type": null, "subscription": null, "success_url": "https://example.com/success" } }, "livemode": false, "pending_webhooks": 1, "request": { "id": null, "idempotency_key": null }, "type": "checkout.session.completed" }
Note the setup_intent
ID for the next step.
5 Retrieve the SetupIntent Server-side
Using the setup_intent
ID, retrieve the SetupIntent object using the
/v1/setup_intents/:id endpoint.
curl https://api.stripe.com/v1/setup_intents/seti_1EzVO3HssDVaQm2PJjXHmLlM \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:curl https://api.stripe.com/v1/setup_intents/seti_1EzVO3HssDVaQm2PJjXHmLlM \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' intent = Stripe::SetupIntent.retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM')# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' intent = Stripe::SetupIntent.retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM')
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' intent = stripe.SetupIntent.retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM')# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' intent = stripe.SetupIntent.retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM')
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $intent = \Stripe\SetupIntent::retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM');// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); $intent = \Stripe\SetupIntent::retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM');
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; SetupIntent intent = Stripe.SetupIntent.retrieve("seti_1EzVO3HssDVaQm2PJjXHmLlM");// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; SetupIntent intent = Stripe.SetupIntent.retrieve("seti_1EzVO3HssDVaQm2PJjXHmLlM");
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const intent = await stripe.setupIntents.retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM');// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const intent = await stripe.setupIntents.retrieve('seti_1EzVO3HssDVaQm2PJjXHmLlM');
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" intent, _ := setupintent.Get("seti_1EzVO3HssDVaQm2PJjXHmLlM", nil)// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" intent, _ := setupintent.Get("seti_1EzVO3HssDVaQm2PJjXHmLlM", nil)
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var service = new SetupIntentService(); var intent = service.Get("seti_1EzVO3HssDVaQm2PJjXHmLlM");// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var service = new SetupIntentService(); var intent = service.Get("seti_1EzVO3HssDVaQm2PJjXHmLlM");
Example response:
{ "id": "seti_1EzVO3HssDVaQm2PJjXHmLlM", "object": "setup_intent", "application": null, "cancellation_reason": null, "client_secret": null, "created": 1561420781, "customer": "cus_FOsk5sbh3ZQpAU", "description": null, "last_setup_error": null, "livemode": false, "metadata": { "subscription_id": "sub_8epEF0PuRhmltU" }, "next_action": null, "on_behalf_of": null, "payment_method": "pm_1F0c9v2eZvKYlo2CJDeTrB4n", "payment_method_types": [ "card" ], "status": "succeeded", "usage": "off_session" }{ "id": "seti_1EzVO3HssDVaQm2PJjXHmLlM", "object": "setup_intent", "application": null, "cancellation_reason": null, "client_secret": null, "created": 1561420781, "customer": "cus_FOsk5sbh3ZQpAU", "description": null, "last_setup_error": null, "livemode": false, "metadata": { "subscription_id": "sub_8epEF0PuRhmltU" }, "next_action": null, "on_behalf_of": null, "payment_method": "pm_1F0c9v2eZvKYlo2CJDeTrB4n", "payment_method_types": [ "card" ], "status": "succeeded", "usage": "off_session" }
Note the customer
ID, subscription_id
, and payment_method
ID for the next steps.
6 Set a default payment method Server-side
There are two ways to ensure that a payment method is used for future invoices:
- Set it as the Customer’s
invoice_settings.default_payment_method
- Set it as the Subscription’s
default_payment_method
Setting invoice_settings.default_payment_method
on the Customer will cause all
future invoices for that customer to be paid with the specified payment method.
Setting default_payment_method
on the Subscription will cause all future
invoices for that subscription to be paid with the specified payment method,
overriding any invoice_settings.default_payment_method
set on the associated
Customer.
Set invoice_settings.default_payment_method
on the Customer
Using the customer ID and the PaymentMethod ID you retrieved, set the
invoice_settings.default_payment_method
for the Customer using the
/v1/customers/:id endpoint.
curl https://api.stripe.com/v1/customers/cus_FOsk5sbh3ZQpAU \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d "invoice_settings[default_payment_method]"=pm_1F0c9v2eZvKYlo2CJDeTrB4ncurl https://api.stripe.com/v1/customers/cus_FOsk5sbh3ZQpAU \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d "invoice_settings[default_payment_method]"=pm_1F0c9v2eZvKYlo2CJDeTrB4n
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' Stripe::Customer.update( 'cus_FOsk5sbh3ZQpAU', { invoice_settings: {default_payment_method: 'pm_1F0c9v2eZvKYlo2CJDeTrB4n'}, } )# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' Stripe::Customer.update( 'cus_FOsk5sbh3ZQpAU', { invoice_settings: {default_payment_method: 'pm_1F0c9v2eZvKYlo2CJDeTrB4n'}, } )
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' stripe.Customer.modify( 'cus_FOsk5sbh3ZQpAU', invoice_settings={'default_payment_method': 'pm_1F0c9v2eZvKYlo2CJDeTrB4n'} )# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' stripe.Customer.modify( 'cus_FOsk5sbh3ZQpAU', invoice_settings={'default_payment_method': 'pm_1F0c9v2eZvKYlo2CJDeTrB4n'} )
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); \Stripe\Customer::update( 'cus_FOsk5sbh3ZQpAU', [ 'invoice_settings' => ['default_payment_method' => 'pm_1F0c9v2eZvKYlo2CJDeTrB4n'], ] );// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); \Stripe\Customer::update( 'cus_FOsk5sbh3ZQpAU', [ 'invoice_settings' => ['default_payment_method' => 'pm_1F0c9v2eZvKYlo2CJDeTrB4n'], ] );
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Customer customer = Customer.retrieve("cus_FOsk5sbh3ZQpAU"); Map<String, Object> invoiceSettings = new HashMap<>(); invoiceSettings.put("default_payment_method", "pm_1F0c9v2eZvKYlo2CJDeTrB4n"); Map<String, Object> params = new HashMap<>(); params.put("invoice_settings", invoiceSettings); customer.update(params);// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Customer customer = Customer.retrieve("cus_FOsk5sbh3ZQpAU"); Map<String, Object> invoiceSettings = new HashMap<>(); invoiceSettings.put("default_payment_method", "pm_1F0c9v2eZvKYlo2CJDeTrB4n"); Map<String, Object> params = new HashMap<>(); params.put("invoice_settings", invoiceSettings); customer.update(params);
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const customer = await stripe.customers.update('cus_FOsk5sbh3ZQpAU', { invoice_settings: { default_payment_method: 'pm_1F0c9v2eZvKYlo2CJDeTrB4n', }, });// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const customer = await stripe.customers.update('cus_FOsk5sbh3ZQpAU', { invoice_settings: { default_payment_method: 'pm_1F0c9v2eZvKYlo2CJDeTrB4n', }, });
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.CustomerParams{ InvoiceSettings: &stripe.CustomerInvoiceSettingsParams{ DefaultPaymentMethod: stripe.String("pm_1F0c9v2eZvKYlo2CJDeTrB4n"), }, } c, _ := customer.Update("cus_FOsk5sbh3ZQpAU", params)// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.CustomerParams{ InvoiceSettings: &stripe.CustomerInvoiceSettingsParams{ DefaultPaymentMethod: stripe.String("pm_1F0c9v2eZvKYlo2CJDeTrB4n"), }, } c, _ := customer.Update("cus_FOsk5sbh3ZQpAU", params)
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new CustomerUpdateOptions { InvoiceSettings = new CustomerInvoiceSettingsOptions { DefaultPaymentMethod = "pm_1F0c9v2eZvKYlo2CJDeTrB4n", }, }; var customerService = new CustomerService(); customerService.Update("cus_FOsk5sbh3ZQpAU", options);// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new CustomerUpdateOptions { InvoiceSettings = new CustomerInvoiceSettingsOptions { DefaultPaymentMethod = "pm_1F0c9v2eZvKYlo2CJDeTrB4n", }, }; var customerService = new CustomerService(); customerService.Update("cus_FOsk5sbh3ZQpAU", options);
All future invoices for this customer will now charge the new PaymentMethod created with the setup mode Checkout Session.
Set default_payment_method
on the Subscription
Using the subscription ID and the PaymentMethod ID you retrieved, set the
default_payment_method
for the subscription using the
/v1/subscriptions/:id endpoint.
curl https://api.stripe.com/v1/subscriptions/sub_8epEF0PuRhmltU \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -X POST \ -d default_payment_method=pm_1F0c9v2eZvKYlo2CJDeTrB4ncurl https://api.stripe.com/v1/subscriptions/sub_8epEF0PuRhmltU \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -X POST \ -d default_payment_method=pm_1F0c9v2eZvKYlo2CJDeTrB4n
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' Stripe::Subscription.update( 'sub_8epEF0PuRhmltU', { default_payment_method: 'pm_1F0c9v2eZvKYlo2CJDeTrB4n', } )# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' Stripe::Subscription.update( 'sub_8epEF0PuRhmltU', { default_payment_method: 'pm_1F0c9v2eZvKYlo2CJDeTrB4n', } )
# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' stripe.Subscription.modify( 'sub_8epEF0PuRhmltU', default_payment_method='pm_1F0c9v2eZvKYlo2CJDeTrB4n' )# Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' stripe.Subscription.modify( 'sub_8epEF0PuRhmltU', default_payment_method='pm_1F0c9v2eZvKYlo2CJDeTrB4n' )
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); \Stripe\Subscription::update( 'sub_8epEF0PuRhmltU', [ 'default_payment_method' => 'pm_1F0c9v2eZvKYlo2CJDeTrB4n', ] );// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); \Stripe\Subscription::update( 'sub_8epEF0PuRhmltU', [ 'default_payment_method' => 'pm_1F0c9v2eZvKYlo2CJDeTrB4n', ] );
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Subscription subscription = Subscription.retrieve("sub_8epEF0PuRhmltU"); Map<String, Object> params = new HashMap<>(); params.put("default_payment_method", "pm_1F0c9v2eZvKYlo2CJDeTrB4n"); subscription.update(params);// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Subscription subscription = Subscription.retrieve("sub_8epEF0PuRhmltU"); Map<String, Object> params = new HashMap<>(); params.put("default_payment_method", "pm_1F0c9v2eZvKYlo2CJDeTrB4n"); subscription.update(params);
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const subscription = await stripe.subscriptions.update('sub_8epEF0PuRhmltU', { default_payment_method: 'pm_1F0c9v2eZvKYlo2CJDeTrB4n', });// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const Stripe = require('stripe'); const stripe = Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const subscription = await stripe.subscriptions.update('sub_8epEF0PuRhmltU', { default_payment_method: 'pm_1F0c9v2eZvKYlo2CJDeTrB4n', });
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.SubscriptionParams{ DefaultPaymentMethod: stripe.String("pm_1F0c9v2eZvKYlo2CJDeTrB4n"), } s, _ := subscription.Update("sub_Ffkm3NXSdcHj4c", params)// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.SubscriptionParams{ DefaultPaymentMethod: stripe.String("pm_1F0c9v2eZvKYlo2CJDeTrB4n"), } s, _ := subscription.Update("sub_Ffkm3NXSdcHj4c", params)
// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new SubscriptionUpdateOptions { DefaultPaymentMethod = "pm_1F0c9v2eZvKYlo2CJDeTrB4n", }; var subscriptionService = new SubscriptionService(); subscriptionService.Update("sub_Ffkrxmb0cvYSoG", options);// Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new SubscriptionUpdateOptions { DefaultPaymentMethod = "pm_1F0c9v2eZvKYlo2CJDeTrB4n", }; var subscriptionService = new SubscriptionService(); subscriptionService.Update("sub_Ffkrxmb0cvYSoG", options);
All future invoices for this subscription will now charge the new PaymentMethod
created with the setup mode Checkout Session, overriding any
invoice_settings.default_payment_method
set on the associated Customer.
See also
Congrats! You can now set a default payment method for future invoices. When testing your integration with your test API key, you can use a test card number to ensure that it works correctly.