| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class Rest_API\Postcode_Check\Client file. |
| 4 |
* |
| 5 |
* @package PostNLWooCommerce\Rest_API\Legacy\Postcode_Check |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace PostNLWooCommerce\Rest_API\Legacy\Postcode_Check; |
| 9 |
|
| 10 |
use PostNLWooCommerce\Rest_API\Base; |
| 11 |
use PostNLWooCommerce\Rest_API\Contracts\Postcode_Check_Service_Interface; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Class Client |
| 19 |
* |
| 20 |
* @package PostNLWooCommerce\Rest_API\Legacy\Postcode_Check |
| 21 |
*/ |
| 22 |
class Client extends Base implements Postcode_Check_Service_Interface { |
| 23 |
/** |
| 24 |
* API Endpoint. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
public $endpoint = '/shipment/checkout/v1/postalcodecheck'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Function for composing API request. |
| 32 |
*/ |
| 33 |
public function compose_body_request() { |
| 34 |
return array( |
| 35 |
'postalcode' => $this->item_info->receiver['postcode'], |
| 36 |
'housenumber' => $this->item_info->receiver['house_number'], |
| 37 |
'housenumberaddition' => $this->item_info->receiver['address_2'], |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Check the given postcode data. |
| 43 |
* |
| 44 |
* @param array $post_data Post data for postcode check. |
| 45 |
* |
| 46 |
* @return array |
| 47 |
*/ |
| 48 |
public function check( array $post_data ): array { |
| 49 |
$item_info = new Item_Info( $post_data ); |
| 50 |
$client = new self( $item_info ); |
| 51 |
|
| 52 |
// send_request() can return null on an empty/non-JSON 200; normalize to honor the array return type. |
| 53 |
$response = $client->send_request(); |
| 54 |
return is_array( $response ) ? $response : array(); |
| 55 |
} |
| 56 |
} |
| 57 |
|