---
updatedAt: 2025-11-13T14:17:43.000Z
agentTools:
  siteIndex: https://docs.affirm.com/llms.txt
  projectIndex: https://docs.affirm.com/payments/llms.txt
---

# About Direct API

Explore how Affirm’s Direct API enables flexible pay-over-time options by directly embedding the checkout and transaction flow into your website. This integration gives you complete control over the customer experience while ensuring secure, end-to-end payment processing.

<HTMLBlock>{`
<style>
  .dropdown-menu {
    font-family: Arial, sans-serif;
    max-width: 250px;
    margin-left: auto; /* Align to the right */
  	margin-right: 0; /* Ensure it's flush to the right */
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    background: #4A4AF4;
    overflow: hidden; /* Ensure the container grows with content */
  }

  .dropdown-item {
    margin-bottom: 10px;
  }

  .dropdown-toggle {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
  }

  .dropdown-toggle:hover {
    background: #f0f0f0;
  }

  .dropdown-content {
    display: none;
    margin-top: 5px;
    padding: 10px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
  }

  .dropdown-item.open .dropdown-content {
    display: block;
  }

  .flag-icon {
    width: 20px;
    height: 20px;
    margin-right: 10px;
  }

  .product-item {
    margin-bottom: 5px;
    color: black;
  }

  .product-icon {
    width: 20px;
    height: 20px;
    margin-right: 10px;
  }
  
  .country-title {
    font-family: Arial, sans-serif;
    font-size:20px;
    text-align: center;
    font-weight: bold;
    color: #ffffff;
  } 

</style>
  <div class="dropdown-menu">
    <p class="country-title" alt="Countries where this product is available">Country Availability</p>

    <div class="dropdown-item">
      <button class="dropdown-toggle" onclick="toggleDropdown(event)" alt="Drop down menu displaying the available countries for this product">
        <b>Country List</b> ⬇️
      </button>
      <div class="dropdown-content">
        <div class="product-item">
          <img src="https://files.readme.io/a4c8b3d6596d943e2b93c82cb1d432a2edaf6998667835c2e97ef4a31d460c7e-us-circle-01.png" alt="USA" class="flag-icon">
          USA
        </div>
        <div class="product-item">
          <img src="https://files.readme.io/3ca294a1b4b8b8506c3ff32876abc6e3e33d0e65a509dab81398915094bdbc5c-61TcZ33ZrJL._AC_UY1000_.jpg" alt="Canada" class="flag-icon">
          Canada
        </div>
        <div class="product-item">
          <img src="https://files.readme.io/db98461fef617df7c9970e98f01150f067fcee1fc823a450f09056138b9f70be-united-kingdom-flag-rounded-icon-uk-flag-union-jack-vector.jpg" alt="UK" class="flag-icon">
          UK
        </div>
      </div>
    </div>

  </div>
`}</HTMLBlock>

## Overview

Affirm’s Direct API is a powerful and flexible integration that allows merchants to embed the full Affirm checkout and payment authorization flow directly into their website. This gives you complete control over the front-end user experience and the back-end transaction processing logic. From initiating checkout to handling confirmations and errors, Direct API provides a customizable and secure solution tailored to your business needs.

## The Customer Experience

Customers selecting Affirm at checkout experience a seamless, branded flow that takes place on your site (via modal) or on affirm.com (via redirect). When they choose Affirm:

1. They’re shown prequalified payment options and loan terms.
2. They confirm their selection and return to your site’s confirmation page.
3. If needed, modal error messaging appears to help customers enter the correct input.

You can configure the customer redirect and cancel URLs, and even choose whether to send the `checkout_token` via `GET` or `POST` methods depending on your flow preferences.

### Customer UX Flow

This flow illustrates the customer’s experience using Affirm via a Direct API integration. After selecting Affirm at checkout, the customer verifies their identity with a mobile number and PIN, creates an account, and selects a payment plan. Once terms are confirmed, the order is completed and a confirmation page is shown.

