Skip to content
Create account or Sign in
The Stripe Docs logo
/
Ask AI
Create accountSign in
Get started
Payments
Revenue
Platforms and marketplaces
Money management
Developer resources
APIs & SDKsHelp
OverviewAccept a paymentUpgrade your integration
Online payments
OverviewFind your use case
Use Payment Links
Use a pre-built checkout page
Build a custom integration with Elements
Build an in-app integration
Use Managed PaymentsRecurring payments
In-person payments
Terminal
Payment Methods
Add payment methods
    Overview
    Payment method integration options
    Manage default payment methods in the Dashboard
    Payment method types
    Cards
    Pay with Stripe balance
    Stablecoin payments
    Bank debits
    Bank redirects
    Bank transfers
    Credit transfers (Sources)
    Buy now, pay later
    Real-time payments
    Vouchers
    Wallets
      Alipay
      Amazon Pay
        Accept a payment
        Set up future payments
      Apple Pay
      Cash App Pay
      Google Pay
      GrabPay
      Link
      MB WAY
      MobilePay
      PayPal
      PayPay
      Revolut Pay
      Satispay
      Secure Remote Commerce
      Vipps
      WeChat Pay
    Enable local payment methods by country
    Custom payment methods
Manage payment methods
Faster checkout with Link
Payment operations
Analytics
Balances and settlement time
Compliance and security
Currencies
Declines
Disputes
Fraud prevention
Radar fraud protection
Payouts
ReceiptsRefunds and cancellations
Advanced integrations
Custom payment flows
Flexible acquiring
Multiprocessor orchestration
Beyond payments
Incorporate your company
Crypto
Agentic commerce
Financial Connections
Climate
Verify identities
United States
English (United Kingdom)
HomePaymentsAdd payment methodsWalletsAmazon Pay

Set up future Amazon Pay payments

Learn how to save Amazon Pay details and charge your customers later.

You can use the Setup Intents API 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

To collect payment method details and charge the saved payment method immediately, use the Payment Intents API.

Learn how to set up a subscription with Amazon Pay to create recurring payments after saving a payment method in Checkout.

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:

Command Line
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
# Available as a gem sudo gem install stripe
Gemfile
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
# 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-off 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, you must attach it to a Customer.

Create a Customer object after your customer creates an account on your business. Associating the ID of the Customer object with your own internal representation of a customer enables you to retrieve and use the payment method details that you store later. If your customer hasn’t created an account, you can still create a Customer object and associate it with your internal representation of their account at a later point.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/customers \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ --data-urlencode description="My First Test Customer (created for API docs)"

Present authorisation terms on your payment form
Client-side

Save your customer’s Amazon Pay credentials to charge their account for future off-session payments. Your custom payment form must present a written notice of authorisation before confirming the PaymentIntent or SetupIntent.

You only need to display the authorisation 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 authorise Rocket Rides to debit your Amazon Pay account for this payment and future payments in accordance with Rocket Rides's terms, until this authorisation is revoked.

Use the Setup Intents API 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

Create a SetupIntent and save a payment method
Server-side

A SetupIntent is an object that represents your intent to set up a customer’s payment method for future payments. The SetupIntent tracks the steps of this set up process. Create a SetupIntent on your server with payment_method_types set to amazon_pay and specify the Customer’s ID and usage=off_session or usage=on_session.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/setup_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -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 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.

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 front-end framework such as React. Create the server endpoint that serves the client secret:

main.rb
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
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:

(async () => { const response = await fetch('/secret'); const {client_secret: clientSecret} = await response.json(); // Render the form using the clientSecret })();

Next, you save Amazon Pay on the client with Stripe.js.

Include the Stripe.js script on your checkout page by adding it to the head of your HTML file.

checkout.html
<head> <title>Checkout</title> <script src="https://js.stripe.com/clover/stripe.js"></script> </head>

When a customer clicks to pay with Amazon Pay, use Stripe.js to submit the payment to Stripe. Stripe.js 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.

checkout.html
<head> <title>Checkout</title> <script src="https://js.stripe.com/clover/stripe.js"></script> </head>

Create an instance of Stripe.js with the following JavaScript on your checkout page.

client.js
// 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(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
);

Use stripe.confirmAmazonPaySetup to confirm the setupIntent on the client side, with a return_url and mandate_data. Use the return_url to redirect customers to a specific page after the SetupIntent succeeds.

client.js
// 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. }

OptionalHandle 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 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.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/payment_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -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.
Response
{ "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
Python
PHP
Java
Node.js
Go
.NET
No results
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 to programmatically confirm the status of a payment.

Create a PaymentIntent using a saved payment method
Server-side

After you create a PaymentMethod, you can accept future Amazon Pay payments by creating and confirming a PaymentIntent. 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.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/payment_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -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

OptionalDetach reusable payment method

To deactivate a reusable payment method, your server can call the detach PaymentMethod API. Stripe sends both a mandate.updated event and a payment_method.detached event. You can subscribe to webhook events to get notifications.

Was this page helpful?
YesNo
  • Need help? Contact Support.
  • Check out our changelog.
  • Questions? Contact Sales.
  • LLM? Read llms.txt.
  • Powered by Markdoc