Passed
Push — main ( 4a5f0c...02f3c9 )
by MyFatoorah
06:23 queued 02:44
created

MyFatoorahShipping   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 52
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A calculateShippingCharge() 0 5 1
A getShippingCountries() 0 5 1
A getShippingCities() 0 9 1
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 2021 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
        $url  = "$this->apiURL/v2/CalculateShippingCharge";
64
        $json = $this->callAPI($url, $curlData, null, 'Calculate Shipping Charge');
65
        return $json->Data;
66
    }
67
68
    //-----------------------------------------------------------------------------------------------------------------------------------------
69
}
70