Skip to content

Conversation

@toupper
Copy link
Contributor

@toupper toupper commented May 17, 2023

Closes: #9672

Description

With this PR we show the Scan to Pay screen with the QR code so it can be scanned.

Testing instructions

  1. Open the app
  2. Go to Menu
  3. Go to Payments
  4. Tap in Collect Payment and follow the flow
  5. When you see the Payment Methods screen, tap on Scan to Pay
  6. See the Scan to Pay Screen. Scan the qr, it should guide you to the checkout page of that order.
  7. Tap on Done
  8. See that the flow is dismissed you see the Order Created notice

Screenshots

Simulator Screen Recording - iPhone SE (3rd generation) - 2023-05-17 at 16 45 24


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

@toupper toupper added type: task An internally driven task. feature: mobile payments Related to mobile payments / card present payments / Woo Payments. labels May 17, 2023
@toupper toupper added this to the 13.7 milestone May 17, 2023
@toupper toupper requested review from iamgabrielma and joshheald May 17, 2023 14:51
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 17, 2023

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr9747-5ae5989 on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@iamgabrielma iamgabrielma self-assigned this May 18, 2023
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.

This is looking good! When testing, I couldn't make work the last step (both simulator and physical device):

6. Tap on Done
7. See that the flow is dismissed you see the Order Created notice

The QR is dismissed and the order is created, but I don't see the Order Created notice, neither I'm redirected outside of the flow, it remains on the "Take payment" view 🤔

As the flow is not dismissed this causes confusion as you can go back, attempt a different payment method, or even swipe-down to dismiss/cancel order, but this has already been created.

Comment on lines +12 to +27
func generateQRCodeImage() -> UIImage? {
guard let paymentURLString = paymentURL?.absoluteString else {
return nil
}

let context = CIContext()
let filter = CIFilter.qrCodeGenerator()
filter.message = Data(paymentURLString.utf8)

guard let outputImage = filter.outputImage,
let cgImage = context.createCGImage(outputImage, from: outputImage.extent) else {
return nil
}

return UIImage(cgImage: cgImage)
}
Copy link
Contributor

@iamgabrielma iamgabrielma May 18, 2023

Choose a reason for hiding this comment

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

Not a blocker: Should we abstract and extract this method somewhere else? Let's say an extension of UIImage, or as an Utility method in WooFoundation, then change the signature to something like the following generateQRCodeFromPaymentDetails(paymentURLString: URL, message: String) -> UIImage?

This way the view model doesn't have to know about the QR generation implementation details, we just pass the URL, the message, and let the system return it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I also considered that and preferred leaving it in the view model. The rationale is that at the moment we only generate a QR code here, and the function is simple enough to keep it in the view model. Furthermore, generating an image that we're going to display in the view from model data matches the responsibility of a view model.

If more logic is added to the QR code generation, e.g., adding the woo logo to it, I will extract it to its own class/extension.

@@ -0,0 +1,74 @@
import SwiftUI
import WooFoundation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import WooFoundation

Seems that this import is not needed! We only use FullScreenCoverClearBackgroundView on the PaymentMethodsView.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Fixed in 5ae5989

@toupper
Copy link
Contributor Author

toupper commented May 18, 2023

Thanks for your review @iamgabrielma !

The QR is dismissed and the order is created, but I don't see the Order Created notice, neither I'm redirected outside of the flow, it remains on the "Take payment" view 🤔

As the flow is not dismissed this causes confusion as you can go back, attempt a different payment method, or even swipe-down to dismiss/cancel order, but this has already been created.

I couldn't reproduce that behavior, but after taking a look at it together, we found a solution that was committed in edb450b. Please take a look at it now.

@peril-woocommerce
Copy link

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 2 days Please, make sure to get it merged by then or assign it to a later expiring milestone

Generated by 🚫 dangerJS

@iamgabrielma
Copy link
Contributor

Works as expected! 🚢

@toupper toupper merged commit 0989b7b into trunk May 18, 2023
@toupper toupper deleted the issue/9672-Scan-to-Pay-QR-code-screen branch May 18, 2023 12:05
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: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Scan To Pay] Add a screen with QR that encodes sharable payment URL

4 participants