Skip to content
Create account or Sign in
The Stripe Docs logo
/
Ask AI
Create accountSign in
Get started
Payments
Revenue
Platforms and marketplaces
Money management
Developer resources
APIs & SDKsHelp
Overview
About Stripe payments
Upgrade your integration
Payments analytics
Online payments
OverviewFind your use caseUse Managed Payments
Use Payment Links
Use a pre-built checkout page
Build a custom integration with Elements
Build an in-app integration
Payment Methods
Add payment methods
    Overview
    Payment method integration options
    Manage default payment methods in the Dashboard
    Payment method types
    Cards
    Pay with Stripe balance
    Stablecoin payments
    Bank debits
    Bank redirects
    Bank transfers
    Credit transfers (Sources)
    Buy now, pay later
      Affirm
      Afterpay / Clearpay
        Accept a payment
        Site messaging
      Alma
      Billie
      Capchase Pay
      Klarna
      Kriya
      Mondu
      Payment on Invoice
      Scalapay
      SeQura
      Sunbit
      Zip
    Real-time payments
    Vouchers
    Wallets
    Enable local payment methods by country
    Custom payment methods
Manage payment methods
Faster checkout with Link
Payment interfaces
Payment Links
Checkout
Web Elements
In-app payments
Payment scenarios
Handle multiple currencies
Custom payment flows
Flexible acquiring
Orchestration
In-person payments
Terminal
Beyond payments
Incorporate your company
Crypto
Agentic commerce
Financial Connections
Climate
Understand fraud
Radar fraud protection
Manage disputes
Verify identities
United States
English (United Kingdom)
HomePaymentsAdd payment methodsBuy now, pay laterAfterpay / Clearpay

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 Stripe
Server-side
Client-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:

Command Line
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
# Available as a gem sudo gem install stripe
Gemfile
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
# If you use bundler, you can add this line to your Gemfile gem 'stripe'

Client-side

The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above.

To install the SDK, follow these steps:

  1. In Xcode, select File > Add Package Dependencies… and enter https://github.com/stripe/stripe-ios-spm as the repository URL.
  2. Select the latest version number from our releases page.
  3. Add the StripePaymentsUI product to the target of your app.

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 on app start. This enables your app to make requests to the Stripe API.

