woocommerce / woocommerce-ios

WooCommerce iOS app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
298 stars 110 forks source link

Requests hit the incorrect `/wc/v3/payments` endpoint when WCPay is not active #9331

Open iamgabrielma opened 1 year ago

iamgabrielma commented 1 year ago

Describe the bug Context: p1680065746242129-slack-C025A8VV728

We seem to use the WCPay wc/v3/payments/ endpoint instead of /wc_stripe/terminal/* when only Stripe plugin is active, which doesn't work because there are no such endpoints to be reached if WCPay is disabled, returning a 404 error.

Somr debugging:

  1. During testing, with both extensions disabled, and a breakpoint on CardPresentPaymentOnboardingState.selectPlugin I got this:
    InPersonPaymentsViewModel
    state = useCase.state
    (lldb) po state
    ▿ CardPresentPaymentOnboardingState
    ▿ pluginNotActivated : 1 element
    - plugin : Yosemite.CardPresentPaymentsPlugin.wcPay

    I'm not positive if this is something introduced with caching the onboarding state, or not. As Andrei shared in slack:

Can it be that you do not invalidate selected plugin cache when onboarding check determines that there is only stripe and that's why wrong plugin is used?

  1. Another test where WCPay was disabled but Stripe extension was enabled, I can see we still call both endpoints /wc/v3/payments/accounts and /wc/v3/wc_stripe/account/, the first request returns 404 and the second returns 200:
https://public-api.wordpress.com/rest/v1.1/jetpack-blogs/194373765/rest-api/?json=true&path=/wc/v3/payments/accounts%26_method%3Dget&query=%7B%22_fields%22%3A%22status%2Cis_live%2Ctest_mode%2Chas_pending_requirements%2Chas_overdue_requirements%2Ccurrent_deadline%2Cstatement_descriptor%2Cstore_currencies%2Ccountry%2Ccard_present_eligible%22%7D

https://public-api.wordpress.com/rest/v1.1/jetpack-blogs/194373765/rest-api/?json=true&path=/wc/v3/wc_stripe/account/summary%26_method%3Dget&query=%7B%22_fields%22%3A%22status%2Cis_live%2Ctest_mode%2Chas_pending_requirements%2Chas_overdue_requirements%2Ccurrent_deadline%2Cstatement_descriptor%2Cstore_currencies%2Ccountry%22%7D

To Reproduce Steps to reproduce the behavior:

  1. In a site with both WCPay and Stripe extensions configured
  2. Disable WCPay
  3. Check the HTTP requests via Proxyman or other
  4. Go to Menu > Payments
  5. See the requests to /wc/v3/payments/failing with 404
Screenshot 2023-03-29 at 18 11 28
reginabally commented 1 year ago

We have another merchant who failed to set up the card reader with Stripe. The site has WCPay, but they're not sure if the extension was active or not at that time. They found out they can only set up IPP when they've completed the pending requirements in WCPay. Is this related to this report?

From the logs, I noticed errors like account_overdue_requirements and multiple_payment_providers_conflict:

2023/04/12 00:18:50:048  🔵 Tracked payments_hub_onboarding_error_tapped, properties: [AnyHashable("blog_id"): 217727750, AnyHashable("is_wpcom_store"): false]
2023/04/12 00:18:50:158  🔵 Tracked card_present_onboarding_not_completed, properties: [AnyHashable("blog_id"): 217727750, AnyHashable("is_wpcom_store"): false, AnyHashable("country"): "US", AnyHashable("reason"): "multiple_payment_providers_conflict"]
2023/04/12 00:20:29:167  🔵 Tracked card_present_payment_gateway_selected, properties: [AnyHashable("is_wpcom_store"): false, AnyHashable("payment_gateway"): "WooCommerce Payments", AnyHashable("blog_id"): 217727750]
2023/04/12 00:20:29:270  🔵 Tracked card_present_onboarding_not_completed, properties: [AnyHashable("is_wpcom_store"): false, AnyHashable("country"): "US", AnyHashable("blog_id"): 217727750, AnyHashable("reason"): "account_overdue_requirements"]
2023/04/12 00:20:45:090  🔵 Tracked payments_hub_onboarding_error_tapped, properties: [AnyHashable("blog_id"): 217727750, AnyHashable("is_wpcom_store"): false]
2023/04/12 00:20:45:197  🔵 Tracked card_present_onboarding_not_completed, properties: [AnyHashable("country"): "US", AnyHashable("reason"): "account_overdue_requirements", AnyHashable("is_wpcom_store"): false, AnyHashable("blog_id"): 217727750]
2023/04/12 00:20:48:606  🔵 Tracked payments_hub_onboarding_error_tapped, properties: [AnyHashable("blog_id"): 217727750, AnyHashable("is_wpcom_store"): false]
2023/04/12 00:20:48:714  🔵 Tracked card_present_onboarding_not_completed, properties: [AnyHashable("country"): "US", AnyHashable("blog_id"): 217727750, AnyHashable("reason"): "account_overdue_requirements", AnyHashable("is_wpcom_store"): false]
2023/04/12 00:20:52:705  🔵 Tracked hub_menu_option_tapped, properties: [AnyHashable("badge_visible"): false, AnyHashable("blog_id"): 217727750, AnyHashable("is_wpcom_store"): false, AnyHashable("option"): "payments"]
2023/04/12 00:20:57:522  🔵 Tracked payments_hub_onboarding_error_tapped, properties: [AnyHashable("is_wpcom_store"): false, AnyHashable("blog_id"): 217727750]
2023/04/12 00:20:57:632  🔵 Tracked card_present_onboarding_not_completed, properties: [AnyHashable("country"): "US", AnyHashable("is_wpcom_store"): false, AnyHashable("blog_id"): 217727750, AnyHashable("reason"): "multiple_payment_providers_conflict"]
2023/04/12 18:52:47:162  🔵 Tracked card_present_payment_gateway_selected, properties: [AnyHashable("blog_id"): 217727750, AnyHashable("payment_gateway"): "WooCommerce Stripe Gateway", AnyHashable("is_wpcom_store"): false]
2023/04/12 18:52:47:265  🔵 Tracked card_present_onboarding_not_completed, properties: [AnyHashable("is_wpcom_store"): false, AnyHashable("country"): "US", AnyHashable("reason"): "account_pending_requirements", AnyHashable("blog_id"): 217727750]
2023/04/12 18:52:47:266  In-Person Payments not available. Stripe has pending requirements without known deadline

Original report: 6194971-zd-woothemes Full logs here: 6197520-zd-woothemes

iamgabrielma commented 1 year ago

Is this related to this report?

I think those are different issues, for this user the main problem would be that they have pending Stripe requirements to be fulfilled, without that they won't be able to use Stripe.

multiple_payment_providers_conflict

AFAIK this stopped to be a problem a few versions ago and having both plugins enabled does not create a conflict (I could be mistaken, I haven't checked all the paths that could return that error), I can see in the ticket they use WCiOS 13.0.0.1 but we could double check with them and confirm if they're using the latest app version, in case they're using multiple devices (one of the tickets references an iPad)