Failed Conditions
Push — develop ( 240468...f473d3 )
by Remco
06:11
created

Extension::subscription_source_text()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 17
ccs 0
cts 14
cp 0
crap 2
rs 9.9332
1
<?php
2
/**
3
 * Extension
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2021 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Extensions\MemberPress
9
 */
10
11
namespace Pronamic\WordPress\Pay\Extensions\MemberPress;
12
13
use MeprDb;
14
use MeprOptions;
15
use MeprProduct;
16
use MeprSubscription;
17
use MeprTransaction;
18
use MeprUtils;
19
use Pronamic\WordPress\Pay\AbstractPluginIntegration;
20
use Pronamic\WordPress\Pay\Payments\PaymentStatus;
21
use Pronamic\WordPress\Pay\Extensions\MemberPress\Gateways\Gateway;
22
use Pronamic\WordPress\Pay\Payments\Payment;
23
use Pronamic\WordPress\Pay\Subscriptions\Subscription;
24
use Pronamic\WordPress\Pay\Subscriptions\SubscriptionStatus;
25
26
/**
27
 * WordPress pay MemberPress extension
28
 *
29
 * @author  Remco Tolsma
30
 * @version 2.2.3
31
 * @since   1.0.0
32
 */
33
class Extension extends AbstractPluginIntegration {
34
	/**
35
	 * The slug of this addon
36
	 *
37
	 * @var string
38
	 */
39
	const SLUG = 'memberpress';
40
41
	/**
42
	 * Construct MemberPress plugin integration.
43
	 */
44
	public function __construct() {
45
		parent::__construct(
46
			array(
47
				'name' => __( 'MemberPress', 'pronamic_ideal' ),
48
			)
49
		);
50
51
		// Dependencies.
52
		$dependencies = $this->get_dependencies();
53
54
		$dependencies->add( new MemberPressDependency() );
55
	}
56
57
	/**
58
	 * Setup.
59
	 */
60
	public function setup() {
61
		\add_filter( 'pronamic_subscription_source_description_' . self::SLUG, array( $this, 'subscription_source_description' ), 10, 2 );
62
		\add_filter( 'pronamic_payment_source_description_' . self::SLUG, array( $this, 'source_description' ), 10, 2 );
63
64
		// Check if dependencies are met and integration is active.
65
		if ( ! $this->is_active() ) {
66
			return;
67
		}
68
69
		// @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprGatewayFactory.php#L48-50
70
		\add_filter( 'mepr-gateway-paths', array( $this, 'gateway_paths' ) );
71
72
		\add_filter( 'pronamic_payment_redirect_url_' . self::SLUG, array( $this, 'redirect_url' ), 10, 2 );
73
		\add_action( 'pronamic_payment_status_update_' . self::SLUG, array( $this, 'status_update' ), 10, 1 );
74
75
		\add_filter( 'pronamic_subscription_source_text_' . self::SLUG, array( $this, 'subscription_source_text' ), 10, 2 );
76
		\add_filter( 'pronamic_subscription_source_url_' . self::SLUG, array( $this, 'subscription_source_url' ), 10, 2 );
77
		\add_filter( 'pronamic_payment_source_text_' . self::SLUG, array( $this, 'source_text' ), 10, 2 );
78
		\add_filter( 'pronamic_payment_source_url_' . self::SLUG, array( $this, 'source_url' ), 10, 2 );
79
80
		\add_action( 'mepr_subscription_pre_delete', array( $this, 'subscription_pre_delete' ), 10, 1 );
81
82
		\add_action( 'mepr_subscription_transition_status', array( $this, 'memberpress_subscription_transition_status' ), 10, 3 );
83
84
		// MemberPress subscription email parameters.
85
		\add_filter( 'mepr_subscription_email_params', array( $this, 'subscription_email_params' ), 10, 2 );
86
		\add_filter( 'mepr_transaction_email_params', array( $this, 'transaction_email_params' ), 10, 2 );
87
88
		// Hide MemberPress columns for payments and subscriptions.
89
		\add_action( 'registered_post_type', array( $this, 'post_type_columns_hide' ), 15, 1 );
90
91
		if ( \is_admin() ) {
92
			$admin_subscriptions = new Admin\AdminSubscriptions();
93
			$admin_transactions  = new Admin\AdminTransactions();
94
95
			$admin_subscriptions->setup();
96
			$admin_transactions->setup();
97
		}
98
	}
99
100
	/**
101
	 * Gateway paths.
102
	 *
103
	 * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprGatewayFactory.php#L49
104
	 * @param string[] $paths Array with gateway paths.
105
	 * @return string[]
106
	 */
107
	public function gateway_paths( $paths ) {
108
		$paths[] = dirname( __FILE__ ) . '/../gateways/';
109
110
		return $paths;
111
	}
112
113
	/**
114
	 * Hide MemberPress columns for payments and subscriptions.
115
	 *
116
	 * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/controllers/MeprAppCtrl.php#L129-146
117
	 *
118
	 * @param string $post_type Registered post type.
119
	 *
120
	 * @return void
121
	 */
122
	public function post_type_columns_hide( $post_type ) {
123
		if ( ! in_array( $post_type, array( 'pronamic_payment', 'pronamic_pay_subscr' ), true ) ) {
124
			return;
125
		}
126
127
		remove_filter( 'manage_edit-' . $post_type . '_columns', 'MeprAppCtrl::columns' );
128
	}
129
130
	/**
131
	 * Payment redirect URL filter.
132
	 *
133
	 * @since 1.0.1
134
	 *
135
	 * @param string  $url     Payment redirect URL.
136
	 * @param Payment $payment Payment to redirect for.
137
	 *
138
	 * @return string
139
	 */
140
	public function redirect_url( $url, Payment $payment ) {
141
		global $transaction;
142
143
		$transaction_id = $payment->get_source_id();
144
145
		$transaction = new MeprTransaction( $transaction_id );
146
147
		switch ( $payment->get_status() ) {
148
			case PaymentStatus::CANCELLED:
149
			case PaymentStatus::EXPIRED:
150
			case PaymentStatus::FAILURE:
151
				$product = $transaction->product();
152
153
				$url = add_query_arg(
154
					array(
155
						'action'   => 'payment_form',
156
						'txn'      => $transaction->trans_num,
157
						'errors'   => array(
158
							__( 'Payment failed. Please try again.', 'pronamic_ideal' ),
159
						),
160
						'_wpnonce' => wp_create_nonce( 'mepr_payment_form' ),
161
					),
162
					$product->url()
163
				);
164
165
				break;
166
			case PaymentStatus::SUCCESS:
167
				// @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/models/MeprOptions.php#L768-782
168
				$mepr_options = MeprOptions::fetch();
169
170
				$product         = new MeprProduct( $transaction->product_id );
171
				$sanitized_title = sanitize_title( $product->post_title );
172
173
				$args = array(
174
					'membership_id' => $product->ID,
175
					'membership'    => $sanitized_title,
176
					'trans_num'     => $transaction->trans_num,
177
				);
178
179
				$url = $mepr_options->thankyou_page_url( http_build_query( $args ) );
180
181
				break;
182
			case PaymentStatus::OPEN:
183
			default:
184
				break;
185
		}
186
187
		return $url;
188
	}
189
190
	/**
191
	 * Update lead status of the specified payment.
192
	 *
193
	 * @param Payment $payment The payment whose status is updated.
194
	 * @return void
195
	 */
196
	public function status_update( Payment $payment ) {
197
		$transaction = new MeprTransaction( $payment->get_source_id() );
198
199
		if ( $payment->get_recurring() || empty( $transaction->id ) ) {
200
			$subscription_id = $payment->get_subscription()->get_source_id();
201
			$subscription    = new MeprSubscription( $subscription_id );
202
203
			// Same source ID and first transaction ID for recurring payment means we need to add a new transaction.
204
			if ( $payment->get_source_id() === $subscription->id ) {
205
				// First transaction.
206
				$first_txn = $subscription->first_txn();
207
208
				if ( false === $first_txn || ! ( $first_txn instanceof MeprTransaction ) ) {
209
					$first_txn             = new MeprTransaction();
210
					$first_txn->user_id    = $subscription->user_id;
211
					$first_txn->product_id = $subscription->product_id;
0 ignored issues
show
Bug Best Practice introduced by
The property product_id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
212
					$first_txn->coupon_id  = $subscription->coupon_id;
0 ignored issues
show
Bug Best Practice introduced by
The property coupon_id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
213
					$first_txn->gateway    = null;
214
				}
215
216
				// Transaction number.
217
				$trans_num = $payment->get_transaction_id();
218
219
				if ( empty( $trans_num ) ) {
220
					$trans_num = uniqid();
221
				}
222
223
				// New transaction.
224
				$end_date = $payment->get_end_date();
225
226
				if ( null === $end_date ) {
227
					$periods = $payment->get_periods();
228
229
					if ( ! empty( $periods ) ) {
230
						$end_date = $periods[0]->get_end_date();
231
					}
232
				}
233
234
				$expires_at = MeprUtils::ts_to_mysql_date( $end_date->getTimestamp(), 'Y-m-d 23:59:59' );
235
236
				// Determine gateway (can be different from original, i.e. via mandate update).
237
				$old_gateway = $subscription->gateway;
238
239
				$new_gateway = $old_gateway;
240
241
				$mepr_options = MeprOptions::fetch();
242
243
				$mepr_gateways = $mepr_options->payment_methods();
244
245
				foreach ( $mepr_gateways as $mepr_gateway ) {
246
					// Check valid gateway.
247
					if ( ! ( $mepr_gateway instanceof \MeprBaseRealGateway ) ) {
248
						continue;
249
					}
250
251
					// Check payment method.
252
					$payment_method = \str_replace( 'pronamic_pay_', '', $mepr_gateway->key );
253
254
					if ( $payment_method !== $payment->get_method() ) {
255
						continue;
256
					}
257
258
					// Set gateway, as payment method matches with this gateway.
259
					$new_gateway = $mepr_gateway->id;
260
261
					$subscription->gateway = $new_gateway;
262
263
					$subscription->store();
264
265
					// Set expires at to subscription expiration date.
266
					$expires_at = $subscription->expires_at;
267
				}
268
269
				$transaction                  = new MeprTransaction();
270
				$transaction->created_at      = $payment->post->post_date_gmt;
271
				$transaction->user_id         = $first_txn->user_id;
272
				$transaction->product_id      = $first_txn->product_id;
273
				$transaction->coupon_id       = $first_txn->coupon_id;
274
				$transaction->gateway         = $new_gateway;
275
				$transaction->trans_num       = $trans_num;
276
				$transaction->txn_type        = MeprTransaction::$payment_str;
277
				$transaction->status          = MeprTransaction::$pending_str;
278
				$transaction->expires_at      = $expires_at;
0 ignored issues
show
Bug Best Practice introduced by
The property expires_at does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
279
				$transaction->subscription_id = $subscription->id;
280
281
				$transaction->set_gross( $payment->get_total_amount()->get_value() );
282
283
				$transaction->store();
284
285
				// Set source ID.
286
				$payment->set_meta( 'source_id', $transaction->id );
287
288
				$payment->source_id = $transaction->id;
289
290
				if ( MeprSubscription::$active_str === $subscription->status && $old_gateway === $new_gateway ) {
291
					/*
292
					 * We create a 'confirmed' 'subscription_confirmation'
293
					 * transaction for a grace period of 15 days.
294
					 *
295
					 * Transactions of type "subscription_confirmation" with a
296
					 * status of "confirmed" are hidden in the UI, and are used
297
					 * as a way to provide free trial periods and the 24 hour
298
					 * grace period on a recurring subscription signup.
299
					 *
300
					 * @link https://docs.memberpress.com/article/219-where-is-data-stored.
301
					 */
302
					$subscription_confirmation                  = new MeprTransaction();
303
					$subscription_confirmation->created_at      = $payment->post->post_date_gmt;
304
					$subscription_confirmation->user_id         = $first_txn->user_id;
305
					$subscription_confirmation->product_id      = $first_txn->product_id;
306
					$subscription_confirmation->coupon_id       = $first_txn->coupon_id;
307
					$subscription_confirmation->gateway         = $new_gateway;
308
					$subscription_confirmation->trans_num       = $trans_num;
309
					$subscription_confirmation->txn_type        = MeprTransaction::$subscription_confirmation_str;
310
					$subscription_confirmation->status          = MeprTransaction::$confirmed_str;
311
					$subscription_confirmation->subscription_id = $subscription->id;
312
					$subscription_confirmation->expires_at      = MeprUtils::ts_to_mysql_date( strtotime( $payment->post->post_date_gmt ) + MeprUtils::days( 15 ), 'Y-m-d 23:59:59' );
313
314
					$subscription_confirmation->set_subtotal( 0.00 );
315
316
					$subscription_confirmation->store();
317
				}
318
			}
319
		}
320
321
		$should_update = ! MemberPress::transaction_has_status(
322
			$transaction,
323
			array(
324
				MeprTransaction::$failed_str,
325
				MeprTransaction::$complete_str,
326
			)
327
		);
328
329
		// Allow successful recurring payments to update failed transaction.
330
		if ( $payment->get_recurring() && PaymentStatus::SUCCESS === $payment->get_status() && MeprTransaction::$failed_str === $transaction->status ) {
331
			$should_update = true;
332
		}
333
334
		if ( $should_update ) {
335
			$gateway = new Gateway();
336
337
			$gateway->pronamic_payment = $payment;
338
			$gateway->mp_txn           = $transaction;
339
340
			switch ( $payment->get_status() ) {
341
				case PaymentStatus::FAILURE:
342
					$gateway->record_payment_failure();
343
344
					// Set subscription 'On Hold' to prevent subsequent
345
					// successful subscriptions from awaking subscription.
346
					if ( ! $payment->get_recurring() ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $payment->get_recurring() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
347
						$subscription = $payment->get_subscription();
348
349
						if ( null !== $subscription ) {
350
							$subscription->set_status( SubscriptionStatus::ON_HOLD );
351
						}
352
					}
353
354
					break;
355
				case PaymentStatus::CANCELLED:
356
				case PaymentStatus::EXPIRED:
357
					$gateway->record_payment_failure();
358
359
					break;
360
				case PaymentStatus::SUCCESS:
361
					if ( $payment->get_recurring() ) {
362
						$gateway->record_subscription_payment();
363
					} else {
364
						$gateway->record_payment();
365
					}
366
367
					break;
368
				case PaymentStatus::OPEN:
369
				default:
370
					break;
371
			}
372
		}
373
	}
374
375
	/**
376
	 * Subscription deleted.
377
	 *
378
	 * @param int $subscription_id MemberPress subscription id.
379
	 * @return void
380
	 */
381
	public function subscription_pre_delete( $subscription_id ) {
382
		$subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $subscription_id );
383
384
		if ( ! $subscription ) {
385
			return;
386
		}
387
388
		// Add note.
389
		$note = sprintf(
390
			/* translators: %s: MemberPress */
391
			__( '%s subscription deleted.', 'pronamic_ideal' ),
392
			__( 'MemberPress', 'pronamic_ideal' )
393
		);
394
395
		$subscription->add_note( $note );
396
397
		// The status of canceled or completed subscriptions will not be changed automatically.
398
		if ( ! in_array( $subscription->get_status(), array( SubscriptionStatus::CANCELLED, SubscriptionStatus::COMPLETED ), true ) ) {
399
			$subscription->set_status( SubscriptionStatus::CANCELLED );
400
401
			$subscription->save();
402
		}
403
	}
