woocommerce / woocommerce-ios

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

[Mobile Payments] Onboarding can complete with `restricted` and `pending_requirements` #13615

Open joshheald opened 1 month ago

joshheald commented 1 month ago

šŸ• I'm still waiting to confirm the second part, I now have "has pending requirements" message with account cache contents:

'has_pending_requirements' => true, 'status' => 'restricted_soon',

I'll split this part out of this PR again ā€“ it's only one commit and Jirka's asked me to investigate further anyway.

_Originally posted by @joshheald in https://github.com/woocommerce/woocommerce-ios/

issues/13610#issuecomment-2288691959_

Split from #13610

We found that after the first payment, using progressive onboarding as an individual, we were put in restricted status with has_pending_requirements and has_future_requirements. This is not expected, and WooPayments folks are working on a fix p1723640322815779-slack-C01BPL3ALGP

Repro

  1. Create a new Jurassic Ninja site ā€“ include WooCommerce, WooPayments, and WooPayments Dev Tools
  2. Link the site with your Jetpack user
  3. Add a US address in WooCommerce settings
  4. Activate WooPayments
  5. Go through the onboarding steps in WP-Admin > Payments > Activate
  6. Launch the app and switch to your new site
  7. Go to Menu > Payments
  8. Tap the Continue button in the onboarding notice that shows
  9. Skip the Enable Pay in Person alert that shows
  10. Observe that you're not shown a generic Unable to verify onboarding error
  11. Take a payment ā€“ observe that you can connect to the card reader and take payment as normal.
  12. Force quit the app and relaunch it, to clear the onboarding state
  13. Repeat steps 7-10 ā€“ Observe that you can skip an onboarding error about pending requirements, and you're then shown the generic onboarding error Unable to verify In-Person Payments for this store

Investigation

Status restricted with pendingRequirements: true

After verification is complete, accounts are put in to restricted with pendingRequirements == true. This should be flagged to the user as a skippable error, and it is... except the error isn't really skippable. When they get in this state, we're looking for restrictedSoon to enable the payments, but blocking restricted.

We could allow restricted as long as the previous onboarding steps have been completed ā€“ i.e. they have skipped the pending requirements, and they don't have overdue requirements.

Onboarding code sort of handles it already...

On iOS, the existing code kinda handles it:

    func isStripeAccountPendingRequirements(account: PaymentGatewayAccount) -> Bool {
        account.wcpayStatus == .restricted
            && account.hasPendingRequirements
            || account.wcpayStatus == .restrictedSoon

    func shouldShowPendingRequirements(account: PaymentGatewayAccount) -> Bool {
        isStripeAccountPendingRequirements(account: account) && !pendingRequirementsStepSkipped
    }

Which is used when deciding which onboarding step to show:

        guard !isStripeAccountOverdueRequirements(account: account) else {
            logMissingRequirements(for: account)
            return .stripeAccountOverdueRequirement(plugin: plugin)
        }
        guard !shouldShowPendingRequirements(account: account) else {
            logMissingRequirements(for: account)
            return .stripeAccountPendingRequirement(plugin: plugin, deadline: account.currentDeadline)
        }

Except that after you skip, it gets past these two and doesn't have a valid account status, so shows the generic error

On Android, the logic is similar except I can't see how the skip bit works, so I'm not sure whether the generic error will show or not.

Testing the restricted with pendingRequirements: true state

After taking a payment, check back on the web to see your account status. You can do this in WP-admin > WCPay Dev > Account cache contents

WCPay dev settings screenshot showing restricted status with pending requirements

Once your account shows status: restricted and has_pending_requirements: true, repeat the testing. You will have to skip the Pending requirements onboarding screen, and then should be able to take payments without being shown the generic error again.

dangermattic commented 1 month ago

Thanks for reporting! šŸ‘