php - Getting JSON $_POST from FoxyCart Order Desk -
i trying create script receive post foxycart's order desk. setup temporary request bin @ requestb.in. when pointed post there new order json fine. copy/pasted json string in script code able parse json , added variables database:
$string = "{"id":"1191583","email":"office@burntimpressions.com","shipping_method":"","quantity_total":1,"weight_total":0,"product_total":0,"shipping_total":0,"handling_total":0,"tax_total":0,"discount_total":0,"order_total":0,"cc_number_masked":"","cc_exp":"","processor_response":"","payment_type":"","payment_status":"approved","processor_balance":0,"customer_id":"","email_count":"1","ip_address":"71.161.83.59","tag_color":"","source_name":"order desk","source_id":"1191583","fulfillment_name":"","fulfillment_id":"","tag_name":"","folder_id":6814,"date_added":"2015-06-14 16:53:54","date_updated":"2015-06-14 16:54:27","shipping":{"first_name":"galen","last_name":"dively","company":"vermont novelty toaster corporation","address1":"136 bay street","address2":"ste 2","address3":"","address4":"","city":"saint johnsbury","state":"vermont","postal_code":"05819","country":"us","phone":"(916) 448-5517"},"customer":{"first_name":"galen","last_name":"dively","company":"vermont novelty toaster corporation","address1":"136 bay street","address2":"ste 2","city":"saint johnsbury","state":"vermont","postal_code":"05819","country":"us","phone":"(916) 448-5517"},"checkout_data":[],"order_metadata":[],"discount_list":[],"order_notes":[],"order_items":[{"id":"2090400","name":"selfie test","price":0,"quantity":1,"weight":0,"code":"selfie","delivery_type":"ship","category_code":"","variation_list":[],"metadata":[]}],"order_shipments":[]}"; $order = json_decode($string, true); $transactionid = $order [id]; $firstname = $order[customer][first_name]; foreach($order [order_items] $p) { $cid = $p[id]; $productname = $p[name]; $code = $p[code]; $quantity = $p[quantity]; }
order desk's documentation says post this:
$order = json_decode($_post['order'], 1);
i not getting anything. have tried can think of. looked through forum , have found nothing json parsed. assuming post successful because not getting errors order desk's admin panel.
order desk has code security purposes. post seemed pass of them.
<?php //check order if (!isset($_post['order'])) { header(':', true, 400); die('no data found'); } //cbeck store id //be sure set store id. ask order desk support if aren't sure is. if (!isset($_server['http_x_order_desk_store_id']) || $_server['http_x_order_desk_store_id'] != "your-store-id") { header(':', true, 403); die('unauthorized request'); } //check hash (optional) //the api key can found in advanced settings section. order desk pro if (!isset($_server['http_x_order_desk_hash']) || hash_hmac('sha256', rawurldecode($_post['order']), 'your_api_key') != $_server['http_x_order_desk_hash']) { header(':', true, 403); die('unauthorized request'); } //check order data $order = json_decode($_post['order'], 1); if (!is_array($order)) { header(':', true, 400); die('invalid order data'); } //everything checks out -- thing echo "<pre>" . print_r($order, 1) . "</pre>";
any appreciated!
i guess asking how parse:
$order = json_decode($_post['order'], 1);
what requestb.in :
form/post parameters
order: {"id":"1191583","email":"office@burntimpressions.com","shipping_method":"","quantity_total":1,"weight_total":0,"product_total":0,"shipping_total":0,"handling_total":0,"tax_total":0,"discount_total":0,"order_total":0,"cc_number_masked":"","cc_exp":"","processor_response":"","payment_type":"","payment_status":"approved","processor_balance":0,"customer_id":"","email_count":"1","ip_address":"71.161.83.59","tag_color":"","source_name":"order desk","source_id":"1191583","fulfillment_name":"","fulfillment_id":"","tag_name":"","folder_id":6814,"date_added":"2015-06-14 16:53:54","date_updated":"2015-06-14 16:54:27","shipping":{"first_name":"galen","last_name":"dively","company":"vermont novelty toaster corporation","address1":"136 bay street","address2":"ste 2","address3":"","address4":"","city":"saint johnsbury","state":"vermont","postal_code":"05819","country":"us","phone":"(916) 448-5517"},"customer":{"first_name":"galen","last_name":"dively","company":"vermont novelty toaster corporation","address1":"136 bay street","address2":"ste 2","city":"saint johnsbury","state":"vermont","postal_code":"05819","country":"us","phone":"(916) 448-5517"},"checkout_data":[],"order_metadata":[],"discount_list":[],"order_notes":[],"order_items":[{"id":"2090400","name":"selfie test","price":0,"quantity":1,"weight":0,"code":"selfie","delivery_type":"ship","category_code":"","variation_list":[],"metadata":[]}],"order_shipments":[]}
headers
total-route-time: 0 connect-time: 1 x-request-id: 26eb3b73-bd15-4d75-9605-ea4fda0191dd user-agent: guzzle/5.3.0 curl/7.19.7 php/5.5.21 x-order-desk-store-id: xxxxxxx content-type: application/x-www-form-urlencoded connection: close content-length: 2228 via: 1.1 vegur host: requestb.in x-order-desk-hash: xxxxxxxxxxxxx
Comments
Post a Comment