Skip to main content

Merchant Help

 

Affirm Merchant Help

Initiate Checkout

Initiating checkout

Redirect

With the checkout object built, you can now call:

affirm.checkout.open();

This method will send a POST request to the /checkout/ API endpoint with the checkout object as the data payload. Then, it will redirect the user to the Affirm checkout flow on the affirm.com domain.

Syntax notes
  • The checkout object is sent as a JSON object.
  • All numerical values must be sent as integer USD cents ($25.00 -> 2500).
  • The items are stored in an object array. You should build this array dynamically by adding item objects to it based on cart contents.
  • The discount object uses the discount code as the name of the nested objects. As a result, you may have to construct each discount without the use of a strongly-typed class.
Checkout object validation

The following data in the checkout object is validated:

  • Name
    • There must be a first and last name.
  • Address
    • The address must have a direct match on both Smarty Streets and Google Maps.
  • Phone number
    • Number must be a valid US cell phone number that is able to receive SMS text messages.
  • Total
    • An order total must be present and greater than 0.
  • Discount
    • Any discount values must be positive integers.
  • Item
    • Item URL   
      • Must be present, but can be an empty string.
Error handling

Errors generated by the checkout request are presented on the page where checkout is initiated, in the form of a pop-up modal window. Specific messaging about the source of the error is presented in this modal (e.g., "Invalid phone number"). 

You may define a callback function when this error modal is closed, but currently that callback does not relay any event data specific to the error message that's displayed in the modal. 

Here's an example of how this event callback would be defined:

affirm.ui.ready(
    function() {
        affirm.ui.error.on("close", function(){
            alert("Please check your contact information for accuracy.");
        });
    }
);