Afterpay Button on Android
The Afterpay Button runs entirely in your app. You pass the order details to the SDK, the customer completes checkout, and the SDK returns a one-time virtual card for the order. You process the card through your existing card payments flow, so your server doesn’t need an Afterpay API integration.
The SDK supports the Afterpay Button in the US and Canada. The SDK calls it Checkout V3.
Step 1: Configure the SDK
Set the Afterpay Button configuration when your app starts. Your Afterpay account manager provides your shopDirectoryMerchantId.
The Afterpay Button doesn’t need your server to fetch the merchant configuration. To show UI components, such as the payment button and price breakdown, fetch the configuration with the SDK and set it. fetchMerchantConfigurationV3 makes a network request, so call it off the main thread:
Step 2: Start the checkout
When the customer taps your payment button, launch the intent from createCheckoutV3Intent with the customer and order details:
consumerimplementsCheckoutV3Consumer. The SDK’sConsumerclass takes the email address, and optionally the name, phone number, and shipping and billing addresses.orderTotal.totalis the amount to charge, including shipping and tax. The SDK sendsshippingandtaxfor fraud detection.itemsis optional. The SDK doesn’t use it to calculate the total.- Set
buyNowtotrueto show a Buy Now button at the end of checkout.
createCheckoutV3Intent throws an IllegalArgumentException if you haven’t set the configuration. A cancellation returns a CancellationStatusV3 of USER_INITIATED or REQUEST_ERROR, with the exception for REQUEST_ERROR.
Step 3: Process the virtual card
A successful result contains CheckoutV3Data:
Authorize the card through your card processor before cardValidUntil, as you would any other card payment.
Step 4: Update the merchant reference
If you don’t have an order number when the checkout starts, associate the order with the virtual card after you create the order. updateMerchantReferenceV3 blocks, so call it off the main thread, or use updateMerchantReferenceV3Async, which returns a CompletableFuture:
Accept Cash App Pay
You can also offer Cash App Pay with the Afterpay Button. The SDK creates the checkout and signs it for Cash App Pay Kit. For the full flow, see Cash App Pay on Android.