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.
Accepting Afterpay in your app consists of displaying a webview for a customer to authenticate their payment. The customer then returns to your app, and you can immediately confirm whether the payment succeeded or failed.
Note
Before you start the integration, make sure your account is eligible for Afterpay by navigating to your Payment methods settings.
Set up StripeServer-sideClient-side
First, you need a Stripe account. Register now.
Server-side 
This integration requires endpoints on your server that talk to the Stripe API. Use the official libraries for access to the Stripe API from your server:
Client-side 
The Stripe Android SDK is open source and fully documented.
To install the SDK, add stripe-android
to the dependencies
block of your app/build.gradle file:
Note
For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.
Configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API, such as in your Application
subclass:
Note
Stripe samples also use OkHttp and GSON to make HTTP requests to a server.
Create a PaymentIntentServer-sideClient-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.
Server-side 
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
.
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.
Client-side 
Included in the returned PaymentIntent is a client secret, which the client side can use to securely complete the payment process instead of passing the entire PaymentIntent object. On the client, request a PaymentIntent from your server and store its client secret.
Collect payment method detailsClient-side
Afterpay requires billing details to be present for the payment to succeed. In your app, collect the required billing details from the customer:
- Full name (first and last)
- Email address
- Full billing address
Create a PaymentMethodCreateParams with these details.
Additionally, while shipping details aren’t required they can help improve authentication rates. To collect shipping details, collect the following from the customer:
- Full name
- Full shipping address
Create a ConfirmPaymentIntentParams.Shipping with these details.
Submit the payment to StripeClient-side
Retrieve the client secret from the PaymentIntent you created in step 2 and call the PaymentLauncher confirm method. This presents a webview where the customer can complete the payment on their bank’s website or app. Afterwards, onActivityResult is called with the result of the payment.
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. |