Skip to main content

Merchant Help

 

Affirm Merchant Help

Checkout Result

Once a user enters the Affirm checkout flow, there are two possible results of the checkout attempt: 'success' and 'error'. 

Success

  • User is approved and confirms the Affirm loan terms: 
    • Success callback is triggered
    • Card token is returned in the event data
    • Server-side script sends the card token to the Affirm Virtual Card API and receives back the card details in the response
    • Custom Javascript fills in the card form on your checkout page automatically

Error

  • User closes the window:
    • Error callback is triggered
    • 'reason: closed' is returned in the event data
    • You can display messaging to the user to 'select another payment method'
       
  • User is denied or uses the cancel icon:
    • Error callback is triggered
    • 'reason: canceled' is returned in the event data
    • You can display messaging to the user to 'select another payment method'
       
  • Pop-up fails to open:
    • Error callback is triggered
    • 'reason: popups_disabled' is returned in the event data
    • You can display instructions to the user to 'enable pop-ups or select another payment method'
Card Token

{
   callback_id:"0cd3bcb1-8592-4ebf-a8cd-08816fbe266a",
   card_token:"1L7Y0UV4IR8LIA9G",
   created:"2016-04-04T14:24:06.386576Z"
}
callback_id
string. Can be ignored, for Affirm internal use.
card_token
string.  The card token that these card details correspond to.
created
timestamp. Time when this card token was generated.

Success Callback

affirm.checkout.open_vcn({

      success: success_callback

  });

Callback trigger

The success callback is triggered when the user confirms their Affirm loan terms in the pop-up window and is returned back to the checkout page.

Event data

The event data you need to utilize is:

  • Card token

Callback behavior

Typically, your callback function will have the following behavior:

  1. Pass the returned card_token to your server-side script that will request the card details from the Affirm API
  2. Upon success, pass the card details to the front-end.
  3. Reference the card form elements on your checkout page that are to be populated
  4. Assign the relevant event data object values to those card form value
  5. Carry over the customer's billing name and address to your card fields (don't use the name/address return with the card data)
  6. Submit the checkout form automatically or prompt the user to submit the checkout form

 

Error Callback

Error Callback

 

affirm.checkout.open_vcn({

      error: cancel_callback

  });

 Event data

{reason: "closed"}
{reason: "canceled"}
{reason: "popups_disabled"}

 

Callback trigger

The error callback is triggered when the user cancels their application, closes the window, or the window is prevented from opening

Event data

The event data you need to utilize is:

  • Reason
    • closed
      • When the window is closed using the native window toolbar.
    • canceled
      • When the cancel icon or return button is clicked.
    • popups_disabled
      • When we detect that the pop up was blocked.

Callback behavior

Typically, your callback function will have the following behavior:

  1. Read the reason 
  2. Display a message if the user has disabled popups

Example function

function cancel_callback(e) {
   if(e.reason === "popups_disabled"){
      window.alert("Please enable pop-ups to checkout with Affirm");
      }