| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Pakkelabels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * PHP version 5 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @category  Pakkelabels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @package   Pakkelabels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @author    Lars Olesen <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright 2015 Lars Olesen | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @license   MIT Open Source License https://opensource.org/licenses/MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @version   GIT: <git_id> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @link      http://github.com/discimport/pakkelabels-dk | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | namespace Pakkelabels; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Pakkelabels\Exception\PakkelabelsException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * Class Pakkelabels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * Usage: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * ---------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * The first thing required is to login | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * $label = new Pakkelabels('api_user', 'api_key'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * This will login and fetch the required token. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * The token is then automatically added to any subsequent calls. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * To see the generated token you can use: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * echo $label->getToken(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * Examples: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * ---------------- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  * // Get all Post Danmark labels shipped to Denmark | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  * $labels = $label->shipments(array('shipping_agent' => 'pdk', 'receiver_country' => 'DK')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  * // Display the PDF for a specific label | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  * $base64 = $label->pdf(31629); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  * $pdf = base64_decode($base64); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  * header('Content-type: application/pdf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  * header('Content-Disposition: inline; filename="label.pdf"'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  * echo $pdf; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  * @category  Pakkelabels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  * @package   Pakkelabels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  * @author    Lars Olesen <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  * @copyright 2015 Lars Olesen | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  * @license   http://opensource.org/licenses/bsd-license.php New BSD License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  * @link      http://github.com/discimport/pakkelabels-dk | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | class Pakkelabels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * API Endpoint URL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     const API_ENDPOINT = 'https://app.pakkelabels.dk/api/public/v2'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * API Endpoint URL | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     const VERSION = '1.1'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * API user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     protected $api_user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * API key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     protected $api_key; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * Token | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     protected $token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * Constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param string $api_user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @param string $api_key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 1 |  |     public function __construct($api_user, $api_key) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 1 |  |         $this->api_user = $api_user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 1 |  |         $this->api_key = $api_key; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 1 |  |         $this->login(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * Login | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 1 |  |     protected function login() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 1 |  |         $result = $this->makeApiCall( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 | 1 |  |             'users/login', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 1 |  |             true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 1 |  |             array('api_user' => $this->api_user, 'api_key' => $this->api_key) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 1 |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $this->token = $result['token']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * Get balance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     public function balance() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $result = $this->makeApiCall('users/balance'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         return $result['balance']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * Get PDF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * @return base64 encoded string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 139 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |     public function pdf($id) | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |         $result = $this->makeApiCall('shipments/pdf', false, array('id' => $id)); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |         return $result['base64']; | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * Search shipments | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * @param array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     public function shipments($params = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |         $result = $this->makeApiCall('shipments/shipments', false, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * Get imported shipments | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      * @param array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     public function importedShipments($params = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         $result = $this->makeApiCall('shipments/imported_shipments', false, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      * Create imported shipment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * @param array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     public function createImportedShipment($params) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $result = $this->makeApiCall('shipments/imported_shipment', true, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      * Create shipment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      * @param array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     public function createShipment($params) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         $result = $this->makeApiCall('shipments/shipment', true, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |      * Get freight rates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |     public function freightRates() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         $result = $this->makeApiCall('shipments/freight_rates'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |      * Get payment requests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |     public function paymentRequests() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         $result = $this->makeApiCall('users/payment_requests'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |      * Get GLS Droppoints | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      * @param array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |     public function glsDroppoints($params) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         $result = $this->makeApiCall('shipments/gls_droppoints', false, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |      * Get PDK Droppoints | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |      * @param array $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |     public function pdkDroppoints($params) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         $result = $this->makeApiCall('shipments/pdk_droppoints', false, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |      * Get token | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |     public function getToken() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         return $this->token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 | 1 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |      * Make API Call | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 | 1 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 | 1 |  |      * @param string  $method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 | 1 |  |      * @param boolean $doPost | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 | 1 |  |      * @param array   $params | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 | 1 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 | 1 |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |      * @throws \PakkelabelsException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 | 1 |  |     protected function makeApiCall($method, $doPost = false, $params = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 | 1 |  |         $ch = curl_init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 | 1 |  |         $params['token'] = $this->token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 | 1 |  |         $params['user_agent'] = 'pdk_php_library v' . self::VERSION; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 | 1 |  |         $query = http_build_query($params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 | 1 |  |         if ($doPost === true) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 | 1 |  |             curl_setopt($ch, CURLOPT_URL, self::API_ENDPOINT . '/' . $method); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |             curl_setopt($ch, CURLOPT_POST, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |             curl_setopt($ch, CURLOPT_POSTFIELDS, $query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |             curl_setopt($ch, CURLOPT_URL, self::API_ENDPOINT . '/' . $method . '?' . $query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |         $output = curl_exec($ch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |         $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         curl_close($ch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |         $output = json_decode($output, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |         if ($http_code != 200) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |             throw new PakkelabelsException($output['message']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |         return $output; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 300 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 301 |  |  |  |