GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( ce7ad9...c183ba )
by Igor
08:49 queued 18s
created
examples/Order_V5/CreateBatchOfOrders.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -15,41 +15,41 @@
 block discarded – undo
15 15
 Route4Me::setApiKey(Constants::API_KEY);
16 16
 
17 17
 $ordersParams = [
18
-    [
19
-        'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US',
20
-        'address_alias' => 'Address for batch workflow 0',
21
-        'address_city' => 'Philadelphia',
22
-        'address_geo' => [
23
-            'lat' => 48.335991,
24
-            'lng' => 31.18287
25
-        ],
26
-        'first_name' => 'John',
27
-        'last_name' => 'Doe',
28
-        'email' => '[email protected]'
29
-    ], [
30
-        'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US',
31
-        'address_alias' => 'Address for batch workflow 1',
32
-        'address_city' => 'Philadelphia',
33
-        'address_geo' => [
34
-            'lat' => 48.335991,
35
-            'lng' => 31.18287
36
-        ],
37
-        'first_name' => 'John',
38
-        'last_name' => 'Doe',
39
-        'email' => '[email protected]'
40
-    ]
18
+	[
19
+		'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US',
20
+		'address_alias' => 'Address for batch workflow 0',
21
+		'address_city' => 'Philadelphia',
22
+		'address_geo' => [
23
+			'lat' => 48.335991,
24
+			'lng' => 31.18287
25
+		],
26
+		'first_name' => 'John',
27
+		'last_name' => 'Doe',
28
+		'email' => '[email protected]'
29
+	], [
30
+		'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US',
31
+		'address_alias' => 'Address for batch workflow 1',
32
+		'address_city' => 'Philadelphia',
33
+		'address_geo' => [
34
+			'lat' => 48.335991,
35
+			'lng' => 31.18287
36
+		],
37
+		'first_name' => 'John',
38
+		'last_name' => 'Doe',
39
+		'email' => '[email protected]'
40
+	]
41 41
 ];
42 42
 
43 43
 try {
44
-    $orders = new Orders();
45
-
46
-    // create a batch of orders
47
-    $res = $orders->batchCreate($ordersParams);
48
-    if ($res) {
49
-        echo "Create a batch of orders." . PHP_EOL;
50
-    } else {
51
-        echo "Error to create a batch of orders." . PHP_EOL;
52
-    }
44
+	$orders = new Orders();
45
+
46
+	// create a batch of orders
47
+	$res = $orders->batchCreate($ordersParams);
48
+	if ($res) {
49
+		echo "Create a batch of orders." . PHP_EOL;
50
+	} else {
51
+		echo "Error to create a batch of orders." . PHP_EOL;
52
+	}
53 53
 } catch (Exception $e) {
54
-    echo "ERROR: " . $e->getMessage() . PHP_EOL;
54
+	echo "ERROR: " . $e->getMessage() . PHP_EOL;
55 55
 }
Please login to merge, or discard this patch.
examples/Order_V5/SearchOrders.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -16,30 +16,30 @@
 block discarded – undo
16 16
 Route4Me::setApiKey(Constants::API_KEY);
17 17
 
18 18
 try {
19
-    $orders = new Orders();
20
-
21
-    // Get all the orders created under the specific Route4Me account
22
-    $ordersAll = $orders->search();
23
-
24
-    // Search orders by known IDs
25
-    $params = [
26
-        "filters" => [
27
-            "order_ids" => ["B3CBB9C07D37406997EE73D9CEC18264", "D91F4962CC4C468A9563896A93DBE4D7"]
28
-        ]
29
-    ];
30
-    $ordersByIds = $orders->search($params);
31
-
32
-    // Search all the orders with specific address_alias, return only specific fields in response.
33
-    $params = [
34
-        "return_provided_fields_as_map" => true,
35
-        "fields" => ["order_uuid", "address_alias", "email", "first_name", "phone"],
36
-        "search" => [
37
-            "matches" => ["address_alias" => "Auto test address"]
38
-        ]
39
-    ];
40
-    $ordersWithAddress = $orders->search($params);
41
-
42
-    print_r($ordersWithAddress);
19
+	$orders = new Orders();
20
+
21
+	// Get all the orders created under the specific Route4Me account
22
+	$ordersAll = $orders->search();
23
+
24
+	// Search orders by known IDs
25
+	$params = [
26
+		"filters" => [
27
+			"order_ids" => ["B3CBB9C07D37406997EE73D9CEC18264", "D91F4962CC4C468A9563896A93DBE4D7"]
28
+		]
29
+	];
30
+	$ordersByIds = $orders->search($params);
31
+
32
+	// Search all the orders with specific address_alias, return only specific fields in response.
33
+	$params = [
34
+		"return_provided_fields_as_map" => true,
35
+		"fields" => ["order_uuid", "address_alias", "email", "first_name", "phone"],
36
+		"search" => [
37
+			"matches" => ["address_alias" => "Auto test address"]
38
+		]
39
+	];
40
+	$ordersWithAddress = $orders->search($params);
41
+
42
+	print_r($ordersWithAddress);
43 43
 } catch (Exception $e) {
44
-    echo "ERROR: " . $e->getMessage() . PHP_EOL;
44
+	echo "ERROR: " . $e->getMessage() . PHP_EOL;
45 45
 }
Please login to merge, or discard this patch.
examples/Order_V5/CreateOrderCustomField.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -16,12 +16,12 @@  discard block
 block discarded – undo
16 16
 Route4Me::setApiKey(Constants::API_KEY);
17 17
 
18 18
 $customField = new CustomField([
19
-    'order_custom_field_name' => 'CustomField1',
20
-    'order_custom_field_label' => 'Custom Field 1',
21
-    'order_custom_field_type' => 'checkbox',
22
-    'order_custom_field_type_info' => [
23
-        'short_label' => 'cFl1'
24
-    ]
19
+	'order_custom_field_name' => 'CustomField1',
20
+	'order_custom_field_label' => 'Custom Field 1',
21
+	'order_custom_field_type' => 'checkbox',
22
+	'order_custom_field_type_info' => [
23
+		'short_label' => 'cFl1'
24
+	]
25 25
 ]);
26 26
 
27 27
 print_r($customField);
@@ -30,41 +30,41 @@  discard block
 block discarded – undo
30 30
 $uuid = null;
31 31
 
32 32
 try {
33
-    $orders = new Orders();
33
+	$orders = new Orders();
34 34
 
35
-    // create custom field
36
-    $newField = $orders->createOrderCustomField($customField);
37
-    $uuid = $newField->order_custom_field_uuid;
38
-    echo "Create Custom field, label is '" . $newField->order_custom_field_label . "'" . PHP_EOL;
35
+	// create custom field
36
+	$newField = $orders->createOrderCustomField($customField);
37
+	$uuid = $newField->order_custom_field_uuid;
38
+	echo "Create Custom field, label is '" . $newField->order_custom_field_label . "'" . PHP_EOL;
39 39
 
40
-    // update custom field
41
-    $customField->order_custom_field_label = 'Custom Field New';
42
-    $updateField = $orders->updateOrderCustomField($uuid, $customField);
43
-    echo "Update Custom field, label is '" . $updateField->order_custom_field_label . "'" . PHP_EOL;
40
+	// update custom field
41
+	$customField->order_custom_field_label = 'Custom Field New';
42
+	$updateField = $orders->updateOrderCustomField($uuid, $customField);
43
+	echo "Update Custom field, label is '" . $updateField->order_custom_field_label . "'" . PHP_EOL;
44 44
 
45
-    // read custom fields
46
-    $readFields = $orders->getOrderCustomFields();
47
-    foreach ($readFields as $key => $field) {
48
-        if ($field->order_custom_field_uuid === $uuid) {
49
-            echo "Found Custom field with label '" . $field->order_custom_field_label . "'" . PHP_EOL;
50
-            break;
51
-        }
52
-    }
53
-    // delete custom field
54
-    if ($orders->deleteOrderCustomField($uuid)) {
55
-        echo "Custom field with uuid='" . $uuid . "' was deleted successful." . PHP_EOL;
56
-    } else {
57
-        echo "Custom field with uuid='" . $uuid . "' was not deleted." . PHP_EOL;
58
-    }
45
+	// read custom fields
46
+	$readFields = $orders->getOrderCustomFields();
47
+	foreach ($readFields as $key => $field) {
48
+		if ($field->order_custom_field_uuid === $uuid) {
49
+			echo "Found Custom field with label '" . $field->order_custom_field_label . "'" . PHP_EOL;
50
+			break;
51
+		}
52
+	}
53
+	// delete custom field
54
+	if ($orders->deleteOrderCustomField($uuid)) {
55
+		echo "Custom field with uuid='" . $uuid . "' was deleted successful." . PHP_EOL;
56
+	} else {
57
+		echo "Custom field with uuid='" . $uuid . "' was not deleted." . PHP_EOL;
58
+	}
59 59
 } catch (Exception $e) {
60
-    echo "ERROR: " . $e->getMessage() . PHP_EOL;
60
+	echo "ERROR: " . $e->getMessage() . PHP_EOL;
61 61
 
62
-    if ($orders && $uuid) {
63
-        try {
64
-            $orders->deleteOrderCustomField($uuid);
65
-            echo "Custom field with uuid='" . $uuid . "' was cleaned up successful." . PHP_EOL;
66
-        } catch (Exception $e) {
67
-            echo "Custom field with uuid='" . $uuid . "' was not cleaned up." . PHP_EOL;
68
-        }
69
-    }
62
+	if ($orders && $uuid) {
63
+		try {
64
+			$orders->deleteOrderCustomField($uuid);
65
+			echo "Custom field with uuid='" . $uuid . "' was cleaned up successful." . PHP_EOL;
66
+		} catch (Exception $e) {
67
+			echo "Custom field with uuid='" . $uuid . "' was not cleaned up." . PHP_EOL;
68
+		}
69
+	}
70 70
 }
Please login to merge, or discard this patch.
examples/Order_V5/GetOrderByUuid.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -17,60 +17,60 @@
 block discarded – undo
17 17
 Route4Me::setApiKey(Constants::API_KEY);
18 18
 
19 19
 $order = new Order([
20
-    'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US',
21
-    'address_alias' => 'Auto test address',
22
-    'address_city' => 'Philadelphia',
23
-    'address_geo' => [
24
-        'lat' => 48.335991,
25
-        'lng' => 31.18287
26
-    ],
27
-    'first_name' => 'John',
28
-    'last_name' => 'Doe',
29
-    'email' => '[email protected]'
20
+	'address_1' => '1358 E Luzerne St, Philadelphia, PA 19124, US',
21
+	'address_alias' => 'Auto test address',
22
+	'address_city' => 'Philadelphia',
23
+	'address_geo' => [
24
+		'lat' => 48.335991,
25
+		'lng' => 31.18287
26
+	],
27
+	'first_name' => 'John',
28
+	'last_name' => 'Doe',
29
+	'email' => '[email protected]'
30 30
 ]);
