-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
58 lines (47 loc) · 1.79 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
use Konectdigital\GlovoApi\GlovoException as Exception;
use Konectdigital\GlovoApi\Models\Address;
use Konectdigital\GlovoApi\Models\Order;
use Konectdigital\GlovoApi\Service;
$apiKey = "158634433098486";
$apiSecret = "d244ec3f6d5b4983a68716e4df443f6b";
$api = new Service($apiKey, $apiSecret);
// $api->sandbox_mode( true );
$source = new Address(Address::TYPE_PICKUP, -34.919861, -57.919027, "Diag. 73 1234", "1st floor");
$destination = new Address(Address::TYPE_DELIVERY, -34.922945, -57.990177, "Diag. 73 75", "3A");
$order = new Order();
$order->setDescription("1 big hammer");
$order->setAddresses([$source, $destination]);
// $order->setScheduleTime( ( new \DateTime( '+1 hour' ) )->setTime( 19, 0 ) );
try {
$orderEstimate = $api->estimateOrderPrice($order);
echo "Estimate: {$orderEstimate['total']['amount']}{$orderEstimate['total']['currency']} \n";
} catch (Exception $e) {
echo $e->getMessage();
}
try {
$orderInfo = $api->createOrder($order);
echo "Order created, ID: {$orderInfo['id']}, state: {$orderInfo['state']} \n";
} catch (Exception $e) {
echo $e->getMessage();
}
$order_id = $orderInfo['id'];
$laststate = $orderInfo['state'];
//Track Order
while ($laststate !== Order::STATE_DELIVERED) {
$info = $api->retrieveOrder($order_id);
if ($info['state'] !== $laststate) {
$laststate = $info['state'];
if ($laststate === Order::STATE_ACTIVE) {
$courier_info = $api->getCourierContact($order_id);
echo "Your courier is {$courier_info['courier']}, Phone number {$courier_info['phone']}\n";
} else {
echo "Current order status is $laststate \n";
}
}
if ($laststate === Order::STATE_ACTIVE) {
$tracking = $api->getOrderTracking($order_id);
echo "Current order position is {$tracking['lat']} lattitude and {$tracking['lon']} longitude\n";
}
sleep(45);
}