Open Affirm Checkout

Use affirm.checkout.open() to redirect your customers to Affirm Checkout, a modal, or a page to securely complete the loan checkout. When the customer completes their purchase, they are redirected back to your website.

To open Affirm Checkout, call the affirm.checkout.open()creating your checkout object with affirm.checkout()\.

affirm.checkout(checkoutObject)
affirm.checkout.open()

Example

affirm.checkout({
 
      "merchant": {
        "user_confirmation_url":    "https://merchantsite.com/confirm",
        "user_cancel_url":          "https://merchantsite.com/cancel",
        "user_confirmation_url_action": "POST",
        "name": "Your Customer-Facing Merchant Name"
      },
      "shipping":{
        "name":{
          "first":"Joe",
          "last":"Doe"
        },
        "address":{
          "line1":"633 Folsom St",
          "line2":"Floor 7",
          "city":"San Francisco",
          "state":"CA",
          "zipcode":"94107",
          "country":"USA"
        },
        "phone_number": "4153334567",
        "email": "[email protected]"
      },
      "billing":{
        "name":{
          "first":"Joe",
          "last":"Doe"
        },
        "address":{
          "line1":"633 Folsom St",
          "line2":"Floor 7",
          "city":"San Francisco",
          "state":"CA",
          "zipcode":"94107",
          "country":"USA"
        },
        "phone_number": "4153334567",
        "email": "[email protected]"
      },
      "items": [{
        "display_name":         "Awesome Pants",
        "sku":                  "ABC-123",
        "unit_price":           10000,
        "qty":                  3,
        "item_image_url":       "http://merchantsite.com/images/awesome-pants.jpg",
        "item_url":             "http://merchantsite.com/products/awesome-pants.html",
        "categories": [
            ["Home", "Bedroom"],
            ["Home", "Furniture", "Bed"]
        ]
      }
   ],
      "discounts":{
         "RETURN5":{
            "discount_amount":500,
            "discount_display_name":"Returning customer 5% discount"
        },
        "PRESDAY10":{
            "discount_amount":1000,
            "discount_display_name":"President's Day 10% off"
      }
   },
   "metadata":{
      "shipping_type":"UPS Ground",
      "mode":"modal"
   },
   "order_id":"JKLMO4321",
   "currency":"USD",  
   "financing_program":"flyus_3z6r12r",
   "shipping_amount":10000,
   "tax_amount":600,
   "total":30100
}

affirm.checkout.open()

Method arguments


ParameterTypeDescription
checkoutObject
required
objectThe object containing the customer's checkout data.

Returns

This method returns nothing normally and you will need to specify the URL to redirect your customers in the checkout object. Unless you have the metadata option set to modal, you will need to handle the callback methods below:

  • onFail: Called when the customer exits, cancels or is declined in the Affirm checkout flow.
  • onSuccess: Called when the customer confirms their Affirm loan. Receives a success object, which contains the checkout_id.
  • onOpen: Called when the customer successfully loads the Affirm checkout flow.
  • onValidationError: Called when there was a validation error with the checkout request submitted.
Affirm.checkout.open({
    onFail: function(error) {
    },
    onSuccess: function(checkout) {
    },
   onOpen: function(token){
    },
   onValidationError: function(checkout_validation_error) {
    }
});