Skip to content
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

[Experiment] Card payments adaptor stream #12736

Closed
wants to merge 4 commits into from

Conversation

joshheald
Copy link
Contributor

Part of: #12734

Description

This is another (incomplete) take on #12735, but using a stream for outputting the events.

There are issues with this approach, particularly because the stream's lifecycle should probably match the lifecycle of the collectPayment call, and everything that does. However, I struggled to make the connection controllers long-lived under those circumstances.

It's probably still possible, so I thought I'd share this as another similar solution for thoughts... but #12735 is more promising right now, I think.

CC. @iamgabrielma @bozidarsevo @jaclync

@joshheald joshheald added status: do not merge Dependent on another PR, ready for review but not ready for merge. feature: POS labels May 14, 2024
@wpmobilebot
Copy link
Collaborator

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 Numberpr12736-425c030
Version18.6
Bundle IDcom.automattic.alpha.woocommerce
Commit425c030
App Center BuildWooCommerce - Prototype Builds #9056
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@dangermattic
Copy link
Collaborator

1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

import Yosemite
import class WooFoundation.CurrencyFormatter

class CardPresentPaymentsAdaptor {
Copy link
Contributor

@jaclync jaclync May 15, 2024

Choose a reason for hiding this comment

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

💬 Payments newbie questions (I've edited it after understanding more about the changes):

  • Is this meant to be a singleton in the app for any card-present payments-related actions and states, including onboarding, reader connection, and payment collection from any entry point? While looking at the reader connection code, the Menu Payments setup seems different from the Orders tab. This adapter solves the problem with one single implementation that maintains various states, with pos being a new entry point.
  • For reuse in the current POS framework, do you think it makes sense to have a protocol for this in Yosemite (given that we don't have plans to create new frameworks) so that the singleton uses the interface? It might help with unit testing as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this meant to be a singleton in the app for any card-present payments-related actions and states, including onboarding, reader connection, and payment collection from any entry point? [...] This adapter solves the problem with one single implementation that maintains various states, with pos being a new entry point.

Yes, exactly.

We may also want to add a separate connection function from the same entry point, but it didn't seem essential to this experiment.

In the app right now, the vast majority of people connect the reader during payment.

While looking at the reader connection code, the Menu Payments setup seems different from the Orders tab.

Yeah, the menu setup screen is a bit different, but it does use the connection controllers. It would be better if we had a single source of truth for these controllers, which we could add via this adaptor in the MVP or beyond, but it's not essential.

For reuse in the current POS framework, do you think it makes sense to have a protocol for this in Yosemite (given that we don't have plans to create new frameworks) so that the singleton uses the interface? It might help with unit testing as well.

I've written this in the App framework, initially thinking about the situation of POS being in the App framework and removing the POS framework.

If we do continue with the POS framework, we have to make some choices if we use this approach...

We certainly could move the code that this depends on to Yosemite, but the singleton itself would need to live there too; using a shared interface wouldn't get us the code reuse benefits of the adaptor.

Alternatively, we could copy all the card reader code, and this adaptor, from the App framework to the POS framework, and build it out from there. That might let us improve on a "fork" (sort of) of the card reader code for the POS, which we could then merge back to the app target, or move down to Yosemite for sharing.

self.siteID = siteID
}

/// The problem with this approach is that making the usecase also makes the preflight controller, which makes the two connection controllers.
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the reasons this adaptor can't keep the 2 connection controllers and then pass them in a preflight controller like in https://github.com/woocommerce/woocommerce-ios/pull/12735/files#diff-2c42212ff82dbd5a932472da2fdfa48bf6af9ca77d78c4d5ea7ad3985b47632cR53?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the connection controllers would also need to have the eventAdaptor, which has to be short-lived as it is tied to the same lifecycle as the stream.

Perhaps we could have a long-lived eventAdaptor which could be given a new streamContinuation whenever a new payment started. That seems like it would be quite error-prone, as streams may not be finished before they're replaced, and if we use streams I want to make it more difficult to misuse them than they are currently.

}
}

enum CardPresentPaymentEvent {
Copy link
Contributor

@jaclync jaclync May 15, 2024

Choose a reason for hiding this comment

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

My guess is that this is for the consumer of this adaptor to have any UI implementation / side tasks for these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, yes.

I'm going to experiment with adapting the existing UI to be presentable without compromises in SwiftUI, but I'm not particularly hopeful about that.

@malinajirka
Copy link
Contributor

Closing as this PR is not active anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: POS status: do not merge Dependent on another PR, ready for review but not ready for merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants