Update values inside javascript object -
i working affirm javascript api , need able update values inside checkout object having trouble doing so. have tried mentioned here isnt working.
basically object looks 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 set on first page load customer can still update items in cart need add these changes above object if occur.
i have tried affirm_checkout["shipping_amount"] = 123
doesn't update shipping total. neither affirm_checkout.shipping_amount = 123
can tell me doing wrong?
you should define checkout object variable outside context of affirm.checkout function. way, can directly access contents of object , pass affirm.checkout(yourcheckoutobject);
var yourcheckoutobject = {}; //define default or placeholder values yourcheckoutobject.shipping_amount = 2000; //amounts expressed in integer usd cents affirm.checkout(yourcheckoutobject); //pass object checkout function
Comments
Post a Comment