-
Notifications
You must be signed in to change notification settings - Fork 121
[Mobile Payments] Disconnect built-in reader when Manage card readers is tapped #8666
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] Disconnect built-in reader when Manage card readers is tapped #8666
Conversation
There’s nothing to manage or view about the built in reader, and from a user’s perspective there isn’t a reader at all, it’s just part of their phone. Since we can’t connect to the Bluetooth reader until the built in reader is disconnected, we just do that automatically for the user here. This saves us updating the display of the connected reader to be suitable for the built in reader too. We can revisit this in future, but for M1 it makes sense.
You can test the changes from this Pull Request by:
|
|
Thanks for the PR @joshheald! I have a question regarding the implementation, also link with my first comment. If I follow the flow correctly, every time the list of connected readers changes we are notified by observing the Is it like that? In that case, what happens if the list changes because the Apple Built-in reader is just connected? From this perspective, we can end up having the opposite effect we expected: We wanted to connect the Apple Built-in reader, but it ends up being disconnected. |
| } | ||
|
|
||
| private func updateProperties() { | ||
| if let connectedReader = connectedReaders.first, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering, is this the best place to disconnect the reader? After all, the purpose of this function is to update the properties with the first connected reader data; disconnecting the reader seems like an unexpected side effect here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point: I could put it directly in the completion block for observeConnectedReaders in beginObservation. It won't make any difference to the functionality or way it works though: updateProperties is only called from that same block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved in 0a92d0f
| newShouldShow = .isUnknown | ||
| } else if connectedReaders.isEmpty { | ||
| newShouldShow = .isFalse | ||
| } else if connectedReaders.first(where: { $0.readerType == .appleBuiltIn }) != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this means that if any of the connected readers is the Apple Built-in one we don't show the view right? What happens if we are connected to a Bluetooth reader apart from of that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, however we don't actually support being connected to more than one reader, and neither do Stripe.
So we can't be connected to more than one at a time, and this class doesn't otherwise handle that situation anyway (it relies on .first to determine the connected reader.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proper fix for this inconsistency would be to change connectedReaders to a single object, not an array, but that is way out of scope here 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proper fix for this inconsistency would be to change connectedReaders to a single object, not an array, but that is way out of scope here 😊
That's what I thought, can we create an issue to change that?
| private var softwareUpdateSubject: CurrentValueSubject<CardReaderSoftwareUpdateState, Never> = .init(.none) | ||
| private var paymentExtension: CardPresentPaymentGatewayExtension | ||
|
|
||
| var recievedActions: [CardPresentPaymentAction] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here, recievedActions -> receivedActions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 791b53b
|
@toupper Thanks for the review
This is not a problem: the code in question is specific to the This is because the merchant is unlikely to think of the built-in reader as a "Card reader" they need to manage, it's just a part of their phone. |
Thanks for your answer @joshheald ! That makes sense now. I have a few suggestions to make this more clear:
to its own function, with naming
|
|
@joshheald The code looks good and it tests well 🎉 I added a few code suggestions, and I have one small finding when testing:
When testing this step, not only are we asked what reader we want to connect, but we also show a loading screen with "Connecting to your account" message. If the reader is connected (step 7) we don't need to connect to our account. Why is being disconnected from a reader causes having to connect to the account? |
|
Thanks for the re-review @toupper
This happens in the onboarding check, it's pre-existing. We always check the onboarding status before any reader connection, so that we can be sure the user's account is in the correct state to connect/take a payment, but we don't do that if they're already connected to a reader as we can presume that they've had the check done recently. |
The CardReaderSettingsConnectedViewModel is now specific to Bluetooth readers, as we do not expect users to view the built-in card reader as something they need to connect to and manage. This commit neatens that up and explains the logic.
Closes: #8664
Description
In sTAP Away, we add support for the built-in card reader, allowing merchants to take card payments using Tap to Pay on iPhone.
We can be connected to either the built-in reader, or a Bluetooth reader, but not both simultaneously.
There’s nothing to manage or view about the built in reader, and from a user’s perspective there isn’t a reader at all, it’s just part of their phone.
Since we can’t connect to the Bluetooth reader until the built in reader is disconnected, we just do that automatically for the user here. This saves us updating the display of the connected reader to be suitable for the built in reader too.
We can revisit this in future, but for M1 it makes sense.
Testing instructions
Using a US-based WCPay or Stripe store:
Menu > Settings > Experimental featuresTap to Pay on iPhoneMenu > Payments > Collect paymentCardon the payment method screenTap to Pay on iPhoneand connect to the readerMenu > Payments > Manage Card ReaderIn general –
Manage Card ReaderDisconnectin theManage Card Readerscreen.Screenshots
disconnect-on-manage-reader.mp4
RELEASE-NOTES.txtif necessary.