| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class Rest_API\Legacy\Checkout_Service file. |
| 4 |
* |
| 5 |
* @package PostNLWooCommerce\Rest_API\Legacy |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace PostNLWooCommerce\Rest_API\Legacy; |
| 9 |
|
| 10 |
use PostNLWooCommerce\Rest_API\Contracts\Pickup_Location_Service_Interface; |
| 11 |
use PostNLWooCommerce\Rest_API\Contracts\Timeframe_Service_Interface; |
| 12 |
use PostNLWooCommerce\Rest_API\Legacy\Checkout\Client; |
| 13 |
use PostNLWooCommerce\Rest_API\Legacy\Checkout\Item_Info; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Class Checkout_Service |
| 21 |
* |
| 22 |
* Stateless service wrapper around Legacy\Checkout\Client. |
| 23 |
* Zero-arg constructable so Service_Factory can return it before request data exists. |
| 24 |
* The PostNL checkout endpoint returns both delivery options and pickup locations in a |
| 25 |
* single response; both interface methods delegate to the same underlying API call. |
| 26 |
* |
| 27 |
* @package PostNLWooCommerce\Rest_API\Legacy |
| 28 |
*/ |
| 29 |
class Checkout_Service implements Timeframe_Service_Interface, Pickup_Location_Service_Interface { |
| 30 |
|
| 31 |
/** |
| 32 |
* Get delivery options for the given post data. |
| 33 |
* |
| 34 |
* @param array $post_data Post data for delivery options request. |
| 35 |
* |
| 36 |
* @return array |
| 37 |
*/ |
| 38 |
public function get_delivery_options( array $post_data ): array { |
| 39 |
$item_info = new Item_Info( $post_data ); |
| 40 |
$client = new Client( $item_info ); |
| 41 |
|
| 42 |
// send_request() can return null on an empty/non-JSON 200; normalize to honor the array return type. |
| 43 |
$response = $client->send_request(); |
| 44 |
return is_array( $response ) ? $response : array(); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get pickup locations for the given post data. |
| 49 |
* |
| 50 |
* @param array $post_data Post data for pickup locations request. |
| 51 |
* |
| 52 |
* @return array |
| 53 |
*/ |
| 54 |
public function get_pickup_locations( array $post_data ): array { |
| 55 |
$item_info = new Item_Info( $post_data ); |
| 56 |
$client = new Client( $item_info ); |
| 57 |
|
| 58 |
// send_request() can return null on an empty/non-JSON 200; normalize to honor the array return type. |
| 59 |
$response = $client->send_request(); |
| 60 |
return is_array( $response ) ? $response : array(); |
| 61 |
} |
| 62 |
} |
| 63 |
|