Test Failed
Push — develop ( 429647...cf37fe )
by Reüel
03:23
created

Gateway::update_status()   F

Complexity

Conditions 19
Paths 1283

Size

Total Lines 69
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 70.2589

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 19
eloc 37
c 5
b 0
f 0
nc 1283
nop 1
dl 0
loc 69
ccs 11
cts 23
cp 0.4783
crap 70.2589
rs 0.3499

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Mollie gateway.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Mollie;
12
13
use DateInterval;
14
use Pronamic\WordPress\DateTime\DateTime;
15
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway;
16
use Pronamic\WordPress\Pay\Core\PaymentMethods;
17
use Pronamic\WordPress\Pay\Core\Recurring as Core_Recurring;
18
use Pronamic\WordPress\Pay\Payments\BankAccountDetails;
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\Payments\BankAccountDetails was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Pronamic\WordPress\Pay\Payments\BankTransferDetails;
0 ignored issues
show
Bug introduced by
The type Pronamic\WordPress\Pay\P...nts\BankTransferDetails was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Pronamic\WordPress\Pay\Payments\PaymentStatus;
21
use Pronamic\WordPress\Pay\Payments\Payment;
22
23
/**
24
 * Title: Mollie
25
 * Description:
26
 * Copyright: 2005-2019 Pronamic
27
 * Company: Pronamic
28
 *
29
 * @author  Remco Tolsma
30
 * @version 2.0.8
31
 * @since   1.1.0
32
 */
33
class Gateway extends Core_Gateway {
34
	/**
35
	 * Client.
36
	 *
37
	 * @var Client
38
	 */
39
	protected $client;
40
41
	/**
42
	 * Meta key for customer ID.
43
	 *
44
	 * @var string
45
	 */
46
	private $meta_key_customer_id = '_pronamic_pay_mollie_customer_id';
47
48
	/**
49
	 * Constructs and initializes an Mollie gateway
50
	 *
51 38
	 * @param Config $config Config.
52 38
	 */
53
	public function __construct( Config $config ) {
54 38
		parent::__construct( $config );
55
56
		$this->set_method( self::METHOD_HTTP_REDIRECT );
57 38
58
		// Supported features.
59
		$this->supports = array(
60
			'payment_status_request',
61
			'recurring_direct_debit',
62
			'recurring_credit_card',
63
			'recurring',
64
		);
65 38
66 38
		// Client.
67
		$this->client = new Client( \strval( $config->api_key ) );
68
		$this->client->set_mode( $config->mode );
69 38
70 37
		// Mollie customer ID meta key.
71
		if ( self::MODE_TEST === $config->mode ) {
72
			$this->meta_key_customer_id = '_pronamic_pay_mollie_customer_id_test';
73
		}
74 38
75 38
		// Actions.
76
		add_action( 'pronamic_payment_status_update', array( $this, 'copy_customer_id_to_wp_user' ), 99, 1 );
77
	}
78
79
	/**
80
	 * Get issuers
81
	 *
82 2
	 * @see Core_Gateway::get_issuers()
83 2
	 */
84
	public function get_issuers() {
85 2
		$groups = array();
86
87 2
		try {
88 2
			$result = $this->client->get_issuers();
89
90 2
			$groups[] = array(
91
				'options' => $result,
92
			);
93
		} catch ( Error $e ) {
94
			// Catch Mollie error.
95
			$error = new \WP_Error(
96
				'mollie_error',
97
				sprintf( '%1$s (%2$s) - %3$s', $e->get_title(), $e->getCode(), $e->get_detail() )
98
			);
99
100
			$this->set_error( $error );
101
		} catch ( \Exception $e ) {
102
			// Catch exceptions.
103
			$error = new \WP_Error( $e->getCode(), $e->getMessage() );
104
105 1
			$this->set_error( $error );
106 1
		}
107
108
		return $groups;
109 1
	}
110
111 1
	/**
112
	 * Get available payment methods.
113 1
	 *
114
	 * @see Core_Gateway::get_available_payment_methods()
115 1
	 */
116
	public function get_available_payment_methods() {
117 1
		$payment_methods = array();
118 1
119
		// Set sequence types to get payment methods for.
120 1
		$sequence_types = array( Sequence::ONE_OFF, Sequence::RECURRING, Sequence::FIRST );
121
122
		$results = array();
123
124
		foreach ( $sequence_types as $sequence_type ) {
125
			// Get active payment methods for Mollie account.
126
			try {
127
				$result = $this->client->get_payment_methods( $sequence_type );
128
			} catch ( Error $e ) {
129
				// Catch Mollie error.
130
				$error = new \WP_Error(
131
					'mollie_error',
132
					sprintf( '%1$s (%2$s) - %3$s', $e->get_title(), $e->getCode(), $e->get_detail() )
133
				);
134
135
				$this->set_error( $error );
136
137
				break;
138
			} catch ( \Exception $e ) {
139
				// Catch exceptions.
140
				$error = new \WP_Error( $e->getCode(), $e->getMessage() );
141
142
				$this->set_error( $error );
143 1
144
				break;
145
			}
146
147
			if ( Sequence::FIRST === $sequence_type ) {
148
				foreach ( $result as $method => $title ) {
149
					unset( $result[ $method ] );
150
151
					// Get WordPress payment method for direct debit method.
152
					$method         = Methods::transform_gateway_method( $method );
153
					$payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true );
154
155 1
					if ( $payment_method ) {
156
						$results[ $payment_method ] = $title;
157 1
					}
158
				}
159
			}
160
161
			if ( is_array( $result ) ) {
162
				$results = array_merge( $results, $result );
163
			}
164
		}
165 2
166
		// Transform to WordPress payment methods.
167 2
		foreach ( $results as $method => $title ) {
168
			if ( PaymentMethods::is_recurring_method( $method ) ) {
169
				$payment_method = $method;
170
			} else {
171
				$payment_method = Methods::transform_gateway_method( $method );
172
			}
173
174
			if ( $payment_method ) {
175
				$payment_methods[] = $payment_method;
176
			}
177
		}
178
179
		$payment_methods = array_unique( $payment_methods );
180
181
		return $payment_methods;
182
	}
