 wp-pay-extensions    /
                    memberpress
                      wp-pay-extensions    /
                    memberpress
                
                            | 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_action( 'pronamic_pay_new_payment', array( $this, 'maybe_create_memberpress_transaction' ) ); | ||
| 76 | |||
| 77 | \add_filter( 'pronamic_subscription_source_text_' . self::SLUG, array( $this, 'subscription_source_text' ), 10, 2 ); | ||
| 78 | \add_filter( 'pronamic_subscription_source_url_' . self::SLUG, array( $this, 'subscription_source_url' ), 10, 2 ); | ||
| 79 | \add_filter( 'pronamic_payment_source_text_' . self::SLUG, array( $this, 'source_text' ), 10, 2 ); | ||
| 80 | \add_filter( 'pronamic_payment_source_url_' . self::SLUG, array( $this, 'source_url' ), 10, 2 ); | ||
| 81 | |||
| 82 | \add_action( 'mepr_subscription_pre_delete', array( $this, 'subscription_pre_delete' ), 10, 1 ); | ||
| 83 | |||
| 84 | \add_action( 'mepr_subscription_transition_status', array( $this, 'memberpress_subscription_transition_status' ), 10, 3 ); | ||
| 85 | |||
| 86 | // MemberPress subscription email parameters. | ||
| 87 | \add_filter( 'mepr_subscription_email_params', array( $this, 'subscription_email_params' ), 10, 2 ); | ||
| 88 | \add_filter( 'mepr_transaction_email_params', array( $this, 'transaction_email_params' ), 10, 2 ); | ||
| 89 | |||
| 90 | // Hide MemberPress columns for payments and subscriptions. | ||
| 91 | \add_action( 'registered_post_type', array( $this, 'post_type_columns_hide' ), 15, 1 ); | ||
| 92 | |||
| 93 | 		if ( \is_admin() ) { | ||
| 94 | $admin_subscriptions = new Admin\AdminSubscriptions(); | ||
| 95 | $admin_transactions = new Admin\AdminTransactions(); | ||
| 96 | |||
| 97 | $admin_subscriptions->setup(); | ||
| 98 | $admin_transactions->setup(); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | /** | ||
| 103 | * Gateway paths. | ||
| 104 | * | ||
| 105 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/lib/MeprGatewayFactory.php#L49 | ||
| 106 | * @param string[] $paths Array with gateway paths. | ||
| 107 | * @return string[] | ||
| 108 | */ | ||
| 109 | 	public function gateway_paths( $paths ) { | ||
| 110 | $paths[] = dirname( __FILE__ ) . '/../gateways/'; | ||
| 111 | |||
| 112 | return $paths; | ||
| 113 | } | ||
| 114 | |||
| 115 | /** | ||
| 116 | * Hide MemberPress columns for payments and subscriptions. | ||
| 117 | * | ||
| 118 | * @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/controllers/MeprAppCtrl.php#L129-146 | ||
| 119 | * | ||
| 120 | * @param string $post_type Registered post type. | ||
| 121 | * | ||
| 122 | * @return void | ||
| 123 | */ | ||
| 124 | 	public function post_type_columns_hide( $post_type ) { | ||
| 125 | 		if ( ! in_array( $post_type, array( 'pronamic_payment', 'pronamic_pay_subscr' ), true ) ) { | ||
| 126 | return; | ||
| 127 | } | ||
| 128 | |||
| 129 | remove_filter( 'manage_edit-' . $post_type . '_columns', 'MeprAppCtrl::columns' ); | ||
| 130 | } | ||
| 131 | |||
| 132 | /** | ||
| 133 | * Payment redirect URL filter. | ||
| 134 | * | ||
| 135 | * @since 1.0.1 | ||
| 136 | * | ||
| 137 | * @param string $url Payment redirect URL. | ||
| 138 | * @param Payment $payment Payment to redirect for. | ||
| 139 | * | ||
| 140 | * @return string | ||
| 141 | */ | ||
| 142 | 	public function redirect_url( $url, Payment $payment ) { | ||
| 143 | global $transaction; | ||
| 144 | |||
| 145 | $transaction_id = $payment->get_source_id(); | ||
| 146 | |||
| 147 | $transaction = new MeprTransaction( $transaction_id ); | ||
| 148 | |||
| 149 | 		switch ( $payment->get_status() ) { | ||
| 150 | case PaymentStatus::CANCELLED: | ||
| 151 | case PaymentStatus::EXPIRED: | ||
| 152 | case PaymentStatus::FAILURE: | ||
| 153 | $product = $transaction->product(); | ||
| 154 | |||
| 155 | $url = add_query_arg( | ||
| 156 | array( | ||
| 157 | 'action' => 'payment_form', | ||
| 158 | 'txn' => $transaction->trans_num, | ||
| 159 | 'errors' => array( | ||
| 160 | __( 'Payment failed. Please try again.', 'pronamic_ideal' ), | ||
| 161 | ), | ||
| 162 | '_wpnonce' => wp_create_nonce( 'mepr_payment_form' ), | ||
| 163 | ), | ||
| 164 | $product->url() | ||
| 165 | ); | ||
| 166 | |||
| 167 | break; | ||
| 168 | case PaymentStatus::SUCCESS: | ||
| 169 | // @link https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/models/MeprOptions.php#L768-782 | ||
| 170 | $mepr_options = MeprOptions::fetch(); | ||
| 171 | |||
| 172 | $product = new MeprProduct( $transaction->product_id ); | ||
| 173 | $sanitized_title = sanitize_title( $product->post_title ); | ||
| 174 | |||
| 175 | $args = array( | ||
| 176 | 'membership_id' => $product->ID, | ||
| 177 | 'membership' => $sanitized_title, | ||
| 178 | 'trans_num' => $transaction->trans_num, | ||
| 179 | ); | ||
| 180 | |||
| 181 | $url = $mepr_options->thankyou_page_url( http_build_query( $args ) ); | ||
| 182 | |||
| 183 | break; | ||
| 184 | case PaymentStatus::OPEN: | ||
| 185 | default: | ||
| 186 | break; | ||
| 187 | } | ||
| 188 | |||
| 189 | return $url; | ||
| 190 | } | ||
| 191 | |||
| 192 | /** | ||
| 193 | * Maybe create create MemberPress transaction for the Pronamic payment. | ||
| 194 | * | ||
| 195 | * @todo Implement. | ||
| 196 | * @param Payment $payment Payment. | ||
| 197 | * @return void | ||
| 198 | */ | ||
| 199 | 	public function maybe_create_memberpress_transaction( Payment $payment ) { | ||
| 200 | |||
| 201 | } | ||
| 202 | |||
| 203 | /** | ||
| 204 | * Update lead status of the specified payment. | ||
| 205 | * | ||
| 206 | * @param Payment $payment The payment whose status is updated. | ||
| 207 | * @return void | ||
| 208 | */ | ||
| 209 | 	public function status_update( Payment $payment ) { | ||
| 210 | $payment_source_id = $payment->get_source_id(); | ||
| 211 | |||
| 212 | $memberpress_transaction = MemberPress::get_transaction_by_id( $payment_source_id ); | ||
| 213 | |||
| 214 | /** | ||
| 215 | * If we can't find a MemberPress transaction by the payment source ID | ||
| 216 | * we can't update the MemberPress transaction, bail out early. | ||
| 217 | */ | ||
| 218 | 		if ( null === $memberpress_transaction ) { | ||
| 219 | return; | ||
| 220 | } | ||
| 221 | |||
| 222 | /** | ||
| 223 | * We don't update MemberPress transactions that already have the | ||
| 224 | * status 'failed' or 'complete'. | ||
| 225 | */ | ||
| 226 | if ( MemberPress::transaction_has_status( | ||
| 227 | $memberpress_transaction, | ||
| 228 | array( | ||
| 229 | MeprTransaction::$failed_str, | ||
| 230 | MeprTransaction::$complete_str, | ||
| 231 | ) | ||
| 232 | 		) ) { | ||
| 233 | return; | ||
| 234 | } | ||
| 235 | |||
| 236 | /** | ||
| 237 | * Payment method. | ||
| 238 | * | ||
| 239 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/models/MeprTransaction.php#L634-L637 | ||
| 240 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/models/MeprOptions.php#L798-L811 | ||
| 241 | */ | ||
| 242 | $memberpress_gateway = $memberpress_transaction->payment_method(); | ||
| 243 | |||
| 244 | 		if ( ! $memberpress_gateway instanceof Gateway ) { | ||
| 245 | return; | ||
| 246 | } | ||
| 247 | |||
| 248 | $memberpress_gateway->set_record_data( $payment, $memberpress_transaction ); | ||
| 249 | |||
| 250 | 		switch ( $payment->get_status() ) { | ||
| 251 | case PaymentStatus::FAILURE: | ||
| 252 | case PaymentStatus::CANCELLED: | ||
| 253 | case PaymentStatus::EXPIRED: | ||
| 254 | $memberpress_gateway->record_payment_failure(); | ||
| 255 | |||
| 256 | break; | ||
| 257 | case PaymentStatus::SUCCESS: | ||
| 258 | 				if ( $payment->get_recurring() ) { | ||
| 259 | $memberpress_gateway->record_subscription_payment(); | ||
| 260 | 				} else { | ||
| 261 | $memberpress_gateway->record_payment(); | ||
| 262 | } | ||
| 263 | |||
| 264 | break; | ||
| 265 | case PaymentStatus::OPEN: | ||
| 266 | default: | ||
| 267 | break; | ||
| 268 | } | ||
| 269 | } | ||
| 270 | |||
| 271 | /** | ||
| 272 | * Subscription deleted. | ||
| 273 | * | ||
| 274 | * @param int $subscription_id MemberPress subscription id. | ||
| 275 | * @return void | ||
| 276 | */ | ||
| 277 | 	public function subscription_pre_delete( $subscription_id ) { | ||
| 278 | $subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $subscription_id ); | ||
| 279 | |||
| 280 | 		if ( ! $subscription ) { | ||
| 281 | return; | ||
| 282 | } | ||
| 283 | |||
| 284 | // Add note. | ||
| 285 | $note = sprintf( | ||
| 286 | /* translators: %s: MemberPress */ | ||
| 287 | __( '%s subscription deleted.', 'pronamic_ideal' ), | ||
| 288 | __( 'MemberPress', 'pronamic_ideal' ) | ||
| 289 | ); | ||
| 290 | |||
| 291 | $subscription->add_note( $note ); | ||
| 292 | |||
| 293 | // The status of canceled or completed subscriptions will not be changed automatically. | ||
| 294 | 		if ( ! in_array( $subscription->get_status(), array( SubscriptionStatus::CANCELLED, SubscriptionStatus::COMPLETED ), true ) ) { | ||
| 295 | $subscription->set_status( SubscriptionStatus::CANCELLED ); | ||
| 296 | |||
| 297 | $subscription->save(); | ||
| 298 | } | ||
| 299 | } | ||
| 300 | |||
| 301 | /** | ||
| 302 | * Subscription email parameters. | ||
| 303 | * | ||
| 304 | * @param array<string, string> $params Email parameters. | ||
| 305 | * @param MeprSubscription $memberpress_subscription MemberPress subscription. | ||
| 306 | * @return array<string, string> | ||
| 307 | */ | ||
| 308 | 	public function subscription_email_params( $params, MeprSubscription $memberpress_subscription ) { | ||
| 309 | $subscriptions = \get_pronamic_subscriptions_by_source( 'memberpress', $memberpress_subscription->id ); | ||
| 310 | |||
| 311 | 		if ( empty( $subscriptions ) ) { | ||
| 312 | return $params; | ||
| 313 | } | ||
| 314 | |||
| 315 | $subscription = reset( $subscriptions ); | ||
| 316 | |||
| 317 | // Add parameters. | ||
| 318 | $next_payment_date = $subscription->get_next_payment_date(); | ||
| 319 | |||
| 320 | return \array_merge( | ||
| 321 | $params, | ||
| 322 | array( | ||
| 323 | 'pronamic_subscription_id' => (string) $subscription->get_id(), | ||
| 324 | 'pronamic_subscription_cancel_url' => $subscription->get_cancel_url(), | ||
| 325 | 'pronamic_subscription_renewal_url' => $subscription->get_renewal_url(), | ||
| 326 | '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  
  Loading history... | |||
| 327 | ) | ||
| 328 | ); | ||
| 329 | } | ||
| 330 | |||
| 331 | /** | ||
| 332 | * Transaction email parameters. | ||
| 333 | * | ||
| 334 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/helpers/MeprTransactionsHelper.php#L233 | ||
| 335 | * @param array<string, string> $params Parameters. | ||
| 336 | * @param MeprTransaction $transaction MemberPress transaction. | ||
| 337 | * @return array<string, string> | ||
| 338 | */ | ||
| 339 | 	public function transaction_email_params( $params, MeprTransaction $transaction ) { | ||
| 340 | $payments = \get_pronamic_payments_by_source( 'memberpress', $transaction->id ); | ||
| 341 | |||
| 342 | 		if ( null === $payments ) { | ||
| 343 | return $params; | ||
| 344 | } | ||
| 345 | |||
| 346 | $payment = \reset( $payments ); | ||
| 347 | |||
| 348 | 		if ( false === $payment ) { | ||
| 349 | return $params; | ||
| 350 | } | ||
| 351 | |||
| 352 | // Get subscription. | ||
| 353 | $periods = $payment->get_periods(); | ||
| 354 | |||
| 355 | 		if ( null === $periods ) { | ||
| 356 | return $params; | ||
| 357 | } | ||
| 358 | |||
| 359 | $period = \reset( $periods ); | ||
| 360 | |||
| 361 | 		if ( false === $period ) { | ||
| 362 | return $params; | ||
| 363 | } | ||
| 364 | |||
| 365 | $subscription = $period->get_phase()->get_subscription(); | ||
| 366 | |||
| 367 | // Add parameters. | ||
| 368 | $memberpress_subscription = new MeprSubscription( $subscription->get_source_id() ); | ||
| 369 | |||
| 370 | return $this->subscription_email_params( $params, $memberpress_subscription ); | ||
| 371 | } | ||
| 372 | |||
| 373 | /** | ||
| 374 | * Source text. | ||
| 375 | * | ||
| 376 | * @param string $text Source text. | ||
| 377 | * @param Payment $payment Payment to create the source text for. | ||
| 378 | * | ||
| 379 | * @return string | ||
| 380 | */ | ||
| 381 | 	public function source_text( $text, Payment $payment ) { | ||
| 382 | $text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />'; | ||
| 383 | |||
| 384 | $text .= sprintf( | ||
| 385 | '<a href="%s">%s</a>', | ||
| 386 | add_query_arg( | ||
| 387 | array( | ||
| 388 | 'page' => 'memberpress-trans', | ||
| 389 | 'action' => 'edit', | ||
| 390 | 'id' => $payment->source_id, | ||
| 391 | ), | ||
| 392 | admin_url( 'admin.php' ) | ||
| 393 | ), | ||
| 394 | /* translators: %s: payment source id */ | ||
| 395 | sprintf( __( 'Transaction %s', 'pronamic_ideal' ), $payment->source_id ) | ||
| 396 | ); | ||
| 397 | |||
| 398 | return $text; | ||
| 399 | } | ||
| 400 | |||
| 401 | /** | ||
| 402 | * Subscription source text. | ||
| 403 | * | ||
| 404 | * @param string $text Source text. | ||
| 405 | * @param Subscription $subscription Subscription to create the source text for. | ||
| 406 | * | ||
| 407 | * @return string | ||
| 408 | */ | ||
| 409 | 	public function subscription_source_text( $text, Subscription $subscription ) { | ||
| 410 | $text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />'; | ||
| 411 | |||
| 412 | $text .= sprintf( | ||
| 413 | '<a href="%s">%s</a>', | ||
| 414 | add_query_arg( | ||
| 415 | array( | ||
| 416 | 'page' => 'memberpress-subscriptions', | ||
| 417 | 'subscription' => $subscription->source_id, | ||
| 418 | ), | ||
| 419 | admin_url( 'admin.php' ) | ||
| 420 | ), | ||
| 421 | /* translators: %s: payment source id */ | ||
| 422 | sprintf( __( 'Subscription %s', 'pronamic_ideal' ), $subscription->source_id ) | ||
| 423 | ); | ||
| 424 | |||
| 425 | return $text; | ||
| 426 | } | ||
| 427 | |||
| 428 | /** | ||
| 429 | * Source description. | ||
| 430 | * | ||
| 431 | * @param string $description Description. | ||
| 432 | * @param Payment $payment Payment to create the description for. | ||
| 433 | * | ||
| 434 | * @return string | ||
| 435 | */ | ||
| 436 | 	public function source_description( $description, Payment $payment ) { | ||
| 437 | return __( 'MemberPress Transaction', 'pronamic_ideal' ); | ||
| 438 | } | ||
| 439 | |||
| 440 | /** | ||
| 441 | * Subscription source description. | ||
| 442 | * | ||
| 443 | * @param string $description Description. | ||
| 444 | * @param Subscription $subscription Subscription to create the description for. | ||
| 445 | * | ||
| 446 | * @return string | ||
| 447 | */ | ||
| 448 | 	public function subscription_source_description( $description, Subscription $subscription ) { | ||
| 449 | return __( 'MemberPress Subscription', 'pronamic_ideal' ); | ||
| 450 | } | ||
| 451 | |||
| 452 | /** | ||
| 453 | * Source URL. | ||
| 454 | * | ||
| 455 | * @param string $url URL. | ||
| 456 | * @param Payment $payment The payment to create the source URL for. | ||
| 457 | * | ||
| 458 | * @return string | ||
| 459 | */ | ||
| 460 | 	public function source_url( $url, Payment $payment ) { | ||
| 461 | $url = add_query_arg( | ||
| 462 | array( | ||
| 463 | 'page' => 'memberpress-trans', | ||
| 464 | 'action' => 'edit', | ||
| 465 | 'id' => $payment->source_id, | ||
| 466 | ), | ||
| 467 | admin_url( 'admin.php' ) | ||
| 468 | ); | ||
| 469 | |||
| 470 | return $url; | ||
| 471 | } | ||
| 472 | |||
| 473 | /** | ||
| 474 | * Subscription source URL. | ||
| 475 | * | ||
| 476 | * @param string $url URL. | ||
| 477 | * @param Subscription $subscription Subscription. | ||
| 478 | * | ||
| 479 | * @return string | ||
| 480 | */ | ||
| 481 | 	public function subscription_source_url( $url, Subscription $subscription ) { | ||
| 482 | $url = add_query_arg( | ||
| 483 | array( | ||
| 484 | 'page' => 'memberpress-subscriptions', | ||
| 485 | 'subscription' => $subscription->source_id, | ||
| 486 | ), | ||
| 487 | admin_url( 'admin.php' ) | ||
| 488 | ); | ||
| 489 | |||
| 490 | return $url; | ||
| 491 | } | ||
| 492 | |||
| 493 | /** | ||
| 494 | * MemberPress update subscription. | ||
| 495 | * | ||
| 496 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/controllers/MeprSubscriptionsCtrl.php#L92-L111 | ||
| 497 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/models/MeprSubscription.php#L100-L123 | ||
| 498 | * @link https://github.com/wp-premium/memberpress-basic/blob/1.3.18/app/models/MeprSubscription.php#L112 | ||
| 499 | * @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/models/MeprSubscription.php#L122 | ||
| 500 | * @param string $status_old Old status identifier. | ||
| 501 | * @param string $status_new New status identifier. | ||
| 502 | * @param MeprSubscription $memberpress_subscription MemberPress subscription object. | ||
| 503 | * @return void | ||
| 504 | */ | ||
| 505 | 	public function memberpress_subscription_transition_status( $status_old, $status_new, $memberpress_subscription ) { | ||
| 506 | $subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $memberpress_subscription->id ); | ||
| 507 | |||
| 508 | 		if ( empty( $subscription ) ) { | ||
| 509 | return; | ||
| 510 | } | ||
| 511 | |||
| 512 | $status = SubscriptionStatuses::transform( $status_new ); | ||
| 513 | |||
| 514 | 		if ( null === $status ) { | ||
| 515 | return; | ||
| 516 | } | ||
| 517 | |||
| 518 | $subscription->set_status( $status ); | ||
| 519 | |||
| 520 | $subscription->save(); | ||
| 521 | } | ||
| 522 | } | ||
| 523 | 
