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 payments via the API #14485

Closed staskus closed 1 hour ago

staskus commented 20 hours ago

Closes: #14163 Wraps up the work from:

Description

Allow inputting and sending receipts after failed payments. Equivalent changes to https://github.com/woocommerce/woocommerce-ios/pull/14422 but for failed payments.

I will enable feature flag only when both WooCommerce and WooPayments versions are officially released and additional CFT is performed.

Solution

  1. To be consistent, now we have three types of alerts:

    • EmailSent (email sent message): CardPresentModalSuccessEmailSent, CardPresentModalErrorEmailSent, CardPresentModalNonRetryableErrorEmailSent
    • WithoutEmail (no email information) : CardPresentModalSuccessWithoutEmail, CardPresentModalErrorWithoutEmail, CardPresentModalNonRetryableErrorWithoutEmail
    • Default (with email receipt button): CardPresentModalSuccess, CardPresentModalError, CardPresentModalNonRetryableError
  2. Since payment failure alert allows to retry the payment, when ReceiptEmailViewController is present, do not automatically dismiss the alert. If email is sent, update the alert to show Email sent message created in the previous PR.

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

Main scenario: No customer + Failed Payment + Input Email

  1. Order
  2. Set a failure amount
  3. Make Card Reader / TTP payment
  4. Confirm Payment failed modal appears with "Email receipt option"
  5. Click "Email receipt"
  6. Confirm a new modal appears
  7. Input a valid email
  8. Tap "Email receipt"
  9. Confirm email modal is dismissed, payment failure alert is updated with an email sent message 10 Confirm email arrives
  10. Tap `Try collecting again'
  11. Confirm email sent message is shown

2nd scenario: No customer + Failed Payment + Retry + Input email

  1. Repeat steps 1-4 until failure modal appears
  2. Tap 'Try collecting again'
  3. Confirm 'Email Receipt' and 'Dismiss' options are shown
  4. Click "Email receipt", enter valid email, confirm
  5. Confirm email modal is dismissed, payment failure alert is updated with an email sent message
  6. Confirm email sent message is shown

Testing information

I additionally tested:

Screenshots

Card Reader + Failed Payment + Input email

https://github.com/user-attachments/assets/81f5be07-25e7-477c-916a-5b09c2c896ea

TTP + Failed Payment + Retry + Input email

https://github.com/user-attachments/assets/f9f592ab-bb76-4e06-98ff-23bdb4d6f9ff


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:

dangermattic commented 20 hours 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

wpmobilebot commented 20 hours 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 Numberpr14485-7dd66ad
Version21.1
Bundle IDcom.automattic.alpha.woocommerce
Commit7dd66add0f93d9c6d85ce1ec7f9293eb17e0b978
App Center BuildWooCommerce - Prototype Builds #11724

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

staskus commented 5 hours ago

@jaclync, thanks for the review!

Do you know if the email receipt works in POS as well? Some presentation logic in the error modal is UIKit specific, just wondering if this works for the adapted SwiftUI version in POS.

This is a great question. A current implementation builds on already existing receipt-related modals. However, as you mention, it implements specific UIKit modals within CollectOrderPaymentUseCase which is not ideal.

We discussed it here as well pdfdoF-5RR-p2#comment-6896.

POS receipts functionality is being implemented right now. POS could use ReceiptState when building CardPresentPaymentEventDetails in CardPresentPaymentsTransactionAlertsProvider. This way there could be a shared logic between POS and IPP. However, we discussed this and we are choosing to untangle receipts from payment flow within POS for more flexibility. In a longer term, it could mean that we should remove receipt-related functionality from CollectOrderPaymentUseCase for clarity. I have a draft task for this on the project board so I could address it later or plan for the future.