";
foreach ($addresses as $destination) {
echo "
| {$destination->priority} |
{$destination->city} |
{$destination->distance} |
{$destination->duration} |
{$destination->price} |
";
}
echo "
| Total |
{$apiResponse->object->distance}(meters) |
{$apiResponse->object->duration}(seconds) |
{$apiResponse->object->price}(toman) |
";
}
```
##### Sample Api Response
```JSON
{
"status": "success",
"message": null,
"object": {
"addresses": [
{
"city": "tehran",
"type": "origin",
"lat": 35.75546,
"lng": 51.416874,
"priority": 0
},
{
"city": "tehran",
"type": "destination",
"lat": 35.758495,
"lng": 51.44255,
"priority": 1,
"distance": 2341,
"duration": 288,
"price": 3000
},
{
"city": "tehran",
"type": "destination",
"lat": 35.895452,
"lng": 51.589632,
"priority": 2,
"distance": 20192,
"duration": 2492,
"price": 16000
}
],
"price": 31500,
"credit": false,
"distance": 22533,
"duration": 2780,
"status": "OK",
"user_credit": "0",
"delay": 0,
"city": "tehran",
"transport_type": "motor_taxi",
"has_return": false,
"cashed": false,
"price_with_return": 47250
}
}
```
#### 5. Create Order
Once you calculated your the price of your order, you can use this endpoint in order to create a new order.
```PHP
use AloPeyk\Model\Address;
use AloPeyk\Model\Order;
/*
* Create Origin: Behjat Abad
*/
$origin = new Address('origin', 'tehran', '35.755460', '51.416874');
$origin->setAddress("... Behjat Abad, Tehran");
$origin->setDescription("Behjat Abad"); // optional
$origin->setUnit("44"); // optional
$origin->setNumber("1"); // optional
$origin->setPersonFullname("Leonardo DiCaprio"); // optional
$origin->setPersonPhone("09370000000"); // optional
/*
* Create First Destination: N Sohrevardi Ave
*/
$firstDest = new Address('destination', 'tehran', '35.758495', '51.442550');
$firstDest->setAddress("... N Sohrevardi Ave, Tehran");
$firstDest->setDescription("N Sohrevardi Ave"); // optional
$firstDest->setUnit("55"); // optional
$firstDest->setNumber("2"); // optional
$firstDest->setPersonFullname("Eddie Redmayne"); // optional
$firstDest->setPersonPhone("09380000000"); // optional
/*
* Create Second Destination: Ahmad Qasir Bokharest St
*/
$secondDest = new Address('destination', 'tehran', '35.895452', '51.589632');
$secondDest->setAddress("... Ahmad Qasir Bokharest St, Tehran");
$secondDest->setDescription("Ahmad Qasir Bokharest St"); // optional
$secondDest->setUnit("66"); // optional
$secondDest->setNumber("3"); // optional
$secondDest->setPersonFullname("Matt Damon"); // optional
$secondDest->setPersonPhone("09390000000"); // optional
$order = new Order('motor_taxi', $origin, [$firstDest, $secondDest]);
$order->setHasReturn(true);
$apiResponse = $order->create($order);
var_dump($apiResponse);
```
##### Sample Api Response
```JSON
{
"status": "success",
"message": null,
"object": {
"city": "tehran",
"transport_type": "motor_taxi",
"customer_id": 99,
"status": "new",
"launched_at": "2017-09-19T12:26:08+04:30",
"delay": 0,
"price": 31500,
"credit": false,
"cashed": false,
"has_return": false,
"distance": 22533,
"duration": 2780,
"invoice_number": "LKH3LN",
"pay_at_dest": false,
"device_id": null,
"weight": 20,
"is_api": true,
"updated_at": "2017-09-19T12:26:08+04:30",
"created_at": "2017-09-19T12:26:08+04:30",
"id": 300,
"signature": null,
"order_token": "099c68a4a300ga2165445145a8eg992375433db",
"nprice": null,
"subsidy": null,
"signed_by": null,
"addresses": [
{
"id": 568522,
"order_id": 300,
"customer_id": 99,
"courier_id": null,
"lat": 35.75546,
"lng": 51.416874,
"type": "origin",
"priority": 0,
"city": "tehran",
"status": "pending",
"address": "address of order s origin",
"description": "some description for origin",
"unit": "unit of origin address",
"number": "number of origin address",
"person_fullname": "sender s name",
"person_phone": "sender s phone",
"signed_by": null,
"distance": null,
"google_distance": null,
"duration": null,
"google_duration": null,
"arrived_at": null,
"handled_at": null,
"created_at": "2017-09-19T12:26:08+04:30",
"updated_at": "2017-09-19T12:26:08+04:30",
"deleted_at": null,
"arrive_lat": null,
"arrive_lng": null,
"handle_lat": null,
"handle_lng": null,
"signature": null
},
{
"id": 568523,
"order_id": 300,
"customer_id": 99,
"courier_id": null,
"lat": 35.758495,
"lng": 51.44255,
"type": "destination",
"priority": 1,
"city": "tehran",
"status": "pending",
"address": "address of order s origin",
"description": "some description for origin",
"unit": "unit of origin address",
"number": "number of origin address",
"person_fullname": "sender s name",
"person_phone": "sender s phone",
"signed_by": null,
"distance": 2341,
"google_distance": null,
"duration": 288,
"google_duration": null,
"arrived_at": null,
"handled_at": null,
"created_at": "2017-09-19T12:26:08+04:30",
"updated_at": "2017-09-19T12:26:08+04:30",
"deleted_at": null,
"arrive_lat": null,
"arrive_lng": null,
"handle_lat": null,
"handle_lng": null,
"signature": null
},
{
"id": 568524,
"order_id": 300,
"customer_id": 99,
"courier_id": null,
"lat": 35.895452,
"lng": 51.589632,
"type": "destination",
"priority": 2,
"city": "tehran",
"status": "pending",
"address": "address of order s origin",
"description": "some description for origin",
"unit": "unit of origin address",
"number": "number of origin address",
"person_fullname": "sender s name",
"person_phone": "sender s phone",
"signed_by": null,
"distance": 20192,
"google_distance": null,
"duration": 2492,
"google_duration": null,
"arrived_at": null,
"handled_at": null,
"created_at": "2017-09-19T12:26:08+04:30",
"updated_at": "2017-09-19T12:26:08+04:30",
"deleted_at": null,
"arrive_lat": null,
"arrive_lng": null,
"handle_lat": null,
"handle_lng": null,
"signature": null
}
]
}
}
```
#### 6. Get Order Detail
In order to get the order details, call this method.
```PHP
use AloPeyk\Model\Order;
// $orderID = " 309 ";
// $orderID = " 309";
// $orderID = '';
// $orderID = null;
$orderID = 309;
$apiResponse = Order::getDetails($orderID);
var_dump($apiResponse);
```
##### Sample Api Response
```JSON
"status": "success",
"message": null,
"object": {
"id": 309,
"invoice_number": "DT63AL",
"customer_id": 99,
"device_id": null,
"courier_id": 130,
"cancelled_by": null,
"status": "delivered",
"distance": 22533,
"duration": 2780,
"price": 31500,
"credit": false,
"cashed": false,
"has_return": false,
"pay_at_dest": false,
"delay": 0,
"transport_type": "motor_taxi",
"city": "tehran",
"is_api": true,
"weight": 20,
"accept_lat": 35.748778183994,
"accept_lng": 51.411911191127,
"rate": 0,
"comment": null,
"scheduled_at": null,
"launched_at": "2017-09-20T11:32:34+04:30",
"accepted_at": "2017-09-20T11:32:37+04:30",
"delivered_at": "2017-09-20T11:39:38+04:30",
"finished_at": null,
"stopped_at": null,
"removed_at": null,
"created_at": "2017-09-20T11:32:34+04:30",
"updated_at": "2017-09-20T11:39:38+04:30",
"deleted_at": null,
"picking_at": "2017-09-20T11:33:37+04:30",
"delivering_at": "2017-09-20T11:34:37+04:30",
"addresses": [
{
"lat": "35.75546",
"lng": "51.416874",
"type": "origin",
"priority": 0,
"arrived_at": "2017-09-20T11:33:37+04:30",
"handled_at": "2017-09-20T11:34:37+04:30",
"id": 568548,
"city": "tehran",
"order_id": "309",
"customer_id": "99",
"courier_id": "130",
"status": "handled",
"address": "address of order s origin",
"description": "some description for origin",
"unit": "unit of origin address",
"number": "number of origin address",
"person_fullname": "sender s name",
"person_phone": "sender s phone",
"signed_by": "",
"distance": "868",
"duration": "107",
"created_at": "2017-09-20T11:32:34+04:30",
"updated_at": "2017-09-20T11:34:37+04:30",
"deleted_at": "",
"arrive_lat": "35.750245509478695",
"arrive_lng": "51.397214392844006",
"handle_lat": "35.7501112063621",
"handle_lng": "51.41630904680925",
"signature": {
"url": "/uploads/order/309/address/568548/signature.jpg?var=1506000110"
}
},
{
"lat": "35.758495",
"lng": "51.44255",
"type": "destination",
"priority": 1,
"arrived_at": "2017-09-20T11:35:38+04:30",
"handled_at": "2017-09-20T11:36:38+04:30",
"id": 568549,
"city": "tehran",
"order_id": "309",
"customer_id": "99",
"courier_id": "130",
"status": "handled",
"address": "address of order s origin",
"description": "some description for origin",
"unit": "unit of origin address",
"number": "number of origin address",
"person_fullname": "sender s name",
"person_phone": "sender s phone",
"signed_by": "",
"distance": "2341",
"duration": "288",
"created_at": "2017-09-20T11:32:34+04:30",
"updated_at": "2017-09-20T11:36:38+04:30",
"deleted_at": "",
"arrive_lat": "35.7581975033594",
"arrive_lng": "51.41919184233538",
"handle_lat": "35.76113384396972",
"handle_lng": "51.414348540631",
"signature": {
"url": "/uploads/order/309/address/568549/signature.jpg?var=1506000110"
}
},
{
"lat": "35.895452",
"lng": "51.589632",
"type": "destination",
"priority": 2,
"arrived_at": "2017-09-20T11:37:38+04:30",
"handled_at": "2017-09-20T11:39:38+04:30",
"id": 568550,
"city": "tehran",
"order_id": "309",
"customer_id": "99",
"courier_id": "130",
"status": "handled",
"address": "address of order s origin",
"description": "some description for origin",
"unit": "unit of origin address",
"number": "number of origin address",
"person_fullname": "sender s name",
"person_phone": "sender s phone",
"signed_by": "",
"distance": "20192",
"duration": "2492",
"created_at": "2017-09-20T11:32:34+04:30",
"updated_at": "2017-09-20T11:39:38+04:30",
"deleted_at": "",
"arrive_lat": "35.76024827733142",
"arrive_lng": "51.3950500507545",
"handle_lat": "35.75058415169185",
"handle_lng": "51.40547057923416",
"signature": {
"url": "/uploads/order/309/address/568550/signature.jpg?var=1506000110"
}
}
],
"screenshot": {
"url": "https:screenshots.alopeyk.com/?size=640x330&maptype=roadmap&language=fa&markers=icon:https:api.alopeyk.com/images/marker-origin.png%7C35.75546,51.416874&markers=icon:https:api.alopeyk.com/images/marker-destination.png%7C35.758495,51.44255&markers=icon:https:api.alopeyk.com/images/marker-destination.png%7C35.895452,51.589632"
},
"progress": "1.0000",
"courier": {
"id": 130,
"phone": "09499359023",
"firstname": "محمد رضا",
"lastname": "نورشی",
"email": "",
"avatar": {
"url": "/uploads/user/130/avatar.jpg?var=1506000110"
},
"last_online": null,
"is_online": null
},
"customer": {
"id": 99,
"phone": "09701234567",
"firstname": "mohammad hassan",
"lastname": "daneshvar",
"email": "daneshvar.email@gmail.com",
"avatar": {
"url": "/uploads/user/99/avatar.jpg?var=1506000110"
},
"last_online": null,
"is_online": null
},
"last_position_minimal": null,
"eta_minimal": {
"id": 46,
"last_position_id": 55,
"duration": 0,
"distance": 0,
"action": "handle",
"address_id": "568550",
"updated_at": "2017-09-20 11:36:39"
},
"signature": {
"url": "/uploads/order/309/address/568550/signature.jpg?var=1506000110"
},
"order_token": "69b9e3f08309g2b19e2458fa429g99734670660",
"nprice": null,
"subsidy": null,
"signed_by": ""
}
}
```
#### 7. Cancel Order
You can cancel any order before courier arrival (before the accepted status)
```PHP
use AloPeyk\Model\Order;
// $orderID = " 300 "; // works fine as 300
// $orderID = " 300
"; // works fine as 300
// $orderID = ''; // throws AloPeykException
// $orderID = null; // throws AloPeykException
$orderID = 300;
$apiResponse = Order::cancel($orderID);
var_dump($apiResponse);
```
##### Sample Api Response
```JSON
{
"status": "success",
"message": null,
"object": {
"id": 300,
"status": "cancelled",
"courier_id": 121,
"customer_id": 99,
"signature": {
"url": "/uploads/order/300/signature.jpg?var=1505807816"
},
"order_token": null,
"nprice": null,
"subsidy": null,
"signed_by": ""
}
}
```
## License
This package is released under the __MIT license__.
Copyright (c) 2012-2017 Markus Poerschke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.