Accept an Afterpay or Clearpay payment
Learn how to accept Afterpay (also known as Clearpay in the UK), a payment method in the US, CA, UK, AU, and NZ.
Caution
The content of this section refers to a Legacy product. You should use the Accept a payment guide for the most recent integration path instead. While Stripe still supports this product, this support might end if the product is deprecated.
Stripe users can use the Payment Intents API—a single integration path for creating payments using any supported method—to accept Afterpay payments from customers in the following countries:
- Australia
- Canada
- New Zealand
- United Kingdom
- United States
Afterpay is a single use, immediate notification payment method that requires customers to authenticate their payment. Customers are redirected to the Afterpay site, where they agree to the terms of an installment plan. When the customer accepts the terms, funds are guaranteed and transferred to your Stripe account. The customer repays Afterpay directly over time.
Note
Before you start the integration, make sure your account is eligible for Afterpay by navigating to your Payment methods settings.
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. First, create a PaymentIntent
on your server and specify the amount to collect and the currency. If you already have an integration using the Payment Intents API, add afterpay_
to the list of payment method types for your PaymentIntent
.
You can manage payment methods from the Dashboard. Stripe handles the return of eligible payment methods based on factors such as the transaction’s amount, currency, and payment flow. The example below uses the automatic_payment_methods attribute but you can list afterpay_
with payment method types. In the latest version of the API, specifying the automatic_
parameter is optional because Stripe enables its functionality by default. Regardless of which option you choose, make sure that you enable Afterpay Clearpay in the Dashboard.
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.
Additional payment method options
You can specify an optional reference
parameter in the payment method options for your PaymentIntent
that sets an internal order identifier for the payment. Although this isn’t typically visible to either the business or the consumer, Afterpay’s internal support team can access it during manual support requests. The identifier is limited to 128 characters and may contain only letters, digits, underscores, backslashes, and dashes.
Submit the payment to StripeClient-side
In this step, you’ll complete Afterpay payments on the client with Stripe.js.
Set up Stripe.js
When a customer clicks to pay with Afterpay, we recommend using Stripe.js to submit the payment to Stripe. Stripe.js is our foundational JavaScript library for building payment flows. It automatically handles complexities like the redirect described below, and enables you to easily extend your integration to other payment methods in the future. Include the Stripe.js script on your checkout page by adding it to the head of your HTML file.
<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.
// Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys var stripe = Stripe(
, );'pk_test_TYooMQauvdEDq54NiTphI7jx'
Rather than sending the entire PaymentIntent object to the client, use its client secret from step 2. This is different from your API keys that authenticate Stripe API requests.
You should still handle the client secret carefully because it can complete the charge. Don’t log it, embed it in URLs, or expose it to anyone but the customer.
Use stripe.confirmAfterpayClearpayPayment to handle the redirect away from your page and to complete the payment. Add a return_url to this function to specify where Stripe redirects the user after they complete the payment on the Afterpay website or mobile application.
// Redirects away from the client const {error} = await stripe.confirmAfterpayClearpayPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}', { payment_method: { billing_details: { email: 'jenny@rosen.com', name: 'Jenny Rosen', address: { line1: '1234 Main Street', city: 'San Francisco', state: 'CA', country: 'US', postal_code: '94111', }, }, }, return_url: 'https://example.com/checkout/complete', } ); if (error) { // Inform the customer that there was an error. }
When your customer submits a payment, Stripe redirects them to the return_
and includes the following URL query parameters. The return page can use them to get the status of the PaymentIntent so it can display the payment status to the customer.
When you specify the return_
, you can also append your own query parameters for use on the return page.
Parameter | Description |
---|---|
payment_ | The unique identifier for the PaymentIntent . |
payment_ | The client secret of the PaymentIntent object. For subscription integrations, this client_secret is also exposed on the Invoice object through confirmation_ |
When the customer is redirected back to your site, you can use the payment_
to query for the PaymentIntent and display the transaction status to your customer.
OptionalAdd line items to the PaymentIntent
You can optionally accept line item data to provide more risk signals to Afterpay. This feature is currently in private beta. Please contact us if you want to request access.
OptionalSeparate authorization and capture
Unlike separate authorization and capture for card payments, Afterpay charges the customer the first installment of the payment at the time of authorization. You then have up to 13 days after authorization to capture the rest of the payment. If you don’t capture the payment in this window, the customer receives a refund of the first installment, and they aren’t charged for any further installments. In these cases, Stripe also cancels the PaymentIntent and sends a payment_intent.canceled event.
If you know that you can’t capture the payment, we recommend canceling the PaymentIntent instead of waiting for the 13-day window to elapse. Proactively canceling the PaymentIntent immediately refunds the first installment to your customer, avoiding any confusion about charges on their statement.
1. Tell Stripe to authorize only
To indicate that you want separate authorization and capture, set capture_method to manual
when creating the PaymentIntent. This parameter instructs Stripe to only authorize the amount on the customer’s Afterpay account.
Upon authorization success, Stripe sends a payment_intent.amount_capturable_updated event. Check out our Events guide for how it may help.
2. Capture the funds
After the authorization succeeds, the PaymentIntent status transitions to requires_
. To capture the authorized funds, make a PaymentIntent capture request. The total authorized amount is captured by default—you can’t capture more than this, but you can capture less.
Optional Cancel the authorization
If you need to cancel an authorization, you can cancel the PaymentIntent.
OptionalHandle the Afterpay redirect manually
We recommend relying on Stripe.js to handle Afterpay redirects and payments client-side with confirmAfterpayClearpayPayment
. Using Stripe.js helps extend your integration to other payment methods. However, you can also manually redirect your customers on your server by following these steps:
Create and confirm a PaymentIntent of type
afterpay_
. You must provide theclearpay payment_
property that is required by Afterpay.method_ data. billing_ details payment_
is optional but recommended for improved authentication rates. By specifyingintent. shipping payment_
, Stripe creates a PaymentMethod and immediately uses it with this PaymentIntent.method_ data You must also provide the redirect URL for your customer after they complete their payment in the
return_
field. You can also provide your own query parameters in this URL. These parameters are included in the final URL upon completing the redirect flow.url The created
PaymentIntent
has a status ofrequires_
and the type foraction next_
isaction redirect_
.to_ url { "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", "amount": 1099,
Redirect the customer to the URL provided in the
next_
property. The code example here is approximate—the redirect method may be different in your web framework.action. redirect_ to_ url. url
When the customer finishes the payment process, they’re sent to the return_
configured in step 1. The payment_
and payment_
URL query parameters are included and you can pass through your own query parameters, as described above.
We recommend that you rely on webhooks to confirm the status of a payment.
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.
OptionalTest Afterpay integration
Test your Afterpay integration with your test API keys by viewing the redirect page. You can test the successful payment case by authenticating the payment on the redirect page. The PaymentIntent will transition from requires_
to succeeded
.
To test the case where the user fails to authenticate, use your test API keys and view the redirect page. On the redirect page, click Fail test payment. The PaymentIntent will transition from requires_
to requires_
.
For manual capture PaymentIntents in testmode, the uncaptured PaymentIntent will auto-expire 10 minutes after successful authorization.
OptionalDisplay payment method messaging on your website
The Payment Method Messaging Element is an embeddable UI component that helps your customers know which buy now, pay later payment options they have at checkout directly from your product, cart, or payment pages.
To add the Payment Method Messaging Element to your website, see Display payment method messaging.

Failed payments 
Afterpay takes into account multiple factors when deciding to accept or decline a transaction (for example, length of time buyer has been using Afterpay, outstanding amount customer has to repay, value of the current order).
You should always present additional payment options such as card
in your checkout flow, as Afterpay payments have a higher rate of decline than many payment methods. In these cases, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions to requires_
.
For an Afterpay PaymentIntent with a status of requires_
, customers need to complete the payment within 3 hours after you redirect them to the Afterpay site (this doesn’t apply to declined payments). If they take no action within 3 hours, the PaymentMethod detaches and the object status for the PaymentIntent automatically transitions to requires_
.
In these cases, inform your customer to try again with a different payment option presented in your checkout flow.
Error codes 
These are the common error codes and corresponding recommended actions:
Error code | Recommended action |
---|---|
payment_ | A generic failure indicating the Afterpay checkout failed. This can also be a decline which does not appear as a decline error code. |
payment_ | Afterpay declined the customer’s payment. As a next step, the customer needs to contact Afterpay for more information. |
payment_ | The customer never completed the payment on Afterpay’s checkout page, and the payment session has expired. Stripe automatically expires Payment Intents that are not successfully authorized 3 hours after initial checkout creation. |
payment_ | Afterpay experienced a service related error and is unable to complete the request. Retry at a later time. |
amount_ | Enter an amount within Afterpay’s default transactions limits for the country. |
amount_ | Enter an amount within Afterpay’s default transactions limits for the country. |