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

[Mobile Payments] Handle Network errors for payments using site credentials #14980

Conversation

joshheald
Copy link
Contributor

@joshheald joshheald commented Jan 24, 2025

Closes: #14409

Description

This PR ensures that we decode specific payment-related NetworkErrors, which we receive when using site credentials rather than Jetpack.

Additionally, it resolves an issue that was preventing localized error messages from being shown when payment capture failed. Without fixing this, it would be very difficult to test.

Two payment errors are covered: errors fetching a charge, and errors capturing a payment.

Steps to reproduce

To cause an error when fetching a charge, replace the path in WCPayRemote.fetchCharge(for:chargeID:completion:) with:

let path = "\(Path.charges)/\(chargeID.lowercased())"
  1. Open the orders tab
  2. Select an order paid using WooPayments
  3. Tap Issue Refund
  4. Observe that the error is shown.
  5. With a breakpoint, observe that a call is made to delete the charge from storage: CardPresentPaymentStore.fetchCharge(siteID:chargeID:completion:)

To cause an error when capturing a payment, replace the minimumAllowedChargeAmount in CardPresentPaymentsConfiguration with a lower number, e.g. 0.1, then try to take payment for an amount between the real minimum and your reduced minimum.

  1. Open the orders tab
  2. Create an order for an amount below the real minimum
  3. Tap Collect Payment
  4. Tap a card
  5. Observe that the descriptive error from the server is shown

Note that this PR does not fully adopt the new error available in WooPayments – pdfdoF-6h1-p2 for context. To do that, we can add to the decoding of the data returned with the error, which will be easier with NetworkError than DotcomError. When we do adopt that, we can provide the localization in the app, rather than relying on the server localization as we do in these cases now.

Testing information

There's no visual difference when refunding a payment, the correct unwrapping of the error triggers a call to delete the charge from storage.

When capturing a payment, you can now see the message from WCPay or the app's localization in the UI, rather than Yosemite.ServerSideCaptureError 0

Screenshots

Capture

Jetpack login

Before After
payment before jetpack payment after jetpack

Site creds login

Before After
payment before site creds payment after site creds

Refund

Jetpack login

Before After
refund before jetpack refund after jetpack

Site creds login

Before After
refund before site creds refund after site creds

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

@joshheald joshheald added type: bug A confirmed bug. feature: mobile payments Related to mobile payments / card present payments / Woo Payments. labels Jan 24, 2025
@joshheald joshheald added this to the 21.6 milestone Jan 24, 2025
When using site credentials, we get `NetworkError` not `DotcomError`.

Previously, we handled the `orderCaptureError` as a special case when we got it while logged in via Jetpack, but as a generic error when using site credentials

By using the new `PaymentError`, we can decode the `NetworkError` responses for `orderCaptureError` and use the special case handling however you log in.
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 24, 2025

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14980-14b7bb8
Version21.5
Bundle IDcom.automattic.alpha.woocommerce
Commit14b7bb8
App Center BuildWooCommerce - Prototype Builds #12698
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@joshheald joshheald force-pushed the issue/14409-handle-network-errors-for-payments-using-site-credentials branch from 908e02d to 14b7bb8 Compare January 24, 2025 15:30
@joshheald joshheald marked this pull request as ready for review January 24, 2025 16:08
@iamgabrielma iamgabrielma self-assigned this Jan 27, 2025
Copy link
Contributor

@iamgabrielma iamgabrielma left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

✅ Triggers a call to delete the charge from storage when needed
✅ When failing capturing a payment, the proper localized error appears

TIL that the chargeID is case-sensitive

@joshheald joshheald merged commit 053c328 into trunk Jan 28, 2025
19 checks passed
@joshheald joshheald deleted the issue/14409-handle-network-errors-for-payments-using-site-credentials branch January 28, 2025 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: mobile payments Related to mobile payments / card present payments / Woo Payments. type: bug A confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle PaymentGatewayAccountError when logged in with site credentials
3 participants