| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class Rest_API\Barcode\Client file. |
| 4 |
* |
| 5 |
* @package PostNLWooCommerce\Rest_API\Legacy\Barcode |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace PostNLWooCommerce\Rest_API\Legacy\Barcode; |
| 9 |
|
| 10 |
use PostNLWooCommerce\Rest_API\Base; |
| 11 |
use PostNLWooCommerce\Rest_API\Contracts\Barcode_Service_Interface; |
| 12 |
use PostNLWooCommerce\Utils; |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Class Client |
| 20 |
* |
| 21 |
* @package PostNLWooCommerce\Rest_API\Legacy\Barcode |
| 22 |
*/ |
| 23 |
class Client extends Base implements Barcode_Service_Interface { |
| 24 |
/** |
| 25 |
* API Endpoint. |
| 26 |
* |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
public $endpoint = '/shipment/v1_1/barcode'; |
| 30 |
|
| 31 |
/** |
| 32 |
* PostnL API Method. |
| 33 |
* |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
public $method = 'GET'; |
| 37 |
|
| 38 |
/** |
| 39 |
* Function for composing API request in the URL for GET request. |
| 40 |
* |
| 41 |
* @return Array. |
| 42 |
*/ |
| 43 |
public function compose_url_params() { |
| 44 |
$range = Utils::get_barcode_range( $this->item_info->query_args['barcode_type'], $this->item_info->query_args['globalpack_customer_code'] ); |
| 45 |
|
| 46 |
return array( |
| 47 |
'Type' => $this->item_info->query_args['barcode_type'], |
| 48 |
'Serie' => $this->item_info->query_args['serie'], |
| 49 |
'CustomerCode' => $this->item_info->query_args['customer_code'], |
| 50 |
'CustomerNumber' => $this->item_info->query_args['customer_num'], |
| 51 |
'Range' => $range, |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Generate a barcode for the given post data. |
| 57 |
* |
| 58 |
* @param array $post_data Post data for barcode generation. |
| 59 |
* |
| 60 |
* @return array |
| 61 |
*/ |
| 62 |
public function generate( array $post_data ): array { |
| 63 |
$item_info = new Item_Info( $post_data ); |
| 64 |
$client = new self( $item_info ); |
| 65 |
|
| 66 |
// send_request() can return null on an empty/non-JSON 200; normalize to honor the array return type. |
| 67 |
$response = $client->send_request(); |
| 68 |
return is_array( $response ) ? $response : array(); |
| 69 |
} |
| 70 |
} |
| 71 |
|