CheckOut Services icon

CheckOut Services

On this page, we will follow the lifecycle of a transaction in detail, with examples of API calls to the AfterPay eCommerce API, and expected responses.

We encourage you to read through the descriptions here from start to finish, to get an overall grasp of the AfterPay eCommerce API and how it works. Then you can refer back as you integrate your webshop.

The examples are in JSON format, for the AfterPay eCommerce REST API v3. Examples in other formats are available in our detailed API documentation.

One-Step Authorization

Astrid places the items into her Cart, and goes to the Checkout page. She sees AfterPay as an option, and selects it.

When she clicks the Buy button, the shop sends a GET call to the AUTHORIZE endpoint of the AfterPay eCommerce API. This call contains Astrid’s name, email, national ID number, and postal address; and the details of the items she is buying. The API responds with a confirmation.

Now a reservation exists in AfterPay’s accounts, in the merchant’s name, for the purchase price. Before responding, AfterPay has used the provided details to run a risk/credit check, and is happy to accept this invoice.

The API call contains the following blocks:

Payment

This determines the payment method, out of those offered by AfterPay.

  • Invoice – the standard 14-day invoice.
  • ConsolidatedInvoice – all captured purchases of this type within a given period (usually a calendar month) are combined into a single 14-day invoice, issued at the end of the period.
  • Fixed Instalment – a fixed-term consumer loan. The customer can pay off the purchase over a fixed number of monthly installments.
    • When using this payment type, you must always include the profileNo value. The correct values will be provided by your Key Account Manager, as they must be configured in the AfterPay backend.
  • Flex Payment – a Minimum-to-Pay method. Instead of paying off the invoice in one go, the customer chooses an amount to pay each month, until the entire amount (including interest and fees) are paid off.
    • When using this payment type, you must always include the profileNo value. The correct values will be provided by your Key Account Manager, as they must be configured in the AfterPay backend.

Any method besides Invoice requires additional information; see the detailed API documentation for more.

Customer

This contains the customer’s personally identifiable information, including their postal address.

Mandatory fields depend on the country. Click here to see which fields are required for each country.

Order

This contains the details of the purchase:

  • Number – this is a unique identifier for the order. It is provided by the merchant, and can be human-readable.
    • Can contain letters, numbers, dashes, and underscores.
    • Not case-sensitive.
  • TotalGrossAmount – the full payable amount of the order. Sum of grossUnitPrice * quantity for all Order Items.

These are the minimum mandatory fields. Further information can be included if you are using special AfterPay features. See the detailed API documentation for more.

Order.Items

Details of the items being purchased

Order item details can be provided either in the AUTHORIZE call, or in the CAPTURE call. If they were not included in AUTHORIZE, they are mandatory for CAPTURE. If they are different, the later details (in CAPTURE) override the earlier ones (in AUTHORIZE).

For each order item, the following information is provided:

  • ProductID – the unique identifier of the item in the invoice. Provided by the merchant. Can be equivalent to the merchant’s own SKU.
  • Description – the name of the item, as it appears on the invoice line.
  • ImageURL – the product image. Optional.
  • GrossUnitPrice – the price for one unit of this item, including VAT.
    • In the base currency of the customer’s country.
    • Optional if vatPercent and netUnitPrice are provided. Otherwise mandatory.
  • vatPercent – the VAT rate for this item, in percent.
    • Optional if grossUnitPrice and netUnitPrice are provided. Otherwise mandatory.
    • Can be replaced with vatAmount – provided as a currency value, not a percentage.
  • NetUnitPrice – the price for one unit of this item, including VAT.
    • In the base currency of the customer’s country.
    • Optional if vatPercent and grossUnitPrice are provided. Otherwise mandatory.
  • Quantity – the amount of units of this item included in the purchase.
  • Type – optional parameter used to identify items like digital downloads, shipping fees, etc. These are handled differently from normal items during refunds and for accounting purposes.
  • LineNumber – the sequential position of this order item’s invoice line within the invoice. Optional.
    • If this is not provided, or two items have the same line number, they are sorted alphabetically by Description.

Further information can be included if you are using special AfterPay features. See the detailed API documentation for more.

POST https://sandbox.afterpay.io/api/v3/checkout/authorize


{
  "payment": {
    "type": "Invoice"
  },
  "customer": {
    "identificationNumber": "800119-3989",
    "salutation": "Mrs",
    "firstName": "Astrid",
    "lastName": "Svensson",
    "email": "astrid.svensson@example.com",
    "customerCategory": "Person",
    "address": {
      "street": "Kungsgatan",
      "streetNumber": "66",
      "postalCode": "11122",
      "postalPlace": "Stockholm",
      "countryCode": "SE"
    }
  },
  "order": {
    "number": "afterpay1",
    "totalGrossAmount": 2085.0,
    "items": [
      {
        "productId": "0001-BLK-M",
        "description": "Leather jacket, Black, size M",
        "grossUnitPrice": 1000.0,
        "quantity": 1.0,
        "vatPercent": 20.0,
        "imageUrl": "https://cdn.afterpay.io/dev-portal/images/black_leather_jacket.jpg",
        "lineNumber": 1
      },
      {
        "productId": "0001-BLK-S",
        "description": "Leather jacket, Black, size S",
        "grossUnitPrice": 1000.0,
        "quantity": 1.0,
        "vatPercent": 20.0,
        "imageUrl": "https://cdn.afterpay.io/dev-portal/images/black_leather_jacket.jpg",
        "lineNumber": 2
      },
      {
        "productId": "0002-GRY-M",
        "description": "Socks, Grey, Size M",
        "grossUnitPrice": 10.0,
        "quantity": 5.0,
        "vatPercent": 20.0,
        "imageUrl": "https://cdn.afterpay.io/dev-portal/images/grey_socks.jpg",
        "lineNumber": 3
      },
      {
        "productId": "0004-BRN-M",
        "description": "Woolen hat, brown, Size M",
        "grossUnitPrice": 30.0,
        "quantity": 1.0,
        "vatPercent": 20.0,
        "imageUrl": "http://cdn.afterpay.io/dev-portal/images/brown_wool_hat.jpg",
        "lineNumber": 4
      }
    ]
  }
}

RESPONSE from eCom API


{
  "Outcome": "Accepted",
  "Customer": {
    "CustomerNumber": "809303697",
    "FirstName": "Astrid",
    "LastName": "Svensson",
    "AddressList": [
      {
        "Street": "Kungsgatan",
        "StreetNumber": "66",
        "PostalCode": "11122",
        "PostalPlace": "Stockholm",
        "CountryCode": "SE"
      }
    ]
  },
  "ReservationId": "9453e3d5-ac75-48d9-b2d2-e599b9cbe6c7",
  "CheckoutId": "47dd743b-99fc-4ec3-a7d3-db802008ff96"
}