# Set up future Amazon Pay payments Learn how to save Amazon Pay details and charge your customers later. # Direct API You can use the [Setup Intents API](https://docs.stripe.com/payments/setup-intents.md) to collect payment method details in advance, with the final amount or payment date determined later. Use this for: - Saving payment methods to a wallet to streamline future purchases - Collecting surcharges after fulfilling a service - [Starting a free trial for a subscription](https://docs.stripe.com/billing/subscriptions/trials.md) To collect payment method details and charge the saved payment method immediately, use the [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md). Learn how to [set up a subscription with Amazon Pay](https://docs.stripe.com/billing/subscriptions/amazon-pay.md) to create recurring payments after saving a payment method in Checkout. ## Set up Stripe [Server-side] First, you need a Stripe account. [Register now](https://dashboard.stripe.com/register). Use our official libraries for access to the Stripe API from your application: #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## Getting permission to save a payment method [Server-side] If you save your customer’s payment method for future use, you need permission. Creating an agreement (sometimes called a mandate) up front allows you to save your customer’s payment details, and charge them when they’re not actively using your website or app. Add terms to your website or app that state how you plan to save your customer’s payment method details, and let your customer opt in. If you plan to charge them when they’re offline, make sure that your terms also cover the following: - The customer’s permission for you to initiate a payment or a series of payments on their behalf for specified transactions - The anticipated frequency (that is, one-time or recurring) and timing of payments - How you determine the payment amount - Your cancellation policy, if you’re setting the payment method up for a subscription service Make sure that you keep a record of your customer’s written agreement to these terms. ## Create or retrieve a customer [Server-side] To save an Amazon Pay payment method for future payments, attach it to an object that represents your customer. > #### Use the Accounts v2 API to represent customers > > The Accounts v2 API is generally available for Connect users, and in public preview for other Stripe users. If you’re part of the Accounts v2 preview, you need to specify a [specify a preview version](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning) in your code. > > To request access to the Accounts v2 preview, > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. Create a customer-configured [Account](https://docs.stripe.com/api/v2/core/accounts/create.md#v2_create_accounts-configuration-customer) or [Customer](https://docs.stripe.com/api/customers/create.md) when your customer creates an account with your business, or when saving a payment method. Associate the object’s ID with your own internal representation of a customer. Create a new customer or retrieve an existing one to associate with this payment. #### Accounts v2 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-05-27.preview" \ --json '{ "contact_email": "jenny.rosen@example.com", "display_name": "Jenny Rosen", "configuration": { "customer": {} }, "include": [ "configuration.customer" ] }' ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d "name=Jenny Rosen" \ --data-urlencode "email=jenny.rosen@example.com" ``` ## Present authorization terms on your payment form [Client-side] Save your customer’s Amazon Pay credentials to charge their account for future *off-session* (A payment is described as off-session if it occurs without the direct involvement of the customer, using previously-collected payment information) payments. Your custom payment form must present a written notice of authorization before confirming the [PaymentIntent](https://docs.stripe.com/api/payment_intents.md) or [SetupIntent](https://docs.stripe.com/api/setup_intents.md). You only need to display the authorization after the first time you save your customer’s Amazon Pay credentials. We recommend that you use the following text for your custom payment form: > By continuing, you authorize Rocket Rides to debit your Amazon Pay account for this payment and future payments in accordance with Rocket Rides's terms, until this authorization is revoked. #### Save a payment method with the Setup Intents API Use the [Setup Intents API](https://docs.stripe.com/payments/setup-intents.md) to collect payment method details in advance and determine the final amount or payment date at a later point. Use it for: - Saving payment methods for customers so their later purchases don’t require authentication - Starting a free trial for a *subscription* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis) ## Create a SetupIntent and save a payment method [Server-side] A [SetupIntent](https://docs.stripe.com/api/setup_intents.md) is an object that represents your intent to set up a customer’s payment method for future payments. Create a `SetupIntent` with the customer’s ID, add `amazon_pay` to the [payment_method_types](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-payment_method_types) array, and set [usage](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-usage) to `off_session` or `on_session`. The `SetupIntent` tracks the steps of the setup process. #### Accounts v2 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=amazon_pay" \ -d "payment_method_data[type]=amazon_pay" \ -d usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/setup_intents \ -u "<>:" \ -d "payment_method_types[]=amazon_pay" \ -d "payment_method_data[type]=amazon_pay" \ -d usage=off_session \ -d customer={{CUSTOMER_ID}} ``` ### Retrieve the client secret The SetupIntent includes a *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) that the client side uses to securely complete the payment process. You can use different approaches to pass the client secret to the client side. #### Single-page application Retrieve the client secret from an endpoint on your server, using the browser’s `fetch` function. This approach is best if your client side is a single-page application, particularly one built with a modern frontend framework like React. Create the server endpoint that serves the client secret: #### Ruby ```ruby get '/secret' do intent = # ... Create or retrieve the SetupIntent {client_secret: intent.client_secret}.to_json end ``` And then fetch the client secret with JavaScript on the client side: ```javascript (async () => { const response = await fetch('/secret'); const {client_secret: clientSecret} = await response.json(); // Render the form using the clientSecret })(); ``` #### Server-side rendering Pass the client secret to the client from your server. This approach works best if your application generates static content on the server before sending it to the browser. Add the [client_secret](https://docs.stripe.com/api/setup_intents/object.md#setup_intent_object-client_secret) in your checkout form. In your server-side code, retrieve the client secret from the SetupIntent: #### Ruby ```erb
``` ```ruby get '/checkout' do @intent = # ... Fetch or create the SetupIntent erb :checkout end ``` Next, you save Amazon Pay on the client with [Stripe.js](https://docs.stripe.com/payments/elements.md). Include the Stripe.js script on your checkout page by adding it to the `head` of your HTML file. ```html Checkout ``` When a customer clicks to pay with Amazon Pay, use Stripe.js to submit the payment to Stripe. [Stripe.js](https://docs.stripe.com/payments/elements.md) is the foundational JavaScript library for building payment flows. It automatically handles complexities like the redirect described below, and enables you to extend your integration to other payment methods. Include the Stripe.js script on your checkout page by adding it to the `head` of your HTML file. ```html Checkout ``` Create an instance of Stripe.js with the following JavaScript on your checkout page. ```javascript // Set your publishable key. Remember to change this to your live publishable key in production! // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe('<>'); ``` Use `stripe.confirmAmazonPaySetup` to confirm the setupIntent on the client side, with a [return_url](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-return_url) and [mandate_data](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-mandate_data). Use the [return_url](https://docs.stripe.com/api/setup_intents/create.md#create_setup_intent-return_url) to redirect customers to a specific page after the SetupIntent succeeds. ```javascript // Redirects away from the client const {error} = await stripe.confirmAmazonPaySetup( '{{SETUP_INTENT_CLIENT_SECRET}}', { return_url: 'https://example.com/setup/complete', mandate_data: { customer_acceptance: { type: 'online', online: { infer_from_client: true } } }, } ); if (error) { // Inform the customer that there was an error. } ``` ## Optional: Handle the Amazon Pay redirect manually Stripe.js helps you extend your integration to other payment methods. However, you can manually redirect your customers on your server. 1. Create and *confirm* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects) a PaymentIntent of type `amazon_pay`. By specifying `payment_method_data`, a PaymentMethod is created and immediately used with the PaymentIntent. You must also provide the URL where your customer is redirected to after they complete their payment in the `return_url` field. You can provide your own query parameters in this URL. These parameters are included in the final URL upon completing the redirect flow. ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1000 \ -d currency=usd \ -d "payment_method_types[]=amazon_pay" \ -d "payment_method_data[type]=amazon_pay" \ --data-urlencode "return_url=https://example.com/checkout/complete" \ -d confirm=true ``` 1. Check that the `PaymentIntent` has a status of `requires_action` and the type for `next_action` is `redirect_to_url`. #### Json ```json {"status": "requires_action", "next_action": { "type": "redirect_to_url", "redirect_to_url": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/checkout/complete" } }, "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", ... } ``` 1. Redirect the customer to the URL provided in the `next_action.redirect_to_url.url` property. This code example is approximate—the redirect method might be different in your web framework. #### Ruby ```ruby if payment_intent.status == 'requires_action' && payment_intent.next_action.type == 'redirect_to_url' url = payment_intent.next_action.redirect_to_url.url redirect(url) end ``` Your customer is redirected to the `return_url` when they complete the payment process. The `payment_intent` and `payment_intent_client_secret` URL query parameters are included along with any of your own query parameters. Stripe recommends setting up a [webhook endpoint](https://docs.stripe.com/payments/payment-intents/verifying-status.md#webhooks) to programmatically confirm the status of a payment. #### Save a payment method with the Payment Intents API Use the [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) to collect payment method details at checkout and save a payment method to a customer. Use this for: - Saving payment methods for customers so their later purchases don’t require authentications - Starting a free trial for a *subscription* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis) ## Create a PaymentIntent and save a payment method [Server-side] A [PaymentIntent](https://docs.stripe.com/api/payment_intents.md) is an object that represents your intent to charge a customer. If you don’t provide a saved payment method with the `PaymentIntent` request, we create a new payment method and attach it to a customer before confirming the `PaymentIntent`. Create a `PaymentIntent` on your server as follows: - Add `amazon_pay` to the [payment_method_types](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types) array. - Specify the ID of the `Customer` or customer-configured `Account`. - Set `confirm` to true. - Set [setup_future_usage](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-setup_future_usage) to `off_session`. - Set the [return_url](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-return_url) to the URL of the page you want to return the customer to after the `PaymentIntent` succeeds. - If you need to create a mandate, set [mandate_data](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-mandate_data). #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=amazon_pay" \ -d "payment_method_data[type]=amazon_pay" \ -d "mandate_data[customer_acceptance][type]=online" \ -d "mandate_data[customer_acceptance][online][ip_address]=127.0.0.0" \ -d "mandate_data[customer_acceptance][online][user_agent]=device" \ --data-urlencode "return_url=https://www.stripe.com" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d setup_future_usage=off_session \ -d amount=1000 \ -d currency=usd \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=amazon_pay" \ -d "payment_method_data[type]=amazon_pay" \ -d "mandate_data[customer_acceptance][type]=online" \ -d "mandate_data[customer_acceptance][online][ip_address]=127.0.0.0" \ -d "mandate_data[customer_acceptance][online][user_agent]=device" \ --data-urlencode "return_url=https://www.stripe.com" \ -d "customer={{CUSTOMER_ID}}" \ -d setup_future_usage=off_session \ -d amount=1000 \ -d currency=usd \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true ``` The returned `PaymentIntent` includes a *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)), which the client side uses to securely complete the payment without needing the `PaymentIntent` object. Pass the client secret to the client-side application to continue with the payment process. ## Create a PaymentIntent using a saved payment method [Server-side] After you create a [PaymentMethod](https://docs.stripe.com/api/payment_methods.md), you can accept future Amazon Pay payments by creating and confirming a [PaymentIntent](https://docs.stripe.com/api/payment_intents.md). When confirming a PaymentIntent, use the same payment method ID from the previous SetupIntent or PaymentIntent object. The `off_session` value must also be set to true if the customer isn’t in a checkout flow for this PaymentIntent. #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=amazon_pay" \ -d "payment_method={{PAYMENTMETHOD_ID}}" \ -d amount=1000 \ -d currency=usd \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=amazon_pay" \ -d payment_method={{PAYMENT_METHOD_ID}} \ -d amount=1000 \ -d currency=usd \ -d customer={{CUSTOMER_ID}} \ -d statement_descriptor=test_statement \ -d capture_method=automatic \ -d confirm=true \ -d off_session=true ``` ## Optional: Detach reusable payment method To deactivate a reusable payment method, your server can call the [detach PaymentMethod](https://docs.stripe.com/api/payment_methods/detach.md) API. Stripe sends both a [mandate.updated](https://docs.stripe.com/api/events/types.md#event_types-mandate.updated) event and a [payment_method.detached](https://docs.stripe.com/api/events/types.md#event_types-payment_method.detached) event. You can subscribe to [webhook](https://docs.stripe.com/webhooks.md) events to get notifications.