{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"JSON format for shopping cart data","type":"basic","slug":"json-format-for-shopping-cart-data","excerpt":"","body":"[block:callout]\n{\n \"type\": \"info\",\n \"title\": \"simpleCart(JS)\",\n \"body\": \"If you are [using simpleCart(JS) as explained at the corresponding page](demo-shop) you needn't be familiar with all the tiny details below. Everything works without considering any JSON formats with simpleCart(JS).\"\n}\n[/block]\nIf you don't want to use simpleCart(JS) but your own shopping cart framework we advise you to store the data in a custom donation field in the following JSON format. By doing so the shopping cart data could be shown as a human readable table in the FundraisingBox backend.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"{\\n \\\"headers\\\":[\\n \\\"name\\\",\\n \\\"quantity\\\",\\n \\\"price\\\"\\n ],\\n \\\"items\\\":{\\n \\\"1\\\":{\\\"name\\\":\\\"Inoculation\\\",\\\"quantity\\\":\\\"1\\\",\\\"price\\\":\\\"20\\\"},\\n \\\"2\\\":{\\\"name\\\":\\\"Pig\\\",\\\"quantity\\\":\\\"3\\\",\\\"price\\\":\\\"5\\\"}\\n },\\n \\\"total\\\":35\\n}\",\n \"language\": \"json\"\n }\n ]\n}\n[/block]\n\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n$donationFormUrl = \\\"\\\"; // TODO url of your donation form\\n$formHash = \\\"\\\"; // TODO hash of the donation form\\n$customFieldId = 0; // TODO id of the custom field that stores the cart content\\n$shoppingCartContentAsJson = \\\"{}\\\"; // TODO shopping cart content as JSON (see above)\\n$shoppingCartSum = 0; // TODO total amount of the shopping cart\\n\\n\\n$curl = curl_init(\\\"https://secure.fundraisingbox.com/app/createSession\\\");\\n \\ncurl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__).'/cacert.pem');\\ncurl_setopt($curl, CURLOPT_RETURNTRANSFER, true);\\ncurl_setopt($curl, CURLOPT_POST, true);\\n \\n// set values\\n$data = array(\\n \\\"hash\\\" => $formHash,\\n \\\"payment\\\" => array(\\n \\\"amount_fix\\\" => $shoppingCartSum,\\n\\t\\\"donation_custom_field_\\\".$customFieldId => $shoppingCartContentAsJson\\n )\\n);\\ncurl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));\\n \\n// receive session\\n$result = json_decode(curl_exec($curl), true);\\n$status = $result[\\\"status\\\"];\\n$session = $result[\\\"session\\\"];\\n \\n// TODO error handling\\n$curl_error = curl_error($curl);\\n$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);\\n$curl_error_no = curl_errno($curl);\\nif($curl_error)\\n{\\n // do something\\n}\\ncurl_close($curl);\\n\\n// redirect to the donation form with session hash\\nheader(\\\"Location: \\\".$donationFormUrl.\\\"?fbSessionHash=\\\".$result[\\\"session\\\"][\\\"hash\\\"]);\\n?>\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]","updates":[],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5899d3cae5ce34250082f71d","project":"571f5e8cd8667f0e00a3c498","parentDoc":null,"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Cart-API (Charity Shop)","slug":"simplecartjs","order":7,"from_sync":false,"reference":false,"_id":"5899c7113514ce0f0014da84","createdAt":"2017-02-07T13:09:37.119Z","__v":1,"project":"571f5e8cd8667f0e00a3c498","version":"571f5e8cd8667f0e00a3c49b"},"user":"5720ba18c669e80e00c35051","version":{"version":"1","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["571f5e8cd8667f0e00a3c49c","571f73cfcb4baa0e00d13a80","571f7451cb4baa0e00d13a88","571f7d2720695f3400f38797","571f7fb0ac2a080e0014c661","571f884be54f2d0e003ebb0a","572200c9ecb38d0e00d80ebd","572c301e7c8eff0e00aaa174","57df91b2c6348d0e0020c452","57e104db9ff1e21900a721ab","57fd04caeaa77f19008b8202","5899c7113514ce0f0014da84","5cbeda4b862d090013abd413","5e60d6278f8b380072f0b1e3"],"_id":"571f5e8cd8667f0e00a3c49b","hasDoc":true,"releaseDate":"2016-04-26T12:26:52.312Z","__v":14,"hasReference":true,"createdAt":"2016-04-26T12:26:52.312Z","project":"571f5e8cd8667f0e00a3c498"},"__v":0,"createdAt":"2017-02-07T14:03:54.746Z","githubsync":""}