404
405
	/**
406
	 * Subscription email parameters.
407
	 *
408
	 * @param array<string, string> $params                   Email parameters.
409
	 * @param MeprSubscription      $memberpress_subscription MemberPress subscription.
410
	 * @return array<string, string>
411
	 */
412
	public function subscription_email_params( $params, MeprSubscription $memberpress_subscription ) {
413
		$subscriptions = \get_pronamic_subscriptions_by_source( 'memberpress', $memberpress_subscription->id );
414
415
		if ( empty( $subscriptions ) ) {
416
			return $params;
417
		}
418
419
		$subscription = reset( $subscriptions );
420
421
		// Add parameters.
422
		$next_payment_date = $subscription->get_next_payment_date();
423
424
		return \array_merge(
425
			$params,
426
			array(
427
				'pronamic_subscription_id'           => (string) $subscription->get_id(),
428
				'pronamic_subscription_cancel_url'   => $subscription->get_cancel_url(),
429
				'pronamic_subscription_renewal_url'  => $subscription->get_renewal_url(),
430
				'pronamic_subscription_renewal_date' => null === $next_payment_date ? '' : \date_i18n( \get_option( 'date_format' ), $next_payment_date->getTimestamp() ),
0 ignored issues
show
Bug introduced by
It seems like get_option('date_format') can also be of type false; however, parameter $format of date_i18n() 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

430
				'pronamic_subscription_renewal_date' => null === $next_payment_date ? '' : \date_i18n( /** @scrutinizer ignore-type */ \get_option( 'date_format' ), $next_payment_date->getTimestamp() ),
Loading history...
431
			)
432
		);
433
	}
