Skip to main content

Merchant Help

 

Affirm Merchant Help

Integration Quick Start

Overview

Complete an end-to-end Affirm transaction yourself, without having to create a local test page or script. Just follow the instructions, and you'll get to see how charge authorization and capture requests are processed.

user_confirmation_url

We need a URL to send the checkout_token to. You can stand-up a test page or use a free hosted test page:

Use a hosted test page
  1. Go to: https://requestb.in/.
  2. Click 'Create a RequestBin'.
  3. Copy the Bin URL in the center of the page. 
Use a local page

Make sure you have localhost configured for this option. Otherwise, use a hosted page above.

  1. Create an .html document in a file location accessible by localhost, or another domain/port mapped to your local machine.
  2. Copy the URL of the local page.
Configure the checkout

You can set the 'user_confirmation_url' of the checkout by editing the JSON object that stores the checkout's configuration.

The JSON can be easily edited in this JSFiddle.

  1. Go to the JSFiddle page.
  2. Find the 'user_confirmation_url' in the JSON, displayed in the Javascript (lower-left) pane of the JSFiddle page.
  3. The 'user_confirmation_url' has a placeholder value ("https://examplemerchant.com/confirm_affirm_charge") that you need to swap out.
  4. Paste in the local or hosted test page URL you copied earlier.
  5. The end result should look something like: "user_confirmation_url": "https://requestb.in/rb1s2wrb".
     
  6. If you're using a local page, you should also set the "user_confirmation_url_action" to "GET". This saves you time so you don't have to setup a server-side script to grab the POST request body.

Go through checkout

Sandbox transactions

 

No real loans are created in the Sandbox environment. You can proceed through all loan application steps without any soft credit checks or any other credit impact.
 

  1. Once you initiate checkout, you'll see the account creation screen.
    • If you've already created an account, click the 'Log In' button. 
    • If you haven't created an account, create one now. This can all be fake information.
      • Any First and last name
      • Valid email address format
      • Valid (random) US cell phone number
      • Birthdate longer than 18 years ago
      • Any four digits for SSN
         
  2. You'll be asked to enter a PIN number, use '1234'.

    We do not text you a PIN number in the Sandbox environment

     
  3. 3, 6, and 12 month terms will display. Select any option and continue.
  4. Accept terms and conditions.
  5. Do not enable Autopay.
  6. Once you click the 'Confirm' button, you'll be redirected to the user_confirmation_url with the checkout_token.

Retrieve the checkout_token

POST method

This is the default request method for the user_confirmation_url.

You'd be using this method if:

  • you chose the easy hosted test page route above, then by default we POST the checkout_token to the user_confirmation_url
  • you setup a test page with server-side scripting to log the POST request body

The server will see the POST request body, but it doesn't show up client-side like a GET request's query string form. Requestb.in will display it for you when you inspect the requestb.in URL.

  1. Visit your requestb.in URL, making sure to add '?inspect' onto the end of the page URL.
    For example: "https://requestb.in/rb1s2wrb?inspect"
  2. The "checkout_token" will be visible on Requestb.in page, shown in the details of the request it received.
    For example: {"checkout_token":"ABC123"}
    ABC123 is the checkout_token.
  3. Copy the checkout_token value and save it to your text editor.
GET method

This is an optional request method, used when you input "GET" as the "user_confirmation_url_action".


You'd be using this method if:

  • you chose the local test page option,
  • you want to receive your token via GET method
  1. The "checkout_token" will be visible in the page location / address bar, as part of the query string.
    For example in this query string: "a_test_page.html?checkout_token=ABC123"
    ABC123 is the checkout_token.
  2. Copy the checkout_token.

Authorize the charge

You'll be POSTing the checkout_token you copied above to our /api/v2/charges/ endpoint. A successful (200) request to this endpoint indicates that the cheheckout_token has been successfully used to authorize the Affirm charge.

The easiest way to accomplish this is using a terminal window and curl, or you can use an online hosted solution.

First, you'll have to put your checkout_token into the request command.

  1. Copy the code below and paste it into your text editor.
    curl https://sandbox.affirm.com/api/v2/charges/ \
         --verbose \
         -X POST \
         -u "ARQBLCL7NAMBTZ7F:RkHBmVSP5ayC2rCUujwhArpGWPxpuTtv" \
         -H "Content-Type: application/json"\
         -d '{"checkout_token": "YOUR_CHECKOUT_TOKEN"}'
  2. Copy the checkout_token you grabbed previously, and paste it into the checkout_token placeholder ('YOUR_CHECKOUT_TOKEN') in the curl command above.
  3. Copy the edited curl command that now has your checkout token.
  4. Open up a Terminal window (OSX/macOS) or 
  5. Paste in your command and press enter.

Store the charge 'id'

The charge object that you get in the authorization response will contain the charge 'id'.

  1. Find the parameter called 'id' in the response body of your authorization API request.
    For example: "id" : "AB12-CD34"
  2. Save this id to your text editor.

Capture the charge

You'll be POSTing the charge 'id' to the api/v2/charges/<your_charge_id>/capture endpoint, to capture the charge and trigger settlement.

First, you'll have to put your charge id into the request command URL.

  1. Copy the code below and paste it into your text editor.
    curl https://sandbox.affirm.com/api/v2/charges/YOUR_CHARGE_ID/capture \
         --verbose \
         -X POST \
         -u "ARQBLCL7NAMBTZ7F:RkHBmVSP5ayC2rCUujwhArpGWPxpuTtv" \
    
  2. Copy the checkout_token you grabbed previously, and paste it into the charge id placeholder ('YOUR_CHARGE_ID') in the curl command above.
  3. Copy the edited curl command that now has your checkout token.
  4. Open up a Terminal window (OSX/macOS) or 
  5. Paste in your command and press enter.