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] Consolidate Return URL Logic #1271

Merged
merged 11 commits into from
Apr 11, 2024

Conversation

jaxdesmarais
Copy link
Contributor

Summary of changes

  • Rename BTPayPalAppSwitchReturnURL to BTPayPalReturnURL since this is now used for both app switch and web based flows
    • Move return URL related logic into this struct
  • Rename BTPayPalAppSwitchReturnURL_Tests to BTPayPalReturnURL_Tests

Checklist

  • [ ] Added a changelog entry

Authors

@jaxdesmarais jaxdesmarais requested a review from a team as a code owner April 11, 2024 13:54
/// This class interprets URLs received from the PayPal app via app switch returns.
///
/// PayPal app switch authorization requests should result in success or user-initiated cancelation. These states are communicated in the url.
struct BTPayPalReturnURL {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file was renamed but is showing additional diff. Adding logic for the web flow in the init as well as adding isValidURLAction plus action methods here are the actual changes.

Comment on lines +60 to +62
/// If we are using the deeplink/ASWeb based PayPal flow we want to check that the host and path matches
/// the static callbackURLHostAndPath. For the universal link flow we do not care about this check.
if hostAndPath != BTPayPalRequest.callbackURLHostAndPath && linkType == "deeplink" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@agedd I know you mentioned this logic for this specific if block being confusing before. I added the docstrings as well as passing/checking the linkType here as deeplink instead of passing in the request and doing some weird stuff with that. Please let me know if this makes it clearer what this check is doing!

Copy link
Contributor

Choose a reason for hiding this comment

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

this looks great! @jaxdesmarais imo definitely a lot more clearer to read :)

import XCTest
@testable import BraintreePayPal

final class BTPayPalReturnURL_Tests: XCTestCase {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of this test class is not new, was just renamed. The testInitWithSchemeURL are the only new tests since we are passing both scheme based URLs and Universal Link URLs into the init now.

notifyFailure(with: BTPayPalError.invalidURLAction, completion: completion)
return
}

guard let response = responseDictionary(from: url) else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The responseDictionary method was a bit odd because it was both building the dictionary to pass into the post parameters as well as doing a check that the URL did not contain cancel. The only part that used the return URL was the cancel check so I broke this out to build the dictionary here which made more sense.

Base automatically changed from update-logic-for-app-switch to paypal-app-switch-feature April 11, 2024 17:55
enum BTPayPalReturnURLState {
case unknownPath
case succeeded
case canceled
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit:

Suggested change
case canceled
case cancelled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our SDKs always use the 1 L canceled/cancelation

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.

looking great!! 🚀

@jaxdesmarais jaxdesmarais merged commit 346e4e9 into paypal-app-switch-feature Apr 11, 2024
6 of 7 checks passed
@jaxdesmarais jaxdesmarais deleted the consolidate-returnURL-logic branch April 11, 2024 20:03
init?(body: BTJSON) {
if let payPalAppRedirectURL = body["agreementSetup"]["paypalAppApprovalUrl"].asURL() {
init?(body: BTJSON, linkType: String?) {
if linkType == "universal", let payPalAppRedirectURL = body["agreementSetup"]["paypalAppApprovalUrl"].asURL() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit for another time - maybe another indicator we should move this to an enum

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I don't think the BTPayPalApprovalURLParser class should care if the merchant has opted into universal links or not. It's only determining which URL type it got back from the GW response.

The flow logic for falling back to the web flow already is taken care of in BTPayPalClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As of Thursday, we were still getting the paypalAppApprovalUrl from the Gateway regardless of the BTPayPalClient. This may have been because we were working with a mock and an update may have been deployed to just allow our client side handling. Worth digging into but I was still getting this URL with the PPBeta app uninstalled.

@jaxdesmarais jaxdesmarais mentioned this pull request Aug 7, 2024
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.

6 participants