31 31
 
32 32
 $orders = null;
33 33
 $orderId = null;
34 34
 
35 35
 try {
36
-    $orders = new Orders();
36
+	$orders = new Orders();
37 37
 
38
-    // create order
39
-    $newOrder = $orders->create($order);
40
-    $orderId = $newOrder->order_id;
41
-    $orderUuid = $newOrder->order_uuid;
42
-    echo "Create Order with id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
38
+	// create order
39
+	$newOrder = $orders->create($order);
40
+	$orderId = $newOrder->order_id;
41
+	$orderUuid = $newOrder->order_uuid;
42
+	echo "Create Order with id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
43 43
 
44
-    // get order by ID
45
-    $orderById = $orders->get($orderId);
46
-    echo "Read Order by id, id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
44
+	// get order by ID
45
+	$orderById = $orders->get($orderId);
46
+	echo "Read Order by id, id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
47 47
 
48
-    // get order by UUID
49
-    $orderByUuid = $orders->get($orderUuid);
50
-    echo "Read Order by uuid, id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
48
+	// get order by UUID
49
+	$orderByUuid = $orders->get($orderUuid);
50
+	echo "Read Order by uuid, id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
51 51
 
52
-    // compare orders
53
-    if ($orderById == $orderByUuid) {
54
-        echo "The Orders are equal." . PHP_EOL;
55
-    } else {
56
-        echo "The Orders are not equal." . PHP_EOL;
57
-    }
52
+	// compare orders
53
+	if ($orderById == $orderByUuid) {
54
+		echo "The Orders are equal." . PHP_EOL;
55
+	} else {
56
+		echo "The Orders are not equal." . PHP_EOL;
57
+	}
58 58
 
59
-    // delete order
60
-    if ($orders->delete($orderUuid)) {
61
-        echo "Order with uuid='" . $orderUuid . "' was deleted successful." . PHP_EOL;
62
-    } else {
63
-        echo "Order with uuid='" . $orderUuid . "' was not deleted." . PHP_EOL;
64
-    }
59
+	// delete order
60
+	if ($orders->delete($orderUuid)) {
61
+		echo "Order with uuid='" . $orderUuid . "' was deleted successful." . PHP_EOL;
62
+	} else {
63
+		echo "Order with uuid='" . $orderUuid . "' was not deleted." . PHP_EOL;
64
+	}
65 65
 } catch (Exception $e) {
66
-    echo "ERROR: " . $e->getMessage() . PHP_EOL;
66
+	echo "ERROR: " . $e->getMessage() . PHP_EOL;
67 67
 
68
-    if ($orders && $orderId) {
69
-        try {
70
-            $orders->delete($orderUuid);
71
-            echo "Order with uuid='" . $orderUuid . "' was cleaned up successful." . PHP_EOL;
72
-        } catch (Exception $e) {
73
-            echo "Order with uuid='" . $orderUuid . "' was not cleaned up." . PHP_EOL;
74
-        }
75
-    }
68
+	if ($orders && $orderId) {
69
+		try {
70
+			$orders->delete($orderUuid);
71
+			echo "Order with uuid='" . $orderUuid . "' was cleaned up successful." . PHP_EOL;
72
+		} catch (Exception $e) {
73
+			echo "Order with uuid='" . $orderUuid . "' was not cleaned up." . PHP_EOL;
74
+		}
75
+	}
76 76
 }
Please login to merge, or discard this patch.
examples/Order/GetOrderByUuid.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -14,59 +14,59 @@
 block discarded – undo
14 14
 Route4Me::setApiKey(Constants::API_KEY);
15 15
 
16 16
 $orderParams = Order::fromArray([
17
-    'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
18
-    'cached_lat'                => 48.335991,
19
-    'cached_lng'                => 31.18287,
20
-    'address_alias'             => 'Auto test address',
21
-    'address_city'              => 'Philadelphia',
22
-    'EXT_FIELD_first_name'      => 'John',
23
-    'EXT_FIELD_last_name'       => 'Doe',
24
-    'EXT_FIELD_email'           => '[email protected]'
17
+	'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
18
+	'cached_lat'                => 48.335991,
19
+	'cached_lng'                => 31.18287,
20
+	'address_alias'             => 'Auto test address',
21
+	'address_city'              => 'Philadelphia',
22
+	'EXT_FIELD_first_name'      => 'John',
23
+	'EXT_FIELD_last_name'       => 'Doe',
24
+	'EXT_FIELD_email'           => '[email protected]'
25 25
 ]);
26 26
 
27 27
 $order = null;
28 28
 $orderId = null;
29 29
 
30 30
 try {
31
-    $order = new Order();
31
+	$order = new Order();
32 32
 
33
-    // create order
34
-    $newOrder = $order->addOrder($orderParams);
35
-    $orderId = $newOrder['order_id'];
36
-    $orderUuid = $newOrder['order_uuid'];
37
-    echo "Create Order with id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
33
+	// create order
34
+	$newOrder = $order->addOrder($orderParams);
35
+	$orderId = $newOrder['order_id'];
36
+	$orderUuid = $newOrder['order_uuid'];
37
+	echo "Create Order with id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
38 38
 
39
-    // get order by ID
40
-    $orderById = $order->getOrder(['order_id' => $orderId]);
41
-    echo "Read Order by id, id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
39
+	// get order by ID
40
+	$orderById = $order->getOrder(['order_id' => $orderId]);
41
+	echo "Read Order by id, id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
42 42
 
43
-    // get order by UUID
44
-    $orderByUuid = $order->getOrder(['order_id' => $orderUuid]);
45
-    echo "Read Order by uuid, id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
43
+	// get order by UUID
44
+	$orderByUuid = $order->getOrder(['order_id' => $orderUuid]);
45
+	echo "Read Order by uuid, id='" . $orderId . "' and uuid='" . $orderUuid . "'" . PHP_EOL;
46 46
 
47
-    // compare orders
48
-    if ($orderById == $orderByUuid) {
49
-        echo "The Orders are equal." . PHP_EOL;
50
-    } else {
51
-        echo "The Orders are not equal." . PHP_EOL;
52
-    }
47
+	// compare orders
48
+	if ($orderById == $orderByUuid) {
49
+		echo "The Orders are equal." . PHP_EOL;
50
+	} else {
51
+		echo "The Orders are not equal." . PHP_EOL;
52
+	}
53 53
 
54
-    // delete order
55
-    $res = $order->removeOrder(['order_ids' => [$orderUuid]]);
56
-    if ($res) {
57
-        echo "Order with uuid='" . $orderUuid . "' was deleted successful." . PHP_EOL;
58
-    } else {
59
-        echo "Order with uuid='" . $orderUuid . "' was not deleted." . PHP_EOL;
60
-    }
54
+	// delete order
55
+	$res = $order->removeOrder(['order_ids' => [$orderUuid]]);
56
+	if ($res) {
57
+		echo "Order with uuid='" . $orderUuid . "' was deleted successful." . PHP_EOL;
58
+	} else {
59
+		echo "Order with uuid='" . $orderUuid . "' was not deleted." . PHP_EOL;
60
+	}
61 61
 } catch (Exception $e) {
62
-    echo "ERROR: " . $e->getMessage() . PHP_EOL;
62
+	echo "ERROR: " . $e->getMessage() . PHP_EOL;
63 63
 
64
-    if ($order && $orderId) {
65
-        try {
66
-            $order->removeOrder(['order_ids' => [$orderUuid]]);
67
-            echo "Order with uuid='" . $orderUuid . "' was cleaned up successful." . PHP_EOL;
68
-        } catch (Exception $e) {
69
-            echo "Order with uuid='" . $orderUuid . "' was not cleaned up." . PHP_EOL;
70
-        }
71
-    }
64
+	if ($order && $orderId) {
65
+		try {
66
+			$order->removeOrder(['order_ids' => [$orderUuid]]);
67
+			echo "Order with uuid='" . $orderUuid . "' was cleaned up successful." . PHP_EOL;
68
+		} catch (Exception $e) {
69
+			echo "Order with uuid='" . $orderUuid . "' was not cleaned up." . PHP_EOL;
70
+		}
71
+	}
72 72
 }
Please login to merge, or discard this patch.
UnitTestFiles/Test/OrderTests.php 1 patch
Indentation   +581 added lines, -581 removed lines patch added patch discarded remove patch
@@ -20,585 +20,585 @@
 block discarded – undo
20 20
 
21 21
 class OrderTests extends \PHPUnit\Framework\TestCase
