PluginProbe
PostNL for WooCommerce / 5.9.12
PostNL for WooCommerce v5.9.12
5.9.12 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 All 72 releases
woo-postnl / src / Rest_API / Legacy / Checkout_Service.php

Checkout_Service.php in PostNL for WooCommerce 5.9.12, at src/Rest_API/Legacy/Checkout_Service.php

63 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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