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 / Postcode_Check / Item_Info.php

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

93 lines 2.1 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\Postcode_Check\Item_Info 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_Info;
11 use PostNLWooCommerce\Utils;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Class Item_Info
19 *
20 * @package PostNLWooCommerce\Rest_API\Legacy\Postcode_Check
21 */
22 class Item_Info extends Base_Info {
23 /**
24 * API args.
25 *
26 * @var api_args
27 */
28 protected $api_args;
29
30
31 /**
32 * Receiver data of the item info.
33 *
34 * @var receiver
35 */
36 public $receiver;
37
38 /**
39 * Parses the arguments and sets the instance's properties.
40 *
41 * @throws \Exception If some data in $args did not pass validation.
42 */
43 protected function parse_args() {
44 $this->receiver = Utils::parse_args( $this->api_args['shipping_address'], $this->get_receiver_info_schema() );
45 }
46
47 /**
48 * Method to convert the post data to API args.
49 *
50 * @param Array $post_data Data from post variable in checkout page.
51 */
52 public function convert_data_to_args( $post_data ) {
53
54 $this->api_args['shipping_address'] = array(
55 'address_2' => $post_data['shipping_address_2'] ?? '',
56 'house_number' => $post_data['shipping_house_number'] ?? '',
57 'postcode' => $post_data['shipping_postcode'] ?? '',
58 );
59 }
60
61 /**
62 * Retrieves the args scheme to use with for parsing shipping address info.
63 *
64 * @return array
65 */
66 protected function get_receiver_info_schema() {
67 // Closures in PHP 5.3 do not inherit class context
68 // So we need to copy $this into a lexical variable and pass it to closures manually.
69 $self = $this;
70
71 return array(
72 'first_name' => array(
73 'default' => '',
74 ),
75 'address_1' => array(
76 'default' => '',
77 ),
78 'address_2' => array(
79 'default' => '',
80 ),
81 'city' => array(
82 'default' => '',
83 ),
84 'house_number' => array(
85 'error' => __( 'Shipping "House number" is empty!', 'postnl-for-woocommerce' ),
86 ),
87 'postcode' => array(
88 'error' => __( 'Shipping "Postcode" is empty!', 'postnl-for-woocommerce' ),
89 ),
90 );
91 }
92 }
93