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

Add ACSS support for WC Subscriptions #4051

Open
wants to merge 7 commits into
base: fix/3813-saved-payment-methods
Choose a base branch
from

Conversation

ricardo
Copy link
Member

@ricardo ricardo commented Mar 13, 2025

Fixes #3831

Changes proposed in this Pull Request:

  • Add ACSS support for WC Subscriptions.
  • Add support for free trial subscriptions for non-deferred intent payment methods.

Testing instructions

  1. Enable the ACSS feature flag:
    • Use the Stripe Dev Tools plugin to enable the ACSS feature flag.
  2. Enable ACSS in Stripe:
    • Navigate to the Stripe Dashboard.
    • Enable "Canadian Pre-Authorized Debits" in the payment methods settings.
  3. Enable ACSS in WC Stripe:
    • Go to WooCommerce > Settings > Payments > Stripe.
    • Enable "Pre-Authorized Debit (ACSS)".
  4. Listen to webhooks:
npm run listen
  1. Change the store currency to CAD.
  2. From the checkout page, use the following information for the address:
    • Country: Canada
    • Province: British Columbia
    • City: Vancouver
    • Postcode: K1A 0B1

Reproduce the following critical flows using ACSS for payments:

  • Purchase subscription product

  • Purchase free trial subscription

  • Renew subscription

  • Automatically renew a subscription:

    1. Purchase a simple subscription or a free trial subscription.
    2. Navigate to Tools > Scheduled Actions.
    3. Run the woocommerce_scheduled_subscription_payment action related to the subscription.
    4. Notice the subscription is updated to "Active" and a new renewal order is created.
    5. Observe the order status and the charge ID for the renewal order, ensure the charge is captured correctly in Stripe.
  • Change default payment method

    • ⚠️ Note: This flow should work, but there's currently an issue with mandate options that I haven't fixed in this PR yet. I'll update the PR or open a follow-up PR as soon as I find how to fix it.

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

Comment on lines +826 to +827
'payment_schedule' => 'combined',
'interval_description' => __( 'Payments as per agreement', 'woocommerce-gateway-stripe' ),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it's best to set the payment schedule to combined and the interval description to something that can fit both one-time payments and subscriptions, because the same payment method (and consequently the mandate) can be used for both recurring and non-recurring payments, depending on how the payment method is saved in WooCommerce.

Reference: https://docs.stripe.com/payments/acss-debit#payment-schedule

@@ -436,7 +437,7 @@ public function update_payment_intent_ajax() {
* @throws Exception If the update intent call returns with an error.
* @return array|null An array with result of the update, or nothing
*/
public function update_payment_intent( $payment_intent_id = '', $order_id = null, $save_payment_method = false, $selected_upe_payment_type = '' ) {
public function update_intent( $payment_intent_id = '', $order_id = null, $save_payment_method = false, $selected_upe_payment_type = '' ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method now handles setup intents as well. Looking at the Stripe logs, there was an error where it was incorrectly calling payment_intents/seti_... instead of setup_intents/seti....

Given the similarity of a potential new method for handling only setup intents, I decided to unify both needs into the same function.

I'd appreciate the reviewer double-checking this approach, but I believe it shouldn't affect existing flows, given how minimal the change is.

Comment on lines +1640 to +1642
if ( isset( $intent->mandate ) ) {
$order->update_meta_data( '_stripe_mandate_id', $intent->mandate );
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For payment intents, the mandate ID is only available from the charge object, however for setup intents, the mandate ID can be accessed directly from the intent object.

Comment on lines +1626 to +1628
// TODO: Refactor and add mandate ID support for other payment methods, if necessary.
// The mandate ID is not available for the intent object, so we need to fetch the charge.
// Mandate ID is necessary for renewal payments for certain payment methods and Indian cards.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mandate ID here is necessary for renewal orders. Without it, renewal orders will fail.

I think it's best to keep this as a TODO just to indicate that the approach should be refactored if adding new payment methods, and also to make sure we test other payment methods because I figured this is necessary for at least card and ACSS.

@asumaran I couldn't test BACS subscriptions, but this doesn't seem necessary for ACH as far as I have tested. Can you try processing a renewal order for BACS and make sure this is not needed for BACS? There's a similar check in line 1631.

@ricardo ricardo requested review from a team and cesarcosta99 and removed request for a team March 13, 2025 04:01
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

Successfully merging this pull request may close these issues.

1 participant