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

Revise update account form feature #19

Open
remcotolsma opened this issue Mar 21, 2024 · 0 comments
Open

Revise update account form feature #19

remcotolsma opened this issue Mar 21, 2024 · 0 comments

Comments

@remcotolsma
Copy link
Member

To update payment details for a subscription we currently have this in place:

/**
* Display update account form.
*
* @link https://github.com/wp-premium/memberpress/blob/1.9.21/app/controllers/MeprAccountCtrl.php#L438
* @param string $sub_id Subscription ID.
* @param string[] $errors Array with errors.
* @param string $message Update message.
* @return void
*/
public function display_update_account_form( $sub_id, $errors = [], $message = '' ) {
$subscriptions = \get_pronamic_subscriptions_by_source( 'memberpress_subscription', $sub_id );
$subscription = \reset( $subscriptions );
$message = \__( 'The payment method for this subscription can not be updated manually.', 'pronamic_ideal' );
if ( false !== $subscription ) {
// Set URL to mandate selection URL.
$url = $subscription->get_mandate_selection_url();
// Maybe set URL to subscription renewal,
// to catch up with last failed payment.
$renewal_period = $subscription->get_renewal_period();
if ( SubscriptionStatus::ACTIVE !== $subscription->get_status() && null !== $renewal_period ) {
$url = $subscription->get_renewal_url();
}
$message = \sprintf(
/* translators: %s: mandate selection URL anchor */
\__( 'To update the payment method for this subscription, please visit the %s page.', 'pronamic_ideal' ),
\sprintf(
'<a href="%1$s" title="%2$s">%3$s</a>',
\esc_url( $url ),
\esc_attr( \__( 'payment method update', 'pronamic_ideal' ) ),
\esc_html( \__( 'payment method update', 'pronamic_ideal' ) )
)
);
}
?>
<h3>
<?php echo \esc_html( __( 'Update payment method', 'pronamic_ideal' ) ); ?>
</h3>
<div>
<?php echo \wp_kses_post( $message ); ?>
</div>
<?php
}

It uses the mandate selection feature from https://github.com/pronamic/wp-pay-core.

If a payment method is chosen on the mandate change page from core for which no MemberPress gateway is active, a strange situation arises.

/**
* 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;
}
}
/**
* 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;
}

We may need to limit updating information to, for example, credit card information. Within MemberPress itself, the options for switching payment methods are limited:

Switch from PayPal to Stripe or Vice Versa

Sometimes a customer may have used PayPal or Stripe when they originally signed up, or they used Stripe and want to switch to PayPal.

If the customer is using PayPal and just wants to change the payment method, they can do this from within their PayPal account and do not need to switch to Stripe. But sometimes a customer will not want to update their PayPal account (or won't be able to access it anymore) in which case they would need to switch to Stripe.

In these scenarios, you would need to cancel their current membership and have them sign up again. You can have them wait until their current term ends (recommended), or if you want them to sign up again right away you will have to create a coupon for them to use to give them a prorated price.

https://memberpress.com/docs/how-to-change-a-customers-payment-method/

CC @rvdsteege

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant