@@ -35,23 +35,23 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param Config $config Config. |
37 | 37 | */ |
38 | - public function __construct( Config $config ) { |
|
39 | - parent::__construct( $config ); |
|
38 | + public function __construct(Config $config) { |
|
39 | + parent::__construct($config); |
|
40 | 40 | |
41 | - $this->set_method( self::METHOD_HTTP_REDIRECT ); |
|
41 | + $this->set_method(self::METHOD_HTTP_REDIRECT); |
|
42 | 42 | |
43 | 43 | // Client. |
44 | 44 | $this->client = new Client(); |
45 | 45 | |
46 | 46 | $url = Client::URL_PRODUCTION; |
47 | 47 | |
48 | - if ( self::MODE_TEST === $config->mode ) { |
|
48 | + if (self::MODE_TEST === $config->mode) { |
|
49 | 49 | $url = Client::URL_SANDBOX; |
50 | 50 | } |
51 | 51 | |
52 | - $this->client->set_url( $url ); |
|
53 | - $this->client->set_refresh_token( $config->refresh_token ); |
|
54 | - $this->client->set_signing_key( $config->signing_key ); |
|
52 | + $this->client->set_url($url); |
|
53 | + $this->client->set_refresh_token($config->refresh_token); |
|
54 | + $this->client->set_signing_key($config->signing_key); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -78,87 +78,87 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @param Payment $payment Payment. |
80 | 80 | */ |
81 | - public function start( Payment $payment ) { |
|
81 | + public function start(Payment $payment) { |
|
82 | 82 | // Merchant order ID. |
83 | - $merchant_order_id = $payment->format_string( $this->config->order_id ); |
|
83 | + $merchant_order_id = $payment->format_string($this->config->order_id); |
|
84 | 84 | |
85 | - $payment->set_meta( 'omnikassa_2_merchant_order_id', $merchant_order_id ); |
|
85 | + $payment->set_meta('omnikassa_2_merchant_order_id', $merchant_order_id); |
|
86 | 86 | |
87 | 87 | // Billing and shipping details. |
88 | 88 | $shipping_address = $payment->get_shipping_address(); |
89 | 89 | $billing_address = $payment->get_billing_address(); |
90 | 90 | |
91 | 91 | $shipping_detail = new Address(); |
92 | - $shipping_detail->set_first_name( $shipping_address->get_name()->get_first_name() ); |
|
93 | - $shipping_detail->set_middle_name( $shipping_address->get_name()->get_middle_name() ); |
|
94 | - $shipping_detail->set_last_name( $shipping_address->get_name()->get_last_name() ); |
|
95 | - $shipping_detail->set_street( $shipping_address->get_street_name() ); |
|
96 | - $shipping_detail->set_house_number( $shipping_address->get_house_number() ); |
|
97 | - $shipping_detail->set_house_number_addition( $shipping_address->get_house_number_addition() ); |
|
98 | - $shipping_detail->set_postal_code( $shipping_address->get_postal_code() ); |
|
99 | - $shipping_detail->set_city( $shipping_address->get_city() ); |
|
100 | - $shipping_detail->set_country_code( $shipping_address->get_country_code() ); |
|
92 | + $shipping_detail->set_first_name($shipping_address->get_name()->get_first_name()); |
|
93 | + $shipping_detail->set_middle_name($shipping_address->get_name()->get_middle_name()); |
|
94 | + $shipping_detail->set_last_name($shipping_address->get_name()->get_last_name()); |
|
95 | + $shipping_detail->set_street($shipping_address->get_street_name()); |
|
96 | + $shipping_detail->set_house_number($shipping_address->get_house_number()); |
|
97 | + $shipping_detail->set_house_number_addition($shipping_address->get_house_number_addition()); |
|
98 | + $shipping_detail->set_postal_code($shipping_address->get_postal_code()); |
|
99 | + $shipping_detail->set_city($shipping_address->get_city()); |
|
100 | + $shipping_detail->set_country_code($shipping_address->get_country_code()); |
|
101 | 101 | |
102 | 102 | $billing_detail = new Address(); |
103 | - $billing_detail->set_first_name( $billing_address->get_name()->get_first_name() ); |
|
104 | - $billing_detail->set_middle_name( $billing_address->get_name()->get_middle_name() ); |
|
105 | - $billing_detail->set_last_name( $billing_address->get_name()->get_last_name() ); |
|
106 | - $billing_detail->set_street( $billing_address->get_street_name() ); |
|
107 | - $billing_detail->set_house_number( $billing_address->get_house_number() ); |
|
108 | - $billing_detail->set_house_number_addition( $billing_address->get_house_number_addition() ); |
|
109 | - $billing_detail->set_postal_code( $billing_address->get_postal_code() ); |
|
110 | - $billing_detail->set_city( $billing_address->get_city() ); |
|
111 | - $billing_detail->set_country_code( $billing_address->get_country_code() ); |
|
103 | + $billing_detail->set_first_name($billing_address->get_name()->get_first_name()); |
|
104 | + $billing_detail->set_middle_name($billing_address->get_name()->get_middle_name()); |
|
105 | + $billing_detail->set_last_name($billing_address->get_name()->get_last_name()); |
|
106 | + $billing_detail->set_street($billing_address->get_street_name()); |
|
107 | + $billing_detail->set_house_number($billing_address->get_house_number()); |
|
108 | + $billing_detail->set_house_number_addition($billing_address->get_house_number_addition()); |
|
109 | + $billing_detail->set_postal_code($billing_address->get_postal_code()); |
|
110 | + $billing_detail->set_city($billing_address->get_city()); |
|
111 | + $billing_detail->set_country_code($billing_address->get_country_code()); |
|
112 | 112 | |
113 | 113 | // Customer information. |
114 | 114 | $customer_information = new CustomerInformation(); |
115 | - $customer_information->set_email_address( $payment->get_contact()->get_email() ); |
|
116 | - $customer_information->set_telephone_number( $payment->get_contact()->get_phone() ); |
|
115 | + $customer_information->set_email_address($payment->get_contact()->get_email()); |
|
116 | + $customer_information->set_telephone_number($payment->get_contact()->get_phone()); |
|
117 | 117 | |
118 | 118 | // Payment brand. |
119 | - $payment_brand = PaymentBrands::transform( $payment->get_method() ); |
|
119 | + $payment_brand = PaymentBrands::transform($payment->get_method()); |
|
120 | 120 | |
121 | 121 | // New order. |
122 | 122 | $order = new Order( |
123 | 123 | $merchant_order_id, |
124 | 124 | new Money( |
125 | 125 | $payment->get_currency(), |
126 | - Core_Util::amount_to_cents( $payment->get_amount()->get_amount() ) |
|
126 | + Core_Util::amount_to_cents($payment->get_amount()->get_amount()) |
|
127 | 127 | ), |
128 | 128 | $payment->get_return_url() |
129 | 129 | ); |
130 | 130 | |
131 | - $order->set_description( $payment->get_description() ); |
|
132 | - $order->set_language( $payment->get_contact()->get_language() ); |
|
133 | - $order->set_order_items( $payment->get_order_items() ); |
|
134 | - $order->set_shipping_detail( $shipping_detail ); |
|
135 | - $order->set_billing_detail( $billing_detail ); |
|
136 | - $order->set_customer_information( $customer_information ); |
|
137 | - $order->set_payment_brand( $payment_brand ); |
|
131 | + $order->set_description($payment->get_description()); |
|
132 | + $order->set_language($payment->get_contact()->get_language()); |
|
133 | + $order->set_order_items($payment->get_order_items()); |
|
134 | + $order->set_shipping_detail($shipping_detail); |
|
135 | + $order->set_billing_detail($billing_detail); |
|
136 | + $order->set_customer_information($customer_information); |
|
137 | + $order->set_payment_brand($payment_brand); |
|
138 | 138 | |
139 | - if ( null !== $payment_brand ) { |
|
139 | + if (null !== $payment_brand) { |
|
140 | 140 | // Payment brand force should only be set if payment brand is not empty. |
141 | - $order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE ); |
|
141 | + $order->set_payment_brand_force(PaymentBrandForce::FORCE_ONCE); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | // Maybe update access token. |
145 | 145 | $this->maybe_update_access_token(); |
146 | 146 | |
147 | 147 | // Handle errors. |
148 | - if ( $this->get_client_error() ) { |
|
148 | + if ($this->get_client_error()) { |
|
149 | 149 | return; |
150 | 150 | } |
151 | 151 | |
152 | 152 | // Announce order. |
153 | - $result = $this->client->order_announce( $this->config, $order ); |
|
153 | + $result = $this->client->order_announce($this->config, $order); |
|
154 | 154 | |
155 | 155 | // Handle errors. |
156 | - if ( $this->get_client_error() ) { |
|
156 | + if ($this->get_client_error()) { |
|
157 | 157 | return; |
158 | 158 | } |
159 | 159 | |
160 | - if ( $result ) { |
|
161 | - $payment->set_action_url( $result->redirectUrl ); |
|
160 | + if ($result) { |
|
161 | + $payment->set_action_url($result->redirectUrl); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -167,45 +167,45 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @param Payment $payment Payment. |
169 | 169 | */ |
170 | - public function update_status( Payment $payment ) { |
|
171 | - if ( ! ReturnParameters::contains( $_GET ) ) { // WPCS: CSRF ok. |
|
170 | + public function update_status(Payment $payment) { |
|
171 | + if ( ! ReturnParameters::contains($_GET)) { // WPCS: CSRF ok. |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - $parameters = ReturnParameters::from_array( $_GET ); // WPCS: CSRF ok. |
|
175 | + $parameters = ReturnParameters::from_array($_GET); // WPCS: CSRF ok. |
|
176 | 176 | |
177 | 177 | // Note. |
178 | 178 | $note_values = array( |
179 | 179 | 'order_id' => $parameters->get_order_id(), |
180 | 180 | 'status' => $parameters->get_status(), |
181 | 181 | 'signature' => $parameters->get_signature(), |
182 | - 'valid' => $parameters->is_valid( $this->config->signing_key ) ? 'true' : 'false', |
|
182 | + 'valid' => $parameters->is_valid($this->config->signing_key) ? 'true' : 'false', |
|
183 | 183 | ); |
184 | 184 | |
185 | 185 | $note = ''; |
186 | 186 | |
187 | 187 | $note .= '<p>'; |
188 | - $note .= __( 'OmniKassa 2.0 return URL requested:', 'pronamic_ideal' ); |
|
188 | + $note .= __('OmniKassa 2.0 return URL requested:', 'pronamic_ideal'); |
|
189 | 189 | $note .= '</p>'; |
190 | 190 | |
191 | 191 | $note .= '<dl>'; |
192 | 192 | |
193 | - foreach ( $note_values as $key => $value ) { |
|
194 | - $note .= sprintf( '<dt>%s</dt>', esc_html( $key ) ); |
|
195 | - $note .= sprintf( '<dd>%s</dd>', esc_html( $value ) ); |
|
193 | + foreach ($note_values as $key => $value) { |
|
194 | + $note .= sprintf('<dt>%s</dt>', esc_html($key)); |
|
195 | + $note .= sprintf('<dd>%s</dd>', esc_html($value)); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | $note .= '</dl>'; |
199 | 199 | |
200 | - $payment->add_note( $note ); |
|
200 | + $payment->add_note($note); |
|
201 | 201 | |
202 | 202 | // Validate. |
203 | - if ( ! $parameters->is_valid( $this->config->signing_key ) ) { |
|
203 | + if ( ! $parameters->is_valid($this->config->signing_key)) { |
|
204 | 204 | return; |
205 | 205 | } |
206 | 206 | |
207 | 207 | // Status. |
208 | - $payment->set_status( Statuses::transform( $parameters->get_status() ) ); |
|
208 | + $payment->set_status(Statuses::transform($parameters->get_status())); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -215,14 +215,14 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return void |
217 | 217 | */ |
218 | - public function handle_notification( Notification $notification ) { |
|
219 | - if ( ! $notification->is_valid( $this->config->signing_key ) ) { |
|
218 | + public function handle_notification(Notification $notification) { |
|
219 | + if ( ! $notification->is_valid($this->config->signing_key)) { |
|
220 | 220 | return; |
221 | 221 | } |
222 | 222 | |
223 | - switch ( $notification->get_event_name() ) { |
|
223 | + switch ($notification->get_event_name()) { |
|
224 | 224 | case 'merchant.order.status.changed': |
225 | - $this->handle_merchant_order_status_changed( $notification ); |
|
225 | + $this->handle_merchant_order_status_changed($notification); |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | |
@@ -233,39 +233,39 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return void |
235 | 235 | */ |
236 | - private function handle_merchant_order_status_changed( Notification $notification ) { |
|
236 | + private function handle_merchant_order_status_changed(Notification $notification) { |
|
237 | 237 | do { |
238 | - $order_results = $this->client->get_order_results( $notification->get_authentication() ); |
|
238 | + $order_results = $this->client->get_order_results($notification->get_authentication()); |
|
239 | 239 | |
240 | - if ( ! $order_results || $order_results->is_valid( $this->config->signing_key ) ) { |
|
240 | + if ( ! $order_results || $order_results->is_valid($this->config->signing_key)) { |
|
241 | 241 | return; |
242 | 242 | } |
243 | 243 | |
244 | - foreach ( $order_results as $order_result ) { |
|
245 | - $payment = get_pronamic_payment_by_meta( '_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id() ); |
|
244 | + foreach ($order_results as $order_result) { |
|
245 | + $payment = get_pronamic_payment_by_meta('_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id()); |
|
246 | 246 | |
247 | - if ( empty( $payment ) ) { |
|
247 | + if (empty($payment)) { |
|
248 | 248 | continue; |
249 | 249 | } |
250 | 250 | |
251 | - $payment->set_transaction_id( $order_result->get_omnikassa_order_id() ); |
|
252 | - $payment->set_status( Statuses::transform( $order_result->get_order_status() ) ); |
|
251 | + $payment->set_transaction_id($order_result->get_omnikassa_order_id()); |
|
252 | + $payment->set_status(Statuses::transform($order_result->get_order_status())); |
|
253 | 253 | |
254 | 254 | // Note. |
255 | 255 | $note = ''; |
256 | 256 | |
257 | 257 | $note .= '<p>'; |
258 | - $note .= __( 'OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal' ); |
|
258 | + $note .= __('OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal'); |
|
259 | 259 | $note .= '</p>'; |
260 | 260 | $note .= '<pre>'; |
261 | - $note .= wp_json_encode( $order_result->get_json(), JSON_PRETTY_PRINT ); |
|
261 | + $note .= wp_json_encode($order_result->get_json(), JSON_PRETTY_PRINT); |
|
262 | 262 | $note .= '</pre>'; |
263 | 263 | |
264 | - $payment->add_note( $note ); |
|
264 | + $payment->add_note($note); |
|
265 | 265 | |
266 | 266 | $payment->save(); |
267 | 267 | } |
268 | - } while ( $order_results->more_available() ); |
|
268 | + } while ($order_results->more_available()); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -274,20 +274,20 @@ discard block |
||
274 | 274 | * @return void |
275 | 275 | */ |
276 | 276 | private function maybe_update_access_token() { |
277 | - if ( $this->config->is_access_token_valid() ) { |
|
277 | + if ($this->config->is_access_token_valid()) { |
|
278 | 278 | return; |
279 | 279 | } |
280 | 280 | |
281 | 281 | $data = $this->client->get_access_token_data(); |
282 | 282 | |
283 | - if ( ! is_object( $data ) ) { |
|
283 | + if ( ! is_object($data)) { |
|
284 | 284 | return; |
285 | 285 | } |
286 | 286 | |
287 | 287 | $this->config->access_token = $data->token; |
288 | 288 | $this->config->access_token_valid_until = $data->validUntil; |
289 | 289 | |
290 | - update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token ); |
|
290 | + update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token); |
|
291 | 291 | update_post_meta( |
292 | 292 | $this->config->post_id, |
293 | 293 | '_pronamic_gateway_omnikassa_2_access_token_valid_until', |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | private function get_client_error() { |
304 | 304 | $error = $this->client->get_error(); |
305 | 305 | |
306 | - if ( is_wp_error( $error ) ) { |
|
306 | + if (is_wp_error($error)) { |
|
307 | 307 | $this->error = $error; |
308 | 308 | |
309 | 309 | return $error; |