{"_id":"5899d3cae5ce34250082f71d","project":"571f5e8cd8667f0e00a3c498","parentDoc":null,"category":{"_id":"5899c7113514ce0f0014da84","__v":0,"project":"571f5e8cd8667f0e00a3c498","version":"571f5e8cd8667f0e00a3c49b","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-02-07T13:09:37.119Z","from_sync":false,"order":9999,"slug":"simplecartjs","title":"Shopping Cart"},"user":"5720ba18c669e80e00c35051","version":{"_id":"571f5e8cd8667f0e00a3c49b","hasDoc":true,"__v":12,"hasReference":true,"project":"571f5e8cd8667f0e00a3c498","createdAt":"2016-04-26T12:26:52.312Z","releaseDate":"2016-04-26T12:26:52.312Z","categories":["571f5e8cd8667f0e00a3c49c","571f73cfcb4baa0e00d13a80","571f7451cb4baa0e00d13a88","571f7d2720695f3400f38797","571f7fb0ac2a080e0014c661","571f884be54f2d0e003ebb0a","572200c9ecb38d0e00d80ebd","572c301e7c8eff0e00aaa174","57df91b2c6348d0e0020c452","57e104db9ff1e21900a721ab","57fd04caeaa77f19008b8202","5899c7113514ce0f0014da84"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-02-07T14:03:54.746Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"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]","excerpt":"","slug":"json-format-for-shopping-cart-data","type":"basic","title":"JSON format for shopping cart data"}

JSON format for shopping cart data


[block:callout] { "type": "info", "title": "simpleCart(JS)", "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)." } [/block] If 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. [block:code] { "codes": [ { "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}", "language": "json" } ] } [/block] [block:code] { "codes": [ { "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?>", "language": "php" } ] } [/block]