AppDelegate.swift
Swift
Objective-C
No results
import UIKit import StripePaymentsUI @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { StripeAPI.defaultPublishableKey =
"pk_test_TYooMQauvdEDq54NiTphI7jx"
// do any other necessary launch configuration return true } }

Note

Use your test keys while you test and develop, and your live mode keys when you publish your app.

Create a PaymentIntent
Server-side
Client-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_clearpay to the list of payment method types for your PaymentIntent.

Command Line
curl
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/payment_intents \ -u
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:
\ -d "amount"=1099 \ -d "currency"="usd" \ -d "payment_method_types[]"="afterpay_clearpay"

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.

Command Line
curl
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/payment_intents \ -u
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:
\ -d "amount"=1099 \ -d "currency"="usd" \ -d "payment_method_types[]"="afterpay_clearpay" \ -d "payment_method_options[afterpay_clearpay][reference]"="order_123"

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.

Swift
Objective C
No results
import UIKit import StripePayments class CheckoutViewController: UIViewController { var paymentIntentClientSecret: String? func startCheckout() { // Request a PaymentIntent from your server and store its client secret } }

Collect payment method details
Client-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 an STPPaymentMethodParams object 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 an STPPaymentIntentShippingDetailsAddressParams with these details.

Swift
Objective C
No results
// Billing details let billingDetails = STPPaymentMethodBillingDetails() billingDetails.name = "Jane Doe" billingDetails.email = "email@email.com" let billingAddress = STPPaymentMethodAddress() billingAddress.line1 = "510 Townsend St." billingAddress.postalCode = "94102" billingAddress.country = "US" billingDetails.address = billingAddress // Afterpay PaymentMethod params let afterpayParams = STPPaymentMethodParams(afterpayClearpay: STPPaymentMethodAfterpayClearpayParams(), billingDetails: billingDetails, metadata: nil) // Shipping details // Shipping details are optional but recommended to pass in. let shippingAddress = STPPaymentIntentShippingDetailsAddressParams(line1: "510 Townsend St.") shippingAddress.country = "US" shippingAddress.postalCode = "94102" let shippingDetails = STPPaymentIntentShippingDetailsParams(address: shippingAddress, name: "Jane Doe")

Submit the payment to Stripe
Client-side

Retrieve the client secret from the PaymentIntent you created in step 2 and call the STPPaymentHandler confirmPayment: method. This presents a webview where the customer can complete the payment, after which the completion block is called with the result of the payment.

Swift
Objective C
No results
let paymentIntentParams = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret) paymentIntentParams.paymentMethodParams = afterpayParams // Shipping details are optional but recommended to pass in. paymentIntentParams.shipping = shippingDetails STPPaymentHandler.shared().confirmPayment(paymentIntentParams, with: self) { (handlerStatus, paymentIntent, error) in switch handlerStatus { case .succeeded: // Payment succeeded case .canceled: // Payment was canceled case .failed: // Payment failed @unknown default: fatalError() } }

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 authorisation and capture for card payments, Afterpay charges the customer the first instalment of the payment at the time of authorisation. You then have up to 13 days after authorisation 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 instalment, and they aren’t charged for any further instalments. 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 cancelling the PaymentIntent instead of waiting for the 13-day window to elapse. Proactively cancelling the PaymentIntent immediately refunds the first instalment to your customer, avoiding any confusion about charges on their statement.

  • Tell Stripe to authorize 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 Afterpay account.

    Command Line
    curl
    Ruby
    Python
    PHP
    Java
    Node.js
    Go
    .NET
    No results
    curl https://api.stripe.com/v1/payment_intents \ -u
    sk_test_BQokikJOvBiI2HlWgH4olfQ2
    :
    \ -d "amount"=1099 \ -d "currency"="usd" \ -d "payment_method_types[]"="afterpay_clearpay" \ -d "capture_method"="manual" \ -d "shipping[name]"="Jenny Rosen" \ -d "shipping[address][line1]"="1234 Main Street" \ -d "shipping[address][city]"="San Francisco" \ -d "shipping[address][state]"="CA" \ -d "shipping[address][country]"="US" \ -d "shipping[address][postal_code]"=94111

    Upon authorisation success, Stripe sends a payment_intent.amount_capturable_updated event. Check out our Events guide for how it may help.

  • Capture the funds
  • After the authorisation succeeds, the PaymentIntent status transitions to requires_capture. To capture the authorised funds, make a PaymentIntent capture request. The total authorised amount is captured by default – you can’t capture more than this, but you can capture less.

    Command Line
    cURL
    Stripe CLI
    Ruby
    Python
    PHP
    Java
    Node.js
    Go
    .NET
    No results
    curl https://api.stripe.com/v1/payment_intents/
    {{PAYMENT_INTENT_ID}}
    /capture
    \ -u "
    sk_test_BQokikJOvBiI2HlWgH4olfQ2
    :"
    \ -d amount_to_capture=750

    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.

    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_action 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_action to requires_payment_method.

    For manual capture PaymentIntents in testmode, the uncaptured PaymentIntent will auto-expire 10 minutes after successful authorization.

    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_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 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_payment_method.

    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 codeRecommended action
    payment_intent_payment_attempt_failedA generic failure indicating the Afterpay checkout failed. This can also be a decline which does not appear as a decline error code.
    payment_method_provider_declineAfterpay declined the customer’s payment. As a next step, the customer needs to contact Afterpay for more information.
    payment_intent_payment_attempt_expiredThe customer never completed the payment on Afterpay’s checkout page and the payment session has expired. Stripe automatically expires PaymentIntents that aren’t successfully authorised 3 hours after initial checkout creation.
    payment_method_not_availableAfterpay experienced a service related error and is unable to complete the request. Retry at a later time.
    amount_too_smallEnter an amount within Afterpay’s default transactions limits for the country.
    amount_too_largeEnter an amount within Afterpay’s default transactions limits for the country.
    Was this page helpful?
    YesNo
    • Need help? Contact Support.
    • Check out our changelog.
    • Questions? Contact Sales.
    • LLM? Read llms.txt.
    • Powered by Markdoc