183
184
	/**
185
	 * Get supported payment methods
186
	 *
187
	 * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods()
188
	 */
189 4
	public function get_supported_payment_methods() {
190 4
		return array(
191
			PaymentMethods::BANCONTACT,
192 4
			PaymentMethods::BANK_TRANSFER,
193
			PaymentMethods::BELFIUS,
194 4
			PaymentMethods::CREDIT_CARD,
195
			PaymentMethods::DIRECT_DEBIT,
196
			PaymentMethods::DIRECT_DEBIT_BANCONTACT,
197
			PaymentMethods::DIRECT_DEBIT_IDEAL,
198
			PaymentMethods::DIRECT_DEBIT_SOFORT,
199 4
			PaymentMethods::EPS,
200
			PaymentMethods::GIROPAY,
201 1
			PaymentMethods::IDEAL,
202 3
			PaymentMethods::KBC,
203
			PaymentMethods::PAYPAL,
204 1
			PaymentMethods::SOFORT,
205 2
		);
206
	}
207 1
208 1
	/**
209
	 * Get webhook URL for Mollie.
210
	 *
211
	 * @return string|null
212
	 */
213 1
	public function get_webhook_url() {
214
		$url = home_url( '/' );
215 1
216
		$host = wp_parse_url( $url, PHP_URL_HOST );
217
218
		if ( is_array( $host ) ) {
219
			// Parsing failure.
220
			$host = '';
221
		}
222
223
		if ( 'localhost' === $host ) {
224
			// Mollie doesn't allow localhost.
225
			return null;
226
		} elseif ( '.dev' === substr( $host, -4 ) ) {
227
			// Mollie doesn't allow the .dev TLD.
228
			return null;
229
		} elseif ( '.local' === substr( $host, -6 ) ) {
230
			// Mollie doesn't allow the .local TLD.
231
			return null;
232
		} elseif ( '.test' === substr( $host, -5 ) ) {
233
			// Mollie doesn't allow the .test TLD.
234
			return null;
235
		}
236
237
		$url = add_query_arg( 'mollie_webhook', '', $url );
238
239
		return $url;
240
	}
241
242
	/**
243
	 * Start
244
	 *
245
	 * @see Pronamic_WP_Pay_Gateway::start()
246
	 *
247
	 * @param Payment $payment Payment.
248
	 */
249
	public function start( Payment $payment ) {
250
		$request               = new PaymentRequest();
251
		$request->amount       = AmountTransformer::transform( $payment->get_total_amount() );
252
		$request->description  = \strval( $payment->get_description() );
253
		$request->redirect_url = $payment->get_return_url();
254
		$request->webhook_url  = $this->get_webhook_url();
255
256
		// Locale.
257
		if ( null !== $payment->get_customer() ) {
258
			$request->locale = LocaleHelper::transform( $payment->get_customer()->get_locale() );
259
		}
260
261
		// Customer ID.
262
		$customer_id = $this->get_customer_id_for_payment( $payment );
263
264
		if ( is_string( $customer_id ) && ! empty( $customer_id ) ) {
265
			$request->customer_id = $customer_id;
266
		}
267
268
		// Payment method.
269
		$payment_method = $payment->get_method();
270
271
		// Recurring payment method.
272
		$is_recurring_method = ( $payment->get_subscription() && PaymentMethods::is_recurring_method( $payment_method ) );
273
274
		if ( false === $is_recurring_method ) {
275
			// Always use 'direct debit mandate via iDEAL/Bancontact/Sofort' payment methods as recurring method.
276
			$is_recurring_method = PaymentMethods::is_direct_debit_method( $payment_method );
277
		}
278
279
		if ( $is_recurring_method ) {
280
			$request->sequence_type = $payment->get_recurring() ? Sequence::RECURRING : Sequence::FIRST;
281
282
			if ( Sequence::FIRST === $request->sequence_type ) {
283
				$payment_method = PaymentMethods::get_first_payment_method( $payment_method );
284
			}
285
286
			if ( Sequence::RECURRING === $request->sequence_type ) {
287
				$payment->set_action_url( $payment->get_return_url() );
288
			}
289
		}
290
291
		// Leap of faith if the WordPress payment method could not transform to a Mollie method?
292
		$request->method = Methods::transform( $payment_method, $payment_method );
293
294
		// Issuer.
295
		if ( Methods::IDEAL === $request->method ) {
296
			$request->issuer = $payment->get_issuer();
297
		}
298
299
		// Due date.
300
		try {
301
			$due_date = new DateTime( sprintf( '+%s days', $this->config->due_date_days ) );
302
		} catch ( \Exception $e ) {
303
			$due_date = null;
304
		}
305
306
		$request->set_due_date( $due_date );
307
308
		// Create payment.
309
		$result = $this->client->create_payment( $request );
310
311
		// Set transaction ID.
312
		if ( isset( $result->id ) ) {
313
			$payment->set_transaction_id( $result->id );
314
		}
315
316
		// Set expiry date.
317
		/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
318
		if ( isset( $result->expiresAt ) ) {
319
			try {
320
				$expires_at = new DateTime( $result->expiresAt );
321
			} catch ( \Exception $e ) {
322
				$expires_at = null;
323
			}
324
325
			$payment->set_expiry_date( $expires_at );
0 ignored issues
show
Bug introduced by
The method set_expiry_date() does not exist on Pronamic\WordPress\Pay\Payments\Payment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

325
			$payment->/** @scrutinizer ignore-call */ 
326
             set_expiry_date( $expires_at );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
326
		}
327
		/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
328
329
		// Set status.
330
		if ( isset( $result->status ) ) {
331
			$payment->set_status( Statuses::transform( $result->status ) );
332
		}
333
334
		// Set bank transfer recipient details.
335
		if ( isset( $result->details ) ) {
336
			$bank_transfer_recipient_details = $payment->get_bank_transfer_recipient_details();
0 ignored issues
show
Bug introduced by
The method get_bank_transfer_recipient_details() does not exist on Pronamic\WordPress\Pay\Payments\Payment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

336
			/** @scrutinizer ignore-call */ 
337
   $bank_transfer_recipient_details = $payment->get_bank_transfer_recipient_details();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
337
338
			if ( null === $bank_transfer_recipient_details ) {
339
				$bank_transfer_recipient_details = new BankTransferDetails();
340
341
				$payment->set_bank_transfer_recipient_details( $bank_transfer_recipient_details );
0 ignored issues
show
Bug introduced by
The method set_bank_transfer_recipient_details() does not exist on Pronamic\WordPress\Pay\Payments\Payment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

341
				$payment->/** @scrutinizer ignore-call */ 
342
              set_bank_transfer_recipient_details( $bank_transfer_recipient_details );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
342
			}
343
344
			$bank_details = $bank_transfer_recipient_details->get_bank_account();
345
346
			if ( null === $bank_details ) {
347
				$bank_details = new BankAccountDetails();
348
349
				$bank_transfer_recipient_details->set_bank_account( $bank_details );
350
			}
351
352
			$details = $result->details;
353
354
			/*
355
			 * @codingStandardsIgnoreStart
356
			 *
357
			 * Ignore coding standards because of sniff WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
358
			 */
359
			if ( isset( $details->bankName ) ) {
360
				/**
361
				 * Set `bankName` as bank details name, as result "Stichting Mollie Payments"
362
				 * is not the name of a bank, but the account holder name.
363
				 */
364
				$bank_details->set_name( $details->bankName );
365
			}
366
367
			if ( isset( $details->bankAccount ) ) {
368 11
				$bank_details->set_iban( $details->bankAccount );
369
			}
370 11
371
			if ( isset( $details->bankBic ) ) {
372
				$bank_details->set_bic( $details->bankBic );
373 11
			}
374
375 11
			if ( isset( $details->transferReference ) ) {
376
				$bank_transfer_recipient_details->set_reference( $details->transferReference );
377
			}
378 11
			// @codingStandardsIgnoreEnd
379 11
		}
380
381
		// Set action URL.
382 11
		if ( isset( $result->_links ) ) {
383 7
			if ( isset( $result->_links->checkout->href ) ) {
384
				$payment->set_action_url( $result->_links->checkout->href );
385 7
			}
386
		}
387
	}
