Test Failed
Push — develop ( ddf0fb...15e561 )
by Remco
03:48
created

src/Gateway.php (4 issues)

1
<?php
2
/**
3
 * Mollie gateway.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 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\Banks\BankAccountDetails;
16
use Pronamic\WordPress\Pay\Banks\BankTransferDetails;
17
use Pronamic\WordPress\Pay\Core\Gateway as Core_Gateway;
18
use Pronamic\WordPress\Pay\Core\PaymentMethods;
19
use Pronamic\WordPress\Pay\Core\Recurring as Core_Recurring;
20
use Pronamic\WordPress\Pay\Payments\PaymentStatus;
21
use Pronamic\WordPress\Pay\Payments\Payment;
22
use Pronamic\WordPress\Pay\Subscriptions\Subscription;
23
24
/**
25
 * Title: Mollie
26
 * Description:
27
 * Copyright: 2005-2020 Pronamic
28
 * Company: Pronamic
29
 *
30
 * @author  Remco Tolsma
31
 * @version 2.0.9
32
 * @since   1.1.0
33
 */
34
class Gateway extends Core_Gateway {
35
	/**
36
	 * Client.
37
	 *
38
	 * @var Client
39
	 */
40
	protected $client;
41
42
	/**
43
	 * Constructs and initializes an Mollie gateway
44
	 *
45
	 * @param Config $config Config.
46
	 */
47
	public function __construct( Config $config ) {
48
		parent::__construct( $config );
49
50
		$this->set_method( self::METHOD_HTTP_REDIRECT );
51
52
		// Supported features.
53 39
		$this->supports = array(
54 39
			'payment_status_request',
55
			'recurring_direct_debit',
56 39
			'recurring_credit_card',
57
			'recurring',
58
			'webhook',
59 39
			'webhook_log',
60
			'webhook_no_config',
61
		);
62
63
		// Client.
64
		$this->client = new Client( \strval( $config->api_key ) );
65
66
		// Actions.
67
		add_action( 'pronamic_payment_status_update', array( $this, 'copy_customer_id_to_wp_user' ), 99, 1 );
68
	}
69
70 39
	/**
71 39
	 * Get issuers
72
	 *
73
	 * @see Core_Gateway::get_issuers()
74 39
	 * @return array<int, array<string, array<string>>>
75 38
	 */
76
	public function get_issuers() {
77
		$groups = array();
78
79 39
		try {
80 39
			$result = $this->client->get_issuers();
81
82
			$groups[] = array(
83
				'options' => $result,
84
			);
85
		} catch ( Error $e ) {
86
			// Catch Mollie error.
87 3
			$error = new \WP_Error(
88 3
				'mollie_error',
89
				sprintf( '%1$s (%2$s) - %3$s', $e->get_title(), $e->getCode(), $e->get_detail() )
90
			);
91 3
92
			$this->set_error( $error );
93
		} catch ( \Exception $e ) {
94
			// Catch exceptions.
95
			$error = new \WP_Error( 'mollie_error', $e->getMessage() );
96 3
97
			$this->set_error( $error );
98 3
		}
99 3
100 3
		return $groups;
101
	}
102
103 3
	/**
104
	 * Get available payment methods.
105
	 *
106
	 * @see Core_Gateway::get_available_payment_methods()
107
	 * @return array<string>
108
	 */
109
	public function get_available_payment_methods() {
110
		$payment_methods = array();
111 3
112
		// Set sequence types to get payment methods for.
113
		$sequence_types = array( Sequence::ONE_OFF, Sequence::RECURRING, Sequence::FIRST );
114
115
		$results = array();
116
117
		foreach ( $sequence_types as $sequence_type ) {
118
			// Get active payment methods for Mollie account.
119 2
			try {
120 2
				$result = $this->client->get_payment_methods( $sequence_type );
121
			} catch ( Error $e ) {
122
				// Catch Mollie error.
123 2
				$error = new \WP_Error(
124
					'mollie_error',
125 2
					sprintf( '%1$s (%2$s) - %3$s', $e->get_title(), $e->getCode(), $e->get_detail() )
126
				);
127 2
128
				$this->set_error( $error );
129
130 2
				break;
131 2
			} catch ( \Exception $e ) {
132
				// Catch exceptions.
133
				$error = new \WP_Error( 'mollie_error', $e->getMessage() );
134
135
				$this->set_error( $error );
136
137
				break;
138
			}
139
140
			if ( Sequence::FIRST === $sequence_type ) {
141 2
				foreach ( $result as $method => $title ) {
142
					unset( $result[ $method ] );
143 2
144
					// Get WordPress payment method for direct debit method.
145 2
					$method         = Methods::transform_gateway_method( $method );
146
					$payment_method = array_search( $method, PaymentMethods::get_recurring_methods(), true );
147 2
148
					if ( $payment_method ) {
149
						$results[ $payment_method ] = $title;
150 2
					}
151
				}
152
			}
153
154
			if ( is_array( $result ) ) {
155
				$results = array_merge( $results, $result );
156
			}
157
		}
158
159
		// Transform to WordPress payment methods.
160
		foreach ( $results as $method => $title ) {
161
			if ( PaymentMethods::is_recurring_method( $method ) ) {
162
				$payment_method = $method;
163
			} else {
164 2
				$payment_method = Methods::transform_gateway_method( $method );
165 2
			}
166
167
			if ( $payment_method ) {
168
				$payment_methods[] = $payment_method;
169
			}
170 2
		}
171 2
172
		$payment_methods = array_unique( $payment_methods );
173
174 2
		return $payment_methods;
175
	}
176
177 2
	/**
178 2
	 * Get supported payment methods
179
	 *
180
	 * @see Pronamic_WP_Pay_Gateway::get_supported_payment_methods()
181
	 * @return array<string>
182 2
	 */
183
	public function get_supported_payment_methods() {
184 2
		return array(
185
			PaymentMethods::BANCONTACT,
186
			PaymentMethods::BANK_TRANSFER,
187
			PaymentMethods::BELFIUS,
188
			PaymentMethods::CREDIT_CARD,
189
			PaymentMethods::DIRECT_DEBIT,
190
			PaymentMethods::DIRECT_DEBIT_BANCONTACT,
191
			PaymentMethods::DIRECT_DEBIT_IDEAL,
192
			PaymentMethods::DIRECT_DEBIT_SOFORT,
193 2
			PaymentMethods::EPS,
194
			PaymentMethods::GIROPAY,
195 2
			PaymentMethods::IDEAL,
196
			PaymentMethods::KBC,
197
			PaymentMethods::PAYPAL,
198
			PaymentMethods::SOFORT,
199
		);
200
	}
201
202
	/**
203
	 * Get webhook URL for Mollie.
204
	 *
205
	 * @return string|null
206
	 */
207
	public function get_webhook_url() {
208
		$url = home_url( '/' );
209
210
		$host = wp_parse_url( $url, PHP_URL_HOST );
211
212
		if ( is_array( $host ) ) {
213
			// Parsing failure.
214
			$host = '';
215
		}
216
217 4
		if ( 'localhost' === $host ) {
218 4
			// Mollie doesn't allow localhost.
219
			return null;
220 4
		} elseif ( '.dev' === substr( $host, -4 ) ) {
221
			// Mollie doesn't allow the .dev TLD.
222 4
			return null;
223
		} elseif ( '.local' === substr( $host, -6 ) ) {
224
			// Mollie doesn't allow the .local TLD.
225
			return null;
226
		} elseif ( '.test' === substr( $host, -5 ) ) {
227 4
			// Mollie doesn't allow the .test TLD.
228
			return null;
229 1
		}
230 3
231
		$url = \rest_url( self::REST_ROUTE_NAMESPACE . '/webhook' );
0 ignored issues
show
The constant Pronamic\WordPress\Pay\G...y::REST_ROUTE_NAMESPACE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
232 1
233 2
		return $url;
234
	}
235 1
236 1
	/**
237
	 * Start
238
	 *
239
	 * @see Pronamic_WP_Pay_Gateway::start()
240
	 * @param Payment $payment Payment.
241 1
	 * @return void
242
	 */
243 1
	public function start( Payment $payment ) {
244
		$request = new PaymentRequest(
245
			AmountTransformer::transform( $payment->get_total_amount() ),
246
			\strval( $payment->get_description() )
247
		);
248
249
		$request->redirect_url = $payment->get_return_url();
250
		$request->webhook_url  = $this->get_webhook_url();
251
252
		// Locale.
253
		$customer = $payment->get_customer();
254
255
		if ( null !== $customer ) {
256
			$request->locale = LocaleHelper::transform( $customer->get_locale() );
257
		}
258
259
		// Customer ID.
260
		$customer_id = $this->get_customer_id_for_payment( $payment );
261
262
		if ( null !== $customer_id ) {
263
			$request->customer_id = $customer_id;
264
		}
265
266
		// Payment method.
267
		$payment_method = $payment->get_method();
268
269
		// Recurring payment method.
270
		$is_recurring_method = ( $payment->get_subscription() && PaymentMethods::is_recurring_method( $payment_method ) );
271
272
		if ( false === $is_recurring_method ) {
273
			// Always use 'direct debit mandate via iDEAL/Bancontact/Sofort' payment methods as recurring method.
274
			$is_recurring_method = PaymentMethods::is_direct_debit_method( $payment_method );
275
		}
276
277
		if ( $is_recurring_method ) {
278
			$request->sequence_type = $payment->get_recurring() ? Sequence::RECURRING : Sequence::FIRST;
279
280
			if ( Sequence::FIRST === $request->sequence_type ) {
281
				$payment_method = PaymentMethods::get_first_payment_method( $payment_method );
282
			}
283
284
			if ( Sequence::RECURRING === $request->sequence_type ) {
285
				$payment->set_action_url( $payment->get_return_url() );
286
			}
287
		}
288
289
		// Leap of faith if the WordPress payment method could not transform to a Mollie method?
290
		$request->method = Methods::transform( $payment_method, $payment_method );
291
292
		// Issuer.
293
		if ( Methods::IDEAL === $request->method ) {
294
			$request->issuer = $payment->get_issuer();
295
		}
296
297
		// Due date.
298
		try {
299
			$due_date = new DateTime( sprintf( '+%s days', $this->config->due_date_days ) );
300
		} catch ( \Exception $e ) {
301
			$due_date = null;
302
		}
303
304
		$request->set_due_date( $due_date );
305
306
		// Create payment.
307
		$result = $this->client->create_payment( $request );
308
309
		// Set transaction ID.
310
		if ( isset( $result->id ) ) {
311
			$payment->set_transaction_id( $result->id );
312
		}
313
314
		// Set expiry date.
315
		/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
316
		if ( isset( $result->expiresAt ) ) {
317
			try {
318
				$expires_at = new DateTime( $result->expiresAt );
319
			} catch ( \Exception $e ) {
320
				$expires_at = null;
321
			}
322
323
			$payment->set_expiry_date( $expires_at );
324
		}
325
		/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
326
327
		// Set status.
328
		if ( isset( $result->status ) ) {
329
			$payment->set_status( Statuses::transform( $result->status ) );
330
		}
331
332
		// Set bank transfer recipient details.
333
		if ( isset( $result->details ) ) {
334
			$bank_transfer_recipient_details = $payment->get_bank_transfer_recipient_details();
335
336
			if ( null === $bank_transfer_recipient_details ) {
337
				$bank_transfer_recipient_details = new BankTransferDetails();
338
339
				$payment->set_bank_transfer_recipient_details( $bank_transfer_recipient_details );
340
			}
341
342
			$bank_details = $bank_transfer_recipient_details->get_bank_account();
343
344
			if ( null === $bank_details ) {
345
				$bank_details = new BankAccountDetails();
346
347
				$bank_transfer_recipient_details->set_bank_account( $bank_details );
348
			}
349
350
			$details = $result->details;
351
352
			/*
353
			 * @codingStandardsIgnoreStart
354
			 *
355
			 * Ignore coding standards because of sniff WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
356
			 */
357
			if ( isset( $details->bankName ) ) {
358
				/**
359
				 * Set `bankName` as bank details name, as result "Stichting Mollie Payments"
360
				 * is not the name of a bank, but the account holder name.
361
				 */
362
				$bank_details->set_name( $details->bankName );
363
			}
364
365
			if ( isset( $details->bankAccount ) ) {
366
				$bank_details->set_iban( $details->bankAccount );
367
			}
368
369
			if ( isset( $details->bankBic ) ) {
370
				$bank_details->set_bic( $details->bankBic );
371
			}
372
373
			if ( isset( $details->transferReference ) ) {
374
				$bank_transfer_recipient_details->set_reference( $details->transferReference );
375
			}
376
			// @codingStandardsIgnoreEnd
377
		}
378
379
		// Set action URL.
380
		if ( isset( $result->_links ) ) {
381
			if ( isset( $result->_links->checkout->href ) ) {
382
				$payment->set_action_url( $result->_links->checkout->href );
383
			}
384
		}
385
	}
386
387
	/**
388
	 * Update status of the specified payment
389
	 *
390
	 * @param Payment $payment Payment.
391
	 * @return void
392
	 */
393
	public function update_status( Payment $payment ) {
394
		$transaction_id = $payment->get_transaction_id();
395
396
		if ( null === $transaction_id ) {
397
			return;
398
		}
399
400
		$mollie_payment = $this->client->get_payment( $transaction_id );
401
402
		if ( isset( $mollie_payment->status ) ) {
403
			$payment->set_status( Statuses::transform( $mollie_payment->status ) );
404
		}
405
406
		if ( isset( $mollie_payment->details ) ) {
407
			$consumer_bank_details = $payment->get_consumer_bank_details();
408
409
			if ( null === $consumer_bank_details ) {
410
				$consumer_bank_details = new BankAccountDetails();
411
412
				$payment->set_consumer_bank_details( $consumer_bank_details );
413
			}
414
415
			$details = $mollie_payment->details;
416
417
			/*
418
			 * @codingStandardsIgnoreStart
419
			 *
420
			 * Ignore coding standards because of sniff WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
421
			 */
422
			if ( isset( $details->consumerName ) ) {
423
				$consumer_bank_details->set_name( $details->consumerName );
424
			}
425
426
			if ( isset( $details->cardHolder ) ) {
427
				$consumer_bank_details->set_name( $details->cardHolder );
428
			}
429
430
			if ( isset( $details->cardNumber ) ) {
431
				// The last four digits of the card number.
432
				$consumer_bank_details->set_account_number( $details->cardNumber );
433
			}
434
435
			if ( isset( $details->cardCountryCode ) ) {
436
				// The ISO 3166-1 alpha-2 country code of the country the card was issued in.
437
				$consumer_bank_details->set_country( $details->cardCountryCode );
438
			}
439
440
			if ( isset( $details->consumerAccount ) ) {
441
				switch ( $mollie_payment->method ) {
442
					case Methods::BELFIUS:
443
					case Methods::DIRECT_DEBIT:
444
					case Methods::IDEAL:
445
					case Methods::KBC:
446
					case Methods::SOFORT:
447
						$consumer_bank_details->set_iban( $details->consumerAccount );
448
449
						break;
450
					case Methods::BANCONTACT:
451
					case Methods::BANKTRANSFER:
452
					case Methods::PAYPAL:
453
					default:
454
						$consumer_bank_details->set_account_number( $details->consumerAccount );
455
456
						break;
457
				}
458
			}
459
460
			if ( isset( $details->consumerBic ) ) {
461
				$consumer_bank_details->set_bic( $details->consumerBic );
462
			}
463
			// @codingStandardsIgnoreEnd
464
		}
465
	}
466
467
	/**
468
	 * Get Mollie customer ID for payment.
469
	 *
470
	 * @param Payment $payment Payment.
471
	 * @return bool|string
472
	 */
473
	public function get_customer_id_for_payment( Payment $payment ) {
474
		// Try to get existing Mollie customer ID.
475
		$customer_ids = $this->get_customer_ids_for_payment( $payment );
476
477
		$subscription_customer_id = $this->get_customer_id_for_subscription( $payment->get_subscription() );
0 ignored issues
show
It seems like $payment->get_subscription() can also be of type null; however, parameter $subscription of Pronamic\WordPress\Pay\G...r_id_for_subscription() does only seem to accept Pronamic\WordPress\Pay\Subscriptions\Subscription, 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

477
		$subscription_customer_id = $this->get_customer_id_for_subscription( /** @scrutinizer ignore-type */ $payment->get_subscription() );
Loading history...
478
479
		\array_unshift( $customer_ids, $subscription_customer_id );
480
481
		$customer_id = $this->get_first_existing_customer_id( $customer_ids );
482
483 10
		// Create new customer if no valid customer was found.
484 10
		if ( null === $customer_id ) {
485
			$customer_id = $this->create_customer_for_payment( $payment );
486
		}
487 10
488
		// Store customer ID in subscription meta.
489
		$subscription = $payment->get_subscription();
490 10
491
		if ( null === $subscription_customer_id && null !== $customer_id && null !== $subscription ) {
492 10
			$subscription->set_meta( 'mollie_customer_id', $customer_id );
493
		}
494
495 10
		// Copy customer ID from subscription to user meta.
496 10
		$this->copy_customer_id_to_wp_user( $payment );
497
498
		return $customer_id;
499 10
	}
500 7
501
	/**
502 7
	 * Get Mollie customers for the specified payment.
503
	 *
504
	 * @param Payment $payment Payment.
505 10
	 * @return array<string>
506 4
	 */
507
	private function get_customer_ids_for_payment( Payment $payment ) {
508
		$customer = $payment->get_customer();
509
510
		if ( null === $customer ) {
511 10
			return array();
512
		}
513
514
		$user_id = $customer->get_user_id();
515
516
		if ( empty( $user_id ) ) {
517
			return array();
518
		}
519
520
		return $this->get_customer_ids_for_user( $user_id );
521
	}
522
523
	/**
524 10
	 * Get Mollie customers for the specified WordPress user ID.
525
	 *
526
	 * @param int $user_id WordPress user ID.
527
	 * @return array<string>
528
	 */
529 10
	private function get_customer_ids_for_user( $user_id ) {
530
		$customer_query = new CustomerQuery(
531 10
			array(
532
				'user_id' => $user_id,
533
			)
534
		);
535
536
		$customers = $customer_query->get_customers();
537
538
		$customer_ids = wp_list_pluck( $customers, 'mollie_id' );
539
540 27
		return $customer_ids;
541 27
	}
542 11
543
	/**
544
	 * Get customer ID for subscription.
545 16
	 *
546
	 * @param Subscription $subscription Subscription.
547
	 *
548
	 * @return string|null
549
	 */
550
	private function get_customer_id_for_subscription( Subscription $subscription ) {
551
		$customer_id = $subscription->get_meta( 'mollie_customer_id' );
552
553
		// Try to get (legacy) customer ID from first payment.
554
		$first_payment = $subscription->get_first_payment();
555 15
556 15
		if ( empty( $customer_id ) && $first_payment ) {
557 3
			$customer_id = $first_payment->get_meta( 'mollie_customer_id' );
558
		}
559
560 12
		if ( ! empty( $customer_id ) ) {
561 11
			return $customer_id;
562
		}
563
564 4
		return null;
565 4
	}
566
567
	/**
568
	 * Get first existing customer from customers list.
569
	 *
570
	 * @param array $customer_ids Customers.
571
	 * @return string|null
572
	 */
573 27
	private function get_first_existing_customer_id( $customer_ids ) {
574 27
		$customer_ids = \array_filter( $customer_ids );
575 1
576
		$customer_ids = \array_unique( $customer_ids );
577
578 26
		foreach ( $customer_ids as $customer_id ) {
579
			$customer = $this->client->get_customer( $customer_id );
580 26
581
			if ( null !== $customer ) {
582
				return $customer;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $customer returns the type object which is incompatible with the documented return type null|string.
Loading history...
583
			}
584 26
		}
585
586 26
		return null;
587 1
	}
588
589
	/**
590 25
	 * Create customer for payment.
591
	 *
592 25
	 * @param Payment $payment
593 10
	 * @return string|null
594
	 * @throws Error Throws Error when Mollie error occurs.
595
	 */
596
	private function create_customer_for_payment( Payment $payment ) {
597 15
		$mollie_customer = new Customer();
598
		$mollie_customer->set_email( $payment->get_email() );
599 15
600
		$pronamic_customer = $payment->get_customer();
601 15
602
		if ( null !== $pronamic_customer ) {
603 15
			$name = $pronamic_customer->get_name();
604
605 15
			if ( null !== $name ) {
606
				$mollie_customer->set_name( \strval( $name ) );
607
			}
608
		}
609
610
		// Create customer.
611
		$mollie_customer = $this->client->create_customer( $mollie_customer );
612
613
		$mollie_customer_id = $mollie_customer->get_id();
614
615
		// Store customer ID for user.
616
		if ( null !== $mollie_customer_id && null !== $customer ) {
617
			$this->update_wp_user_customer_id( $customer->get_user_id(), $mollie_customer_id );
618
		}
619
620
		return $mollie_customer_id;
621
	}
622
623
	/**
624
	 * Update Mollie customer ID meta for WordPress user.
625
	 *
626
	 * @param int         $user_id     WordPress user ID.
627
	 * @param string      $customer_id Mollie Customer ID.
628
	 * @param string|null $email       Email address.
629
	 * @return void
630
	 */
631
	private function update_wp_user_customer_id( $user_id, $customer_id, $email = null ) {
632
		global $wpdb;
633
634
		if ( empty( $user_id ) || is_bool( $user_id ) ) {
635
			return;
636
		}
637
638
		if ( ! is_string( $customer_id ) || empty( $customer_id ) || 1 === strlen( $customer_id ) ) {
639
			return;
640
		}
641
642
		$customer_ids = $this->get_customer_ids_for_user( $user_id );
643
644
		if ( false !== \array_search( $customer_id, $customer_ids ) ) {
645
			return;
646
		}
647
648
		/**
649
		 * Insert Mollie customer.
650
		 *
651
		 * @link https://developer.wordpress.org/reference/classes/wpdb/insert/
652
		 */
653
		$result = $wpdb->insert(
654
			$wpdb->pronamic_pay_mollie_customers,
655
			array(
656
				'mollie_id' => $customer_id,
657
				'test_mode' => $this->config->is_test_mode(),
658
				'email'     => $email,
659
			),
660
			array(
661
				'mollie_id' => '%s',
662
				'test_mode' => '%d',
663
				'email'     => '%s',
664
			)
665
		);
666
667
		if ( false === $result ) {
668
			throw new \Exception(
669
				sprintf(
670
					'Could not insert Mollie customer ID: %s, error: %s.',
671
					$customer_id,
672
					$wpdb->last_error
673
				)
674
			);
675
		}
676
677
		$customer_id = $wpdb->insert_id;
678
	}
679
680
	/**
681
	 * Copy Mollie customer ID from subscription meta to WordPress user meta.
682
	 *
683
	 * @param Payment $payment Payment.
684
	 * @return void
685
	 */
686
	public function copy_customer_id_to_wp_user( Payment $payment ) {
687
		if ( $this->config->id !== $payment->config_id ) {
688
			return;
689
		}
690
691
		$subscription = $payment->get_subscription();
692
693
		// Check subscription customer.
694
		$customer = $subscription->get_customer();
695
696
		if ( null === $customer ) {
697
			return;
698
		}
699
700
		// Get customer ID for subscription.
701
		$customer_id = $this->get_customer_id_for_subscription( $subscription );
0 ignored issues
show
It seems like $subscription can also be of type null; however, parameter $subscription of Pronamic\WordPress\Pay\G...r_id_for_subscription() does only seem to accept Pronamic\WordPress\Pay\Subscriptions\Subscription, 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

701
		$customer_id = $this->get_customer_id_for_subscription( /** @scrutinizer ignore-type */ $subscription );
Loading history...
702
703
		if ( null === $customer_id ) {
704
			return;
705
		}
706
707
		// Update user customer IDs.
708
		$this->update_wp_user_customer_id( $customer->get_user_id(), (string) $customer_id, $customer->get_email() );
709
	}
710
}
711