-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update RCP membership status on subscription status update (fix #13).
- Loading branch information
Showing
2 changed files
with
82 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
use Pronamic\WordPress\Pay\Payments\PaymentStatus as Core_PaymentStatus; | ||
use Pronamic\WordPress\Pay\Payments\Payment; | ||
use Pronamic\WordPress\Pay\Subscriptions\Subscription; | ||
use Pronamic\WordPress\Pay\Subscriptions\SubscriptionStatus; | ||
use RCP_Membership; | ||
use RCP_Payments; | ||
use WP_Query; | ||
|
@@ -70,17 +71,17 @@ public function __construct( $args = [] ) { | |
* @return void | ||
*/ | ||
public function setup() { | ||
add_filter( 'pronamic_payment_source_description', [ $this, 'payment_source_description' ], 10, 2 ); | ||
add_filter( 'pronamic_payment_source_url', [ $this, 'payment_source_url' ], 10, 2 ); | ||
add_filter( 'pronamic_subscription_source_description', [ $this, 'subscription_source_description' ], 10, 2 ); | ||
add_filter( 'pronamic_subscription_source_url', [ $this, 'subscription_source_url' ], 10, 2 ); | ||
\add_filter( 'pronamic_payment_source_description', [ $this, 'payment_source_description' ], 10, 2 ); | ||
\add_filter( 'pronamic_payment_source_url', [ $this, 'payment_source_url' ], 10, 2 ); | ||
\add_filter( 'pronamic_subscription_source_description', [ $this, 'subscription_source_description' ], 10, 2 ); | ||
\add_filter( 'pronamic_subscription_source_url', [ $this, 'subscription_source_url' ], 10, 2 ); | ||
|
||
/* | ||
* The Restrict Content Pro plugin gets bootstrapped with priority `4`. | ||
* | ||
* @link https://gitlab.com/pronamic-plugins/restrict-content-pro/-/blob/3.3.3/restrict-content-pro.php#L119 | ||
*/ | ||
add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ], 5 ); | ||
\add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ], 5 ); | ||
} | ||
|
||
/** | ||
|
@@ -101,25 +102,26 @@ public function plugins_loaded() { | |
* @link https://gitlab.com/pronamic-plugins/restrict-content-pro/blob/3.2.3/includes/class-restrict-content-pro.php#L199-215 | ||
* @link https://github.com/wp-pay/core/blob/2.2.0/src/Admin/Install.php#L65 | ||
*/ | ||
add_action( 'admin_init', [ $this, 'admin_init_upgrades_executable' ], 4 ); | ||
\add_action( 'admin_init', [ $this, 'admin_init_upgrades_executable' ], 4 ); | ||
|
||
add_filter( 'rcp_payment_gateways', [ $this, 'register_pronamic_gateways' ] ); | ||
add_action( 'rcp_payments_settings', [ $this, 'payments_settings' ] ); | ||
add_action( 'rcp_transition_membership_status', [ $this, 'rcp_transition_membership_status' ], 10, 3 ); | ||
\add_filter( 'rcp_payment_gateways', [ $this, 'register_pronamic_gateways' ] ); | ||
\add_action( 'rcp_payments_settings', [ $this, 'payments_settings' ] ); | ||
\add_action( 'rcp_transition_membership_status', [ $this, 'rcp_transition_membership_status' ], 10, 3 ); | ||
|
||
add_filter( 'rcp_membership_can_cancel', [ $this, 'rcp_membership_can_cancel' ], 10, 3 ); | ||
add_filter( 'rcp_membership_payment_profile_cancelled', [ $this, 'rcp_membership_payment_profile_cancelled' ], 10, 5 ); | ||
\add_filter( 'rcp_membership_can_cancel', [ $this, 'rcp_membership_can_cancel' ], 10, 3 ); | ||
\add_filter( 'rcp_membership_payment_profile_cancelled', [ $this, 'rcp_membership_payment_profile_cancelled' ], 10, 5 ); | ||
|
||
add_action( 'pronamic_payment_status_update_rcp_payment', [ $this, 'payment_status_update' ], 10, 1 ); | ||
add_filter( 'pronamic_payment_redirect_url', [ $this, 'payment_redirect_url' ], 10, 2 ); | ||
add_filter( 'pronamic_payment_source_text_rcp_payment', [ $this, 'payment_source_text' ], 10, 2 ); | ||
\add_action( 'pronamic_payment_status_update_rcp_payment', [ $this, 'payment_status_update' ], 10, 1 ); | ||
\add_filter( 'pronamic_payment_redirect_url', [ $this, 'payment_redirect_url' ], 10, 2 ); | ||
\add_filter( 'pronamic_payment_source_text_rcp_payment', [ $this, 'payment_source_text' ], 10, 2 ); | ||
|
||
add_filter( 'pronamic_subscription_source_text_rcp_membership', [ $this, 'subscription_source_text' ], 10, 2 ); | ||
\add_action( 'pronamic_subscription_status_update_rcp_membership', [ $this, 'subscription_status_update' ], 10, 1 ); | ||
\add_filter( 'pronamic_subscription_source_text_rcp_membership', [ $this, 'subscription_source_text' ], 10, 2 ); | ||
|
||
add_action( 'pronamic_pay_new_payment', [ $this, 'new_payment' ] ); | ||
\add_action( 'pronamic_pay_new_payment', [ $this, 'new_payment' ] ); | ||
|
||
add_action( 'rcp_edit_membership_after', [ $this, 'rcp_edit_membership_after' ] ); | ||
add_action( 'rcp_edit_payment_after', [ $this, 'rcp_edit_payment_after' ] ); | ||
\add_action( 'rcp_edit_membership_after', [ $this, 'rcp_edit_membership_after' ] ); | ||
\add_action( 'rcp_edit_payment_after', [ $this, 'rcp_edit_payment_after' ] ); | ||
|
||
/** | ||
* Filter the subscription next payment delivery date. | ||
|
@@ -143,7 +145,7 @@ private function are_upgrades_executable() { | |
* | ||
* @link https://gitlab.com/pronamic-plugins/restrict-content-pro/blob/3.2.3/includes/class-restrict-content-pro.php#L199-215 | ||
*/ | ||
if ( ! is_admin() ) { | ||
if ( ! \is_admin() ) { | ||
throw new \Exception( 'Can not run `are_upgrades_executable` function outside the WordPress admin environment.' ); | ||
} | ||
|
||
|
@@ -385,7 +387,7 @@ public function payment_status_update( Payment $payment ) { | |
$rcp_payments->update( $rcp_payment_id, $rcp_payment_data ); | ||
|
||
// Renew membership if not active. | ||
$rcp_membership = rcp_get_membership( $rcp_payment->membership_id ); | ||
$rcp_membership = \rcp_get_membership( $rcp_payment->membership_id ); | ||
|
||
if ( MembershipStatus::ACTIVE !== $rcp_membership->get_status() ) { | ||
$expiration = ''; | ||
|
@@ -414,6 +416,37 @@ public function payment_status_update( Payment $payment ) { | |
} | ||
} | ||
|
||
/** | ||
* Update RCP membership status on subscription status update. | ||
* | ||
* @param Subscription $pronamic_subscription Subscription. | ||
* @return void | ||
*/ | ||
public function subscription_status_update( Subscription $pronamic_subscription ) { | ||
// Check status. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
if ( SubscriptionStatus::COMPLETED === $pronamic_subscription->get_status() ) { | ||
return; | ||
This comment has been minimized.
Sorry, something went wrong.
remcotolsma
Member
|
||
} | ||
|
||
// Get Restrict Content Pro membership. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
$membership_id = $pronamic_subscription->get_source_id(); | ||
|
||
$rcp_membership = \rcp_get_membership( $membership_id ); | ||
|
||
if ( false === $rcp_membership ) { | ||
return; | ||
} | ||
|
||
// Set status. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
$status = MembershipStatus::transform_from_pronamic( $pronamic_subscription->get_status() ); | ||
|
||
if ( null === $status ) { | ||
return; | ||
} | ||
|
||
$rcp_membership->set_status( $status ); | ||
} | ||
|
||
/** | ||
* Restrict Content Pro transition membership status. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment has no added value?