388 11
389 5
	/**
390
	 * Update status of the specified payment
391
	 *
392
	 * @param Payment $payment Payment.
393
	 *
394 11
	 * @return void
395
	 */
396
	public function update_status( Payment $payment ) {
397
		$transaction_id = $payment->get_transaction_id();
398
399
		if ( null === $transaction_id ) {
400
			return;
401
		}
402
403
		$mollie_payment = $this->client->get_payment( $transaction_id );
404
405
		if ( isset( $mollie_payment->status ) ) {
406
			$payment->set_status( Statuses::transform( $mollie_payment->status ) );
407 11
		}
408
409
		if ( isset( $mollie_payment->details ) ) {
410
			$consumer_bank_details = $payment->get_consumer_bank_details();
0 ignored issues
show
Bug introduced by
The method get_consumer_bank_details() does not exist on Pronamic\WordPress\Pay\Payments\Payment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

410
			/** @scrutinizer ignore-call */ 
411
   $consumer_bank_details = $payment->get_consumer_bank_details();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
411
412 11
			if ( null === $consumer_bank_details ) {
413
				$consumer_bank_details = new BankAccountDetails();
414 11
415
				$payment->set_consumer_bank_details( $consumer_bank_details );
0 ignored issues
show
Bug introduced by
The method set_consumer_bank_details() does not exist on Pronamic\WordPress\Pay\Payments\Payment. Did you maybe mean set_consumer_bic()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

415
				$payment->/** @scrutinizer ignore-call */ 
416
              set_consumer_bank_details( $consumer_bank_details );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
416
			}
417
418
			$details = $mollie_payment->details;
419
420
			/*
421
			 * @codingStandardsIgnoreStart
422
			 *
423
			 * Ignore coding standards because of sniff WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
424 28
			 */
425 28
			if ( isset( $details->consumerName ) ) {
426 11
				$consumer_bank_details->set_name( $details->consumerName );
427
			}
428
429 17
			if ( isset( $details->cardHolder ) ) {
430
				$consumer_bank_details->set_name( $details->cardHolder );
431
			}
432
433
			if ( isset( $details->cardNumber ) ) {
434
				// The last four digits of the card number.
435
				$consumer_bank_details->set_account_number( $details->cardNumber );
436
			}
437
438
			if ( isset( $details->cardCountryCode ) ) {
439
				// The ISO 3166-1 alpha-2 country code of the country the card was issued in.
440
				$consumer_bank_details->set_country( $details->cardCountryCode );
441
			}
442
443
			if ( isset( $details->consumerAccount ) ) {
444
				switch ( $mollie_payment->method ) {
445
					case Methods::BELFIUS:
446
					case Methods::DIRECT_DEBIT:
447
					case Methods::IDEAL:
448
					case Methods::KBC:
449
					case Methods::SOFORT:
450
						$consumer_bank_details->set_iban( $details->consumerAccount );
451
452
						break;
453
					case Methods::BANCONTACT:
454
					case Methods::BANKTRANSFER:
455
					case Methods::PAYPAL:
456
					default:
457
						$consumer_bank_details->set_account_number( $details->consumerAccount );
458
459 28
						break;
460 28
				}
461 1
			}
462
463
			if ( isset( $details->consumerBic ) ) {
464 27
				$consumer_bank_details->set_bic( $details->consumerBic );
465
			}
466 27
			// @codingStandardsIgnoreEnd
467 27
		}
468
	}
