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

[QL] Conform BTPayPalClient to BTAppContextSwitchClient Protocol #1218

Conversation

jaxdesmarais
Copy link
Contributor

@jaxdesmarais jaxdesmarais commented Mar 13, 2024

This work is into paypal-app-switch-feature

Summary of changes

  • Conform BTPayPalClient to BTAppContextSwitchClient
  • Add BTPayPalAppSwitchReturnURL struct
  • Add Unit Tests

Checklist

  • [ ] Added a changelog entry

Authors

@jaxdesmarais jaxdesmarais requested a review from a team as a code owner March 13, 2024 13:46
@jaxdesmarais jaxdesmarais changed the title Conform BTPayPalClient to BTAppContextSwitchClient Protocol [QL] Conform BTPayPalClient to BTAppContextSwitchClient Protocol Mar 13, 2024
/// :nodoc:
@_documentation(visibility: private)
@objc public static func canHandleReturnURL(_ url: URL) -> Bool {
url.scheme == "https" && (url.path.contains("cancel") || url.path.contains("success"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on the current contracts I don't believe we will ever get an error path back. In the future if we do we can consider adding it here. We can also consider adding a check here that the host contains the universalLink set on BTAppContextSwitcher. What do folks think?

Copy link
Contributor

Choose a reason for hiding this comment

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

There won't be an error specific scenario in the URL, no.

Though we will want to surface the cancel as an error to the merchant, as well as continue with the flow to call the paypal_accounts API in the case of success. Are you planning to add those paths in this PR? If not, can we add TODOs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though we will want to surface the cancel as an error to the merchant

🤔 how would we both surface the cancel as an error and continue the flow? If we surfaced it in our completion I would expect the execution of that path would also end? Or do we want to diverge from that pattern and latter in the flow return both a nonce and an error?

Are you planning to add those paths in this PR? If not, can we add TODOs?

There is a TODO in handleOpen above where we will build out the logic in a future PR to handle the return URL. This is just the logic that determines if our SDK can process the URL we get back (though I did notice just now BTAppContextSwitcher wasn't registered properly and updated here along with deploying a success path so we can test that these methods are hit: 9efbff2)

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 how would we both surface the cancel as an error and continue the flow? If we surfaced it in our completion I would expect the execution of that path would also end?

Yes! Like we do today when we get back cancel in the URL for the web-based flow, we end the flow for the merchant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes since, sorry I read that wrong at first as we want to continue the flow on cancel, but that portion was for success. 🙈

Do we think it'd be helpful to also validate that the host contains the value passed into BTAppContextSwitcher.shared.universalLink or do we think this is sufficient (checking for https and cancel or success)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question - maybe we can assume that if the switch successfully made it into the merchant app, that the host of the URL is fine. I vote for not doing that check, for now. But don't feel strongly if you have other thoughts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with that too, we can always add it in a future PR if we decide we need additional validation.

Base automatically changed from app-context-switcher-universal-link to paypal-app-switch-feature March 14, 2024 15:48
…ient-protocol-conformance

# Conflicts:
#	Demo/Application/Base/SceneDelegate.swift
#	Demo/Application/Features/PayPalWebCheckoutViewController.swift
#	Sources/BraintreeCore/BTAppContextSwitcher.swift
/// :nodoc:
@_documentation(visibility: private)
@objc public static func canHandleReturnURL(_ url: URL) -> Bool {
url.scheme == "https" && (url.path.contains("cancel") || url.path.contains("success"))
Copy link
Contributor

@scannillo scannillo Mar 19, 2024

Choose a reason for hiding this comment

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

Another thought - might be more readable to keep this similar to Venmo which has a separate class (BTVenmoAppSwitchReturnURL) for the isValid() logic & eventual param parsing? So adding something like a BTVeniceAppSwitchReturnURL class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm down, updated here (I opted to call it BTPayPalAppSwitchReturnURL since I assume Venice is somewhat internal): 4b39541

@@ -221,6 +229,12 @@ import BraintreeDataCollector
performSwitchRequest(appSwitchURL: url, paymentType: paymentType, completion: completion)
}

// MARK: - App Switch Methods

func handleOpen(_ url: URL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is the naming we use in Venmo, but it's a little confusing to me since without looking through the code callsites you don't know if this method is for opening the Venmo app, or opening the merchant app.

Take it or leave it comment - but we could rename to handleReturnURL() or something similar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense to me too: 2d53f54

@jaxdesmarais jaxdesmarais merged commit 2bff949 into paypal-app-switch-feature Mar 19, 2024
7 checks passed
@jaxdesmarais jaxdesmarais deleted the app-context-switcher-client-protocol-conformance branch March 19, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants