@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @param Config $config |
40 | 40 | */ |
41 | - public function __construct( Config $config ) { |
|
42 | - parent::__construct( $config ); |
|
41 | + public function __construct(Config $config) { |
|
42 | + parent::__construct($config); |
|
43 | 43 | |
44 | 44 | $this->supports = array( |
45 | 45 | 'payment_status_request', |
@@ -48,20 +48,20 @@ discard block |
||
48 | 48 | 'recurring', |
49 | 49 | ); |
50 | 50 | |
51 | - $this->set_method( Core_Gateway::METHOD_HTTP_REDIRECT ); |
|
52 | - $this->set_has_feedback( true ); |
|
53 | - $this->set_amount_minimum( 1.20 ); |
|
54 | - $this->set_slug( self::SLUG ); |
|
51 | + $this->set_method(Core_Gateway::METHOD_HTTP_REDIRECT); |
|
52 | + $this->set_has_feedback(true); |
|
53 | + $this->set_amount_minimum(1.20); |
|
54 | + $this->set_slug(self::SLUG); |
|
55 | 55 | |
56 | - $this->client = new Client( $config->api_key ); |
|
57 | - $this->client->set_mode( $config->mode ); |
|
56 | + $this->client = new Client($config->api_key); |
|
57 | + $this->client->set_mode($config->mode); |
|
58 | 58 | |
59 | - if ( 'test' === $config->mode ) { |
|
59 | + if ('test' === $config->mode) { |
|
60 | 60 | $this->meta_key_customer_id = '_pronamic_pay_mollie_customer_id_test'; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // Actions. |
64 | - add_action( 'pronamic_payment_status_update', array( $this, 'move_customer_id_to_wp_user' ), 99, 1 ); |
|
64 | + add_action('pronamic_payment_status_update', array($this, 'move_customer_id_to_wp_user'), 99, 1); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | $result = $this->client->get_issuers(); |
76 | 76 | |
77 | - if ( ! $result ) { |
|
77 | + if ( ! $result) { |
|
78 | 78 | $this->error = $this->client->get_error(); |
79 | 79 | |
80 | 80 | return $groups; |
@@ -96,51 +96,51 @@ discard block |
||
96 | 96 | $payment_methods = array(); |
97 | 97 | |
98 | 98 | // Set recurring types to get payment methods for. |
99 | - $recurring_types = array( null, Recurring::RECURRING, Recurring::FIRST ); |
|
99 | + $recurring_types = array(null, Recurring::RECURRING, Recurring::FIRST); |
|
100 | 100 | |
101 | 101 | $results = array(); |
102 | 102 | |
103 | - foreach ( $recurring_types as $recurring_type ) { |
|
103 | + foreach ($recurring_types as $recurring_type) { |
|
104 | 104 | // Get active payment methods for Mollie account. |
105 | - $result = $this->client->get_payment_methods( $recurring_type ); |
|
105 | + $result = $this->client->get_payment_methods($recurring_type); |
|
106 | 106 | |
107 | - if ( ! $result ) { |
|
107 | + if ( ! $result) { |
|
108 | 108 | $this->error = $this->client->get_error(); |
109 | 109 | |
110 | 110 | break; |
111 | 111 | } |
112 | 112 | |
113 | - if ( Recurring::FIRST === $recurring_type ) { |
|
114 | - foreach ( $result as $method => $title ) { |
|
115 | - unset( $result[ $method ] ); |
|
113 | + if (Recurring::FIRST === $recurring_type) { |
|
114 | + foreach ($result as $method => $title) { |
|
115 | + unset($result[$method]); |
|
116 | 116 | |
117 | 117 | // Get WordPress payment method for direct debit method. |
118 | - $method = Methods::transform_gateway_method( $method ); |
|
119 | - $payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true ); |
|
118 | + $method = Methods::transform_gateway_method($method); |
|
119 | + $payment_method = array_search($method, PaymentMethods::get_recurring_methods(), true); |
|
120 | 120 | |
121 | - if ( $payment_method ) { |
|
122 | - $results[ $payment_method ] = $title; |
|
121 | + if ($payment_method) { |
|
122 | + $results[$payment_method] = $title; |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
126 | 126 | |
127 | - $results = array_merge( $results, $result ); |
|
127 | + $results = array_merge($results, $result); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | // Transform to WordPress payment methods. |
131 | - foreach ( $results as $method => $title ) { |
|
132 | - if ( PaymentMethods::is_recurring_method( $method ) ) { |
|
131 | + foreach ($results as $method => $title) { |
|
132 | + if (PaymentMethods::is_recurring_method($method)) { |
|
133 | 133 | $payment_method = $method; |
134 | 134 | } else { |
135 | - $payment_method = Methods::transform_gateway_method( $method ); |
|
135 | + $payment_method = Methods::transform_gateway_method($method); |
|
136 | 136 | } |
137 | 137 | |
138 | - if ( $payment_method ) { |
|
138 | + if ($payment_method) { |
|
139 | 139 | $payment_methods[] = $payment_method; |
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | - $payment_methods = array_unique( $payment_methods ); |
|
143 | + $payment_methods = array_unique($payment_methods); |
|
144 | 144 | |
145 | 145 | return $payment_methods; |
146 | 146 | } |
@@ -174,22 +174,22 @@ discard block |
||
174 | 174 | * @return string |
175 | 175 | */ |
176 | 176 | private function get_webhook_url() { |
177 | - $url = home_url( '/' ); |
|
177 | + $url = home_url('/'); |
|
178 | 178 | |
179 | - $host = wp_parse_url( $url, PHP_URL_HOST ); |
|
179 | + $host = wp_parse_url($url, PHP_URL_HOST); |
|
180 | 180 | |
181 | - if ( 'localhost' === $host ) { |
|
181 | + if ('localhost' === $host) { |
|
182 | 182 | // Mollie doesn't allow localhost. |
183 | 183 | return null; |
184 | - } elseif ( '.dev' === substr( $host, -4 ) ) { |
|
184 | + } elseif ('.dev' === substr($host, -4)) { |
|
185 | 185 | // Mollie doesn't allow the .dev TLD. |
186 | 186 | return null; |
187 | - } elseif ( '.local' === substr( $host, -6 ) ) { |
|
187 | + } elseif ('.local' === substr($host, -6)) { |
|
188 | 188 | // Mollie doesn't allow the .local TLD. |
189 | 189 | return null; |
190 | 190 | } |
191 | 191 | |
192 | - $url = add_query_arg( 'mollie_webhook', '', $url ); |
|
192 | + $url = add_query_arg('mollie_webhook', '', $url); |
|
193 | 193 | |
194 | 194 | return $url; |
195 | 195 | } |
@@ -199,19 +199,19 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @see Pronamic_WP_Pay_Gateway::start() |
201 | 201 | */ |
202 | - public function start( Payment $payment ) { |
|
202 | + public function start(Payment $payment) { |
|
203 | 203 | $request = new PaymentRequest(); |
204 | 204 | |
205 | 205 | $request->amount = $payment->get_amount()->get_amount(); |
206 | 206 | $request->description = $payment->get_description(); |
207 | 207 | $request->redirect_url = $payment->get_return_url(); |
208 | 208 | $request->webhook_url = $this->get_webhook_url(); |
209 | - $request->locale = LocaleHelper::transform( $payment->get_language() ); |
|
209 | + $request->locale = LocaleHelper::transform($payment->get_language()); |
|
210 | 210 | |
211 | 211 | // Customer ID. |
212 | - $customer_id = $this->get_customer_id_for_payment( $payment ); |
|
212 | + $customer_id = $this->get_customer_id_for_payment($payment); |
|
213 | 213 | |
214 | - if ( ! empty( $customer_id ) ) { |
|
214 | + if ( ! empty($customer_id)) { |
|
215 | 215 | $request->customer_id = $customer_id; |
216 | 216 | } |
217 | 217 | |
@@ -221,49 +221,49 @@ discard block |
||
221 | 221 | // Subscription. |
222 | 222 | $subscription = $payment->get_subscription(); |
223 | 223 | |
224 | - if ( $subscription && PaymentMethods::is_recurring_method( $payment_method ) ) { |
|
224 | + if ($subscription && PaymentMethods::is_recurring_method($payment_method)) { |
|
225 | 225 | $request->recurring_type = $payment->get_recurring() ? Recurring::RECURRING : Recurring::FIRST; |
226 | 226 | |
227 | - if ( Recurring::FIRST === $request->recurring_type ) { |
|
228 | - $payment_method = PaymentMethods::get_first_payment_method( $payment_method ); |
|
227 | + if (Recurring::FIRST === $request->recurring_type) { |
|
228 | + $payment_method = PaymentMethods::get_first_payment_method($payment_method); |
|
229 | 229 | } |
230 | 230 | |
231 | - if ( Recurring::RECURRING === $request->recurring_type ) { |
|
232 | - $payment->set_action_url( $payment->get_return_url() ); |
|
231 | + if (Recurring::RECURRING === $request->recurring_type) { |
|
232 | + $payment->set_action_url($payment->get_return_url()); |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | |
236 | 236 | // Leap of faith if the WordPress payment method could not transform to a Mollie method? |
237 | - $request->method = Methods::transform( $payment_method, $payment_method ); |
|
237 | + $request->method = Methods::transform($payment_method, $payment_method); |
|
238 | 238 | |
239 | 239 | // Issuer. |
240 | - if ( Methods::IDEAL === $request->method ) { |
|
240 | + if (Methods::IDEAL === $request->method) { |
|
241 | 241 | // If payment method is iDEAL we set the user chosen issuer ID. |
242 | 242 | $request->issuer = $payment->get_issuer(); |
243 | 243 | } |
244 | 244 | |
245 | 245 | // Create payment. |
246 | - $result = $this->client->create_payment( $request ); |
|
246 | + $result = $this->client->create_payment($request); |
|
247 | 247 | |
248 | - if ( ! $result ) { |
|
248 | + if ( ! $result) { |
|
249 | 249 | $this->error = $this->client->get_error(); |
250 | 250 | |
251 | 251 | return false; |
252 | 252 | } |
253 | 253 | |
254 | 254 | // Set transaction ID. |
255 | - if ( isset( $result->id ) ) { |
|
256 | - $payment->set_transaction_id( $result->id ); |
|
255 | + if (isset($result->id)) { |
|
256 | + $payment->set_transaction_id($result->id); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | // Set status |
260 | - if ( isset( $result->status ) ) { |
|
261 | - $payment->set_status( Statuses::transform( $result->status ) ); |
|
260 | + if (isset($result->status)) { |
|
261 | + $payment->set_status(Statuses::transform($result->status)); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | // Set action URL. |
265 | - if ( isset( $result->links, $result->links->paymentUrl ) ) { |
|
266 | - $payment->set_action_url( $result->links->paymentUrl ); |
|
265 | + if (isset($result->links, $result->links->paymentUrl)) { |
|
266 | + $payment->set_action_url($result->links->paymentUrl); |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
@@ -272,36 +272,36 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @param Payment $payment |
274 | 274 | */ |
275 | - public function update_status( Payment $payment ) { |
|
276 | - $mollie_payment = $this->client->get_payment( $payment->get_transaction_id() ); |
|
275 | + public function update_status(Payment $payment) { |
|
276 | + $mollie_payment = $this->client->get_payment($payment->get_transaction_id()); |
|
277 | 277 | |
278 | - if ( ! $mollie_payment ) { |
|
279 | - $payment->set_status( Core_Statuses::FAILURE ); |
|
278 | + if ( ! $mollie_payment) { |
|
279 | + $payment->set_status(Core_Statuses::FAILURE); |
|
280 | 280 | |
281 | 281 | $this->error = $this->client->get_error(); |
282 | 282 | |
283 | 283 | return; |
284 | 284 | } |
285 | 285 | |
286 | - $payment->set_status( Statuses::transform( $mollie_payment->status ) ); |
|
286 | + $payment->set_status(Statuses::transform($mollie_payment->status)); |
|
287 | 287 | |
288 | - if ( isset( $mollie_payment->details ) ) { |
|
288 | + if (isset($mollie_payment->details)) { |
|
289 | 289 | $details = $mollie_payment->details; |
290 | 290 | |
291 | - if ( isset( $details->consumerName ) ) { |
|
292 | - $payment->set_consumer_name( $details->consumerName ); |
|
291 | + if (isset($details->consumerName)) { |
|
292 | + $payment->set_consumer_name($details->consumerName); |
|
293 | 293 | } |
294 | 294 | |
295 | - if ( isset( $details->cardHolder ) ) { |
|
296 | - $payment->set_consumer_name( $details->cardHolder ); |
|
295 | + if (isset($details->cardHolder)) { |
|
296 | + $payment->set_consumer_name($details->cardHolder); |
|
297 | 297 | } |
298 | 298 | |
299 | - if ( isset( $details->consumerAccount ) ) { |
|
300 | - $payment->set_consumer_iban( $details->consumerAccount ); |
|
299 | + if (isset($details->consumerAccount)) { |
|
300 | + $payment->set_consumer_iban($details->consumerAccount); |
|
301 | 301 | } |
302 | 302 | |
303 | - if ( isset( $details->consumerBic ) ) { |
|
304 | - $payment->set_consumer_bic( $details->consumerBic ); |
|
303 | + if (isset($details->consumerBic)) { |
|
304 | + $payment->set_consumer_bic($details->consumerBic); |
|
305 | 305 | } |
306 | 306 | } |
307 | 307 | } |
@@ -313,40 +313,40 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @return bool|string |
315 | 315 | */ |
316 | - private function get_customer_id_for_payment( Payment $payment ) { |
|
316 | + private function get_customer_id_for_payment(Payment $payment) { |
|
317 | 317 | // Get Mollie customer ID from user meta. |
318 | - $customer_id = $this->get_customer_id_by_wp_user_id( $payment->user_id ); |
|
318 | + $customer_id = $this->get_customer_id_by_wp_user_id($payment->user_id); |
|
319 | 319 | |
320 | - if ( Core_Recurring::FIRST === $payment->recurring_type ) { |
|
320 | + if (Core_Recurring::FIRST === $payment->recurring_type) { |
|
321 | 321 | // Create new customer if the customer does not exist at Mollie. |
322 | - if ( empty( $customer_id ) || ! $this->client->get_customer( $customer_id ) ) { |
|
323 | - $customer_id = $this->client->create_customer( $payment->get_email(), $payment->get_customer_name() ); |
|
322 | + if (empty($customer_id) || ! $this->client->get_customer($customer_id)) { |
|
323 | + $customer_id = $this->client->create_customer($payment->get_email(), $payment->get_customer_name()); |
|
324 | 324 | |
325 | - $this->update_wp_user_customer_id( $payment->user_id, $customer_id ); |
|
325 | + $this->update_wp_user_customer_id($payment->user_id, $customer_id); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // Temporarily store customer ID in subscription meta for guest users. |
329 | - if ( empty( $payment->user_id ) && ! empty( $customer_id ) ) { |
|
329 | + if (empty($payment->user_id) && ! empty($customer_id)) { |
|
330 | 330 | $subscription = $payment->get_subscription(); |
331 | 331 | |
332 | - if ( $subscription ) { |
|
333 | - $subscription->set_meta( 'mollie_customer_id', $customer_id ); |
|
332 | + if ($subscription) { |
|
333 | + $subscription->set_meta('mollie_customer_id', $customer_id); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | } |
337 | 337 | |
338 | 338 | // Try to move customer ID from subscription meta to user. |
339 | - if ( empty( $customer_id ) ) { |
|
339 | + if (empty($customer_id)) { |
|
340 | 340 | // Move customer ID from subscription meta to user meta. |
341 | - $this->move_customer_id_to_wp_user( $payment ); |
|
341 | + $this->move_customer_id_to_wp_user($payment); |
|
342 | 342 | |
343 | 343 | // Get customer ID from user meta, again. |
344 | - $customer_id = $this->get_customer_id_by_wp_user_id( $payment->user_id ); |
|
344 | + $customer_id = $this->get_customer_id_by_wp_user_id($payment->user_id); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | // Try to get customer ID from subscription meta. |
348 | - if ( empty( $customer_id ) && $payment->get_subscription() ) { |
|
349 | - $customer_id = $payment->get_subscription()->get_meta( 'mollie_customer_id' ); |
|
348 | + if (empty($customer_id) && $payment->get_subscription()) { |
|
349 | + $customer_id = $payment->get_subscription()->get_meta('mollie_customer_id'); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | return $customer_id; |
@@ -359,12 +359,12 @@ discard block |
||
359 | 359 | * |
360 | 360 | * @return string |
361 | 361 | */ |
362 | - private function get_customer_id_by_wp_user_id( $user_id ) { |
|
363 | - if ( empty( $user_id ) ) { |
|
362 | + private function get_customer_id_by_wp_user_id($user_id) { |
|
363 | + if (empty($user_id)) { |
|
364 | 364 | return false; |
365 | 365 | } |
366 | 366 | |
367 | - return get_user_meta( $user_id, $this->meta_key_customer_id, true ); |
|
367 | + return get_user_meta($user_id, $this->meta_key_customer_id, true); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -375,12 +375,12 @@ discard block |
||
375 | 375 | * |
376 | 376 | * @return bool |
377 | 377 | */ |
378 | - private function update_wp_user_customer_id( $user_id, $customer_id ) { |
|
379 | - if ( empty( $user_id ) || empty( $customer_id ) ) { |
|
378 | + private function update_wp_user_customer_id($user_id, $customer_id) { |
|
379 | + if (empty($user_id) || empty($customer_id)) { |
|
380 | 380 | return false; |
381 | 381 | } |
382 | 382 | |
383 | - update_user_meta( $user_id, $this->meta_key_customer_id, $customer_id ); |
|
383 | + update_user_meta($user_id, $this->meta_key_customer_id, $customer_id); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -390,26 +390,26 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @return void |
392 | 392 | */ |
393 | - public function move_customer_id_to_wp_user( Payment $payment ) { |
|
394 | - if ( $this->config->id !== $payment->config_id ) { |
|
393 | + public function move_customer_id_to_wp_user(Payment $payment) { |
|
394 | + if ($this->config->id !== $payment->config_id) { |
|
395 | 395 | return; |
396 | 396 | } |
397 | 397 | |
398 | 398 | $subscription = $payment->get_subscription(); |
399 | 399 | |
400 | - if ( ! $subscription || empty( $subscription->user_id ) ) { |
|
400 | + if ( ! $subscription || empty($subscription->user_id)) { |
|
401 | 401 | return; |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Get customer ID from subscription meta. |
405 | - $customer_id = $subscription->get_meta( 'mollie_customer_id' ); |
|
405 | + $customer_id = $subscription->get_meta('mollie_customer_id'); |
|
406 | 406 | |
407 | - if ( ! empty( $customer_id ) && ! empty( $subscription->user_id ) ) { |
|
407 | + if ( ! empty($customer_id) && ! empty($subscription->user_id)) { |
|
408 | 408 | // Set customer ID as user meta. |
409 | - $this->update_wp_user_customer_id( $subscription->user_id, $customer_id ); |
|
409 | + $this->update_wp_user_customer_id($subscription->user_id, $customer_id); |
|
410 | 410 | |
411 | 411 | // Delete customer ID from subscription meta. |
412 | - $subscription->set_meta( 'mollie_customer_id', null ); |
|
412 | + $subscription->set_meta('mollie_customer_id', null); |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | } |
@@ -79,8 +79,8 @@ |
||
79 | 79 | * |
80 | 80 | * @return string|null Pay status. |
81 | 81 | */ |
82 | - public static function transform( $status ) { |
|
83 | - switch ( $status ) { |
|
82 | + public static function transform($status) { |
|
83 | + switch ($status) { |
|
84 | 84 | case self::PENDING: |
85 | 85 | case self::OPEN: |
86 | 86 | return Core_Statuses::OPEN; |