22 22
 {
23
-    public static $createdOrders = [];
24
-    public static $createdProblems = [];
25
-
26
-    public static function setUpBeforeClass()
27
-    {
28
-        Route4Me::setApiKey(Constants::API_KEY);
29
-
30
-        //region -- Create Test Optimization --
31
-
32
-        // Huge list of addresses
33
-        $json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);
34
-        $json = array_slice($json, 0, 10);
35
-
36
-        $addresses = [];
37
-        foreach ($json as $address) {
38
-            $addresses[] = Address::fromArray($address);
39
-        }
40
-
41
-        $parameters = RouteParameters::fromArray([
42
-            'algorithm_type'    => Algorithmtype::TSP,
43
-            'route_name'        => 'Single Driver Multiple TW 10 Stops '.date('Y-m-d H:i'),
44
-            'route_date'        => time() + 24 * 60 * 60,
45
-            'route_time'        => 5 * 3600 + 30 * 60,
46
-            'distance_unit'     => DistanceUnit::MILES,
47
-            'device_type'       => DeviceType::WEB,
48
-            'optimize'          => OptimizationType::DISTANCE,
49
-            'metric'            => Metric::GEODESIC,
50
-        ]);
51
-
52
-        $optimizationParams = new OptimizationProblemParams();
53
-        $optimizationParams->setAddresses($addresses);
54
-        $optimizationParams->setParameters($parameters);
55
-
56
-        $problem = OptimizationProblem::optimize($optimizationParams);
57
-
58
-        self::$createdProblems[] = $problem;
59
-
60
-        //endregion
61
-
62
-        //region -- Create Test Order --
63
-
64
-        $orderParameters = Order::fromArray([
65
-            'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
66
-            'cached_lat'                => 48.335991,
67
-            'cached_lng'                => 31.18287,
68
-            'address_alias'             => 'Auto test address',
69
-            'address_city'              => 'Philadelphia',
70
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
71
-            'EXT_FIELD_first_name'      => 'Igor',
72
-            'EXT_FIELD_last_name'       => 'Progman',
73
-            'EXT_FIELD_email'           => '[email protected]',
74
-            'EXT_FIELD_phone'           => '380380380380',
75
-            'EXT_FIELD_custom_data'     => [
76
-                0 => [
77
-                    'order_id'  => '10',
78
-                    'name'      => 'Bill Soul',
79
-                ],
80
-            ],
81
-        ]);
82
-
83
-        $order = new Order();
84
-
85
-        $response = $order->addOrder($orderParameters);
86
-
87
-        self::assertNotNull($response);
88
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
89
-
90
-        self::$createdOrders[] = $response;
91
-
92
-        //endregion
93
-    }
94
-
95
-    public function testFromArray()
96
-    {
97
-        $orderParameters = Order::fromArray([
98
-            'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
99
-            'cached_lat'                => 48.335991,
100
-            'cached_lng'                => 31.18287,
101
-            'address_alias'             => 'Auto test address',
102
-            'address_city'              => 'Philadelphia',
103
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
104
-            'EXT_FIELD_first_name'      => 'Igor',
105
-            'EXT_FIELD_last_name'       => 'Progman',
106
-            'EXT_FIELD_email'           => '[email protected]',
107
-            'EXT_FIELD_phone'           => '380380380380',
108
-            'EXT_FIELD_custom_data'     => [
109
-                0 => [
110
-                    'order_id'  => '10',
111
-                    'name'      => 'Bill Soul',
112
-                ],
113
-            ],
114
-            'EXT_FIELD_cost'            => 50
115
-        ]);
116
-
117
-        $this->assertEquals('1358 E Luzerne St, Philadelphia, PA 19124, US', $orderParameters->address_1);
118
-        $this->assertEquals(48.335991, $orderParameters->cached_lat);
119
-        $this->assertEquals(31.18287, $orderParameters->cached_lng);
120
-        $this->assertEquals('Auto test address', $orderParameters->address_alias);
121
-        $this->assertEquals('Philadelphia', $orderParameters->address_city);
122
-        $this->assertEquals(date('Y-m-d'), $orderParameters->day_scheduled_for_YYMMDD);
123
-        $this->assertEquals('Igor', $orderParameters->EXT_FIELD_first_name);
124
-        $this->assertEquals('Progman', $orderParameters->EXT_FIELD_last_name);
125
-        $this->assertEquals('[email protected]', $orderParameters->EXT_FIELD_email);
126
-        $this->assertEquals('380380380380', $orderParameters->EXT_FIELD_phone);
127
-        $this->assertEquals([
128
-            0 => [
129
-                'order_id'  => '10',
130
-                'name'      => 'Bill Soul',
131
-            ],
132
-        ], $orderParameters->EXT_FIELD_custom_data);
133
-        $this->assertEquals(50, $orderParameters->EXT_FIELD_cost);
134
-    }
135
-
136
-    public function testToArray()
137
-    {
138
-        $orderParameters = Order::fromArray([
139
-            'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
140
-            'cached_lat'                => 48.335991,
141
-            'cached_lng'                => 31.18287,
142
-            'address_alias'             => 'Auto test address',
143
-            'address_city'              => 'Philadelphia',
144
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
145
-            'EXT_FIELD_first_name'      => 'Igor',
146
-            'EXT_FIELD_last_name'       => 'Progman',
147
-            'EXT_FIELD_email'           => '[email protected]',
148
-            'EXT_FIELD_phone'           => '380380380380',
149
-            'EXT_FIELD_custom_data'     => [
150
-                0 => [
151
-                    'order_id'  => '10',
152
-                    'name'      => 'Bill Soul',
153
-                ],
154
-            ],
155
-        ]);
156
-
157
-        $this->assertEquals(
158
-            $orderParameters->toArray(),
159
-            [
160
-                'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
161
-                'cached_lat'                => 48.335991,
162
-                'cached_lng'                => 31.18287,
163
-                'address_alias'             => 'Auto test address',
164
-                'address_city'              => 'Philadelphia',
165
-                'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
166
-                'EXT_FIELD_first_name'      => 'Igor',
167
-                'EXT_FIELD_last_name'       => 'Progman',
168
-                'EXT_FIELD_email'           => '[email protected]',
169
-                'EXT_FIELD_phone'           => '380380380380',
170
-                'EXT_FIELD_custom_data'     => [
171
-                    0 => [
172
-                        'order_id'  => '10',
173
-                        'name'      => 'Bill Soul',
174
-                    ],
175
-                ],
176
-            ],
177
-        ]);
178
-    }
179
-
180
-    public function testGetOrders()
181
-    {
182
-        $order = new Order();
183
-
184
-        $orderParameters = Order::fromArray([
185
-            'offset'    => 0,
186
-            'limit'     => 5,
187
-        ]);
188
-
189
-        $response = $order->getOrders($orderParameters);
190
-
191
-        $this->assertNotNull($response);
192
-        $this->assertTrue(is_array($response));
193
-        $this->assertTrue(isset($response['total']));
194
-        $this->assertTrue(isset($response['results']));
195
-        $this->assertInstanceOf(
196
-            Order::class,
197
-            Order::fromArray($response['results'][0])
198
-        );
199
-    }
200
-
201
-    public function testCreateNewOrder()
202
-    {
203
-        $orderParameters = Order::fromArray([
204
-            'address_1'                 => '106 Liberty St, New York, NY 10006, USA',
205
-            'address_alias'             => 'BK Restaurant #: 2446',
206
-            'cached_lat'                => 40.709637,
207
-            'cached_lng'                => -74.011912,
208
-            'curbside_lat'              => 40.709637,
209
-            'curbside_lng'              => -74.011912,
210
-            'address_city'              => 'New York',
211
-            'EXT_FIELD_first_name'      => 'Lui',
212
-            'EXT_FIELD_last_name'       => 'Carol',
213
-            'EXT_FIELD_email'           => '[email protected]',
214
-            'EXT_FIELD_phone'           => '897946541',
215
-            'local_time_window_end'     => 39000,
216
-            'local_time_window_end_2'   => 46200,
217
-            'local_time_window_start'   => 37800,
218
-            'local_time_window_start_2' => 45000,
219
-            'local_timezone_string'     => 'America/New_York',
220
-            'order_icon'                => 'emoji/emoji-bank',
221
-        ]);
222
-
223
-        $order = new Order();
224
-
225
-        $response = $order->addOrder($orderParameters);
226
-
227
-        self::assertNotNull($response);
228
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
229
-
230
-        self::$createdOrders[] = $response;
231
-    }
232
-
233
-    public function testAddOrdersToOptimization()
234
-    {
235
-        $body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_optimization_data.json'), true);
236
-
237
-        $optimizationProblemId = self::$createdProblems[0]->optimization_problem_id;
238
-
239
-        $orderParameters = [
240
-            'optimization_problem_id'   => $optimizationProblemId,
241
-            'redirect'                  => 0,
242
-            'device_type'               => 'web',
243
-            'addresses'                 => $body['addresses'],
244
-        ];
245
-
246
-        $order = new Order();
247
-
248
-        $response = $order->addOrder2Optimization($orderParameters);
249
-
250
-        self::assertNotNull($response);
251
-        self::assertInstanceOf(OptimizationProblem::class, OptimizationProblem::fromArray($response));
252
-    }
253
-
254
-    public function testAddOrdersToRoute()
255
-    {
256
-        $this->markTestSkipped('Read old data.');
257
-
258
-        $body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_route_data.json'), true);
259
-
260
-        $routeId = self::$createdProblems[0]->routes[0]->route_id;
261
-
262
-        $orderParameters = Order::fromArray([
263
-            'route_id'  => $routeId,
264
-            'redirect'  => 0,
265
-            'addresses' => $body['addresses'],
266
-        ]);
267
-
268
-        $order = new Order();
269
-
270
-        $response = $order->addOrder2Route($orderParameters);
271
-
272
-        self::assertNotNull($response);
273
-        self::assertInstanceOf(Route::class, Route::fromArray($response));
274
-    }
275
-
276
-    public function testAddScheduledOrder()
277
-    {
278
-        $orderParameters = Order::fromArray([
279
-            'address_1'                 => '318 S 39th St, Louisville, KY 40212, USA',
280
-            'cached_lat'                => 38.259326,
281
-            'cached_lng'                => -85.814979,
282
-            'curbside_lat'              => 38.259326,
283
-            'curbside_lng'              => -85.814979,
284
-            'address_alias'             => '318 S 39th St 40212',
285
-            'address_city'              => 'Louisville',
286
-            'EXT_FIELD_first_name'      => 'Lui',
287
-            'EXT_FIELD_last_name'       => 'Carol',
288
-            'EXT_FIELD_email'           => '[email protected]',
289
-            'EXT_FIELD_phone'           => '897946541',
290
-            'EXT_FIELD_custom_data'     => ['order_type' => 'scheduled order'],
291
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
292
-            'local_time_window_end'     => 39000,
293
-            'local_time_window_end_2'   => 46200,
294
-            'local_time_window_start'   => 37800,
295
-            'local_time_window_start_2' => 45000,
296
-            'local_timezone_string'     => 'America/New_York',
297
-            'order_icon'                => 'emoji/emoji-bank',
298
-        ]);
299
-
300
-        $order = new Order();
301
-
302
-        $response = $order->addOrder($orderParameters);
303
-
304
-        self::assertNotNull($response);
305
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
306
-
307
-        self::$createdOrders[] = $response;
308
-    }
309
-
310
-    public function testCreateOrderWithCustomField()
311
-    {
312
-        $orderParameters = Order::fromArray([
313
-            'address_1'                => '1358 E Luzerne St, Philadelphia, PA 19124, US',
314
-            'cached_lat'               => 48.335991,
315
-            'cached_lng'               => 31.18287,
316
-            'day_scheduled_for_YYMMDD' => '2019-10-11',
317
-            'address_alias'            => 'Auto test address',
318
-            'custom_user_fields' => [
319
-                OrderCustomField::fromArray([
320
-                    'order_custom_field_id'    => 93,
321
-                    'order_custom_field_value' => 'false'
322
-                ])
323
-            ]
324
-        ]);
325
-
326
-        $order = new Order();
327
-
328
-        $response = $order->addOrder($orderParameters);
329
-
330
-        self::assertNotNull($response);
331
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
332
-        $this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
333
-        $this->assertEquals(false, $response['custom_user_fields'][0]['order_custom_field_value']);
334
-
335
-        self::$createdOrders[] = $response;
336
-    }
337
-
338
-    public function testGetOrderByID()
339
-    {
340
-        $order = new Order();
341
-
342
-        $orderID = self::$createdOrders[0]['order_id'];
343
-
344
-        // Get an order
345
-        $orderParameters = Order::fromArray([
346
-            'order_id' => $orderID,
347
-        ]);
348
-
349
-        $response = $order->getOrder($orderParameters);
350
-
351
-        self::assertNotNull($response);
352
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
353
-    }
354
-
355
-    public function testGetOrderByUUID()
356
-    {
357
-        $order = new Order();
358
-
359
-        $orderUUID = self::$createdOrders[0]['order_uuid'];
360
-
361
-        // Get an order
362
-        $orderParameters = Order::fromArray([
363
-            'order_id' => $orderUUID,
364
-        ]);
365
-
366
-        $response = $order->getOrder($orderParameters);
367
-
368
-        self::assertNotNull($response);
369
-        self::assertInstanceOf(Order::class, Order::fromArray($response));
370
-    }
371
-
372
-    public function testGetOrderByInsertedDate()
373
-    {
374
-        $orderParameters = Order::fromArray([
375
-            'day_added_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
376
-            'offset'            => 0,
377
-            'limit'             => 5,
378
-        ]);
379
-
380
-        $order = new Order();
381
-
382
-        $response = $order->getOrder($orderParameters);
383
-
384
-        $this->assertNotNull($response);
385
-        $this->assertTrue(is_array($response));
386
-        $this->assertTrue(isset($response['total']));
387
-        $this->assertTrue(isset($response['results']));
388
-        $this->assertInstanceOf(
389
-            Order::class,
390
-            Order::fromArray($response['results'][0])
391
-        );
392
-    }
393
-
394
-    public function testGetOrderByScheduledDate()
395
-    {
396
-        $orderParameters = Order::fromArray([
397
-            'day_scheduled_for_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
398
-            'offset'                    => 0,
399
-            'limit'                     => 5,
400
-        ]);
401
-
402
-        $order = new Order();
403
-
404
-        $response = $order->getOrder($orderParameters);
405
-
406
-        $this->assertNotNull($response);
407
-        $this->assertTrue(is_array($response));
408
-        $this->assertTrue(isset($response['total']));
409
-        $this->assertTrue(isset($response['results']));
410
-        $this->assertInstanceOf(
411
-            Order::class,
412
-            Order::fromArray($response['results'][0])
413
-        );
414
-    }
415
-
416
-    public function testGetOrdersByCustomFields()
417
-    {
418
-        $orderParameters = Order::fromArray([
419
-            'fields'    => 'order_id,member_id',
420
-            'offset'    => 0,
421
-            'limit'     => 5,
422
-        ]);
423
-
424
-        $order = new Order();
425
-
426
-        $response = $order->getOrder($orderParameters);
427
-
428
-        $response = $order->getOrder($orderParameters);
429
-
430
-        $this->assertNotNull($response);
431
-        $this->assertTrue(is_array($response));
432
-        $this->assertTrue(isset($response['total']));
433
-        $this->assertTrue(isset($response['results']));
434
-        $this->assertTrue(isset($response['fields']));
435
-        $this->assertInstanceOf(
436
-            Order::class,
437
-            Order::fromArray($response['results'][0])
438
-        );
439
-    }
440
-
441
-    public function testGetOrdersByScheduleFilter()
442
-    {
443
-        $orderParameters = Order::fromArray([
444
-            'limit'  => 5,
445
-            'filter' => [
446
-                'display'               => 'all',
447
-                'scheduled_for_YYMMDD'  => [
448
-                    date('Y-m-d', strtotime('-1 days')),
449
-                    date('Y-m-d', strtotime('1 days'))
450
-                ]
451
-            ]
452
-        ]);
453
-
454
-        $order = new Order();
455
-
456
-        $response = $order->getOrder($orderParameters);
457
-
458
-        $this->assertNotNull($response);
459
-        $this->assertTrue(is_array($response));
460
-        $this->assertTrue(isset($response['total']));
461
-        $this->assertTrue(isset($response['results']));
462
-        $this->assertInstanceOf(
463
-            Order::class,
464
-            Order::fromArray($response['results'][0])
465
-        );
466
-    }
467
-
468
-    public function testGetOrdersBySpecifiedText()
469
-    {
470
-        $orderParameters = Order::fromArray([
471
-            'query'     => 'Auto test',
472
-            'offset'    => 0,
473
-            'limit'     => 5,
474
-        ]);
475
-
476
-        $order = new Order();
477
-
478
-        $response = $order->getOrder($orderParameters);
479
-
480
-        $this->assertNotNull($response);
481
-        $this->assertTrue(is_array($response));
482
-        $this->assertTrue(isset($response['total']));
483
-        $this->assertTrue(isset($response['results']));
484
-        $this->assertInstanceOf(
485
-            Order::class,
486
-            Order::fromArray($response['results'][0])
487
-        );
488
-    }
489
-
490
-    public function testUpdateOrder()
491
-    {
492
-        $order = new Order();
493
-
494
-        // Update the order
495
-        self::$createdOrders[0]['address_2'] = 'Lviv';
496
-        self::$createdOrders[0]['EXT_FIELD_phone'] = '032268593';
497
-        self::$createdOrders[0]['EXT_FIELD_custom_data'] = [
498
-            0 => [
499
-                'customer_no' => '11',
500
-            ],
501
-        ];
502
-
503
-        $response = $order->updateOrder(self::$createdOrders[0]);
504
-
505
-        $this->assertNotNull($response);
506
-        $this->assertInstanceOf(Order::class, Order::fromArray($response));
507
-        $this->assertEquals('Lviv', $response['address_2']);
508
-        $this->assertEquals('032268593', $response['EXT_FIELD_phone']);
509
-        $this->assertEquals(
510
-            [
511
-                0 => '{"order_id":"10","name":"Bill Soul"}'
512
-            ],
513
-            $response['EXT_FIELD_custom_data']
514
-        );
515
-    }
516
-
517
-    public function testUpdateOrderWithCustomFiel()
518
-    {
519
-        $orderParameters = Order::fromArray([
520
-            'order_id'              => self::$createdOrders[0]['order_id'],
521
-            'custom_user_fields'    => [
522
-                OrderCustomField::fromArray([
523
-                    'order_custom_field_id'    => 93,
524
-                    'order_custom_field_value' => 'true'
525
-                ])
526
-            ]
527
-        ]);
528
-
529
-        $order = new Order();
530
-
531
-        $response = $order->updateOrder($orderParameters);
532
-
533
-        $this->assertNotNull($response);
534
-        $this->assertInstanceOf(Order::class, Order::fromArray($response));
535
-        $this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
536
-        $this->assertEquals(true, $response['custom_user_fields'][0]['order_custom_field_value']);
537
-    }
538
-
539
-    public function testDeleteOrderByUuid()
540
-    {
541
-        $lastOrder = array_pop(self::$createdOrders);
542
-        if ($lastOrder != null) {
543
-            $order = new Order();
544
-            $ids = [
545
-                "order_ids" => [$lastOrder['order_uuid']]
546
-            ];
547
-
548
-            $response = $order->removeOrder($ids);
549
-
550
-            if (!is_null($response) && isset($response['status']) && $response['status']) {
551
-                echo "The test order removed by UUID <br>";
552
-            }
553
-        }
554
-    }
555
-
556
-    public static function tearDownAfterClass()
557
-    {
558
-        if (sizeof(self::$createdOrders)) {
559
-            $orderIDs = [];
560
-
561
-            foreach (self::$createdOrders as $ord) {
562
-                $orderIDs[] = $ord['order_id'];
563
-            }
564
-
565
-            $orderParameters = Order::fromArray([
566
-                'order_ids' => $orderIDs
567
-            ]);
568
-
569
-            $order = new Order();
570
-
571
-            $response = $order->removeOrder($orderParameters);
572
-
573
-            if (!is_null($response) &&
574
-                isset($response['status']) &&
575
-                $response['status']) {
576
-                echo "The test orders removed <br>";
577
-            }
578
-        }
579
-
580
-        if (sizeof(self::$createdProblems)>0) {
581
-            $optimizationProblemIDs = [];
582
-
583
-            foreach (self::$createdProblems as $problem) {
584
-                $optimizationProblemId = $problem->optimization_problem_id;
585
-
586
-                $optimizationProblemIDs[] = $optimizationProblemId;
587
-            }
588
-
589
-            $params = [
590
-                'optimization_problem_ids' => $optimizationProblemIDs,
591
-                'redirect'                 => 0,
592
-            ];
593
-
594
-            $problem = new OptimizationProblem();
595
-            $result = $problem->removeOptimization($params);
596
-
597
-            if ($result!=null && $result['status']==true) {
598
-                echo "The test optimizations were removed <br>";
599
-            } else {
600
-                echo "Cannot remove the test optimizations <br>";
601
-            }
602
-        }
603
-    }
23
+	public static $createdOrders = [];
24
+	public static $createdProblems = [];
25
+
26
+	public static function setUpBeforeClass()
27
+	{
28
+		Route4Me::setApiKey(Constants::API_KEY);
29
+
30
+		//region -- Create Test Optimization --
31
+
32
+		// Huge list of addresses
33
+		$json = json_decode(file_get_contents(dirname(__FILE__).'/data/addresses.json'), true);
34
+		$json = array_slice($json, 0, 10);
35
+
36
+		$addresses = [];
37
+		foreach ($json as $address) {
38
+			$addresses[] = Address::fromArray($address);
39
+		}
40
+
41
+		$parameters = RouteParameters::fromArray([
42
+			'algorithm_type'    => Algorithmtype::TSP,
43
+			'route_name'        => 'Single Driver Multiple TW 10 Stops '.date('Y-m-d H:i'),
44
+			'route_date'        => time() + 24 * 60 * 60,
45
+			'route_time'        => 5 * 3600 + 30 * 60,
46
+			'distance_unit'     => DistanceUnit::MILES,
47
+			'device_type'       => DeviceType::WEB,
48
+			'optimize'          => OptimizationType::DISTANCE,
49
+			'metric'            => Metric::GEODESIC,
50
+		]);
51
+
52
+		$optimizationParams = new OptimizationProblemParams();
53
+		$optimizationParams->setAddresses($addresses);
54
+		$optimizationParams->setParameters($parameters);
55
+
56
+		$problem = OptimizationProblem::optimize($optimizationParams);
57
+
58
+		self::$createdProblems[] = $problem;
59
+
60
+		//endregion
61
+
62
+		//region -- Create Test Order --
63
+
64
+		$orderParameters = Order::fromArray([
65
+			'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
66
+			'cached_lat'                => 48.335991,
67
+			'cached_lng'                => 31.18287,
68
+			'address_alias'             => 'Auto test address',
69
+			'address_city'              => 'Philadelphia',
70
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
71
+			'EXT_FIELD_first_name'      => 'Igor',
72
+			'EXT_FIELD_last_name'       => 'Progman',
73
+			'EXT_FIELD_email'           => '[email protected]',
74
+			'EXT_FIELD_phone'           => '380380380380',
75
+			'EXT_FIELD_custom_data'     => [
76
+				0 => [
77
+					'order_id'  => '10',
78
+					'name'      => 'Bill Soul',
79
+				],
80
+			],
81
+		]);
82
+
83
+		$order = new Order();
84
+
85
+		$response = $order->addOrder($orderParameters);
86
+
87
+		self::assertNotNull($response);
88
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
89
+
90
+		self::$createdOrders[] = $response;
91
+
92
+		//endregion
93
+	}
94
+
95
+	public function testFromArray()
96
+	{
97
+		$orderParameters = Order::fromArray([
98
+			'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
99
+			'cached_lat'                => 48.335991,
100
+			'cached_lng'                => 31.18287,
101
+			'address_alias'             => 'Auto test address',
102
+			'address_city'              => 'Philadelphia',
103
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
104
+			'EXT_FIELD_first_name'      => 'Igor',
105
+			'EXT_FIELD_last_name'       => 'Progman',
106
+			'EXT_FIELD_email'           => '[email protected]',
107
+			'EXT_FIELD_phone'           => '380380380380',
108
+			'EXT_FIELD_custom_data'     => [
109
+				0 => [
110
+					'order_id'  => '10',
111
+					'name'      => 'Bill Soul',
112
+				],
113
+			],
114
+			'EXT_FIELD_cost'            => 50
115
+		]);
116
+
117
+		$this->assertEquals('1358 E Luzerne St, Philadelphia, PA 19124, US', $orderParameters->address_1);
118
+		$this->assertEquals(48.335991, $orderParameters->cached_lat);
119
+		$this->assertEquals(31.18287, $orderParameters->cached_lng);
120
+		$this->assertEquals('Auto test address', $orderParameters->address_alias);
121
+		$this->assertEquals('Philadelphia', $orderParameters->address_city);
122
+		$this->assertEquals(date('Y-m-d'), $orderParameters->day_scheduled_for_YYMMDD);
123
+		$this->assertEquals('Igor', $orderParameters->EXT_FIELD_first_name);
124
+		$this->assertEquals('Progman', $orderParameters->EXT_FIELD_last_name);
125
+		$this->assertEquals('[email protected]', $orderParameters->EXT_FIELD_email);
126
+		$this->assertEquals('380380380380', $orderParameters->EXT_FIELD_phone);
127
+		$this->assertEquals([
128
+			0 => [
129
+				'order_id'  => '10',
130
+				'name'      => 'Bill Soul',
131
+			],
132
+		], $orderParameters->EXT_FIELD_custom_data);
133
+		$this->assertEquals(50, $orderParameters->EXT_FIELD_cost);
134
+	}
135
+
136
+	public function testToArray()
137
+	{
138
+		$orderParameters = Order::fromArray([
139
+			'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
140
+			'cached_lat'                => 48.335991,
141
+			'cached_lng'                => 31.18287,
142
+			'address_alias'             => 'Auto test address',
143
+			'address_city'              => 'Philadelphia',
144
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
145
+			'EXT_FIELD_first_name'      => 'Igor',
146
+			'EXT_FIELD_last_name'       => 'Progman',
147
+			'EXT_FIELD_email'           => '[email protected]',
148
+			'EXT_FIELD_phone'           => '380380380380',
149
+			'EXT_FIELD_custom_data'     => [
150
+				0 => [
151
+					'order_id'  => '10',
152
+					'name'      => 'Bill Soul',
153
+				],
154
+			],
155
+		]);
156
+
157
+		$this->assertEquals(
158
+			$orderParameters->toArray(),
159
+			[
160
+				'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
161
+				'cached_lat'                => 48.335991,
162
+				'cached_lng'                => 31.18287,
163
+				'address_alias'             => 'Auto test address',
164
+				'address_city'              => 'Philadelphia',
165
+				'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
166
+				'EXT_FIELD_first_name'      => 'Igor',
167
+				'EXT_FIELD_last_name'       => 'Progman',
168
+				'EXT_FIELD_email'           => '[email protected]',
169
+				'EXT_FIELD_phone'           => '380380380380',
170
+				'EXT_FIELD_custom_data'     => [
171
+					0 => [
172
+						'order_id'  => '10',
173
+						'name'      => 'Bill Soul',
174
+					],
175
+				],
176
+			],
177
+		]);
178
+	}
179
+
180
+	public function testGetOrders()
181
+	{
182
+		$order = new Order();
183
+
184
+		$orderParameters = Order::fromArray([
185
+			'offset'    => 0,
186
+			'limit'     => 5,
187
+		]);
188
+
189
+		$response = $order->getOrders($orderParameters);
190
+
191
+		$this->assertNotNull($response);
192
+		$this->assertTrue(is_array($response));
193
+		$this->assertTrue(isset($response['total']));
194
+		$this->assertTrue(isset($response['results']));
195
+		$this->assertInstanceOf(
196
+			Order::class,
197
+			Order::fromArray($response['results'][0])
198
+		);
199
+	}
200
+
201
+	public function testCreateNewOrder()
202
+	{
203
+		$orderParameters = Order::fromArray([
204
+			'address_1'                 => '106 Liberty St, New York, NY 10006, USA',
205
+			'address_alias'             => 'BK Restaurant #: 2446',
206
+			'cached_lat'                => 40.709637,
207
+			'cached_lng'                => -74.011912,
208
+			'curbside_lat'              => 40.709637,
209
+			'curbside_lng'              => -74.011912,
210
+			'address_city'              => 'New York',
211
+			'EXT_FIELD_first_name'      => 'Lui',
212
+			'EXT_FIELD_last_name'       => 'Carol',
213
+			'EXT_FIELD_email'           => '[email protected]',
214
+			'EXT_FIELD_phone'           => '897946541',
215
+			'local_time_window_end'     => 39000,
216
+			'local_time_window_end_2'   => 46200,
217
+			'local_time_window_start'   => 37800,
218
+			'local_time_window_start_2' => 45000,
219
+			'local_timezone_string'     => 'America/New_York',
220
+			'order_icon'                => 'emoji/emoji-bank',
221
+		]);
222
+
223
+		$order = new Order();
224
+
225
+		$response = $order->addOrder($orderParameters);
226
+
227
+		self::assertNotNull($response);
228
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
229
+
230
+		self::$createdOrders[] = $response;
231
+	}
232
+
233
+	public function testAddOrdersToOptimization()
234
+	{
235
+		$body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_optimization_data.json'), true);
236
+
237
+		$optimizationProblemId = self::$createdProblems[0]->optimization_problem_id;
238
+
239
+		$orderParameters = [
240
+			'optimization_problem_id'   => $optimizationProblemId,
241
+			'redirect'                  => 0,
242
+			'device_type'               => 'web',
243
+			'addresses'                 => $body['addresses'],
244
+		];
245
+
246
+		$order = new Order();
247
+
248
+		$response = $order->addOrder2Optimization($orderParameters);
249
+
250
+		self::assertNotNull($response);
251
+		self::assertInstanceOf(OptimizationProblem::class, OptimizationProblem::fromArray($response));
252
+	}
253
+
254
+	public function testAddOrdersToRoute()
255
+	{
256
+		$this->markTestSkipped('Read old data.');
257
+
258
+		$body = json_decode(file_get_contents(dirname(__FILE__).'/data/add_order_to_route_data.json'), true);
259
+
260
+		$routeId = self::$createdProblems[0]->routes[0]->route_id;
261
+
262
+		$orderParameters = Order::fromArray([
263
+			'route_id'  => $routeId,
264
+			'redirect'  => 0,
265
+			'addresses' => $body['addresses'],
266
+		]);
267
+
268
+		$order = new Order();
269
+
270
+		$response = $order->addOrder2Route($orderParameters);
271
+
272
+		self::assertNotNull($response);
273
+		self::assertInstanceOf(Route::class, Route::fromArray($response));
274
+	}
275
+
276
+	public function testAddScheduledOrder()
277
+	{
278
+		$orderParameters = Order::fromArray([
279
+			'address_1'                 => '318 S 39th St, Louisville, KY 40212, USA',
280
+			'cached_lat'                => 38.259326,
281
+			'cached_lng'                => -85.814979,
282
+			'curbside_lat'              => 38.259326,
283
+			'curbside_lng'              => -85.814979,
284
+			'address_alias'             => '318 S 39th St 40212',
285
+			'address_city'              => 'Louisville',
286
+			'EXT_FIELD_first_name'      => 'Lui',
287
+			'EXT_FIELD_last_name'       => 'Carol',
288
+			'EXT_FIELD_email'           => '[email protected]',
289
+			'EXT_FIELD_phone'           => '897946541',
290
+			'EXT_FIELD_custom_data'     => ['order_type' => 'scheduled order'],
291
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
292
+			'local_time_window_end'     => 39000,
293
+			'local_time_window_end_2'   => 46200,
294
+			'local_time_window_start'   => 37800,
295
+			'local_time_window_start_2' => 45000,
296
+			'local_timezone_string'     => 'America/New_York',
297
+			'order_icon'                => 'emoji/emoji-bank',
298
+		]);
299
+
300
+		$order = new Order();
301
+
302
+		$response = $order->addOrder($orderParameters);
303
+
304
+		self::assertNotNull($response);
305
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
306
+
307
+		self::$createdOrders[] = $response;
308
+	}
309
+
310
+	public function testCreateOrderWithCustomField()
311
+	{
312
+		$orderParameters = Order::fromArray([
313
+			'address_1'                => '1358 E Luzerne St, Philadelphia, PA 19124, US',
314
+			'cached_lat'               => 48.335991,
315
+			'cached_lng'               => 31.18287,
316
+			'day_scheduled_for_YYMMDD' => '2019-10-11',
317
+			'address_alias'            => 'Auto test address',
318
+			'custom_user_fields' => [
319
+				OrderCustomField::fromArray([
320
+					'order_custom_field_id'    => 93,
321
+					'order_custom_field_value' => 'false'
322
+				])
323
+			]
324
+		]);
325
+
326
+		$order = new Order();
327
+
328
+		$response = $order->addOrder($orderParameters);
329
+
330
+		self::assertNotNull($response);
331
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
332
+		$this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
333
+		$this->assertEquals(false, $response['custom_user_fields'][0]['order_custom_field_value']);
334
+
335
+		self::$createdOrders[] = $response;
336
+	}
337
+
338
+	public function testGetOrderByID()
339
+	{
340
+		$order = new Order();
341
+
342
+		$orderID = self::$createdOrders[0]['order_id'];
343
+
344
+		// Get an order
345
+		$orderParameters = Order::fromArray([
346
+			'order_id' => $orderID,
347
+		]);
348
+
349
+		$response = $order->getOrder($orderParameters);
350
+
351
+		self::assertNotNull($response);
352
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
353
+	}
354
+
355
+	public function testGetOrderByUUID()
356
+	{
357
+		$order = new Order();
358
+
359
+		$orderUUID = self::$createdOrders[0]['order_uuid'];
360
+
361
+		// Get an order
362
+		$orderParameters = Order::fromArray([
363
+			'order_id' => $orderUUID,
364
+		]);
365
+
366
+		$response = $order->getOrder($orderParameters);
367
+
368
+		self::assertNotNull($response);
369
+		self::assertInstanceOf(Order::class, Order::fromArray($response));
370
+	}
371
+
372
+	public function testGetOrderByInsertedDate()
373
+	{
374
+		$orderParameters = Order::fromArray([
375
+			'day_added_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
376
+			'offset'            => 0,
377
+			'limit'             => 5,
378
+		]);
379
+
380
+		$order = new Order();
381
+
382
+		$response = $order->getOrder($orderParameters);
383
+
384
+		$this->assertNotNull($response);
385
+		$this->assertTrue(is_array($response));
386
+		$this->assertTrue(isset($response['total']));
387
+		$this->assertTrue(isset($response['results']));
388
+		$this->assertInstanceOf(
389
+			Order::class,
390
+			Order::fromArray($response['results'][0])
391
+		);
392
+	}
393
+
394
+	public function testGetOrderByScheduledDate()
395
+	{
396
+		$orderParameters = Order::fromArray([
397
+			'day_scheduled_for_YYMMDD'  => date('Y-m-d', strtotime('0 days')),
398
+			'offset'                    => 0,
399
+			'limit'                     => 5,
400
+		]);
401
+
402
+		$order = new Order();
403
+
404
+		$response = $order->getOrder($orderParameters);
405
+
406
+		$this->assertNotNull($response);
407
+		$this->assertTrue(is_array($response));
408
+		$this->assertTrue(isset($response['total']));
409
+		$this->assertTrue(isset($response['results']));
410
+		$this->assertInstanceOf(
411
+			Order::class,
412
+			Order::fromArray($response['results'][0])
413
+		);
414
+	}
415
+
416
+	public function testGetOrdersByCustomFields()
417
+	{
418
+		$orderParameters = Order::fromArray([
419
+			'fields'    => 'order_id,member_id',
420
+			'offset'    => 0,
421
+			'limit'     => 5,
422
+		]);
423
+
424
+		$order = new Order();
425
+
426
+		$response = $order->getOrder($orderParameters);
427
+
428
+		$response = $order->getOrder($orderParameters);
429
+
430
+		$this->assertNotNull($response);
431
+		$this->assertTrue(is_array($response));
432
+		$this->assertTrue(isset($response['total']));
433
+		$this->assertTrue(isset($response['results']));
434
+		$this->assertTrue(isset($response['fields']));
435
+		$this->assertInstanceOf(
436
+			Order::class,
437
+			Order::fromArray($response['results'][0])
438
+		);
439
+	}
440
+
441
+	public function testGetOrdersByScheduleFilter()
442
+	{
443
+		$orderParameters = Order::fromArray([
444
+			'limit'  => 5,
445
+			'filter' => [
446
+				'display'               => 'all',
447
+				'scheduled_for_YYMMDD'  => [
448
+					date('Y-m-d', strtotime('-1 days')),
449
+					date('Y-m-d', strtotime('1 days'))
450
+				]
451
+			]
452
+		]);
453
+
454
+		$order = new Order();
455
+
456
+		$response = $order->getOrder($orderParameters);
457
+
458
+		$this->assertNotNull($response);
459
+		$this->assertTrue(is_array($response));
460
+		$this->assertTrue(isset($response['total']));
461
+		$this->assertTrue(isset($response['results']));
462
+		$this->assertInstanceOf(
463
+			Order::class,
464
+			Order::fromArray($response['results'][0])
465
+		);
466
+	}
467
+
468
+	public function testGetOrdersBySpecifiedText()
469
+	{
470
+		$orderParameters = Order::fromArray([
471
+			'query'     => 'Auto test',
472
+			'offset'    => 0,
473
+			'limit'     => 5,
474
+		]);
475
+
476
+		$order = new Order();
477
+
478
+		$response = $order->getOrder($orderParameters);
479
+
480
+		$this->assertNotNull($response);
481
+		$this->assertTrue(is_array($response));
482
+		$this->assertTrue(isset($response['total']));
483
+		$this->assertTrue(isset($response['results']));
484
+		$this->assertInstanceOf(
485
+			Order::class,
486
+			Order::fromArray($response['results'][0])
487
+		);
488
+	}
489
+
490
+	public function testUpdateOrder()
491
+	{
492
+		$order = new Order();
493
+
494
+		// Update the order
495
+		self::$createdOrders[0]['address_2'] = 'Lviv';
496
+		self::$createdOrders[0]['EXT_FIELD_phone'] = '032268593';
497
+		self::$createdOrders[0]['EXT_FIELD_custom_data'] = [
498
+			0 => [
499
+				'customer_no' => '11',
500
+			],
501
+		];
502
+
503
+		$response = $order->updateOrder(self::$createdOrders[0]);
504
+
505
+		$this->assertNotNull($response);
506
+		$this->assertInstanceOf(Order::class, Order::fromArray($response));
507
+		$this->assertEquals('Lviv', $response['address_2']);
508
+		$this->assertEquals('032268593', $response['EXT_FIELD_phone']);
509
+		$this->assertEquals(
510
+			[
511
+				0 => '{"order_id":"10","name":"Bill Soul"}'
512
+			],
513
+			$response['EXT_FIELD_custom_data']
514
+		);
515
+	}
516
+
517
+	public function testUpdateOrderWithCustomFiel()
518
+	{
519
+		$orderParameters = Order::fromArray([
520
+			'order_id'              => self::$createdOrders[0]['order_id'],
521
+			'custom_user_fields'    => [
522
+				OrderCustomField::fromArray([
523
+					'order_custom_field_id'    => 93,
524
+					'order_custom_field_value' => 'true'
525
+				])
526
+			]
527
+		]);
528
+
529
+		$order = new Order();
530
+
531
+		$response = $order->updateOrder($orderParameters);
532
+
533
+		$this->assertNotNull($response);
534
+		$this->assertInstanceOf(Order::class, Order::fromArray($response));
535
+		$this->assertEquals(93, $response['custom_user_fields'][0]['order_custom_field_id']);
536
+		$this->assertEquals(true, $response['custom_user_fields'][0]['order_custom_field_value']);
537
+	}
538
+
539
+	public function testDeleteOrderByUuid()
540
+	{
541
+		$lastOrder = array_pop(self::$createdOrders);
542
+		if ($lastOrder != null) {
543
+			$order = new Order();
544
+			$ids = [
545
+				"order_ids" => [$lastOrder['order_uuid']]
546
+			];
547
+
548
+			$response = $order->removeOrder($ids);
549
+
550
+			if (!is_null($response) && isset($response['status']) && $response['status']) {
551
+				echo "The test order removed by UUID <br>";
552
+			}
553
+		}
554
+	}
555
+
556
+	public static function tearDownAfterClass()
557
+	{
558
+		if (sizeof(self::$createdOrders)) {
559
+			$orderIDs = [];
560
+
561
+			foreach (self::$createdOrders as $ord) {
562
+				$orderIDs[] = $ord['order_id'];
563
+			}
564
+
565
+			$orderParameters = Order::fromArray([
566
+				'order_ids' => $orderIDs
567
+			]);
568
+
569
+			$order = new Order();
570
+
571
+			$response = $order->removeOrder($orderParameters);
572
+
573
+			if (!is_null($response) &&
574
+				isset($response['status']) &&
575
+				$response['status']) {
576
+				echo "The test orders removed <br>";
577
+			}
578
+		}
579
+
580
+		if (sizeof(self::$createdProblems)>0) {
581
+			$optimizationProblemIDs = [];
582
+
583
+			foreach (self::$createdProblems as $problem) {
584
+				$optimizationProblemId = $problem->optimization_problem_id;
585
+
586
+				$optimizationProblemIDs[] = $optimizationProblemId;
587
+			}
588
+
589
+			$params = [
590
+				'optimization_problem_ids' => $optimizationProblemIDs,
591
+				'redirect'                 => 0,
592
+			];
593
+
594
+			$problem = new OptimizationProblem();
595
+			$result = $problem->removeOptimization($params);
596
+
597
+			if ($result!=null && $result['status']==true) {
598
+				echo "The test optimizations were removed <br>";
599
+			} else {
600
+				echo "Cannot remove the test optimizations <br>";
601
+			}
602
+		}
603
+	}
604 604
 }
