PHP code example of alopeyk / alopeyk-api-php
1. Go to this page and download the library: Download alopeyk/alopeyk-api-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alopeyk / alopeyk-api-php example snippets
use AloPeyk\AloPeykApiHandler;
$apiResponse = AloPeykApiHandler::authenticate();
if ($apiResponse && $apiResponse->status == "success") {
$user = $apiResponse->object->user;
echo $user->firstname . " " . $user->lastname;
}
use AloPeyk\Model\Location;
$apiResponse = Location::getAddress("35.732595", "51.413379");
if ($apiResponse && $apiResponse->status == "success") {
echo $apiResponse->object->district;
}
use AloPeyk\Model\Location;
// $locationName = null; // returns AloPeyk Exception
// $locationName = ''; // returns AloPeyk Exception
$locationName = "أرژ";
$apiResponse = Location::getSuggestions($locationName);
if ($apiResponse && $apiResponse->status == "success") {
$locations = $apiResponse->object;
echo "<ol>";
foreach ($locations as $location) {
echo "<li>";
echo $location->region . ": " . $location->title;
echo "</li>";
}
echo "</ol>";
}
use AloPeyk\Model\Address;
use AloPeyk\Model\Order;
/*
* Create Origin Address
*/
$origin = new Address('origin', '35.723711', '51.410547');
/*
* Create First Destination
*/
$firstDest = new Address('destination', '35.728457', '51.436969');
/*
* Create Second Destination
*/
$secondDest = new Address('destination', '35.729379', '51.418151');
/*
* Create New Order
*/
$order = new Order('motor_taxi', $origin, [$firstDest, $secondDest]);
$order->setHasReturn(true);
$apiResponse = $order->getPrice();
if ($apiResponse && $apiResponse->status == "success") {
$addresses = $apiResponse->object->addresses;
$origin = $addresses[0];
echo "ORIGIN: {$origin->city} ({$origin->lat} , {$origin->lng})";
echo "<br/>";
echo "Transport Type: " . $apiResponse->object->transport_type;
echo "<hr/>";
$destinations = array_shift($addresses);
echo "<table border='1' cellspacing='0'>
<thead>
<tr style='background: #bddaf5'>
<th>#</th>
<th>City</th>
<th>Distance</th>
<th>Duration</th>
<th>Price</th>
</tr>
</thead>
<tbody>
";
foreach ($addresses as $destination) {
echo "<tr>
<td>{$destination->priority}</td>
<td>{$destination->city}</td>
<td>{$destination->distance}</td>
<td>{$destination->duration}</td>
<td>{$destination->price}</td>
</tr>";
}
echo "<tr style='background: #7ab2a5; text-align: center'>
<td colspan='2'>Total</td>
<td>{$apiResponse->object->distance}(meters)</td>
<td>{$apiResponse->object->duration}(seconds)</td>
<td>{$apiResponse->object->price}(toman)</td>
</tr>";
}
use AloPeyk\Model\Address;
use AloPeyk\Model\Order;
/*
* Create Origin: Behjat Abad
*/
$origin = new Address('origin', '35.755460', '51.416874');
$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', '35.758495', '51.442550');
$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', '35.895452', '51.589632');
$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);
use AloPeyk\Model\Order;
// $orderID = " 309 ";
// $orderID = " 309<p>";
// $orderID = '';
// $orderID = null;
$orderID = 309;
$apiResponse = Order::getDetails($orderID);
var_dump($apiResponse);
use AloPeyk\Model\Order;
// $orderID = " 300 "; // works fine as 300
// $orderID = " 300<p>"; // works fine as 300
// $orderID = ''; // throws AloPeykException
// $orderID = null; // throws AloPeykException
$orderID = 300;
$apiResponse = Order::cancel($orderID);
var_dump($apiResponse);
use AloPeyk\Model\Address;
use AloPeyk\Model\Order;
/*
* Create Origin Address
*/
$origin = new Address('origin', '35.723711', '51.410547');
/*
* Create First Destination
*/
$firstDest = new Address('destination', '35.728457', '51.436969');
/*
* Create Second Destination
*/
$secondDest = new Address('destination', '35.729379', '51.418151');
/*
* Create New Order
*/
$orders[] = new Order('motor_taxi', $origin, [$firstDest, $secondDest]);
$orders[] = new Order('car', $origin, [$firstDest, $secondDest]);
$orders[] = new Order('cargo_s', $origin, [$firstDest, $secondDest]);
$orders[] = new Order('cargo', $origin, [$firstDest, $secondDest]);
$apiResponse = AloPeykApiHandler::getBatchPrice($orders);