post https://apiv4.ordering.co////orders/custom
This API endpoint is used to create orders.
The customer, business and products must have the following structure to be accepted.
{
"name": "name",
"cellphone": 3003003030,
"phone": 5757577,
"address": "5th Avenue",
"address_notes": "AP 505",
"location": "{\"lat\": 15.5,\"lng\": 15.5 }"
}
{
"name": "name",
"cellphone": 3003003030,
"phone": 5757577,
"address": "5th Avenue",
"address_notes": "AP 505",
"location": "location": "{\"lat\": 15.5,\"lng\": 15.5 }",
"timezone": "Ametica/BuenosAires"
}
{
"name": "product",
"price": 10,
"quantity": 1,
"comment": "commnent"
}
Total
If the params total is sent, will create a product called "Total" (is translated depending on lang) with the the price equal to total. So products are not necessary when this param is sent.
History
The customer, business and products will be register in the database if are properly write, but not as new, only history registers.
X-APP-X
It is a header parameter to know from what medium the order was created for example, web, ios app, android app, etc.
<?php
$input = json_decode(file_get_contents('php://input'));
//IMPUT MUST BE TRANSFOR TO THIS
// {
// "business_id": 7, //INTEGER: IDENTIFIER OF THE STORE IN ODERING
// "delivery_type": "1", //INTEGER: THE ORDER TYPE IN ORDERING
// "driver_tip": 10, //FLOAT: THE TIP FOR THE DRIVER
// "delivery_zone_id": 20, //INTEGER: IDENTIFIER OF THE DELIVERY ZONE IN ORDERING
// "location": { //JSON: THE LOCATION OF THE CUSTOMER
// "lat": 40.7127753,
// "lng": -74.0059728
// ],
// "code": "M86O35RZIgCDKaQmXMXHwBjoe96z2Z", // RANDOM STRING TO AVOID COLITION WITH SIMILAR ORDERS
// "products": "[{\"id\":489,\"code\":\"UyWj4a\",\"quantity\":1,\"options\":[],\"ingredients\":[]},{\"id\":488,\"code\":\"gPQAhf\",\"quantity\":1,\"options\":[],\"ingredients\":[]}]",
// "customer_id": 2, //CUSTOMER IDENTIFIER IF REGISTERED ON ORDERING
// "customer": "{\"id\":2,\"name\":\"Customer\",\"middle_name\":null,\"lastname\":\"Demo\",\"second_lastname\":null,\"photo\":null,\"email\":\"[email protected]\",\"cellphone\":\"\",\"address\":\"New York, NY, USA\",\"location\":\"{\\\"lat\\\":40.7127753,\\\"lng\\\":-74.0059728}\",\"tag\":\"other\"}"
// }
//CUSTOMER OBJECT
$customer = [
"name" => "Customer", //Customer Name (string)
"email" => "[email protected]", //Customer Email (string)
"cellphone" => "", //customer phone (string)
"address" => "New York, NY, USA", //Customer Address (string)
"location" => "{\"lat\":40.7127753,\"lng\":-74.0059728}", //Customer location Must be a valid JSON string
];
//BUSINESS OBJECT
$business = [
"name" => "Customer", //Customer Name (string)
"email" => "[email protected]", //Customer Email (string)
"cellphone" => "", //customer phone (string)
"address" => "New York, NY, USA", //Customer Address (string)
"location" => "{\"lat\":40.7127753,\"lng\":-74.0059728}", //Customer location Must be a valid JSON string
"timezone" => "Ametica/BuenosAires"
];
//PRODUCTS OBJECT
$products = [
[
"code" => "UyWj4a", //STRING: RAMDOM IDEMTIFIER TO AVOID COLITION BETWEN TO SIMILAR PRODUCTS IN THE ORDER
"quantity" => 1, //INTEGER: QUANTITY OF PRODUCT SELECTED
"options" => [
"id" => 53,
"suboptions" => [
[
"id" => 172, //INTEGER: IDENTIFIER OF THE SUBOPTION
"position" => "whole", //STRING : SIDE OF SUBOPTION LEFT, RIGT, WHOLE.
"quantity" => 1 //INTEGER: QUANTITY OF SUBOPTION
]
]
],
[
"suboptions" => [
[
"position" => "whole",
"quantity" => 1
]
]
],
[
"suboptions" => [
[
"position" => "whole",
"quantity" => 1
]
]
],
"ingredients" => []
],
[
"code" => "gPQAhf",
"quantity" => 1,
"options" => [],
"ingredients" => []
]
];
//ORDER OBJECT
$order = [
"business_id" => 7, //INTEGER => IDENTIFIER OF THE STORE IN ODERING
"external_business_id" => 7, //INTEGER => IDENTIFIER OF THE STORE IN EXTERNAL PLATFORM
"delivery_type" => "1", //INTEGER => THE ORDER TYPE IN ORDERING
"delivery_datetime" => "2022-05-25 11:59", //DATE
"total" => 20.5, //FLOAT => TOTAL AMOUNT OF THE ORDER
"location" => [ //JSON: THE LOCATION OF THE CUSTOMER
"lat" => 40.7127753,
"lng" => -74.0059728
],
"products" => json_encode($products),
"customer" => json_decode($customer),
"business" => json_decode($business),
];
//NOTES REPLACE ALL THE VALUES WITH YOUR INPUT
function request($url, $method, $additional_headers, $data = null)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (in_array($method, ['PUT', 'POST'])) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
}
$additional_headers[] = 'Accept: application/json';
$additional_headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $additional_headers);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
//https://apiv4.ordering.co/v400/en/demo/orders
$api = "https://apiv4.ordering.co";
$version = 'v400';
$lang = 'en';
$project = 'demo';
$api_key = 'haiq567a7@215';
$url = "{$api}/{$version}/{$lang}/{$project}/orders/custom";
$headers[] = 'x-api-key: '.$api_key;
$create_order = request($url, 'POST', $headers, json_encode($order));