woocommerce / woocommerce-ios

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

Send receipts after successful payments via the API #14422

Closed staskus closed 1 week ago

staskus commented 1 week ago

Partially addresses: #14163, I'll address failed payments in the next tasks.

Description

This PR implements sending receipts after successful payments with a new API. Until now, it was only possible to send a receipt after payment using the email client.

However, after https://github.com/woocommerce/woocommerce-ios/pull/14368 was implemented and with Woo 9.5, it's possible to trigger sending receipts via API.

Note: There's an issue with this functionality on the WooCommerce trunk (p91TBi-csN-p2#comment-13579) therefore I'm not implementing an eligibility handler. I recommend doing testing on my provided site.

Solution

  1. Created ReceiptEmailView and ReceiptEmailViewViewModel for displaying a view with a single email address field and processing the "Email Receipt" action. It emulates the UI of the existing Customer Billing Information screens and reuses existing fields and buttons.
  2. Presenting this view within CollectOrderPaymentUseCase when users select "Email Receipt" option.

Steps to reproduce

Before testing

  1. Edit project to return true from isEligibleSendingReceiptAfterPayment
  2. Use my testing site https://lovely-aware-sturgeon.jurassic.ninja/ details: PdfdoF-5Qj-p2

Main scenario: Successful payment + No customer

  1. Order
  2. Add custom amount / product
  3. Make Card Reader / TTP payment
  4. Confirm Payment successful modal appears with three options: "Print receipt", "Email receipt", "Save receipt and continue"
  5. Click "Email receipt"
  6. Confirm a new modal appears
  7. Confirm "Email Receipt" button only enables when the valid email is added
  8. Input a valid email
  9. Tap "Email receipt"
  10. Confirm modals are dismissed
  11. Confirm email arrives

Testing information

I tested additional scenarios:

Regression cases where isEligibleSendingReceiptAfterPayment returns false:

Screenshots

Payment Successful Email Receipt to Customer
Simulator Screenshot - iPhone 16 - 2024-11-14 at 17 00 51 Simulator Screenshot - iPhone 16 - 2024-11-14 at 17 00 19

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 1 week 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 1 week 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 Numberpr14422-0322fe4
Version21.1
Bundle IDcom.automattic.alpha.woocommerce
Commit0322fe4f25521b18197752d299818a4b6bb7a5b5
App Center BuildWooCommerce - Prototype Builds #11634

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

staskus commented 1 week ago

Are we going to be able to select an email from existing customers, rather than writing it?

Good question. I opted for simplicity now, but I imagine a scenario where we would have a button that opens Customer search and allows them to pick one instead.

Are going to be able to "resend" to the same address (eg: retry button, reusing the already-entered email) and/or different addresses prompted from the order view?

Not in the scope of this feature. But all of that is supported by a new API.

Something I've missed is some sort of UI feedback between sending was completed and all the modals were dismissed, something like what we do when creating a coupon (a big animated checkmark before calling for dismiss)

Good point. I'll check what is done in the coupon view and try to implement it as well. 👍