Integration Checklist
Prerequisites
- Confirm Affirm has enabled your merchant account for Connected Accounts (contact your TAM)
- Obtain your public/private API key pair for the target environment (sandbox and production are separate credentials)
- Stand up secure, encrypted-at-rest, server-side storage for refresh tokens, keyed by
account_linking_id(see 'Recommended Storage Schema') - Decide on a stable
account_linking_idsource (internal customer DB ID, UUID, etc.) that must never change for a given customer - Choose your refresh-token delivery method: Webhook (recommended) or Token Lookup API
Step 1: Initial Linking
- Add
account_linking_id(Affirm.js) oraccount_linking.id(Direct API) to your checkout-creation call - If using the Webhook method: register your HTTPS endpoint with your TAM for the
linking_status_changedevent, and verify it’s working - If using the Token Lookup API: call
POST /api/pba/v1/oauth/token/lookupafter the cancel/confirmation callback and store the returnedrefresh_token - Persist the
refresh_tokenand itsexpires_atagainst the customer'saccount_linking_idas soon as it's received
Step 2: Returning-User Token Exchange
- Generate the PKCE pair via
affirm.checkout.prepareAuth()(Affirm.js) or the Web Crypto API (Direct) - Call
POST /api/pba/v1/oauth/tokenwith the storedrefresh_tokento obtain anaccess_token - Atomically store the new
refresh_tokenreturned in that response and discard the old one; never retry with a stale refresh token - (Affirm.js only) Call
POST /api/pba/v1/oauth/sessionwith theaccess_tokenandcode_challengeto obtain a session_code
Step 3: Accelerated Checkout
-
(Affirm.js) Pass
session_codeintoaffirm.checkout.open() -
(Direct API) Pass
account_linking.access_tokenandaccount_linking.code_challengein the DirectCheckout request, then append
code_verifierto the returnedredirect_urlbefore sending the customer's browser there -
Implement the fail-open principle: any failure in the exchange must fall through to a standard, non-accelerated checkout and never block or error out the customer
Step 4: Re-linking & Unlinking
- Handle
unauthorizedon any future token exchange by deleting the stored refresh token and falling back to standard checkout
Step 5: Testing
- Go through the test scenarios in Reliabilty & Testing on both a pre-production and production environment
Updated 2 days ago
Did this page help you?