434
435
	/**
436
	 * Transaction email parameters.
437
	 *
438
	 * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/helpers/MeprTransactionsHelper.php#L233
439
	 * @param array<string, string> $params      Parameters.
440
	 * @param MeprTransaction       $transaction MemberPress transaction.
441
	 * @return array<string, string>
442
	 */
443
	public function transaction_email_params( $params, MeprTransaction $transaction ) {
444
		$payments = \get_pronamic_payments_by_source( 'memberpress', $transaction->id );
445
446
		if ( null === $payments ) {
0 ignored issues
show
introduced by
The condition null === $payments is always false.
Loading history...
447
			return $params;
448
		}
449
450
		$payment = \reset( $payments );
451
452
		if ( false === $payment ) {
453
			return $params;
454
		}
455
456
		// Get subscription.
457
		$periods = $payment->get_periods();
458
459
		if ( null === $periods ) {
460
			return $params;
461
		}
462
463
		$period = \reset( $periods );
464
465
		if ( false === $period ) {
466
			return $params;
467
		}
468
469
		$subscription = $period->get_phase()->get_subscription();
470
471
		// Add parameters.
472
		$memberpress_subscription = new MeprSubscription( $subscription->get_source_id() );
473
474
		return $this->subscription_email_params( $params, $memberpress_subscription );
475
	}
