Accept a payment with Amazon Pay
Learn how to set up your integration with Amazon Pay.
This guide describes how to embed a custom Stripe payment form in your website or application using the Payment Element. The Payment Element allows you to support Amazon Pay and other payment methods automatically. For more configurations and customisations, refer to the Accept a Payment integration guide.
Set up StripeServer-side
First, you need a Stripe account. Register now.
Use our official libraries for access to the Stripe API from your application:
Create a PaymentIntentServer-side
A PaymentIntent is an object that represents your intent to collect payment from a customer and tracks the lifecycle of the payment process through each stage.
Retrieve the client secret
The PaymentIntent 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.
Collect payment detailsClient-side
Collect payment details on the client with the Payment Element. The Payment Element is a pre-built UI component that simplifies collecting payment details for a variety of payment methods.
The Payment Element contains an iframe that securely sends payment information to Stripe over an HTTPS connection. Avoid placing the Payment Element within another iframe because some payment methods require redirecting to another page for payment confirmation.
The checkout page address must start with https:// rather than http:// for your integration to work. You can test your integration without using HTTPS, but remember to enable it when you’re ready to accept live payments.
Submit the payment to StripeClient-side
Use stripe.confirmPayment to complete the payment using details from the Payment Element. Provide a return_url to this function to indicate where Stripe should redirect the user after they complete the payment. Your user may be first redirected to an intermediate site, such as a bank authorisation page, before being redirected to the return_. Card payments immediately redirect to the return_ when a payment is successful.
Make sure the return_ corresponds to a page on your website that provides the status of the payment. When Stripe redirects the customer to the return_, we provide the following URL query parameters:
| Parameter | Description |
|---|---|
payment_ | The unique identifier for the PaymentIntent. |
payment_ | The client secret of the PaymentIntent object. |
Caution
If you have tooling that tracks the customer’s browser session, you might need to add the stripe. domain to the referrer exclude list. Redirects cause some tools to create new sessions, which prevents you from tracking the complete session.
Use one of the query parameters to retrieve the PaymentIntent. Inspect the status of the PaymentIntent to decide what to show your customers. You can also append your own query parameters when providing the return_, which persist through the redirect process.
Redirect and authenticate transactions
Customers can authenticate Amazon Pay transactions in the browser. After calling confirmPayment, customers are redirected to Amazon Pay’s website to confirm their payment.
When confirmation is complete, customers are redirected to the return_.
OptionalSeparate authorisation and capture
You can separate authorisation and capture to create a charge now, but capture funds later. Stripe cancels the PaymentIntent and sends a payment_intent.canceled event if the payment isn’t captured during the 7-day window.
If you know that you can’t capture the payment, we recommend cancelling the PaymentIntent instead of waiting for the 7-day window to elapse.
Tell Stripe to authorise only
To indicate that you want separate authorisation and capture, set capture_method to manual when creating the PaymentIntent. This parameter instructs Stripe to only authorise the amount on the customer’s Amazon Pay account.
curl https://api.stripe.com/v1/payment_intents \ -u sk_test123: \ -d amount=6000 \ -d confirm=true \ -d currency=usd \ -d "payment_method_types[]"=amazon_pay \ -d "payment_method_data[type]"=amazon_pay \ -d capture_method=manual \ --data-urlencode return_url="https://www.example.com/checkout/done"
Capture the funds
After the authorisation succeeds, the PaymentIntent status transitions to requires_. To capture the authorised funds, make a PaymentIntent capture request.
The total authorised amount is captured by default. You can also specify amount_ which can be less or equal to the total.
Optional Cancel the authorisation
If you need to cancel an authorisation, you can cancel the PaymentIntent.
OptionalHandle post-payment events
Stripe sends a payment_intent.succeeded event when the payment completes. Use the Dashboard, a custom webhook, or a partner solution to receive these events and run actions, like sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events also helps you accept more payment methods in the future. Learn about the differences between all supported payment methods.
Handle events manually in the Dashboard
Use the Dashboard to View your test payments in the Dashboard, send email receipts, handle payouts or retry failed payments.
Build a custom webhook
Build a custom webhook handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI.
Integrate a prebuilt app
Handle common business events, such as automation or marketing and sales, by integrating a partner application.
Test your integration
To test your integration, choose Amazon Pay as the payment method and tap Pay. In a sandbox, this redirects you to a test payment page where you can approve or decline the payment.
In live mode, tapping Pay redirects you to the Amazon Pay website – you don’t have the option to approve or decline the payment with Amazon Pay.
Failed payments
If Amazon Pay declines the transaction for any reason, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions to requires_.
Other than a payment being declined, if an Amazon Pay PaymentIntent has a status of requires_, customers must complete the payment within 10 minutes after they’re redirected to Amazon. If no action is taken after 10 minutes, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions to requires_.
When this happens, the Payment Element renders error messages and instructs your customer to retry using a different payment method.
Error codes
The following table details common error codes and recommended actions:
| Error Code | Recommended Action |
|---|---|
payment_ | Enter the appropriate currency. Amazon Pay only supports usd. |
missing_ | Check the error message for more information about the required parameter. |
payment_ | This code can appear in the last_payment_error.code field of a PaymentIntent. Check the error message for a detailed failure reason and suggestion on error handling. |
payment_ | Provide a return_ when confirming a PaymentIntent with Amazon Pay. |