Automattic / woocommerce-payments

Accept payments via credit card. Manage transactions within WordPress.
https://wordpress.org/plugins/woocommerce-payments/
Other
174 stars 69 forks source link

Subscriptions via WCPay fail with no notice if `Authorize now, capture later` is enabled. Subscription creation event never gets completed #4499

Open Brianmitchtay opened 2 years ago

Brianmitchtay commented 2 years ago

Describe the bug

When trying to create a subscription product using the built in subscriptions functionality and having the Authorize now, capture later option enabled, at all points in the customer journey and site admin experience things seem to go smooth and function as intended.

Then when the first renewal comes around, no renewal order is created, and the subscription remains Active indefinitely.

On the stripe dashboard we see that 23 hours after being created, the subscription payment intent is canceled, however, this message is not relayed to the site, and so the subscriptions on the site remain active.

To Reproduce

  1. On a test site, Install WooCommerce and WooCommerce Payments
  2. Make sure that the Authorize now, capture later and Enable Subscriptions with WooCommerce Payments options are enabled.
  3. Create a simple subscription product, and check out with it using WooCommerce Payments
  4. Capture Payment on the parent order
  5. See that the subscription creation does not get completed

Actual behavior

You would expect that if the subscription's parent order has its payment captured within the ~23 hour Payment Window that the subscription creation event would complete, and the subscription would be established in Stripe.

Screenshots

After capturing payment for parent order, subscription creation event is not completed. Screen Shot 2022-07-28 at 18 04 42

However, parent order is completed, and so subscription on the site becomes active

Screen Shot 2022-07-28 at 18 19 36 Screen Shot 2022-07-28 at 18 18 51

Expected behavior

I would expect that when the parent order has its payment captured successfully, that the subscription creation in Stripe would be completed

I would also expect that if the subscription creation event gets canceled in Stripe, the corresponding sub would be canceled on the site, or at least have some kind of error displayed.

Additional context

This issue was first surfaced in 5405801-zen, where a user was trying to create subscriptions for physical advertisements using WooCommerce Payments where their subscribers upload media for their ads, and so the site admin doesn't capture payment until verifying that the media is acceptable.

aheckler commented 2 years ago

On the stripe dashboard we see that 23 hours after being created, the subscription payment intent is canceled

Ahh, yes, this! I've run into this before here: p1655229139591099-slack-CGGCLBN58

TLDR: In the above case, it came up in the context of synchronized subscriptions. I was worried that if the payment intent only lasts 23 hours, but the subscription is synced, the pi_ would expire before the first charge. However, WC Pay works around this by creating a behind-the-scenes free trial on the subscription in Stripe's billing engine only (i.e. not in the actual WooCommerce product). This allows us to keep the intent open/active/whatever until the first synced date rolls around.

Anyway, I'll leave solving this bug to the experts, but just thought I'd provide some related backstory. :)

johndcoy commented 2 years ago

@aheckler I think that issue is reported in #4565 but this use case doesn't involve synchronized renewals.

mouligreenlaw commented 2 years ago

With reference to 5405801-zen, would a workaround be as follows?

I'm not sure if this uses the same Authorize now, capture later process which is causing the issue or whether it will create a valid subscription in Stripe with no cancellation.

haszari commented 1 year ago

Marking this as high priority, as these two features should ideally work well when both enabled:

Alternatively, if it's not practical to support auth for subscriptions, we could potentially require Auth = no for WCPay Subscriptions.

Although this is important we may not get to it quickly as we have limited maintenance bandwidth.

In the mean time, maybe we can recommend not enabling Authorize when using WCPay Subscriptions.

zmaglica commented 9 months ago

I am not certain which team can work on this issue. @diegocurbelo do you think that team Quark can work on this issue? Does it belong under Quark team responsibilities?

zmaglica commented 8 months ago

Silent ping @diegocurbelo :) . Sorry for disturbing.

james-allan commented 8 months ago

Hey @zmaglica.

Yes, it's my understanding that Quark is team responsible for this is given it involves WCPay Subscriptions.

I'll take a look into this and see if I can submit a fix.

james-allan commented 8 months ago

I'll take a look into this and see if I can submit a fix.

There are 2 issues at play here:

  1. When you capture the initial charge it doesn't update the Stripe Billing subscription to record that the subscription payment was completed and therefore had started. I have WIP changes for this already on https://github.com/Automattic/woocommerce-payments/compare/issue/4499?expand=1 to fix this.
  2. Stripe automatically cancel any subscription which has not started within 23 hours of it being created. This means that merchants would need to capture the charge within 23 hours otherwise they would be capturing an initial payment for a subscription which was cancelled on Stripe's end.

There are 2 ways to go about fixing this second point:

  1. When Stripe cancels the subscription because it was incomplete after 23 hours, cancel it on the WC side and cancel the payment authorization.
  2. or, attempt to recreate the subscription when the initial payment is captured if Stripe cancelled the original one.

I think the second one may actually be easier and would leave the existing 7 day authorize and capture window of time available.