PluginProbe
Pay with Vipps and MobilePay for WooCommerce / 6.1.8
Pay with Vipps and MobilePay for WooCommerce v6.1.8
6.2.3 6.2.2 6.2.1 6.2.0 6.1.10 6.1.9 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1.0 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.4.3 5.4.2 5.4.1 5.4.0 All 185 releases
woo-vipps / recurring / includes / models / WC_Vipps_Checkout_Session_Configuration.php

WC_Vipps_Checkout_Session_Configuration.php in Pay with Vipps and MobilePay for WooCommerce 6.1.8, at recurring/includes/models/WC_Vipps_Checkout_Session_Configuration.php

131 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || exit;
4
5 class WC_Vipps_Checkout_Session_Configuration extends WC_Vipps_Model {
6 public const CUSTOMER_INTERACTION_PRESENT = "CUSTOMER_PRESENT";
7 public const CUSTOMER_INTERACTION_NOT_PRESENT = "CUSTOMER_NOT_PRESENT";
8
9 protected array $valid_customer_interactions = [
10 self::CUSTOMER_INTERACTION_PRESENT,
11 self::CUSTOMER_INTERACTION_NOT_PRESENT,
12 ];
13
14 public const ELEMENTS_FULL = "Full";
15 public const ELEMENTS_PAYMENT_AND_CONTACT_INFO = "PaymentAndContactInfo";
16 public const ELEMENTS_PAYMENT_ONLY = "PaymentOnly";
17
18 protected array $valid_elements = [
19 self::ELEMENTS_FULL,
20 self::ELEMENTS_PAYMENT_AND_CONTACT_INFO,
21 self::ELEMENTS_PAYMENT_ONLY,
22 ];
23
24 public const USER_FLOW_WEB_REDIRECT = "WEB_REDIRECT";
25 public const USER_FLOW_NATIVE_REDIRECT = "NATIVE_REDIRECT";
26
27 protected array $valid_user_flows = [
28 self::USER_FLOW_WEB_REDIRECT,
29 self::USER_FLOW_NATIVE_REDIRECT,
30 ];
31
32 public ?string $customer_interaction = null;
33 public ?string $elements = null;
34 public ?array $countries = null;
35 public ?string $user_flow = null;
36 public ?bool $require_user_info = null;
37 public ?array $custom_consent = null;
38 public ?bool $show_order_summary = null;
39
40
41 /**
42 * @throws WC_Vipps_Recurring_Invalid_Value_Exception
43 */
44 public function set_customer_interaction( string $customer_interaction ): self {
45 if ( ! in_array( $customer_interaction, $this->valid_customer_interactions, true ) ) {
46 $class = get_class( $this );
47 throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$customer_interaction is not a valid value for `customer_interaction` in $class." );
48 }
49
50 $this->customer_interaction = $customer_interaction;
51
52 return $this;
53 }
54
55 /**
56 * @throws WC_Vipps_Recurring_Invalid_Value_Exception
57 */
58 public function set_elements( string $elements ): self {
59 if ( ! in_array( $elements, $this->valid_elements, true ) ) {
60 $class = get_class( $this );
61 throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$elements is not a valid value for `elements` in $class." );
62 }
63
64 $this->elements = $elements;
65
66 return $this;
67 }
68
69 // Available: NO, DK, FI
70 public function set_countries( array $countries ): self {
71 $this->countries = $countries;
72
73 return $this;
74 }
75
76 /**
77 * @throws WC_Vipps_Recurring_Invalid_Value_Exception
78 */
79 public function set_user_flow( string $user_flow ): self {
80 if ( ! in_array( $user_flow, $this->valid_user_flows, true ) ) {
81 $class = get_class( $this );
82 throw new WC_Vipps_Recurring_Invalid_Value_Exception( "$user_flow is not a valid value for `user_flow` in $class." );
83 }
84
85 $this->user_flow = $user_flow;
86
87 return $this;
88 }
89
90 public function set_require_user_info( bool $require_user_info ): self {
91 $this->require_user_info = $require_user_info;
92
93 return $this;
94 }
95
96 public function set_custom_consent( string $text, bool $required ): self {
97 $this->custom_consent = [
98 "text" => $text,
99 "required" => $required
100 ];
101
102 return $this;
103 }
104
105 public function set_show_order_summary( bool $show_order_summary ): self {
106 $this->show_order_summary = $show_order_summary;
107
108 return $this;
109 }
110
111
112 /**
113 * @throws WC_Vipps_Recurring_Missing_Value_Exception
114 */
115 public function to_array( bool $check_required = false ): array {
116 if ( $check_required ) {
117 $this->check_required();
118 }
119
120 return array_merge(
121 $this->conditional( "termsAndConditionsUrl", $this->customer_interaction ),
122 $this->conditional( "elements", $this->elements ),
123 $this->conditional( "countries", $this->countries ),
124 $this->conditional( "userFlow", $this->user_flow ),
125 $this->conditional( "requireUserInfo", $this->require_user_info ),
126 $this->conditional( "customConsent", $this->custom_consent ),
127 $this->conditional( "showOrderSummary", $this->show_order_summary ),
128 );
129 }
130 }
131