469
470
	/**
471
	 * Get Mollie customer ID for payment.
472
	 *
473
	 * @param Payment $payment Payment.
474
	 *
475
	 * @return bool|string
476
	 */
477
	public function get_customer_id_for_payment( Payment $payment ) {
478
		// Get WordPress user ID from payment customer.
479
		$user_id = ( null === $payment->get_customer() ? null : $payment->get_customer()->get_user_id() );
480
481
		// Get Mollie customer ID from user meta.
482
		$customer_id = $this->get_customer_id_by_wp_user_id( $user_id );
483
484
		$subscription = $payment->get_subscription();
485
486
		// Get customer ID from subscription meta.
487
		if ( $subscription ) {
488
			$subscription_customer_id = $subscription->get_meta( 'mollie_customer_id' );
489
490
			// Try to get (legacy) customer ID from first payment.
491
			if ( empty( $subscription_customer_id ) && $subscription->get_first_payment() ) {
492
				$first_payment = $subscription->get_first_payment();
493
494
				$subscription_customer_id = $first_payment->get_meta( 'mollie_customer_id' );
495
			}
496
497
			if ( ! empty( $subscription_customer_id ) ) {
498
				$customer_id = $subscription_customer_id;
499
			}
500
		}
501
502
		// Create new customer if the customer does not exist at Mollie.
503
		if ( ( empty( $customer_id ) || ! $this->client->get_customer( $customer_id ) ) && Core_Recurring::RECURRING !== $payment->recurring_type ) {
504
			$customer_name = null;
505
506
			if ( null !== $payment->get_customer() && null !== $payment->get_customer()->get_name() ) {
507
				$customer_name = strval( $payment->get_customer()->get_name() );
508
			}
509
510
			$customer_id = $this->client->create_customer( $payment->get_email(), $customer_name );
511
512
			$this->update_wp_user_customer_id( $user_id, $customer_id );
513
		}
514
515
		// Store customer ID in subscription meta.
516
		if ( $subscription && empty( $subscription_customer_id ) && ! empty( $customer_id ) ) {
517
			$subscription->set_meta( 'mollie_customer_id', $customer_id );
518
		}
519
520
		// Copy customer ID from subscription to user meta.
521
		$this->copy_customer_id_to_wp_user( $payment );
522
523
		return $customer_id;
524
	}
