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] Parse App Switch Return URL #1237

Merged
merged 26 commits into from
Apr 3, 2024

Conversation

jaxdesmarais
Copy link
Contributor

@jaxdesmarais jaxdesmarais commented Mar 28, 2024

Summary of changes

  • Add implementation to BTPayPalAppSwitchReturnURL
  • Rename BTPayPalClient.handleBrowserSwitchReturn to handleReturn since it will be used for both app switch and ASWeb returns
  • Add implementation for handleReturnURL for App Switch flows
  • Add new BTPayPalError.unknownAppSwitchError and update typo on invalidURL error
  • Add BTPayPalAppSwitchReturnURL_Tests
  • Add new BTPayPalClient_Tests for new code

Checklist

  • [ ] Added a changelog entry

Authors

@jaxdesmarais jaxdesmarais requested a review from a team as a code owner March 28, 2024 13:15
@@ -73,7 +78,7 @@ public enum BTPayPalError: Error, CustomNSError, LocalizedError, Equatable {
case .httpPostRequestError(let error):
return "HTTP POST request failed with \(error)."
case .invalidURL(let error):
return "An error occured with retrieving a PayPal authentication URL: \(error)"
return "An error occurred with retrieving a PayPal URL: \(error)"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We had a typo here and also are using this error for URLs outside of authentication so updated this string.

@scannillo
Copy link
Contributor

Were you able to test with any stubbed redirect URL (using our demo apps fly.io site)? I'm curious if /v1/payment_methods/paypal_accounts works as expected with an HTTPS path or if we'll need an update from the GW

…valid; update docstring; update localizedDescription
@jaxdesmarais
Copy link
Contributor Author

Were you able to test with any stubbed redirect URL (using our demo apps fly.io site)? I'm curious if /v1/payment_methods/paypal_accounts works as expected with an HTTPS path or if we'll need an update from the GW

I was able to test this and there were no issues with the HTTPS path, since we are mainly parsing the data from that path to send into paypal_accounts. It's a bit awkward to test since we are working off of mocks right now, but this is what I did (it needs a real EC token and BA token to work):

  1. Comment out our UIApplication.shared.open line in the View Controller
  2. Add a breakpoint in line 169 of handleReturn and grab the valid EC and BA token from the URL
  3. Stop the app and replace line 169-175 with:
        let newURL = URL(string: "https://www.paypal.com/success?token=MY_EC_TOKEN&ba_token=MY_BA_TOKEN&switch_initiated_time=123456789")!
        guard isValidURLAction(url: newURL) else {
            notifyFailure(with: BTPayPalError.invalidURLAction, completion: completion)
            return
        }
        
        guard let response = responseDictionary(from: newURL) else {
  1. Run the app again with this change
  2. No errors are returned in paypal_accounts and we get a nonce back as expected in notifySuccess

We can really only test pieces of this so far until we actually start getting the expected data back, but working off of our mocks this should work as expected 🤞. Let me know if I misunderstood what you were thinking we'd test here, did a lot of very hacky workarounds based on mocks to test different pieces. 😅

@@ -368,7 +382,7 @@ import BraintreeDataCollector
hostAndPath.append("/")
}

if hostAndPath != BTPayPalRequest.callbackURLHostAndPath {
if hostAndPath != BTPayPalRequest.callbackURLHostAndPath && (payPalRequest as? BTPayPalVaultRequest)?.universalLink == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

curious why we add the check for universalLink being nil here 👀

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 question, we only care about (and want to return false here for isValidURLAction) if the hostAndPath is not the callbackURLHostAndPath and if the universalLink is nil. That combination would mean that we aren't using the UL flow and the hostAndPath is invalid we wouldn't have a valid URL action. If we are using the UL flow we can essentially skip this check since it's not relevant to that flow.

Copy link
Contributor

Choose a reason for hiding this comment

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

This line is a little confusing to read IMO. I think it will clear up in DTBTSDK-3751

@@ -368,7 +382,7 @@ import BraintreeDataCollector
hostAndPath.append("/")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Now we have some return URL parsing happening in BTPayPalClient and some happening in BTPayPalAppSwitchReturnURL. Maybe for another PR, we can repurpose BTPayPalAppSwitchReturnURL to do URL parsing for both the web flow & app switch flows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created DTBTSDK-3751 for this

Copy link
Contributor

@agedd agedd left a comment

Choose a reason for hiding this comment

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

left a few minor comments, looks good to me!

Comment on lines 27 to 28
/// The timestamp from the return URL.
var timestamp: String?
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment here, we aren't using this.

This surfaces that we need to ask the analytics folks what they want us to do with this number, let's ask them! They may want us including it in an additional analytic event send

@jaxdesmarais jaxdesmarais merged commit b692e41 into paypal-app-switch-feature Apr 3, 2024
6 of 7 checks passed
@jaxdesmarais jaxdesmarais deleted the parse-return-url branch April 3, 2024 15:11
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