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

MemberPress subscription gateway not updating to "Pronamic" payment method #22

Closed
rvdsteege opened this issue Aug 7, 2024 · 3 comments · Fixed by #24
Closed

MemberPress subscription gateway not updating to "Pronamic" payment method #22

rvdsteege opened this issue Aug 7, 2024 · 3 comments · Fixed by #24
Assignees
Labels

Comments

@rvdsteege
Copy link
Member

rvdsteege commented Aug 7, 2024

When a recurring payment is created, we're updating the MemberPress subscription gateway to the one corresponding to the payment method of the recurring payment (if it exists). This ensures that the correct MemberPress gateway is listed in the admin and with subscription payments in the customer account.

For recurring payments, we also create a MemberPress transaction for the subscription, which MemberPress then uses to determine the membership status. However, we only create this transaction if the MemberPress subscription gateway is 'one of ours'.

We came across a case where:

  1. only the "Pronamic" payment method is set-up in MemberPress;
  2. the initial payment method being used has been removed from the MemberPress settings (showing IDs like Sei0x6-q2 as "Method" in the admin).

As recurring payments are created for active Pronamic subscriptions for these memberships, the payment gateway of the MemberPress subscription should be updated to the "Pronamic" payment method. However, this doesn't seem to work for this payment method:

/**
* If the payment method is changed we have to update the MemberPress
* subscription.
*
* @link https://github.com/wp-pay-extensions/memberpress/commit/3631bcb24f376fb637c1317e15f540cb1f9136f4#diff-6f62438f6bf291e85f644dbdbb14b2a71a9a7ed205b01ce44290ed85abe2aa07L259-L290
*/
$memberpress_gateways = MeprOptions::fetch()->payment_methods();
foreach ( $memberpress_gateways as $memberpress_gateway ) {
if ( ! $memberpress_gateway instanceof Gateway ) {
continue;
}
if ( $memberpress_gateway->get_payment_method() === $payment->get_payment_method() ) {
$memberpress_subscription->gateway = $memberpress_gateway->id;
}
}

Because of this, the MemberPress transaction is not created, which results in an expiring membership.

This can be fixed by updating to either the "Pronamic" payment method or — with priority — the specific payment method, so that the null payment method is no longer ignored when updating the MemberPress subscription payment method.

I'm also wondering why/if we should only create the MemberPress transaction if the gateway is one of ours? We might be able to remove this?

/**
* Payment method.
*
* @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/models/MeprTransaction.php#L634-L637
* @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/models/MeprOptions.php#L798-L811
*/
$memberpress_gateway = $memberpress_subscription->payment_method();
if ( ! $memberpress_gateway instanceof Gateway ) {
return;
}

Internal Help Scout ticket: https://secure.helpscout.net/conversation/2670974885/27569

CC @remcotolsma

@remcotolsma
Copy link
Member

I'm not entirely convinced we need to fix this.

We came across a case where:

  1. only the "Pronamic" payment method is set-up in MemberPress;
  2. the initial payment method being used has been removed from the MemberPress settings (showing IDs like Sei0x6-q2 as "Method" in the admin).

As recurring payments are created for active Pronamic subscriptions for these memberships, the payment gateway of the MemberPress subscription should be updated to the "Pronamic" payment method. However, this doesn't seem to work for this payment method:

Why should we update the payment gateway of the MemberPress subscription to the "Pronamic" payment method? If users disable gateways, do they expect recurring payments to continue? And what if the "Pronamic" gateway is not active/available?

I also find the code as in the PR a bit difficult to follow. If we want to continue with this, some clarification would be nice. Perhaps by introducing a helper function find_memberpress_gateway_for_pronamic_payment_method( $payment_method ) that explains the "Pronamic" gateway (without specific payment method) use case?

