Skip to content
Create account
or
Sign in
The Stripe Docs logo
/
Ask AI
Create account
Sign in
Get started
Payments
Revenue
Platforms and marketplaces
Money management
Developer resources
Overview
Billing
OverviewAbout the Billing APIs
Subscriptions
    Overview
    How subscriptions work
    Get started
    Quickstart
    Plan an integration
    Build an integration
    Use cases
    About subscriptions
    Enable billing mode
    Subscription event definitions
    Entitlements
    Subscription invoices
    Subscription schedules
    Recurring pricing models
    Strong Customer Authentication (SCA)
    Set up subscriptions
    Configure collection methods
    Embed a pricing table
    Set quantities
    Set billing cycles
    Manage subscriptions
    Migrate subscriptions to Stripe
    Subscribe to multiple items
    Backdate subscriptions
    Set trial periods
    Handle subscriptions with deferred payment
    Apply coupons
    Modify subscriptions
    Manage subscription payment methods
      ACH Direct Debit
      Amazon Pay
      Bacs Direct Debit in the UK
      Bank transfer
      BECS Direct Debit in Australia
      Cash App Pay
      PayPal
      Revolut Pay
      Korean Cards
      Kakao Pay
      Naver Pay
      Pre-authorized debit in Canada
      SEPA Direct Debit in the EU
      iDEAL with SEPA Direct Debit
      Bancontact with SEPA Direct Debit
    Analytics
Invoicing
Usage-based billing
Quotes
Customer management
Billing with other products
Revenue recovery
Automations
Test your integration
Tax
Overview
Use Stripe tax
Manage compliance
Reporting
Overview
Select a report
Configure reports
Reports API
Reports for multiple accounts
Revenue recognition
Data
OverviewSchema
Custom reports
Data Pipeline
Data management
HomeRevenueSubscriptionsManage subscription payment methods

Set up a subscription with Amazon Pay

Learn how to create and charge for a subscription with Amazon Pay.

Use this guide to set up a subscription using Amazon Pay as a payment method.

Create and confirm a subscription using two API calls. The first API call uses the Setup Intents API to set Amazon Pay as a payment method. The second API call sends customer, product, and payment method information to the Subscriptions API to create a Subscription and confirm a payment in one call.

Create a product and price
Dashboard

Products represent the item or service you’re selling. Prices define how much and how frequently you charge for a product. This includes how much the product costs, what currency you accept, and whether it’s a one-time or recurring charge. If you only have a few products and prices, create and manage them in the Dashboard.

This guide uses a stock photo service as an example and charges customers a 15 USD monthly subscription. To model this:

  1. Go to the Products page and click Create product.
  2. Enter a Name for the product. You can optionally add a Description and upload an image of the product.
  3. Select a Product tax code. Learn more about product tax codes.
  4. Select Recurring. Then enter 15 for the price and select USD as the currency.
  5. Choose whether to Include tax in price. You can either use the default value from your tax settings or set the value manually. In this example, select Auto.
  6. Select Monthly for the Billing period.
  7. Click More pricing options. Then select Flat rate as the pricing model for this example. Learn more about flat rate and other pricing models.
  8. Add an internal Price description and Lookup key to organize, query, and update specific prices in the future.
  9. Click Next. Then click Add product.

After you create the product and the price, record the price ID so you can use it in subsequent steps. The pricing page displays the ID and it looks similar to this: price_G0FvDp6vZvdwRZ.

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
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)"

Create a SetupIntent
Server-side

Create a SetupIntent to save a customer’s payment method for future payments. 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
No results
curl https://api.stripe.com/v1/setup_intents \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d confirm=true \ --data-urlencode return_url="https://www.stripe.com" \ -d usage=off_session \ -d customer=cus_ODQluYFNl44ODI \ -d "payment_method_data[type]"=amazon_pay \ -d "payment_method_types[]"=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

The SetupIntent object contains a client_secret, which is a unique key that you must pass to Stripe.js on the client side to redirect your buyer to Amazon Pay and authorize the mandate.

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 frontend framework like React. Create the server endpoint that serves the client secret:

main.rb
Ruby
Python
PHP
Java
Node
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, 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/basil/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/basil/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. }

Create a subscription
Server-side

Create a subscription that has a price and a customer. Set the value of the default_payment_method parameter to the PaymentMethod ID from the SetupIntent response.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node
Go
.NET
No results
curl https://api.stripe.com/v1/subscriptions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d customer={{CUSTOMER_ID}} \ -d "items[0][price]"={{PRICE_ID}} \ -d default_payment_method={{PAYMENT_METHOD_ID}} \ -d off_session=true

Creating subscriptions automatically charges customers due to the pre-set default payment method. After a successful payment, the status in the Stripe Dashboard changes to Active. The price that you previously set up determines the amount for future billings. Learn how to create a subscription with a free trial period.

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