<Image alt="Simulated iphone screens showing Affirm's 7 steps for customer checkout." align="center" width="900px" src="https://files.readme.io/8943147f389027a28dac1325321ee21f4d8087cbbd9f4878c4fcab5ec4212c63-UX_Flows_Direct_API.svg" />

## The Merchant Experience

### Transaction Flow

This diagram outlines the key steps in Affirm’s Direct API transaction flow. After a customer selects Affirm and initiates checkout, the merchant creates and sends a checkout object containing order and customer details. Affirm then collects customer information, and upon approval, returns a `checkout_token`. The merchant uses this token to authorize the transaction and complete the order, enabling a secure, end-to-end payment process.

<Image alt="Diagram showing the 4 main steps involved with authorizing a transaction on the merchant-side." align="center" width="300px" src="https://files.readme.io/def1746686c3b019834051bd3252e0b3dfb88734aea846210193e6b04829477c-Direct_API_Transaction_Flow.svg" />

<br />

### Key Steps

### 1. Embed Affirm.js

Add Affirm’s JavaScript SDK to your site’s `<head>`. This script creates the global affirm object and enables key features like checkout and promotional messaging. You’ll find the script in the Recipes section of our developer docs.

<Embed url="https://player.vimeo.com/video/941391122?h=515c1bfa8f&badge=0&autopause=0&player_id=0&app_id=58479" title="iframe" provider="player.vimeo.com" href="https://player.vimeo.com/video/941391122?h=515c1bfa8f&badge=0&autopause=0&player_id=0&app_id=58479" typeOfEmbed="iframe" height="400px" width="100%" iframe="true" />

<br />

### 2. Add Promotional Messaging

Use `affirm.ui` components to display “as low as” messaging on product pages, cart, or banners. This helps customers understand payment options and encourages conversion.

<Embed url="https://player.vimeo.com/video/941391097?h=adfd801ce4&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" title="iframe" provider="player.vimeo.com" href="https://player.vimeo.com/video/941391097?h=adfd801ce4&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" typeOfEmbed="iframe" height="400px" width="100%" iframe="true" />

<br />

### 3. Initiate Checkout

Call `affirm.checkout()` and define a checkout object with customer, cart, and merchant details. Then trigger `affirm.checkout.open()` to launch the checkout experience.

<Embed url="https://player.vimeo.com/video/941391078?h=93c9318736&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" title="iframe" provider="player.vimeo.com" href="https://player.vimeo.com/video/941391078?h=93c9318736&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" typeOfEmbed="iframe" height="400px" width="100%" iframe="true" />

<br />

### 4. Authorize the Transaction

After checkout, receive the `checkout_token` at your confirmation URL and send it to Affirm’s API to authorize the transaction. Store the `transaction_id` for any post-purchase actions.

<Embed url="https://player.vimeo.com/video/941391054?h=abe959b9d7&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" title="iframe" provider="player.vimeo.com" href="https://player.vimeo.com/video/941391054?h=abe959b9d7&amp;badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479" typeOfEmbed="iframe" height="400px" width="100%" iframe="true" />

<br />

## Recommended Topics

* [Set Up Direct API](https://docs.affirm.com/payments/docs/transactions-web)
* [About Split Capture](https://docs.affirm.com/payments/docs/split-capture)
* [Transactions API](https://docs.affirm.com/developers/reference/the-transaction-object)
* [Itinerary Object (Travel Merchants)](https://docs.affirm.com/developers/reference/the-itinerary-object)

# Sibling pages

* [Set Up Direct API](https://docs.affirm.com/payments/docs/transactions-web.md)
* [Inline Integration Overview](https://docs.affirm.com/payments/docs/inline-integration.md)
* [About Split Capture](https://docs.affirm.com/payments/docs/split-capture.md)
* [Set Up Split Capture](https://docs.affirm.com/payments/docs/integrate-affirm-split-capture.md)