@@ -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,71 +78,71 @@ 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 | // New order. |
88 | 88 | $order = new Order( |
89 | 89 | $merchant_order_id, |
90 | - MoneyTransformer::transform( $payment->get_total_amount() ), |
|
90 | + MoneyTransformer::transform($payment->get_total_amount()), |
|
91 | 91 | $payment->get_return_url() |
92 | 92 | ); |
93 | 93 | |
94 | 94 | // Shipping address. |
95 | - $order->set_shipping_detail( AddressTransformer::transform( $payment->get_shipping_address() ) ); |
|
95 | + $order->set_shipping_detail(AddressTransformer::transform($payment->get_shipping_address())); |
|
96 | 96 | |
97 | 97 | // Billing address. |
98 | - $order->set_billing_detail( AddressTransformer::transform( $payment->get_billing_address() ) ); |
|
98 | + $order->set_billing_detail(AddressTransformer::transform($payment->get_billing_address())); |
|
99 | 99 | |
100 | 100 | // Customer information. |
101 | 101 | $customer = $payment->get_customer(); |
102 | 102 | |
103 | - if ( null !== $customer ) { |
|
104 | - $order->set_language( $customer->get_language() ); |
|
103 | + if (null !== $customer) { |
|
104 | + $order->set_language($customer->get_language()); |
|
105 | 105 | |
106 | 106 | $customer_information = new CustomerInformation(); |
107 | 107 | |
108 | - $customer_information->set_email_address( $customer->get_email() ); |
|
109 | - $customer_information->set_date_of_birth( $customer->get_birth_date() ); |
|
110 | - $customer_information->set_gender( $customer->get_gender() ); |
|
111 | - $customer_information->set_telephone_number( $customer->get_phone() ); |
|
108 | + $customer_information->set_email_address($customer->get_email()); |
|
109 | + $customer_information->set_date_of_birth($customer->get_birth_date()); |
|
110 | + $customer_information->set_gender($customer->get_gender()); |
|
111 | + $customer_information->set_telephone_number($customer->get_phone()); |
|
112 | 112 | |
113 | - $order->set_customer_information( $customer_information ); |
|
113 | + $order->set_customer_information($customer_information); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | // Payment brand. |
117 | - $payment_brand = PaymentBrands::transform( $payment->get_method() ); |
|
117 | + $payment_brand = PaymentBrands::transform($payment->get_method()); |
|
118 | 118 | |
119 | - $order->set_payment_brand( $payment_brand ); |
|
119 | + $order->set_payment_brand($payment_brand); |
|
120 | 120 | |
121 | - if ( null !== $payment_brand ) { |
|
121 | + if (null !== $payment_brand) { |
|
122 | 122 | // Payment brand force should only be set if payment brand is not empty. |
123 | - $order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE ); |
|
123 | + $order->set_payment_brand_force(PaymentBrandForce::FORCE_ONCE); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | // Description. |
127 | - $order->set_description( substr( $payment->get_description(), 0, 35 ) ); |
|
127 | + $order->set_description(substr($payment->get_description(), 0, 35)); |
|
128 | 128 | |
129 | 129 | // Lines. |
130 | - if ( null !== $payment->get_lines() ) { |
|
130 | + if (null !== $payment->get_lines()) { |
|
131 | 131 | $order_items = $order->new_items(); |
132 | 132 | |
133 | - foreach ( $payment->get_lines() as $line ) { |
|
133 | + foreach ($payment->get_lines() as $line) { |
|
134 | 134 | $item = $order_items->new_item( |
135 | 135 | $line->get_name(), |
136 | 136 | $line->get_quantity(), |
137 | - MoneyTransformer::transform( $line->get_total_amount() ), |
|
138 | - ProductCategories::transform( $line->get_type() ) |
|
137 | + MoneyTransformer::transform($line->get_total_amount()), |
|
138 | + ProductCategories::transform($line->get_type()) |
|
139 | 139 | ); |
140 | 140 | |
141 | - $item->set_id( $line->get_id() ); |
|
142 | - $item->set_description( $line->get_description() ); |
|
141 | + $item->set_id($line->get_id()); |
|
142 | + $item->set_description($line->get_description()); |
|
143 | 143 | |
144 | - if ( null !== $line->get_tax_amount() ) { |
|
145 | - $item->set_tax( MoneyTransformer::transform( $line->get_tax_amount() ) ); |
|
144 | + if (null !== $line->get_tax_amount()) { |
|
145 | + $item->set_tax(MoneyTransformer::transform($line->get_tax_amount())); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
@@ -151,27 +151,27 @@ discard block |
||
151 | 151 | $this->maybe_update_access_token(); |
152 | 152 | |
153 | 153 | // Handle errors. |
154 | - if ( $this->get_client_error() ) { |
|
154 | + if ($this->get_client_error()) { |
|
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Announce order. |
159 | - $response = $this->client->order_announce( $this->config, $order ); |
|
159 | + $response = $this->client->order_announce($this->config, $order); |
|
160 | 160 | |
161 | 161 | // Handle errors. |
162 | - if ( $this->get_client_error() ) { |
|
162 | + if ($this->get_client_error()) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | 165 | |
166 | - if ( false === $response ) { |
|
166 | + if (false === $response) { |
|
167 | 167 | return; |
168 | 168 | } |
169 | 169 | |
170 | - if ( ! $response->is_valid( $this->config->signing_key ) ) { |
|
170 | + if ( ! $response->is_valid($this->config->signing_key)) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
174 | - $payment->set_action_url( $response->get_redirect_url() ); |
|
174 | + $payment->set_action_url($response->get_redirect_url()); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -179,48 +179,48 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @param Payment $payment Payment. |
181 | 181 | */ |
182 | - public function update_status( Payment $payment ) { |
|
183 | - if ( ! ReturnParameters::contains( $_GET ) ) { // WPCS: CSRF ok. |
|
182 | + public function update_status(Payment $payment) { |
|
183 | + if ( ! ReturnParameters::contains($_GET)) { // WPCS: CSRF ok. |
|
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
187 | - $parameters = ReturnParameters::from_array( $_GET ); // WPCS: CSRF ok. |
|
187 | + $parameters = ReturnParameters::from_array($_GET); // WPCS: CSRF ok. |
|
188 | 188 | |
189 | 189 | // Note. |
190 | 190 | $note_values = array( |
191 | 191 | 'order_id' => $parameters->get_order_id(), |
192 | 192 | 'status' => $parameters->get_status(), |
193 | 193 | 'signature' => $parameters->get_signature(), |
194 | - 'valid' => $parameters->is_valid( $this->config->signing_key ) ? 'true' : 'false', |
|
194 | + 'valid' => $parameters->is_valid($this->config->signing_key) ? 'true' : 'false', |
|
195 | 195 | ); |
196 | 196 | |
197 | 197 | $note = ''; |
198 | 198 | |
199 | 199 | $note .= '<p>'; |
200 | - $note .= __( 'OmniKassa 2.0 return URL requested:', 'pronamic_ideal' ); |
|
200 | + $note .= __('OmniKassa 2.0 return URL requested:', 'pronamic_ideal'); |
|
201 | 201 | $note .= '</p>'; |
202 | 202 | |
203 | 203 | $note .= '<dl>'; |
204 | 204 | |
205 | - foreach ( $note_values as $key => $value ) { |
|
206 | - $note .= sprintf( '<dt>%s</dt>', esc_html( $key ) ); |
|
207 | - $note .= sprintf( '<dd>%s</dd>', esc_html( $value ) ); |
|
205 | + foreach ($note_values as $key => $value) { |
|
206 | + $note .= sprintf('<dt>%s</dt>', esc_html($key)); |
|
207 | + $note .= sprintf('<dd>%s</dd>', esc_html($value)); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | $note .= '</dl>'; |
211 | 211 | |
212 | - $payment->add_note( $note ); |
|
212 | + $payment->add_note($note); |
|
213 | 213 | |
214 | 214 | // Validate. |
215 | - if ( ! $parameters->is_valid( $this->config->signing_key ) ) { |
|
215 | + if ( ! $parameters->is_valid($this->config->signing_key)) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Status. |
220 | - $pronamic_status = Statuses::transform( $parameters->get_status() ); |
|
220 | + $pronamic_status = Statuses::transform($parameters->get_status()); |
|
221 | 221 | |
222 | - if ( null !== $pronamic_status ) { |
|
223 | - $payment->set_status( $pronamic_status ); |
|
222 | + if (null !== $pronamic_status) { |
|
223 | + $payment->set_status($pronamic_status); |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
@@ -231,14 +231,14 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return void |
233 | 233 | */ |
234 | - public function handle_notification( Notification $notification ) { |
|
235 | - if ( ! $notification->is_valid( $this->config->signing_key ) ) { |
|
234 | + public function handle_notification(Notification $notification) { |
|
235 | + if ( ! $notification->is_valid($this->config->signing_key)) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
239 | - switch ( $notification->get_event_name() ) { |
|
239 | + switch ($notification->get_event_name()) { |
|
240 | 240 | case 'merchant.order.status.changed': |
241 | - $this->handle_merchant_order_status_changed( $notification ); |
|
241 | + $this->handle_merchant_order_status_changed($notification); |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
@@ -249,44 +249,44 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @return void |
251 | 251 | */ |
252 | - private function handle_merchant_order_status_changed( Notification $notification ) { |
|
252 | + private function handle_merchant_order_status_changed(Notification $notification) { |
|
253 | 253 | do { |
254 | - $order_results = $this->client->get_order_results( $notification->get_authentication() ); |
|
254 | + $order_results = $this->client->get_order_results($notification->get_authentication()); |
|
255 | 255 | |
256 | - if ( ! $order_results || $order_results->is_valid( $this->config->signing_key ) ) { |
|
256 | + if ( ! $order_results || $order_results->is_valid($this->config->signing_key)) { |
|
257 | 257 | return; |
258 | 258 | } |
259 | 259 | |
260 | - foreach ( $order_results as $order_result ) { |
|
261 | - $payment = get_pronamic_payment_by_meta( '_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id() ); |
|
260 | + foreach ($order_results as $order_result) { |
|
261 | + $payment = get_pronamic_payment_by_meta('_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id()); |
|
262 | 262 | |
263 | - if ( empty( $payment ) ) { |
|
263 | + if (empty($payment)) { |
|
264 | 264 | continue; |
265 | 265 | } |
266 | 266 | |
267 | - $payment->set_transaction_id( $order_result->get_omnikassa_order_id() ); |
|
267 | + $payment->set_transaction_id($order_result->get_omnikassa_order_id()); |
|
268 | 268 | |
269 | - $pronamic_status = Statuses::transform( $order_result->get_order_status() ); |
|
269 | + $pronamic_status = Statuses::transform($order_result->get_order_status()); |
|
270 | 270 | |
271 | - if ( null !== $pronamic_status ) { |
|
272 | - $payment->set_status( $pronamic_status ); |
|
271 | + if (null !== $pronamic_status) { |
|
272 | + $payment->set_status($pronamic_status); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | // Note. |
276 | 276 | $note = ''; |
277 | 277 | |
278 | 278 | $note .= '<p>'; |
279 | - $note .= __( 'OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal' ); |
|
279 | + $note .= __('OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal'); |
|
280 | 280 | $note .= '</p>'; |
281 | 281 | $note .= '<pre>'; |
282 | - $note .= wp_json_encode( $order_result->get_json(), JSON_PRETTY_PRINT ); |
|
282 | + $note .= wp_json_encode($order_result->get_json(), JSON_PRETTY_PRINT); |
|
283 | 283 | $note .= '</pre>'; |
284 | 284 | |
285 | - $payment->add_note( $note ); |
|
285 | + $payment->add_note($note); |
|
286 | 286 | |
287 | 287 | $payment->save(); |
288 | 288 | } |
289 | - } while ( $order_results->more_available() ); |
|
289 | + } while ($order_results->more_available()); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -295,23 +295,23 @@ discard block |
||
295 | 295 | * @return void |
296 | 296 | */ |
297 | 297 | private function maybe_update_access_token() { |
298 | - if ( $this->config->is_access_token_valid() ) { |
|
298 | + if ($this->config->is_access_token_valid()) { |
|
299 | 299 | return; |
300 | 300 | } |
301 | 301 | |
302 | 302 | $data = $this->client->get_access_token_data(); |
303 | 303 | |
304 | - if ( ! is_object( $data ) ) { |
|
304 | + if ( ! is_object($data)) { |
|
305 | 305 | return; |
306 | 306 | } |
307 | 307 | |
308 | - if ( isset( $data->token ) ) { |
|
308 | + if (isset($data->token)) { |
|
309 | 309 | $this->config->access_token = $data->token; |
310 | 310 | |
311 | - update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token ); |
|
311 | + update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token); |
|
312 | 312 | } |
313 | 313 | |
314 | - if ( isset( $data->validUntil ) ) { |
|
314 | + if (isset($data->validUntil)) { |
|
315 | 315 | $this->config->access_token_valid_until = $data->validUntil; |
316 | 316 | |
317 | 317 | update_post_meta( |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | private function get_client_error() { |
331 | 331 | $error = $this->client->get_error(); |
332 | 332 | |
333 | - if ( is_wp_error( $error ) ) { |
|
333 | + if (is_wp_error($error)) { |
|
334 | 334 | $this->error = $error; |
335 | 335 | |
336 | 336 | return $error; |