Please login to merge, or discard this patch.
examples/Order/NewOrderWithEXTFields.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -12,21 +12,21 @@
 block discarded – undo
12 12
 Route4Me::setApiKey(Constants::API_KEY);
13 13
 
14 14
 $orderParameters = Order::fromArray([
15
-    'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
16
-    'cached_lat'                => 48.335991,
17
-    'cached_lng'                => 31.18287,
18
-    'address_alias'             => 'Auto test address',
19
-    'address_city'              => 'Philadelphia',
20
-    'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
21
-    'EXT_FIELD_first_name'      => 'Igor',
22
-    'EXT_FIELD_last_name'       => 'Progman',
23
-    'EXT_FIELD_email'           => '[email protected]',
24
-    'EXT_FIELD_phone'           => '380380380380',
25
-    'EXT_FIELD_weight'          => 100.0,
26
-    'EXT_FIELD_cost'            => 50,
27
-    'EXT_FIELD_revenue'         => 150,
28
-    'EXT_FIELD_cube'            => 5,
29
-    'EXT_FIELD_pieces'          => 10
15
+	'address_1'                 => '1358 E Luzerne St, Philadelphia, PA 19124, US',
16
+	'cached_lat'                => 48.335991,
17
+	'cached_lng'                => 31.18287,
18
+	'address_alias'             => 'Auto test address',
19
+	'address_city'              => 'Philadelphia',
20
+	'day_scheduled_for_YYMMDD'  => date('Y-m-d'),
21
+	'EXT_FIELD_first_name'      => 'Igor',
22
+	'EXT_FIELD_last_name'       => 'Progman',
23
+	'EXT_FIELD_email'           => '[email protected]',
24
+	'EXT_FIELD_phone'           => '380380380380',
25
+	'EXT_FIELD_weight'          => 100.0,
26
+	'EXT_FIELD_cost'            => 50,
27
+	'EXT_FIELD_revenue'         => 150,
28
+	'EXT_FIELD_cube'            => 5,
29
+	'EXT_FIELD_pieces'          => 10
30 30
 ]);
