Edit in JSFiddle

/**************************************************************\
            Include Affirm.js Snippet
\**************************************************************/
var _affirm_config = {
  public_api_key: "5GDPSC5HC4Y7Y9TX",  /* replace with public api key */
  script:         "https://cdn1.affirm.com/js/v2/affirm.js"
};
(function(l,g,m,e,a,f,b){var d,c=l[m]||{},h=document.createElement(f),n=document.getElementsByTagName(f)[0],k=function(a,b,c){return function(){a[b]._.push([c,arguments])}};c[e]=k(c,e,"set");d=c[e];c[a]={};c[a]._=[];d._=[];c[a][b]=k(c,a,b);a=0;for(b="set add save post open empty reset on off trigger ready setProduct".split(" ");a<b.length;a++)d[b[a]]=k(c,e,b[a]);a=0;for(b=["get","token","url","items"];a<b.length;a++)d[b[a]]=function(){};h.async=!0;h.src=g[f];n.parentNode.insertBefore(h,n);delete g[f];d(g);l[m]=c})(window,_affirm_config,"affirm","checkout","ui","script","ready");


/**************************************************************\
          Set Affirm Checkout Values
\**************************************************************/
//checkout_time expressed in minutes
// expressed in minutes
var checkout_time = 20;

// include expire_time() in your checkout object for the expiration timestamp
var expire_time = function(){
    var current_time = Date.now();
    var new_time = current_time + (checkout_time*60*1000);
    var timestamp = new Date(new_time);
    var iso_timestamp = timestamp.toISOString().split('.')[0]+"Z";
    return iso_timestamp
}

affirm.checkout({

  "config": {
    "financial_product_key" : "CN29VP56R79EMSEI", //replace with your Affirm financial product key
  },

  "merchant": {
    "user_cancel_url"              : "https://examplemerchant.com/checkout/payment",
    "user_confirmation_url"        : "https://examplemerchant.com/confirm_affirm_charge",
    "user_confirmation_url_action" : "POST"
  },

  //shipping contact
  "shipping": {
    "name": {
      "full" : "John Doe"
    },
    "address": {
      "line1"  : "225 Bush Street",
      "line2"  : "Floor 16",
      "city"   : "San Francisco",
      "state"  : "CA",
      "zipcode": "94104"
    },
    "email"          : "joe.doe@email.com",
    "phone_number"   : "4155555555"
  },

  // cart 
  "items": [{
    "display_name"   : "Acme SLR-NG",
    "sku"            : "ACME-SLR-NG-01",
    "unit_price"     : 1500,
    "qty"            : 1,
    "item_image_url" : "https://examplemerchant.com/static/item.png",
    "item_url"       : "https://examplemerchant.com/acme-slr-ng-01.htm",
  }],

  // pricing / charge amount
  "currency"        : "USD",
  "discounts": {
    "savemoney123": {
      "discount_amount" : 500
    }
  },
  "tax_amount"      : 199,
  "shipping_amount" : 399,
  "total"           : 15980,
  "checkout_expiration" : expire_time()
});

    
/**************************************************************\
              Handle the form submission
\**************************************************************/
$("#submit-form").click(function(){
  affirm.checkout.post();
});