Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renewing subscriptions with next payment date in past (ex missed payment) can cause new profile start date in past #26

Open
3 tasks done
dparker1005 opened this issue May 23, 2024 · 0 comments

Comments

@dparker1005
Copy link
Member

dparker1005 commented May 23, 2024

Describe the bug
This is the function where we set the profile start date to (potentially) a date in the past:

/**
* Set the date that the first recurring payment will be charged.
*
* @param string $startdate The start date for the membership.
* @param object $order The order that is being purchased
*/
function pmprorate_set_startdate_to_next_payment_date( $startdate, $order ) {
global $current_user;
// If using PMPro v2.x, we don't have the PMPro_Subscription class. Use old logic.
if ( ! class_exists( 'PMPro_Subscription' ) ) {
//use APIs to be more specific
if( $order->gateway == 'stripe' ) {
remove_filter('pmpro_next_payment', array('PMProGateway_stripe', 'pmpro_next_payment'), 10, 3);
add_filter('pmpro_next_payment', array('PMProGateway_stripe', 'pmpro_next_payment'), 10, 3);
} elseif( $order->gateway == 'paypalexpress' ) {
remove_filter('pmpro_next_payment', array('PMProGateway_paypalexpress', 'pmpro_next_payment'), 10, 3);
add_filter('pmpro_next_payment', array('PMProGateway_paypalexpress', 'pmpro_next_payment'), 10, 3);
}
// Note. This is not MMPU-compatible for PMPro v2.x.
$next_payment_date = pmpro_next_payment( $current_user->ID );
if( !empty( $next_payment_date ) )
$startdate = date( "Y-m-d", $next_payment_date ) . "T0:0:0";
return $startdate;
}
// Get the level ID that the user is switching from.
$clevel_id = pmproprorate_get_level_id_being_switched_from( $current_user->ID, $order->membership_id );
// Get the user's current subscription for that level.
$current_subscriptions = PMPro_Subscription::get_subscriptions_for_user( get_current_user_id(), $clevel_id );
// If the user doesn't have a subscription, bail. This shouldn't ever happen though since we check for this earlier.
if ( empty( $current_subscriptions ) ) {
return $startdate;
}
// Return the next payment date.
$current_subscription = current( $current_subscriptions );
return $current_subscription->get_next_payment_date( 'Y-m-d H:i:s' );
}

Option 1: Set next payment date to today instead of to the past - The issue here is that we may as well just charge the billing amount at checkout

Option 2: If $next_payment_date is in the past when calculated in the pmprorate_pmpro_checkout_level() function, just bail from the function. This feels like it makes more sense. If a payment was missed, try to treat this checkout as a "new checkout".

Isolating the problem (mark completed items with an [x]):

  • I have deactivated other plugins and confirmed this bug occurs when only Paid Memberships Pro plugin is active.
  • This bug happens with a default WordPress theme active, or Memberlite.
  • I can reproduce this bug consistently using the steps above.

WordPress Environment

``` Please share non-sensitive information about your hosting environment such as WordPress version, PHP version, Paid Memberships Pro and any related plugins versions. ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant