0

I am working with the Affirm javascript API and I need to be able to update the values inside the checkout object but am having trouble doing so. I have tried what is mentioned here but it isnt working.

Basically the object looks something like this:

affirm.checkout({  
   "merchant":{  
      "user_confirmation_url":"https://example.com/checkout/",
      "user_cancel_url":"https://example.com/exit"
   },
   "config":{  
      "financial_product_key":"XXXXXXXXX"
   },
   "shipping":{  
      "name":{  
         "full":"Blah Person"
      },
      "address":{  
         "line1":"123 example street",
         "city":"Blah",
         "state":"IL",
         "zipcode":"12345",
         "country":"US"
      }
   },
   "billing":{  
      "name":{  
         "full":"Dirty Larry"
      },
      "address":{  
         "line1":"123 blah street",
         "city":"foo",
         "state":"IL",
         "zipcode":"12345",
         "country":"US"
      }
   },
   "items":[  
      {  
         "display_name":"Example Product",
         "sku":"123",
         "unit_price":"1222",
         "qty":"1",
         "item_image_url":"https://example.com/kitty.jpg",
         "item_url":"https://example.com/product/123"
      }
   ],
   "discounts":{  
      "discount_name":{  
         "discount_amount":0
      }
   },
   "metadata":{  
      "shipping_type":"Ground"
   },
   "order_id":"XXXXXXXXXXXXXXXXXX",
   "shipping_amount":0,
   "tax_amount":0,
   "total":67599
});

The above is all set on the first page load but the customer can still update items in their cart so I need to add these changes to the above object if they occur.

I have tried affirm_checkout["shipping_amount"] = 123 that doesn't update the shipping total. Neither does affirm_checkout.shipping_amount = 123 can someone tell me what I am doing wrong?

Community
  • 1
  • 1
Yamaha32088
  • 4,125
  • 9
  • 46
  • 97

2 Answers2

0

You should define the checkout object as a variable outside the context of the affirm.checkout function. This way, you can directly access the contents of the object and pass it to affirm.checkout(yourCheckoutObject);

var yourCheckoutObject = {}; //define default or placeholder values
yourCheckoutObject.shipping_amount = 2000; //amounts are expressed in integer USD cents
affirm.checkout(yourCheckoutObject); //pass the object to the checkout function
-2

You can try this:

{
merchant: "foo bar",
config: "baz"
}

Then you can access that by

checkout.merchant = 123
MrOnlineCoder
  • 333
  • 3
  • 15
  • OP already tried that. It's not just an object, it's an object that gets passed to a function. So accessing it is not as straight forward. – putvande Feb 08 '16 at 15:11