31 31
 
32 32
 $order = new Order();
Please login to merge, or discard this patch.
src/Route4Me/Order.php 1 patch
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -6,349 +6,349 @@
 block discarded – undo
6 6
 
7 7
 class Order extends Common
8 8
 {
9
-    public $address_1;
10
-    public $address_2;
11
-    public $cached_lat;
12
-    public $cached_lng;
13
-    public $curbside_lat;
14
-    public $curbside_lng;
15
-    public $address_alias;
16
-    public $address_city;
17
-    public $EXT_FIELD_first_name;
18
-    public $EXT_FIELD_last_name;
19
-    public $EXT_FIELD_email;
20
-    public $EXT_FIELD_phone;
21
-    public $EXT_FIELD_custom_data;
22
-
23
-    public $color;
24
-    public $order_icon;
25
-    public $local_time_window_start;
26
-    public $local_time_window_end;
27
-    public $local_time_window_start_2;
28
-    public $local_time_window_end_2;
29
-    public $service_time;
30
-
31
-    public $day_scheduled_for_YYMMDD;
32
-
33
-    public $route_id;
34
-    public $redirect;
35
-    public $optimization_problem_id;
36
-    public $order_id;
37
-    public $order_uuid;
38
-    public $order_ids;
39
-
40
-    public $day_added_YYMMDD;
41
-    public $scheduled_for_YYMMDD;
42
-    public $fields;
43
-    public $offset;
44
-    public $limit;
45
-    public $query;
46
-
47
-    public $created_timestamp;
48
-    public $order_status_id;
49
-    public $member_id;
50
-    public $address_state_id;
51
-    public $address_country_id;
52
-    public $address_zip;
53
-    public $in_route_count;
54
-    public $last_visited_timestamp;
55
-    public $last_routed_timestamp;
56
-    public $local_timezone_string;
57
-    public $is_validated;
58
-    public $is_pending;
59
-    public $is_accepted;
60
-    public $is_started;
61
-    public $is_completed;
62
-    public $custom_user_fields;
63
-
64
-    public $addresses = [];
65
-
66
-    /**
67
-     * Weight of the order.
68
-     * @since 1.2.11
69
-     */
70
-    public $EXT_FIELD_weight;
71
-
72
-    /**
73
-     * Cost of the order.
74
-     * @since 1.2.11
75
-     */
76
-    public $EXT_FIELD_cost;
77
-
78
-    /**
79
-     * The total revenue for the order.
80
-     * @since 1.2.11
81
-     */
82
-    public $EXT_FIELD_revenue;
83
-
84
-    /**
85
-     * The cubic volume of the cargo.
86
-     * @since 1.2.11
87
-     */
88
-    public $EXT_FIELD_cube;
89
-
90
-    /**
91
-     *The item quantity of the cargo.
92
-     * @since 1.2.11
93
-     */
94
-    public $EXT_FIELD_pieces;
95
-
96
-    public function __construct()
97
-    {
98
-        Route4Me::setBaseUrl(Endpoint::BASE_URL);
99
-    }
100
-
101
-    /**
102
-     * @param Order $params
103
-     */
104
-    public static function addOrder($params)
105
-    {
106
-        $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id',
107
-            'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid'];
108
-
109
-        $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
110
-
111
-        $response = Route4Me::makeRequst([
112
-            'url'       => Endpoint::ORDER_V4,
113
-            'method'    => 'POST',
114
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
115
-        ]);
116
-
117
-        return $response;
118
-    }
119
-
120
-    public static function addOrder2Route($params)
121
-    {
122
-        $allQueryFields = ['route_id', 'redirect'];
123
-        $allBodyFields = ['addresses'];
124
-
125
-        $response = Route4Me::makeRequst([
126
-            'url'       => Endpoint::ROUTE_V4,
127
-            'method'    => 'PUT',
128
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
129
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
130
-        ]);
131
-
132
-        return $response;
133
-    }
134
-
135
-    public static function addOrder2Optimization($params)
136
-    {
137
-        $allQueryFields = ['optimization_problem_id', 'redirect', 'device_type'];
138
-        $allBodyFields  = ['addresses'];
139
-
140
-        $response = Route4Me::makeRequst([
141
-            'url'       => Endpoint::OPTIMIZATION_PROBLEM,
142
-            'method'    => 'PUT',
143
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
144
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
145
-        ]);
146
-
147
-        return $response;
148
-    }
149
-
150
-    public static function getOrder($params)
151
-    {
152
-        $allQueryFields = ['order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query',
153
-            'offset', 'limit'];
154
-
155
-        $response = Route4Me::makeRequst([
156
-            'url'       => Endpoint::ORDER_V4,
157
-            'method'    => 'GET',
158
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
159
-        ]);
160
-
161
-        return $response;
162
-    }
163
-
164
-    public static function getOrders($params)
165
-    {
166
-        $allQueryFields = ['offset', 'limit'];
167
-
168
-        $response = Route4Me::makeRequst([
169
-            'url'       => Endpoint::ORDER_V4,
170
-            'method'    => 'GET',
171
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
172
-        ]);
173
-
174
-        return $response;
175
-    }
176
-
177
-    public function getRandomOrderId($offset, $limit)
178
-    {
179
-        $randomOrder = $this->getRandomOrder($offset, $limit);
180
-
181
-        if (is_null($randomOrder) || !isset($randomOrder)) {
182
-            return null;
183
-        }
184
-
185
-        return $randomOrder['order_id'];
186
-    }
187
-
188
-    public function getRandomOrder($offset, $limit)
189
-    {
190
-        $params = ['offset' => $offset, 'limit' => $limit];
191
-
192
-        $orders = self::getOrders($params);
193
-
194
-        if (is_null($orders) || !isset($orders['results'])) {
195
-            return null;
196
-        }
197
-
198
-        $randomIndex = rand(0, sizeof($orders['results']) - 1);
199
-
200
-        $order = $orders['results'][$randomIndex];
201
-
202
-        return $order;
203
-    }
204
-
205
-    public static function removeOrder($params)
206
-    {
207
-        $allBodyFields = ['order_ids'];
208
-
209
-        $response = Route4Me::makeRequst([
210
-            'url'       => Endpoint::ORDER_V4,
211
-            'method'    => 'DELETE',
212
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
213
-        ]);
214
-
215
-        return $response;
216
-    }
217
-
218
-    public static function updateOrder($params)
219
-    {
220
-        $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_ids',
221
-            'fields', 'offset', 'limit', 'query', 'created_timestamp', 'route_uuid'];
222
-
223
-        $allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
224
-
225
-        $response = Route4Me::makeRequst([
226
-            'url'       => Endpoint::ORDER_V4,
227
-            'method'    => 'PUT',
228
-            'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
229
-        ]);
230
-
231
-        return $response;
232
-    }
233
-
234
-    public static function searchOrder($params)
235
-    {
236
-        $allQueryFields = ['fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'];
237
-
238
-        $response = Route4Me::makeRequst([
239
-            'url'       => Endpoint::ORDER_V4,
240
-            'method'    => 'GET',
241
-            'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
242
-        ]);
243
-
244
-        return $response;
245
-    }
9
+	public $address_1;
10
+	public $address_2;
11
+	public $cached_lat;
12
+	public $cached_lng;
13
+	public $curbside_lat;
14
+	public $curbside_lng;
15
+	public $address_alias;
16
+	public $address_city;
17
+	public $EXT_FIELD_first_name;
18
+	public $EXT_FIELD_last_name;
19
+	public $EXT_FIELD_email;
20
+	public $EXT_FIELD_phone;
21
+	public $EXT_FIELD_custom_data;
22
+
23
+	public $color;
24
+	public $order_icon;
25
+	public $local_time_window_start;
26
+	public $local_time_window_end;
27
+	public $local_time_window_start_2;
28
+	public $local_time_window_end_2;
29
+	public $service_time;
30
+
31
+	public $day_scheduled_for_YYMMDD;
32
+
33
+	public $route_id;
34
+	public $redirect;
35
+	public $optimization_problem_id;
36
+	public $order_id;
37
+	public $order_uuid;
38
+	public $order_ids;
39
+
40
+	public $day_added_YYMMDD;
41
+	public $scheduled_for_YYMMDD;
42
+	public $fields;
43
+	public $offset;
44
+	public $limit;
45
+	public $query;
46
+
47
+	public $created_timestamp;
48
+	public $order_status_id;
49
+	public $member_id;
50
+	public $address_state_id;
51
+	public $address_country_id;
52
+	public $address_zip;
53
+	public $in_route_count;
54
+	public $last_visited_timestamp;
55
+	public $last_routed_timestamp;
56
+	public $local_timezone_string;
57
+	public $is_validated;
58
+	public $is_pending;
59
+	public $is_accepted;
60
+	public $is_started;
61
+	public $is_completed;
62
+	public $custom_user_fields;
63
+
64
+	public $addresses = [];
65
+
66
+	/**
67
+	 * Weight of the order.
68
+	 * @since 1.2.11
69
+	 */
70
+	public $EXT_FIELD_weight;
71
+
72
+	/**
73
+	 * Cost of the order.
74
+	 * @since 1.2.11
75
+	 */
76
+	public $EXT_FIELD_cost;
77
+
78
+	/**
79
+	 * The total revenue for the order.
80
+	 * @since 1.2.11
81
+	 */
82
+	public $EXT_FIELD_revenue;
83
+
84
+	/**
85
+	 * The cubic volume of the cargo.
86
+	 * @since 1.2.11
87
+	 */
88
+	public $EXT_FIELD_cube;
89
+
90
+	/**
91
+	 *The item quantity of the cargo.
92
+	 * @since 1.2.11
93
+	 */
94
+	public $EXT_FIELD_pieces;
95
+
96
+	public function __construct()
97
+	{
98
+		Route4Me::setBaseUrl(Endpoint::BASE_URL);
99
+	}
100
+
101
+	/**
102
+	 * @param Order $params
103
+	 */
104
+	public static function addOrder($params)
105
+	{
106
+		$excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id',
107
+			'order_ids', 'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid'];
108
+
109
+		$allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
110
+
111
+		$response = Route4Me::makeRequst([
112
+			'url'       => Endpoint::ORDER_V4,
113
+			'method'    => 'POST',
114
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
115
+		]);
116
+
117
+		return $response;
118
+	}
119
+
120
+	public static function addOrder2Route($params)
121
+	{
122
+		$allQueryFields = ['route_id', 'redirect'];
123
+		$allBodyFields = ['addresses'];
124
+
125
+		$response = Route4Me::makeRequst([
126
+			'url'       => Endpoint::ROUTE_V4,
127
+			'method'    => 'PUT',
128
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
129
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
130
+		]);
131
+
132
+		return $response;
133
+	}
134
+
135
+	public static function addOrder2Optimization($params)
136
+	{
137
+		$allQueryFields = ['optimization_problem_id', 'redirect', 'device_type'];
138
+		$allBodyFields  = ['addresses'];
139
+
140
+		$response = Route4Me::makeRequst([
141
+			'url'       => Endpoint::OPTIMIZATION_PROBLEM,
142
+			'method'    => 'PUT',
143
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
144
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
145
+		]);
146
+
147
+		return $response;
148
+	}
149
+
150
+	public static function getOrder($params)
151
+	{
152
+		$allQueryFields = ['order_id', 'fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query',
153
+			'offset', 'limit'];
154
+
155
+		$response = Route4Me::makeRequst([
156
+			'url'       => Endpoint::ORDER_V4,
157
+			'method'    => 'GET',
158
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
159
+		]);
160
+
161
+		return $response;
162
+	}
163
+
164
+	public static function getOrders($params)
165
+	{
166
+		$allQueryFields = ['offset', 'limit'];
167
+
168
+		$response = Route4Me::makeRequst([
169
+			'url'       => Endpoint::ORDER_V4,
170
+			'method'    => 'GET',
171
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
172
+		]);
173
+
174
+		return $response;
175
+	}
176
+
177
+	public function getRandomOrderId($offset, $limit)
178
+	{
179
+		$randomOrder = $this->getRandomOrder($offset, $limit);
180
+
181
+		if (is_null($randomOrder) || !isset($randomOrder)) {
182
+			return null;
183
+		}
184
+
185
+		return $randomOrder['order_id'];
186
+	}
187
+
188
+	public function getRandomOrder($offset, $limit)
189
+	{
190
+		$params = ['offset' => $offset, 'limit' => $limit];
191
+
192
+		$orders = self::getOrders($params);
193
+
194
+		if (is_null($orders) || !isset($orders['results'])) {
195
+			return null;
196
+		}
197
+
198
+		$randomIndex = rand(0, sizeof($orders['results']) - 1);
199
+
200
+		$order = $orders['results'][$randomIndex];
201
+
202
+		return $order;
203
+	}
204
+
205
+	public static function removeOrder($params)
206
+	{
207
+		$allBodyFields = ['order_ids'];
208
+
209
+		$response = Route4Me::makeRequst([
210
+			'url'       => Endpoint::ORDER_V4,
211
+			'method'    => 'DELETE',
212
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
213
+		]);
214
+
215
+		return $response;
216
+	}
217
+
218
+	public static function updateOrder($params)
219
+	{
220
+		$excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_ids',
221
+			'fields', 'offset', 'limit', 'query', 'created_timestamp', 'route_uuid'];
222
+
223
+		$allBodyFields = Route4Me::getObjectProperties(new self(), $excludeFields);
224
+
225
+		$response = Route4Me::makeRequst([
226
+			'url'       => Endpoint::ORDER_V4,
227
+			'method'    => 'PUT',
228
+			'body'      => Route4Me::generateRequestParameters($allBodyFields, $params),
229
+		]);
230
+
231
+		return $response;
232
+	}
233
+
234
+	public static function searchOrder($params)
235
+	{
236
+		$allQueryFields = ['fields', 'day_added_YYMMDD', 'scheduled_for_YYMMDD', 'query', 'offset', 'limit'];
237
+
238
+		$response = Route4Me::makeRequst([
239
+			'url'       => Endpoint::ORDER_V4,
240
+			'method'    => 'GET',
241
+			'query'     => Route4Me::generateRequestParameters($allQueryFields, $params),
242
+		]);
243
+
244
+		return $response;
245
+	}
246 246
 
247
-    public static function validateCoordinate($coord)
248
-    {
249
-        $key = key($coord);
250
-
251
-        if (!is_numeric($coord[$key])) {
252
-            return false;
253
-        }
254
-
255
-        switch ($key) {
256
-            case 'cached_lat':
257
-            case 'curbside_lat':
258
-                if ($coord[$key] > 90 || $coord[$key] < -90) {
259
-                    return false;
260
-                }
261
-                break;
262
-            case 'cached_lng':
263
-            case 'curbside_lng':
264
-                if ($coord[$key] > 180 || $coord[$key] < -180) {
265
-                    return false;
266
-                }
267
-                break;
268
-        }
269
-
270
-        return true;
271
-    }
247
+	public static function validateCoordinate($coord)
248
+	{
249
+		$key = key($coord);
250
+
251
+		if (!is_numeric($coord[$key])) {
252
+			return false;
253
+		}
254
+
255
+		switch ($key) {
256
+			case 'cached_lat':
257
+			case 'curbside_lat':
258
+				if ($coord[$key] > 90 || $coord[$key] < -90) {
259
+					return false;
260
+				}
261
+				break;
262
+			case 'cached_lng':
263
+			case 'curbside_lng':
264
+				if ($coord[$key] > 180 || $coord[$key] < -180) {
265
+					return false;
266
+				}
267
+				break;
268
+		}
269
+
270
+		return true;
271
+	}
272 272
 
