woocommerce / woocommerce-ios

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

Send receipts after failed payment to attached customer email #14475

Closed staskus closed 1 day ago

staskus commented 1 day ago

Show "A receipt has been sent to {email}" message after a failed payment when the order has a customer email set.

Partially addresses #14163, I'll address failed payments sent via the API in the next task.

Description

I planned to implement the whole remaining failure receipt functionality within a single PR but it already grew more complex than I anticipated.

In this PR I address the functionality of sending receipts after failed payment to attached customer and displaying "Email sent" message. Equivalent of https://github.com/woocommerce/woocommerce-ios/pull/14390 but to failed payments.

Solution

Reminder of backend changes:

I had to make more changes than anticipated before development:

  1. I expanded the card presentation failure models with two more options shown when a payment fails.
Class Description
CardPresentModalErrorEmailSent Is shown if the failed payment has customer email set
CardPresentModalNonRetryableErrorEmailSent Is shown if the failed has customer email set and is not retryable anymore
  1. Show email sent only for CardReaderServiceError.paymentCapture(.paymentDeclinedByPaymentProcessorAPI) errors. Other types of errors related to order preparation, card readers, and network issues don't produce failed order status. I haven't found any other way to determine whether the order turned into a failed state. Retrieving an order and checking status after payment failure is unreliable since webhook usually doesn't manage to update the order status before we make a call. I will use the same logic to display a button to send failure receipts as well.
  2. When an order is in failed status and is retried and fails again, the new receipt doesn't get sent. To avoid this, I set the order status back to pending when the order payment is collected again.

Steps to reproduce

Before testing:

  1. Enable sendReceiptAfterPayment in DefaultFeatureFlagService
  2. Use my testing site https://lovely-aware-sturgeon.jurassic.ninja/ details: PdfdoF-5Qj-p2

Test cases:

Testing information

The feature is still behind the feature flag. Added new unit tests.

Screenshots


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:

wpmobilebot commented 1 day ago

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 Numberpr14475-914f8db
Version21.1
Bundle IDcom.automattic.alpha.woocommerce
Commit914f8dbe122ef8ed8382244db99780af7bdca462
App Center BuildWooCommerce - Prototype Builds #11690

Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

dangermattic commented 1 day ago
1 Warning
:warning: This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by :no_entry_sign: Danger

iamgabrielma commented 1 day ago

Failed Card Reader Payment: Create an order, attach a customer with an email, set a failure amount, and pay with a card reader. Confirm 'Email sent' message is shown and the email is received.

✅ "A receipt has been sent to xxxx" shows ✅ Email "your order was unsuccesful" received (bit of email title congratulating) ✅ After retrying once, I cannot retry again, a dismiss button appears

Failed TTP payment: Create an order, attach a customer with an email, set a failure amount, and pay with TTP. Confirm 'Email sent' message is shown and the email is received.

✅ "A receipt has been sent to xxxx" shows ✅ Email "your order was unsuccesful" received (bit of email title congratulating)

Try Collecting Again: After payment failure, try collecting again, Confirm the 'Email sent' message is shown.

✅ "A receipt has been sent to xxxx" shows ✅ Email "your order was unsuccesful" received (bit of email title congratulating)

Payment-unrelated failure: Create an order, attach a customer with an email, trigger a card payment, instead of tapping a card, disable Bluetooth on the phone. Confirm no 'Email sent' message is displayed and email is not received.

✅ No "A receipt has been sent" message appears ✅ No email is received

Try Collecting Later: Make 'Failed Card Reader Payment', come back to the order screen, tap 'Collect Payment' again, try to make a card reader. Confirm 'Email sent' message is shown and the email is received.

✅ "A receipt has been sent to xxxx" shows ✅ Email "your order was unsuccesful" received (bit of email title congratulating) ✅ After retrying once, I cannot retry again, a dismiss button appears

staskus commented 1 day ago

Unrelated to the app, but from the web and email delivery: Is a bit odd the email that we receive "congrats on the purchase" when we have an unsuccessful purchase 😅

Good catch. I'll bring this up.

We improved some of the failure receipt text just yesterday https://github.com/woocommerce/woocommerce/pull/52977, shouldn;t be a problem.

staskus commented 1 day ago

Follow up on "Congrats on the purchase!" @iamgabrielma

For some reason it's set as "From" field on Jurassic Ninja site (WooCommerce -> Settings -> Emails):

image

It appears as site name on a Pressable site:

image