476
477
	/**
478
	 * Source text.
479
	 *
480
	 * @param string  $text    Source text.
481
	 * @param Payment $payment Payment to create the source text for.
482
	 *
483
	 * @return string
484
	 */
485
	public function source_text( $text, Payment $payment ) {
486
		$text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />';
487
488
		$text .= sprintf(
489
			'<a href="%s">%s</a>',
490
			add_query_arg(
491
				array(
492
					'page'   => 'memberpress-trans',
493
					'action' => 'edit',
494
					'id'     => $payment->source_id,
495
				),
496
				admin_url( 'admin.php' )
497
			),
498
			/* translators: %s: payment source id */
499
			sprintf( __( 'Transaction %s', 'pronamic_ideal' ), $payment->source_id )
500
		);
501
502
		return $text;
503
	}
504
505
	/**
506
	 * Subscription source text.
507
	 *
508
	 * @param string       $text         Source text.
509
	 * @param Subscription $subscription Subscription to create the source text for.
510
	 *
511
	 * @return string
512
	 */
513
	public function subscription_source_text( $text, Subscription $subscription ) {
514
		$text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />';
515
516
		$text .= sprintf(
517
			'<a href="%s">%s</a>',
518
			add_query_arg(
519
				array(
520
					'page'         => 'memberpress-subscriptions',
521
					'subscription' => $subscription->source_id,
522
				),
523
				admin_url( 'admin.php' )
524
			),
525
			/* translators: %s: payment source id */
526
			sprintf( __( 'Subscription %s', 'pronamic_ideal' ), $subscription->source_id )
527
		);
528
529
		return $text;
530
	}
