PluginProbe
PostNL for WooCommerce / trunk
PostNL for WooCommerce vtrunk
5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 4.4.2 All 71 releases
woo-postnl / src / Rest_API / Contracts / Timeframe_Service_Interface.php

Timeframe_Service_Interface.php in PostNL for WooCommerce trunk, at src/Rest_API/Contracts/Timeframe_Service_Interface.php

82 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Interface Timeframe_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 delivery-day timeframe retrieval services.
16 *
17 * Covers the DeliveryOptions portion of the PostNL Checkout API response
18 * (/shipment/v1/checkout). The same API endpoint also returns PickupOptions;
19 * those are covered by Pickup_Location_Service_Interface.
20 *
21 * Both the Legacy (V1) and any future V4 transport must implement this interface.
22 * Callers in Frontend\Container and Checkout_Blocks\Extend_Block_Core never need
23 * to know which transport provided the data.
24 */
25 interface Timeframe_Service_Interface {
26
27 /**
28 * Retrieve available delivery-day timeframes for a given checkout address.
29 *
30 * Derived from Frontend\Container::get_checkout_data(), which:
31 * 1. Constructs Checkout\Item_Info from $post_data.
32 * 2. Constructs Checkout\Client with that Item_Info.
33 * 3. Calls send_request() on the client.
34 * 4. Returns the full response as $checkout_data['response'], which is then
35 * passed to the template and to get_default_value() for rendering the
36 * delivery-day tab in the classic and blocks checkouts.
37 *
38 * The current PostNL endpoint is /shipment/v1/checkout (POST).
39 * The request includes cut-off times, drop-off days, shipping duration, and
40 * enabled options (Daytime, Evening, 08:00-12:00).
41 *
42 * @param array $post_data {
43 * Checkout POST data as collected from the classic checkout or the blocks
44 * AJAX handler. All keys map to the fields set by Address_Utils and the
45 * shipping settings injected by Base_Info::set_settings_data().
46 *
47 * @type string $shipping_postcode Required. Receiver postcode.
48 * @type string $shipping_country Required. Receiver country code (NL or BE).
49 * @type string $shipping_address_1 Street name.
50 * @type string $shipping_address_2 House number or extension.
51 * @type string $shipping_city City.
52 * }
53 *
54 * @return array {
55 * JSON-decoded PostNL /shipment/v1/checkout response body.
56 * The DeliveryOptions key is consumed by Frontend\Delivery_Day and the
57 * blocks postnl-delivery-day component.
58 *
59 * @type array $DeliveryOptions {
60 * Indexed array of delivery day entries.
61 * @type array $item {
62 * @type string $DeliveryDate Delivery date in 'd-m-Y' or 'Y-m-d' format.
63 * @type array $Timeframe Indexed array of timeframe windows.
64 * @type array $window {
65 * @type string $From Window start time, e.g. '09:00:00'.
66 * @type string $To Window end time, e.g. '18:00:00'.
67 * @type string[] $Options Option codes for this window,
68 * e.g. array( 'Daytime' ),
69 * array( 'Evening' ),
70 * array( '08:00-12:00' ).
71 * }
72 * }
73 * }
74 * }
75 *
76 * @throws \Exception If the API request fails (network error or authentication
77 * failure). Missing or empty DeliveryOptions is not an
78 * exception; the caller handles empty responses gracefully.
79 */
80 public function get_delivery_options( array $post_data ): array;
81 }
82