/**
* If the payment method is changed we have to update the MemberPress
* subscription.
*
* @link https://github.com/wp-pay-extensions/memberpress/commit/3631bcb24f376fb637c1317e15f540cb1f9136f4#diff-6f62438f6bf291e85f644dbdbb14b2a71a9a7ed205b01ce44290ed85abe2aa07L259-L290
*/
$memberpress_gateways = MeprOptions::fetch()->payment_methods();
foreach ( $memberpress_gateways as $memberpress_gateway ) {
if ( ! $memberpress_gateway instanceof Gateway ) {
continue;
}
$gateway_method = $memberpress_gateway->get_payment_method();
$payment_method = $payment->get_payment_method();
if ( ! \in_array( $gateway_method, [ null, $payment_method ] ) ) {
continue;
}
$memberpress_subscription->gateway = $memberpress_gateway->id;
if ( $gateway_method === $payment_method ) {
break;
}
}

@remcotolsma remcotolsma moved this from Todo to In Progress in Pronamic Pay Sep 3, 2024
@rvdsteege
Copy link
Member Author

Why should we update the payment gateway of the MemberPress subscription to the "Pronamic" payment method?

Because we're only creating transactions for MemberPress subscriptions having a 'Pronamic Pay gateway'. Not updating the gateway will currently result in an expiring membership (as was the case in https://secure.helpscout.net/conversation/2670974885/27569) even though the recurring payment has been completed successfully.

If users disable gateways, do they expect recurring payments to continue?

I'd expect so and at least the user in https://secure.helpscout.net/conversation/2670974885/27569 did too, otherwise the membership should be cancelled if they no longer want to receive payments for it.

And what if the "Pronamic" gateway is not active/available?

Then we're back at "we're only creating transactions for MemberPress subscriptions having a 'Pronamic Pay gateway'" and the the membership will expire, even though the next (possibly successful) recurring payment has already been started by Pronamic Pay. That is why I was wondering why we're only creating a MemberPress transaction if the gateway is 'ours'. If we do not want to create any recurring payments anymore if the gateway changes, it would be better to prevent the next recurring payment already, instead of starting the payment and not creating a corresponding MemberPress transaction to prolong the membership.

@rvdsteege rvdsteege assigned remcotolsma and unassigned rvdsteege Sep 23, 2024
@remcotolsma
Copy link
Member

This has been discussed @pronamic HQ, we will process payment method changes (source = subscription_payment_method_change) immediately as they occur via a separate maybe_update_memberpress_subscription_gateway( Payment $payment ) method. We will remove the checking and updating of the MemberPress gateway based on the payment method from the maybe_create_memberpress_transaction( Payment $payment ) method.

https://github.com/pronamic/wp-pay-core/blob/78e8e0327ed26a55a9a79f95c8470ecfae257ee4/src/Subscriptions/SubscriptionsModule.php#L510

/**
* If the payment method is changed we have to update the MemberPress
* subscription.
*
* @link https://github.com/wp-pay-extensions/memberpress/commit/3631bcb24f376fb637c1317e15f540cb1f9136f4#diff-6f62438f6bf291e85f644dbdbb14b2a71a9a7ed205b01ce44290ed85abe2aa07L259-L290
*/
$memberpress_gateways = MeprOptions::fetch()->payment_methods();
foreach ( $memberpress_gateways as $memberpress_gateway ) {
if ( ! $memberpress_gateway instanceof Gateway ) {
continue;
}
$gateway_method = $memberpress_gateway->get_payment_method();
$payment_method = $payment->get_payment_method();
if ( ! \in_array( $gateway_method, [ null, $payment_method ] ) ) {
continue;
}
$memberpress_subscription->gateway = $memberpress_gateway->id;
if ( $gateway_method === $payment_method ) {
break;
}
}
/**
* Payment method.
*
* @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/models/MeprTransaction.php#L634-L637
* @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/models/MeprOptions.php#L798-L811
*/
$memberpress_gateway = $memberpress_subscription->payment_method();
if ( ! $memberpress_gateway instanceof Gateway ) {
return;
}
/**
* At this point we should call `MeprBaseRealGateway->record_subscription_payment`.
*
* @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprStripeGateway.php#L587-L714
* @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/gateways/MeprAuthorizeGateway.php#L205-L255
*/
$memberpress_gateway->record_subscription_payment();

$memberpress_transaction->gateway = $memberpress_gateway->id;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment