1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MyFatoorah\Library\API; |
4
|
|
|
|
5
|
|
|
use MyFatoorah\Library\MyFatoorah; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* MyFatoorahShipping handles the shipping process of MyFatoorah API endpoints |
9
|
|
|
* |
10
|
|
|
* @author MyFatoorah <[email protected]> |
11
|
|
|
* @copyright MyFatoorah, All rights reserved |
12
|
|
|
* @license GNU General Public License v3.0 |
13
|
|
|
*/ |
14
|
|
|
class MyFatoorahShipping extends MyFatoorah |
15
|
|
|
{ |
16
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get MyFatoorah Shipping Countries (GET API) |
20
|
|
|
* |
21
|
|
|
* @return array |
22
|
|
|
*/ |
23
|
|
|
public function getShippingCountries() |
24
|
|
|
{ |
25
|
|
|
$url = "$this->apiURL/v2/GetCountries"; |
26
|
|
|
$json = $this->callAPI($url, null, null, 'Get Countries'); |
27
|
|
|
return $json->Data; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get Shipping Cities (GET API) |
34
|
|
|
* |
35
|
|
|
* @param int $method [1 for DHL, 2 for Aramex] |
36
|
|
|
* @param string $countryCode It can be obtained from getShippingCountries |
37
|
|
|
* @param string $searchValue The key word that will be used in searching |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public function getShippingCities($method, $countryCode, $searchValue = '') |
42
|
|
|
{ |
43
|
|
|
$url = $this->apiURL . '/v2/GetCities' |
44
|
|
|
. '?shippingMethod=' . $method |
45
|
|
|
. '&countryCode=' . $countryCode |
46
|
|
|
. '&searchValue=' . urlencode(substr($searchValue, 0, 30)); |
47
|
|
|
|
48
|
|
|
$json = $this->callAPI($url, null, null, "Get Cities: $countryCode"); |
49
|
|
|
return array_map('ucwords', $json->Data->CityNames); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Calculate Shipping Charge (POST API) |
56
|
|
|
* |
57
|
|
|
* @param array $curlData the curl data contains the shipping information |
58
|
|
|
* |
59
|
|
|
* @return object |
60
|
|
|
*/ |
61
|
|
|
public function calculateShippingCharge($curlData) |
62
|
|
|
{ |
63
|
|
|
if (!empty($curlData['Items'])) { |
64
|
|
|
foreach ($curlData['Items'] as &$item) { |
65
|
|
|
$item['ProductName'] = strip_tags($item['ProductName']); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$url = "$this->apiURL/v2/CalculateShippingCharge"; |
70
|
|
|
$json = $this->callAPI($url, $curlData, null, 'Calculate Shipping Charge'); |
71
|
|
|
return $json->Data; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
//----------------------------------------------------------------------------------------------------------------------------------------- |
75
|
|
|
} |
76
|
|
|
|