531
532
	/**
533
	 * Source description.
534
	 *
535
	 * @param string  $description Description.
536
	 * @param Payment $payment     Payment to create the description for.
537
	 *
538
	 * @return string
539
	 */
540
	public function source_description( $description, Payment $payment ) {
541
		return __( 'MemberPress Transaction', 'pronamic_ideal' );
542
	}
543
544
	/**
545
	 * Subscription source description.
546
	 *
547
	 * @param string       $description  Description.
548
	 * @param Subscription $subscription Subscription to create the description for.
549
	 *
550
	 * @return string
551
	 */
552
	public function subscription_source_description( $description, Subscription $subscription ) {
553
		return __( 'MemberPress Subscription', 'pronamic_ideal' );
554
	}
555
556
	/**
557
	 * Source URL.
558
	 *
559
	 * @param string  $url     URL.
560
	 * @param Payment $payment The payment to create the source URL for.
561
	 *
562
	 * @return string
563
	 */
564
	public function source_url( $url, Payment $payment ) {
565
		$url = add_query_arg(
566
			array(
567
				'page'   => 'memberpress-trans',
568
				'action' => 'edit',
569
				'id'     => $payment->source_id,
570
			),
571
			admin_url( 'admin.php' )
572
		);
573
574
		return $url;
575
	}
