@@ -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 | /** |
@@ -76,53 +76,53 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @param Payment $payment Payment. |
78 | 78 | */ |
79 | - public function start( Payment $payment ) { |
|
79 | + public function start(Payment $payment) { |
|
80 | 80 | // Merchant order ID. |
81 | - $merchant_order_id = $payment->format_string( $this->config->order_id ); |
|
81 | + $merchant_order_id = $payment->format_string($this->config->order_id); |
|
82 | 82 | |
83 | - $payment->set_meta( 'omnikassa_2_merchant_order_id', $merchant_order_id ); |
|
83 | + $payment->set_meta('omnikassa_2_merchant_order_id', $merchant_order_id); |
|
84 | 84 | |
85 | 85 | // New order. |
86 | 86 | $order = new Order( |
87 | 87 | $merchant_order_id, |
88 | 88 | new Money( |
89 | 89 | $payment->get_currency(), |
90 | - Core_Util::amount_to_cents( $payment->get_amount()->get_amount() ) |
|
90 | + Core_Util::amount_to_cents($payment->get_amount()->get_amount()) |
|
91 | 91 | ), |
92 | 92 | $payment->get_return_url() |
93 | 93 | ); |
94 | 94 | |
95 | - $order->set_description( $payment->get_description() ); |
|
96 | - $order->set_language( $payment->get_language() ); |
|
95 | + $order->set_description($payment->get_description()); |
|
96 | + $order->set_language($payment->get_language()); |
|
97 | 97 | |
98 | 98 | // Payment brand. |
99 | - $payment_brand = PaymentBrands::transform( $payment->get_method() ); |
|
99 | + $payment_brand = PaymentBrands::transform($payment->get_method()); |
|
100 | 100 | |
101 | - $order->set_payment_brand( $payment_brand ); |
|
101 | + $order->set_payment_brand($payment_brand); |
|
102 | 102 | |
103 | - if ( null !== $payment_brand ) { |
|
103 | + if (null !== $payment_brand) { |
|
104 | 104 | // Payment brand force should only be set if payment brand is not empty. |
105 | - $order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE ); |
|
105 | + $order->set_payment_brand_force(PaymentBrandForce::FORCE_ONCE); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Maybe update access token. |
109 | 109 | $this->maybe_update_access_token(); |
110 | 110 | |
111 | 111 | // Handle errors. |
112 | - if ( $this->get_client_error() ) { |
|
112 | + if ($this->get_client_error()) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Announce order. |
117 | - $result = $this->client->order_announce( $this->config, $order ); |
|
117 | + $result = $this->client->order_announce($this->config, $order); |
|
118 | 118 | |
119 | 119 | // Handle errors. |
120 | - if ( $this->get_client_error() ) { |
|
120 | + if ($this->get_client_error()) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | |
124 | - if ( $result ) { |
|
125 | - $payment->set_action_url( $result->redirectUrl ); |
|
124 | + if ($result) { |
|
125 | + $payment->set_action_url($result->redirectUrl); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
@@ -131,45 +131,45 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @param Payment $payment Payment. |
133 | 133 | */ |
134 | - public function update_status( Payment $payment ) { |
|
135 | - if ( ! ReturnParameters::contains( $_GET ) ) { // WPCS: CSRF ok. |
|
134 | + public function update_status(Payment $payment) { |
|
135 | + if ( ! ReturnParameters::contains($_GET)) { // WPCS: CSRF ok. |
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | - $parameters = ReturnParameters::from_array( $_GET ); // WPCS: CSRF ok. |
|
139 | + $parameters = ReturnParameters::from_array($_GET); // WPCS: CSRF ok. |
|
140 | 140 | |
141 | 141 | // Note. |
142 | 142 | $note_values = array( |
143 | 143 | 'order_id' => $parameters->get_order_id(), |
144 | 144 | 'status' => $parameters->get_status(), |
145 | 145 | 'signature' => $parameters->get_signature(), |
146 | - 'valid' => $parameters->is_valid( $this->config->signing_key ) ? 'true' : 'false', |
|
146 | + 'valid' => $parameters->is_valid($this->config->signing_key) ? 'true' : 'false', |
|
147 | 147 | ); |
148 | 148 | |
149 | 149 | $note = ''; |
150 | 150 | |
151 | 151 | $note .= '<p>'; |
152 | - $note .= __( 'OmniKassa 2.0 return URL requested:', 'pronamic_ideal' ); |
|
152 | + $note .= __('OmniKassa 2.0 return URL requested:', 'pronamic_ideal'); |
|
153 | 153 | $note .= '</p>'; |
154 | 154 | |
155 | 155 | $note .= '<dl>'; |
156 | 156 | |
157 | - foreach ( $note_values as $key => $value ) { |
|
158 | - $note .= sprintf( '<dt>%s</dt>', esc_html( $key ) ); |
|
159 | - $note .= sprintf( '<dd>%s</dd>', esc_html( $value ) ); |
|
157 | + foreach ($note_values as $key => $value) { |
|
158 | + $note .= sprintf('<dt>%s</dt>', esc_html($key)); |
|
159 | + $note .= sprintf('<dd>%s</dd>', esc_html($value)); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | $note .= '</dl>'; |
163 | 163 | |
164 | - $payment->add_note( $note ); |
|
164 | + $payment->add_note($note); |
|
165 | 165 | |
166 | 166 | // Validate. |
167 | - if ( ! $parameters->is_valid( $this->config->signing_key ) ) { |
|
167 | + if ( ! $parameters->is_valid($this->config->signing_key)) { |
|
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | 171 | // Status. |
172 | - $payment->set_status( Statuses::transform( $parameters->get_status() ) ); |
|
172 | + $payment->set_status(Statuses::transform($parameters->get_status())); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -179,14 +179,14 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return void |
181 | 181 | */ |
182 | - public function handle_notification( Notification $notification ) { |
|
183 | - if ( ! $notification->is_valid( $this->config->signing_key ) ) { |
|
182 | + public function handle_notification(Notification $notification) { |
|
183 | + if ( ! $notification->is_valid($this->config->signing_key)) { |
|
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
187 | - switch ( $notification->get_event_name() ) { |
|
187 | + switch ($notification->get_event_name()) { |
|
188 | 188 | case 'merchant.order.status.changed': |
189 | - $this->handle_merchant_order_status_changed( $notification ); |
|
189 | + $this->handle_merchant_order_status_changed($notification); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
@@ -197,39 +197,39 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @return void |
199 | 199 | */ |
200 | - private function handle_merchant_order_status_changed( Notification $notification ) { |
|
200 | + private function handle_merchant_order_status_changed(Notification $notification) { |
|
201 | 201 | do { |
202 | - $order_results = $this->client->get_order_results( $notification->get_authentication() ); |
|
202 | + $order_results = $this->client->get_order_results($notification->get_authentication()); |
|
203 | 203 | |
204 | - if ( ! $order_results || $order_results->is_valid( $this->config->signing_key ) ) { |
|
204 | + if ( ! $order_results || $order_results->is_valid($this->config->signing_key)) { |
|
205 | 205 | return; |
206 | 206 | } |
207 | 207 | |
208 | - foreach ( $order_results as $order_result ) { |
|
209 | - $payment = get_pronamic_payment_by_meta( '_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id() ); |
|
208 | + foreach ($order_results as $order_result) { |
|
209 | + $payment = get_pronamic_payment_by_meta('_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id()); |
|
210 | 210 | |
211 | - if ( empty( $payment ) ) { |
|
211 | + if (empty($payment)) { |
|
212 | 212 | continue; |
213 | 213 | } |
214 | 214 | |
215 | - $payment->set_transaction_id( $order_result->get_omnikassa_order_id() ); |
|
216 | - $payment->set_status( Statuses::transform( $order_result->get_order_status() ) ); |
|
215 | + $payment->set_transaction_id($order_result->get_omnikassa_order_id()); |
|
216 | + $payment->set_status(Statuses::transform($order_result->get_order_status())); |
|
217 | 217 | |
218 | 218 | // Note. |
219 | 219 | $note = ''; |
220 | 220 | |
221 | 221 | $note .= '<p>'; |
222 | - $note .= __( 'OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal' ); |
|
222 | + $note .= __('OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal'); |
|
223 | 223 | $note .= '</p>'; |
224 | 224 | $note .= '<pre>'; |
225 | - $note .= wp_json_encode( $order_result->get_json(), JSON_PRETTY_PRINT ); |
|
225 | + $note .= wp_json_encode($order_result->get_json(), JSON_PRETTY_PRINT); |
|
226 | 226 | $note .= '</pre>'; |
227 | 227 | |
228 | - $payment->add_note( $note ); |
|
228 | + $payment->add_note($note); |
|
229 | 229 | |
230 | 230 | $payment->save(); |
231 | 231 | } |
232 | - } while ( $order_results->more_available() ); |
|
232 | + } while ($order_results->more_available()); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -238,20 +238,20 @@ discard block |
||
238 | 238 | * @return void |
239 | 239 | */ |
240 | 240 | private function maybe_update_access_token() { |
241 | - if ( $this->config->is_access_token_valid() ) { |
|
241 | + if ($this->config->is_access_token_valid()) { |
|
242 | 242 | return; |
243 | 243 | } |
244 | 244 | |
245 | 245 | $data = $this->client->get_access_token_data(); |
246 | 246 | |
247 | - if ( ! is_object( $data ) ) { |
|
247 | + if ( ! is_object($data)) { |
|
248 | 248 | return; |
249 | 249 | } |
250 | 250 | |
251 | 251 | $this->config->access_token = $data->token; |
252 | 252 | $this->config->access_token_valid_until = $data->validUntil; |
253 | 253 | |
254 | - update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token ); |
|
254 | + update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token); |
|
255 | 255 | update_post_meta( |
256 | 256 | $this->config->post_id, |
257 | 257 | '_pronamic_gateway_omnikassa_2_access_token_valid_until', |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | private function get_client_error() { |
268 | 268 | $error = $this->client->get_error(); |
269 | 269 | |
270 | - if ( is_wp_error( $error ) ) { |
|
270 | + if (is_wp_error($error)) { |
|
271 | 271 | $this->error = $error; |
272 | 272 | |
273 | 273 | return $error; |