| [ Web Proxy ] |
| Viewing: https://docs.stripe.com/payments/afterpay-clearpay/accept-a-payment | [Back] [Original] |
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, Afterpay guarantees that the funds are available to the customer and transfers the funds to your Stripe account. The customer repays Afterpay directly over time.
Before you start the integration, make sure your account is eligible for Afterpay by navigating to your Payment methods settings.
Customer Geography: Australia, Canada, New Zealand, UK, US
Supported currencies: aud, cad, nzd, gbp, usd
Presentment currencies: aud, cad, nzd, gbp, usd
Payment mode: Yes
Setup mode: No
Subscription mode: No
A Checkout Session must satisfy all of the following conditions to support Afterpay payments:
This guide builds on the foundational accept a payment Checkout integration.
When creating a new Checkout Session, you need to:
payment_method_types, see the migration guide.line_items use your domestic currency and the total amount doesnt exceed Afterpays transaction amount limits.shipping_address_collection[allowed_countries].curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_wU7nrJCZspk1NPDxiQgAF05q:" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "shipping_address_collection[allowed_countries][0]=AU" \ -d "shipping_address_collection[allowed_countries][1]=CA" \ -d "shipping_address_collection[allowed_countries][2]=GB" \ -d "shipping_address_collection[allowed_countries][3]=NZ" \ -d "shipping_address_collection[allowed_countries][4]=US" \ --data-urlencode "success_url=https://example.com/success"
If you dont want to collect shipping addresses with Checkout, you can also provide the shipping address using payment_intent_data[shipping]. Doing so helps with loan acceptance rates.
curl https://api.stripe.com/v1/checkout/sessions \ -u "sk_test_wU7nrJCZspk1NPDxiQgAF05q:" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_intent_data[shipping][name]=Jenny Rosen" \ -d "payment_intent_data[shipping][address][line1]=1234 Main Street" \ -d "payment_intent_data[shipping][address][city]=San Francisco" \ -d "payment_intent_data[shipping][address][state]=CA" \ -d "payment_intent_data[shipping][address][country]=US" \ -d "payment_intent_data[shipping][address][postal_code]=94111" \ --data-urlencode "success_url=https://example.com/success"
Use a method such as webhooks to handle order fulfillment, instead of relying on your customer to return to the payment status page.
The following events are sent when the payment status changes:
| Event Name | Description | Next steps |
|---|---|---|
| checkout.session.completed | The customer successfully authorized the payment by submitting the Checkout form. | Wait for the payment to succeed or fail. |
| payment_intent.succeeded | The customers payment succeeded. The PaymentIntent transitions to succeeded. | Fulfill the goods or services that the customer purchased. |
| payment_intent.payment_failed | The customers payment was declined, or failed for some other reason. The PaymentIntent returns to the requires_payment_method status. | Email the customer to request that they place a new order. |
Learn more about fulfilling orders.
When testing your Checkout integration, select Afterpay as the payment method and click the Pay button.
Test your Afterpay integration with your test API keys by viewing the redirect page. You can test a successful payment by authenticating the payment on the redirect page. The PaymentIntent will transition from requires_action to succeeded.
To test authentication failure, use your test API keys and view the redirect page. On the redirect page, click Fail test payment. The PaymentIntent will transition from requires_action to requires_payment_method.
For manual capture PaymentIntents in testmode, the uncaptured PaymentIntent will auto-expire 10 minutes after successful authorization.
Afterpay takes into account multiple factors when deciding to accept or decline a transaction (for example, the length of time the customer has been using Afterpay, the outstanding amount the customer has to repay, or the 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 objects status automatically transitions to requires_payment_method.
For an Afterpay PaymentIntent with a status of requires_action, customers need to complete the payment within 3 hours after you redirect them to the Afterpay site (this doesnt 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_payment_method.
In these cases, inform your customer to try again with a different payment option presented in your checkout flow.
These are the common error codes and corresponding recommended actions:
| Error code | Recommended action |
|---|---|
payment_intent_payment_attempt_failed | A generic failure indicating the Afterpay checkout failed. This can also be a decline which doesnt appear as a decline error code. |
payment_method_provider_decline | Afterpay declined the customers payment. As a next step, the customer needs to contact Afterpay for more information. |
payment_intent_payment_attempt_expired | The customer never completed the payment on Afterpays checkout page, and the payment session has expired. Stripe automatically expires PaymentIntents that arent successfully authorized 3 hours after initial checkout creation. |
payment_method_not_available | Afterpay experienced a service related error and is unable to complete the request. Retry at a later time. |
amount_too_small | Enter an amount within Afterpays default transactions limits for the country. |
amount_too_large | Enter an amount within Afterpays default transactions limits for the country. |
| Web Proxy Viewer | New URL | Original Page |