576
577
	/**
578
	 * Subscription source URL.
579
	 *
580
	 * @param string       $url          URL.
581
	 * @param Subscription $subscription Subscription.
582
	 *
583
	 * @return string
584
	 */
585
	public function subscription_source_url( $url, Subscription $subscription ) {
586
		$url = add_query_arg(
587
			array(
588
				'page'         => 'memberpress-subscriptions',
589
				'subscription' => $subscription->source_id,
590
			),
591
			admin_url( 'admin.php' )
592
		);
593
594
		return $url;
595
	}
596
597
	/**
598
	 * MemberPress update subscription.
599
	 *
600
	 * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/controllers/MeprSubscriptionsCtrl.php#L92-L111
601
	 * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/models/MeprSubscription.php#L100-L123
602
	 * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/models/MeprSubscription.php#L112
603
	 * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/models/MeprSubscription.php#L122
604
	 * @param string           $status_old               Old status identifier.
605
	 * @param string           $status_new               New status identifier.
606
	 * @param MeprSubscription $memberpress_subscription MemberPress subscription object.
607
	 * @return void
608
	 */
609
	public function memberpress_subscription_transition_status( $status_old, $status_new, $memberpress_subscription ) {
610
		$subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $memberpress_subscription->id );
611
612
		if ( empty( $subscription ) ) {
613
			return;
614
		}
615
616
		$status = SubscriptionStatuses::transform( $status_new );
617
618
		if ( null === $status ) {
619
			return;
620
		}
621
622
		$subscription->set_status( $status );
623
624
		$subscription->save();
625
	}
626
}
627