Next Commerce

Afterpay Admin API Guide

Afterpay is a fully integrated Buy Now Pay Later (BNPL) payment method via Stripe, supported in the storefront checkout and through the Admin API.

Afterpay transactions send the customer through an Afterpay redirect flow, with the resulting order information returned to your application. Before using Afterpay, activate it on the Stripe account connected to the gateway. In the United Kingdom the same method is branded Clearpay.

API Payment Redirect Flow

Below is a high-level overview of the user flow when creating orders on the Admin API that utilize the payment method redirect flow.

Create Order on Admin API

When creating an order with the orders_create API method, specify payment_method=afterpay and provide a payment_return_url. The payment_return_url is your endpoint that receives a POST request containing the final order data.

Payment Details for Order with Afterpay
{
    "payment_method": "afterpay",
    "payment_details": {
        "payment_return_url": "<external checkout url>",
        "payment_gateway": "<gateway id>", // optional
        "payment_gateway_group": "<gateway group id>" // optional
    }
}

You can optionally provide a payment_gateway when creating the order to use an Afterpay account connected to a specific gateway.

Redirect Customer to Afterpay

The order response provides a payment_complete_url. Redirect the customer to this URL to complete the payment with Afterpay.

Response with Payment Complete URL
{
    "reference_transaction_id": null,
    "payment_complete_url": "<unique checkout url>"
}

Receiving Order Data

After the customer has completed their payment, they will be redirected to your application with a POST request containing data in the response key comprising all of the order information as a string. See examples below.

Order data structure follows Admin Order API and is application/x-www-form-urlencoded in a variable called response. If the order data is an empty dictionary , it means payment collection was unsuccessful and the order was not created.

Example Parsing of Order Data
import json

def order_receiver_view(request):
    data = json.loads(request.POST.get("response"))
    ...
    return HttpResponse(status=201)

Upsells

One-click post-purchase upsells are not supported with Afterpay payments. Afterpay authorizes a single sale and the payment method cannot be reused for a later merchant-initiated charge.

Recurring

Afterpay cannot be used as the payment method for an order with subscription items.

On this page