525
526
	/**
527
	 * Get Mollie customer ID by the specified WordPress user ID.
528
	 *
529
	 * @param int $user_id WordPress user ID.
530
	 *
531
	 * @return string|bool
532
	 */
533
	public function get_customer_id_by_wp_user_id( $user_id ) {
534
		if ( empty( $user_id ) ) {
535
			return false;
536
		}
537
538
		return get_user_meta( $user_id, $this->meta_key_customer_id, true );
539
	}
540
541
	/**
542
	 * Update Mollie customer ID meta for WordPress user.
543
	 *
544
	 * @param int    $user_id     WordPress user ID.
545
	 * @param string $customer_id Mollie Customer ID.
546
	 *
547
	 * @return bool
548
	 */
549
	private function update_wp_user_customer_id( $user_id, $customer_id ) {
550
		if ( empty( $user_id ) || is_bool( $user_id ) ) {
551
			return false;
552
		}
553
554
		if ( ! is_string( $customer_id ) || empty( $customer_id ) || 1 === strlen( $customer_id ) ) {
0 ignored issues
show
introduced by
The condition is_string($customer_id) is always true.
Loading history...
555
			return false;
556
		}
557
558
		update_user_meta( $user_id, $this->meta_key_customer_id, $customer_id );
559
	}
560
561
	/**
562
	 * Copy Mollie customer ID from subscription meta to WordPress user meta.
563
	 *
564
	 * @param Payment $payment Payment.
565
	 *
566
	 * @return void
567
	 */
568
	public function copy_customer_id_to_wp_user( Payment $payment ) {
569
		if ( $this->config->id !== $payment->config_id ) {
570
			return;
571
		}
572
573
		$subscription = $payment->get_subscription();
574
575
		if ( ! $subscription || empty( $subscription->user_id ) ) {
576
			return;
577
		}
578
579
		// Get customer ID from subscription meta.
580
		$customer_id = $subscription->get_meta( 'mollie_customer_id' );
581
582
		$user_customer_id = $this->get_customer_id_by_wp_user_id( $subscription->user_id );
0 ignored issues
show
Bug introduced by
It seems like $subscription->user_id can also be of type string; however, parameter $user_id of Pronamic\WordPress\Pay\G...omer_id_by_wp_user_id() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

582
		$user_customer_id = $this->get_customer_id_by_wp_user_id( /** @scrutinizer ignore-type */ $subscription->user_id );
Loading history...
583
584
		if ( empty( $user_customer_id ) ) {
585
			// Set customer ID as user meta.
586
			$this->update_wp_user_customer_id( $subscription->user_id, $customer_id );
0 ignored issues
show
Bug introduced by
It seems like $subscription->user_id can also be of type string; however, parameter $user_id of Pronamic\WordPress\Pay\G...e_wp_user_customer_id() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

586
			$this->update_wp_user_customer_id( /** @scrutinizer ignore-type */ $subscription->user_id, $customer_id );
Loading history...
Bug introduced by
It seems like $customer_id can also be of type false; however, parameter $customer_id of Pronamic\WordPress\Pay\G...e_wp_user_customer_id() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

586
			$this->update_wp_user_customer_id( $subscription->user_id, /** @scrutinizer ignore-type */ $customer_id );
Loading history...
587
		}
588
	}
589
}
590