woocommerce / woocommerce-gateway-stripe

The official Stripe Payment Gateway for WooCommerce
https://wordpress.org/plugins/woocommerce-gateway-stripe/
229 stars 200 forks source link

_stripe_net and _stripe_fee missing on Subscriptions renewal #3274

Closed danieleperilli closed 1 month ago

danieleperilli commented 1 month ago

Describe the bug After upgrading to version 8.5.1, the Stripe fee and Stripe net are no longer saved in the orders meta. This happens only with subscriptions renewals (using WooSubscriptions), not regular orders. Our custom plugins use that information to integrate and create Journal Entries on QuickBooks, so this is very important for us.

Please refer to the same issue reported here: https://wordpress.org/support/topic/no-longer-shows-stripe-fee-and-payout/

aheckler commented 1 month ago

I tested this just now and can confirm there is a bug. Interestingly, I see duplicate meta on the initial subscription order:

Screenshot taken on 2024-07-15 at 11 41 39 UTC@2x

That meta is missing from the renewal:

Screenshot taken on 2024-07-15 at 11 43 08 UTC@2x

OmarFPG commented 1 month ago

8472579-zd

james-allan commented 1 month ago

It looks like this could be related to the Stripe API version bump included in 8.5.0.

After making a subscription charge, we use to receive from Stripe a response that included a balance_transaction. That balance transaction is what we used to process the fee data.

Stripe API version 2019-09-09 response includes the charge object with a balance transaction ID directly:

Screenshot 2024-07-17 at 1 03 15 PM

That's no longer the case though. In the 2024-06-20 version, the charges arg doesn't exist, we have a latest_charge but when you fetch the charge, the balance transaction is empty.

Screenshot 2024-07-17 at 1 05 14 PM Screenshot 2024-07-17 at 1 07 01 PM

What I haven't yet worked out is why the balance transaction is missing when processing subscription payments, but aren't missing when you process payments on the front end. 🤔

james-allan commented 1 month ago

Just following up, I've confirmed it's definitely related to the api version change. I switched out the API version used when create_and_confirm_intent_for_off_session() is called and that resolved it.

I'd still like to look at what could be causing the difference between checkout payments and subscription payments. All I have been able to tell so far, is that Stripe updates the charge with the balance transaction after it has succeeded so there's a short delay (3ms).

Screenshot 2024-07-17 at 3 52 36 PM

The only potential fix that comes to mind is listening to that charge.updated webhook or scheduling an async job to go update the order fee from the balance information shortly after the transaction has been processed.

james-allan commented 1 month ago

I'd still like to look at what could be causing the difference between checkout payments and subscription payments.

I think I found what the difference is and what will fix it. Subscription payments don't have the capture_method set to automatic. I'll submit a PR later tonight.

james-allan commented 1 month ago

FWIW this is the relevant change to the API:

Screenshot 2024-07-17 at 6 17 18 PM
Ref: https://docs.stripe.com/upgrades#2024-04-10

In the 2024-04-10 version they changed the default payment intent capture_method to async so we don't get charge information immediately. As I mentioned above changing it to automatic will cause the payment to be captured as soon as it is raised and we will receive charge information.

chouseal commented 5 days ago

It's not just with subscription payments. No orders since updating to 8.5.1 have included the Stripe fees in the admin order details, and I'm seeing this consistently across several sites on different servers.

Some of my clients use this fee information in their accounting, so it's important.