| 1 |
<?php |
| 2 |
/** |
| 3 |
* Interface Pickup_Location_Service_Interface. |
| 4 |
* |
| 5 |
* @package PostNLWooCommerce\Rest_API\Contracts |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace PostNLWooCommerce\Rest_API\Contracts; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Contract for pickup-location (dropoff-point) retrieval services. |
| 16 |
* |
| 17 |
* Covers the PickupOptions portion of the PostNL Checkout API response |
| 18 |
* (/shipment/v1/checkout). The same API endpoint also returns DeliveryOptions; |
| 19 |
* those are covered by Timeframe_Service_Interface. |
| 20 |
* |
| 21 |
* Both the Legacy (V1) and any future V4 transport must implement this interface. |
| 22 |
* Callers in Frontend\Container and the blocks postnl-dropoff-points component |
| 23 |
* never need to know which transport provided the data. |
| 24 |
*/ |
| 25 |
interface Pickup_Location_Service_Interface { |
| 26 |
|
| 27 |
/** |
| 28 |
* Retrieve available PostNL pickup locations for a given checkout address. |
| 29 |
* |
| 30 |
* Derived from Frontend\Container::get_checkout_data(), which uses the same |
| 31 |
* Checkout\Client request that returns both DeliveryOptions and PickupOptions. |
| 32 |
* The PickupOptions portion is consumed by Frontend\Dropoff_Points and the |
| 33 |
* blocks postnl-dropoff-points component to render the pickup-point tab. |
| 34 |
* |
| 35 |
* The current PostNL endpoint is /shipment/v1/checkout (POST). |
| 36 |
* The number of returned locations is a fixed count |
| 37 |
* (see Settings::get_number_pickup_points()). |
| 38 |
* |
| 39 |
* @param array $post_data { |
| 40 |
* Checkout POST data as collected from the classic checkout or the blocks |
| 41 |
* AJAX handler. All keys map to the fields set by Address_Utils and the |
| 42 |
* shipping settings injected by Base_Info::set_settings_data(). |
| 43 |
* |
| 44 |
* @type string $shipping_postcode Required. Receiver postcode. |
| 45 |
* @type string $shipping_country Required. Receiver country code (NL or BE). |
| 46 |
* @type string $shipping_address_1 Street name. |
| 47 |
* @type string $shipping_address_2 House number or extension. |
| 48 |
* @type string $shipping_city City. |
| 49 |
* } |
| 50 |
* |
| 51 |
* @return array { |
| 52 |
* JSON-decoded PostNL /shipment/v1/checkout response body. |
| 53 |
* The PickupOptions key is consumed by Frontend\Dropoff_Points and the |
| 54 |
* blocks postnl-dropoff-points component. |
| 55 |
* |
| 56 |
* @type array $PickupOptions { |
| 57 |
* Indexed array of pickup-option groups. |
| 58 |
* @type array $item { |
| 59 |
* @type string $PickupDate Earliest available customer pickup date. |
| 60 |
* @type string $ShippingDate Date the parcel needs to be dispatched. |
| 61 |
* @type array $Locations Indexed array of pickup location records. |
| 62 |
* @type array $location { |
| 63 |
* @type string $LocationCode Unique location identifier stored |
| 64 |
* in _postnl_order_metadata['frontend'] |
| 65 |
* as dropoff_points_id. |
| 66 |
* @type string $Name Human-readable location name stored |
| 67 |
* as dropoff_points_company. |
| 68 |
* @type array $Address { |
| 69 |
* @type string $Street Street name. |
| 70 |
* @type string $Zipcode Postal code. |
| 71 |
* @type string $City City name. |
| 72 |
* @type string $Countrycode ISO-2 country code. |
| 73 |
* } |
| 74 |
* @type string $OpeningHours Location opening hours (optional). |
| 75 |
* @type string $Distance Distance from the receiver address |
| 76 |
* in metres (optional). |
| 77 |
* } |
| 78 |
* } |
| 79 |
* } |
| 80 |
* } |
| 81 |
* |
| 82 |
* @throws \Exception If the API request fails (network error or authentication |
| 83 |
* failure). An empty or missing PickupOptions key is not an |
| 84 |
* exception; the caller hides the pickup-point tab in that case. |
| 85 |
*/ |
| 86 |
public function get_pickup_locations( array $post_data ): array; |
| 87 |
} |
| 88 |
|