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.
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
curlhttps://api.stripe.com/v1/customers \
-u"
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:" \
--data-urlencodedescription="My First Test Customer (created for API docs)"
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 authorization before confirming the PaymentIntent or SetupIntent.
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.
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
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.
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.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 =awaitfetch('/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.
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.
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/apikeysconst 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 clientconst{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.}
Stripe.js helps you extend your integration to other payment methods. However, you can manually redirect your customers on your server.
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.
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.
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.