273
-    public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping)
274
-    {
275
-        $max_line_length = 512;
276
-        $delemietr = ',';
277
-
278
-        $results = [];
279
-        $results['fail'] = [];
280
-        $results['success'] = [];
281
-
282
-        $columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
273
+	public function addOrdersFromCsvFile($csvFileHandle, $ordersFieldsMapping)
274
+	{
275
+		$max_line_length = 512;
276
+		$delemietr = ',';
277
+
278
+		$results = [];
279
+		$results['fail'] = [];
280
+		$results['success'] = [];
281
+
282
+		$columns = fgetcsv($csvFileHandle, $max_line_length, $delemietr);
283 283
 
284
-        $excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id', 'order_ids',
285
-            'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid'];
286
-
287
-        $allOrderFields = Route4Me::getObjectProperties(new self(), $excludeFields);
288
-
289
-        if (!empty($columns)) {
290
-            array_push($results['fail'], 'Empty CSV table');
284
+		$excludeFields = ['route_id', 'redirect', 'optimization_problem_id', 'order_id', 'order_ids',
285
+			'fields', 'offset', 'limit', 'query', 'created_timestamp', 'order_uuid'];
286
+
287
+		$allOrderFields = Route4Me::getObjectProperties(new self(), $excludeFields);
288
+
289
+		if (!empty($columns)) {
290
+			array_push($results['fail'], 'Empty CSV table');
291 291
 
292
-            return $results;
293
-        }
294
-
295
-        $iRow = 1;
296
-
297
-        while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
298
-            if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null] !== $rows) {
299
-                $cached_lat = 0.000;
300
-                $cached_lng = 0.000;
301
-
302
-                foreach (['cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng'] as $coord) {
303
-                    if (!$this->validateCoordinate([$coord => $rows[$ordersFieldsMapping[$coord]]])) {
304
-                        array_push($results['fail'], "$iRow --> Wrong " + $coord);
305
-                        ++$iRow;
306
-                        continue;
307
-                    } else {
308
-                        switch ($coord) {
309
-                            case 'cached_lat':
310
-                                $cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]);
311
-                                break;
312
-                            case 'cached_lng':
313
-                                $cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]);
314
-                                break;
315
-                        }
316
-                    }
317
-                }
318
-
319
-                $address = $rows[$ordersFieldsMapping['address_1']];
320
-
321
-                foreach (['order_city', 'order_state_id', 'order_zip_code', 'order_country_id'] as $addressPart) {
322
-                    if (isset($ordersFieldsMapping[$addressPart])) {
323
-                        $address .= ', '.$rows[$ordersFieldsMapping[$addressPart]];
324
-                    }
325
-                }
326
-
327
-                echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].', '.$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']].'<br>';
328
-
329
-                $parametersArray = [];
330
-
331
-                $parametersArray['cached_lat'] = $cached_lat;
332
-                $parametersArray['cached_lng'] = $cached_lng;
333
-
334
-                foreach ($allOrderFields as $orderField) {
335
-                    if (isset($ordersFieldsMapping[$orderField])) {
336
-                        $parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]];
337
-                    }
338
-                }
339
-
340
-                $orderParameters = self::fromArray($parametersArray);
341
-
342
-                $order = new self();
343
-
344
-                $orderResults = $order->addOrder($orderParameters);
345
-
346
-                array_push($results['success'], 'The order with order_id = '.strval($orderResults['order_id']).' added successfuly.');
347
-            } else {
348
-                array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set");
349
-            }
350
-
351
-            ++$iRow;
352
-        }
353
-    }
292
+			return $results;
293
+		}
294
+
295
+		$iRow = 1;
296
+
297
+		while (false !== ($rows = fgetcsv($csvFileHandle, $max_line_length, $delemietr))) {
298
+			if ($rows[$ordersFieldsMapping['cached_lat']] && $rows[$ordersFieldsMapping['cached_lng']] && $rows[$ordersFieldsMapping['address_1']] && [null] !== $rows) {
299
+				$cached_lat = 0.000;
300
+				$cached_lng = 0.000;
301
+
302
+				foreach (['cached_lat', 'cached_lng', 'curbside_lat', 'curbside_lng'] as $coord) {
303
+					if (!$this->validateCoordinate([$coord => $rows[$ordersFieldsMapping[$coord]]])) {
304
+						array_push($results['fail'], "$iRow --> Wrong " + $coord);
305
+						++$iRow;
306
+						continue;
307
+					} else {
308
+						switch ($coord) {
309
+							case 'cached_lat':
310
+								$cached_lat = doubleval($rows[$ordersFieldsMapping[$coord]]);
311
+								break;
312
+							case 'cached_lng':
313
+								$cached_lng = doubleval($rows[$ordersFieldsMapping[$coord]]);
314
+								break;
315
+						}
316
+					}
317
+				}
318
+
319
+				$address = $rows[$ordersFieldsMapping['address_1']];
320
+
321
+				foreach (['order_city', 'order_state_id', 'order_zip_code', 'order_country_id'] as $addressPart) {
322
+					if (isset($ordersFieldsMapping[$addressPart])) {
323
+						$address .= ', '.$rows[$ordersFieldsMapping[$addressPart]];
324
+					}
325
+				}
326
+
327
+				echo "$iRow --> ".$ordersFieldsMapping['day_scheduled_for_YYMMDD'].', '.$rows[$ordersFieldsMapping['day_scheduled_for_YYMMDD']].'<br>';
328
+
329
+				$parametersArray = [];
330
+
331
+				$parametersArray['cached_lat'] = $cached_lat;
332
+				$parametersArray['cached_lng'] = $cached_lng;
333
+
334
+				foreach ($allOrderFields as $orderField) {
335
+					if (isset($ordersFieldsMapping[$orderField])) {
336
+						$parametersArray[$orderField] = $rows[$ordersFieldsMapping[$orderField]];
337
+					}
338
+				}
339
+
340
+				$orderParameters = self::fromArray($parametersArray);
341
+
342
+				$order = new self();
343
+
344
+				$orderResults = $order->addOrder($orderParameters);
345
+
346
+				array_push($results['success'], 'The order with order_id = '.strval($orderResults['order_id']).' added successfuly.');
347
+			} else {
348
+				array_push($results['fail'], "$iRow --> one of the parameters cached_lat, cached_lng, address_1 is not set");
349
+			}
350
+
351
+			++$iRow;
352
+		}
353
+	}
354 354
 }
Please login to merge, or discard this patch.