From 893d7363221beaa8711f453415fd6249d22d43bf Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Wed, 7 Aug 2024 16:01:06 -0500 Subject: [PATCH] pass isPayPalAppInstalled into parameters; update tests; remove application from VaultRequest --- Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift | 2 +- Sources/BraintreePayPal/BTPayPalClient.swift | 6 +++++- Sources/BraintreePayPal/BTPayPalRequest.swift | 2 +- Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift | 2 +- Sources/BraintreePayPal/BTPayPalVaultRequest.swift | 7 ++----- UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift | 2 -- .../BraintreePayPalTests/BTPayPalVaultRequest_Tests.swift | 6 +----- 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift b/Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift index adeb355c9b..7032253a99 100644 --- a/Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift +++ b/Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift @@ -120,7 +120,7 @@ import BraintreeCore /// :nodoc: Exposed publicly for use by PayPal Native Checkout module. This method is not covered by semantic versioning. @_documentation(visibility: private) - public override func parameters(with configuration: BTConfiguration, universalLink: URL? = nil) -> [String: Any] { + public override func parameters(with configuration: BTConfiguration, universalLink: URL? = nil, isPayPalAppInstalled: Bool = false) -> [String: Any] { var baseParameters = super.parameters(with: configuration) var checkoutParameters: [String: Any] = [ "intent": intent.stringValue, diff --git a/Sources/BraintreePayPal/BTPayPalClient.swift b/Sources/BraintreePayPal/BTPayPalClient.swift index a699de6bb1..8ea2136b6c 100644 --- a/Sources/BraintreePayPal/BTPayPalClient.swift +++ b/Sources/BraintreePayPal/BTPayPalClient.swift @@ -332,7 +332,11 @@ import BraintreeDataCollector self.payPalRequest = request self.apiClient.post( request.hermesPath, - parameters: request.parameters(with: configuration, universalLink: self.universalLink) + parameters: request.parameters( + with: configuration, + universalLink: self.universalLink, + isPayPalAppInstalled: self.application.isPayPalAppInstalled() + ) ) { body, response, error in if let error = error as? NSError { guard let jsonResponseBody = error.userInfo[BTCoreConstants.jsonResponseBodyKey] as? BTJSON else { diff --git a/Sources/BraintreePayPal/BTPayPalRequest.swift b/Sources/BraintreePayPal/BTPayPalRequest.swift index 2ec43edfdb..a2aefcec84 100644 --- a/Sources/BraintreePayPal/BTPayPalRequest.swift +++ b/Sources/BraintreePayPal/BTPayPalRequest.swift @@ -135,7 +135,7 @@ import BraintreeCore /// :nodoc: Exposed publicly for use by PayPal Native Checkout module. This method is not covered by semantic versioning. @_documentation(visibility: private) - public func parameters(with configuration: BTConfiguration, universalLink: URL? = nil) -> [String: Any] { + public func parameters(with configuration: BTConfiguration, universalLink: URL? = nil, isPayPalAppInstalled: Bool = false) -> [String: Any] { var experienceProfile: [String: Any] = [:] experienceProfile["no_shipping"] = !isShippingAddressRequired diff --git a/Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift b/Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift index 7d2fbe7743..4a8f5b58a4 100644 --- a/Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift +++ b/Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift @@ -27,7 +27,7 @@ import BraintreeCore /// :nodoc: Exposed publicly for use by PayPal Native Checkout module. This method is not covered by semantic versioning. @_documentation(visibility: private) - public override func parameters(with configuration: BTConfiguration, universalLink: URL? = nil) -> [String: Any] { + public override func parameters(with configuration: BTConfiguration, universalLink: URL? = nil, isPayPalAppInstalled: Bool = false) -> [String: Any] { let baseParameters = super.parameters(with: configuration) var vaultParameters: [String: Any] = ["offer_paypal_credit": offerCredit] diff --git a/Sources/BraintreePayPal/BTPayPalVaultRequest.swift b/Sources/BraintreePayPal/BTPayPalVaultRequest.swift index 080dd3f419..4114ba940e 100644 --- a/Sources/BraintreePayPal/BTPayPalVaultRequest.swift +++ b/Sources/BraintreePayPal/BTPayPalVaultRequest.swift @@ -19,9 +19,6 @@ import BraintreeCore /// - Warning: This property is currently in beta and may change or be removed in future releases. var enablePayPalAppSwitch: Bool = false - /// exposed for mocking in tests - var application: URLOpener = UIApplication.shared - // MARK: - Initializers /// Initializes a PayPal Vault request for the PayPal App Switch flow @@ -49,14 +46,14 @@ import BraintreeCore super.init(offerCredit: offerCredit) } - public override func parameters(with configuration: BTConfiguration, universalLink: URL? = nil) -> [String: Any] { + public override func parameters(with configuration: BTConfiguration, universalLink: URL? = nil, isPayPalAppInstalled: Bool = false) -> [String: Any] { var baseParameters = super.parameters(with: configuration) if let userAuthenticationEmail { baseParameters["payer_email"] = userAuthenticationEmail } - if let universalLink, enablePayPalAppSwitch, application.isPayPalAppInstalled() { + if let universalLink, enablePayPalAppSwitch, isPayPalAppInstalled { let appSwitchParameters: [String: Any] = [ "launch_paypal_app": enablePayPalAppSwitch, "os_version": UIDevice.current.systemVersion, diff --git a/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift b/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift index ef1dffb9c4..7fff4ad489 100644 --- a/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift +++ b/UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift @@ -938,8 +938,6 @@ class BTPayPalClient_Tests: XCTestCase { enablePayPalAppSwitch: true ) - vaultRequest.application = fakeApplication - mockAPIClient.cannedResponseBody = BTJSON(value: [ "agreementSetup": [ "paypalAppApprovalUrl": "https://www.some-url.com/some-path?token=value1" diff --git a/UnitTests/BraintreePayPalTests/BTPayPalVaultRequest_Tests.swift b/UnitTests/BraintreePayPalTests/BTPayPalVaultRequest_Tests.swift index d4d21bfb63..dedae48fee 100644 --- a/UnitTests/BraintreePayPalTests/BTPayPalVaultRequest_Tests.swift +++ b/UnitTests/BraintreePayPalTests/BTPayPalVaultRequest_Tests.swift @@ -77,11 +77,7 @@ class BTPayPalVaultRequest_Tests: XCTestCase { enablePayPalAppSwitch: true ) - let fakeApplication = FakeApplication() - fakeApplication.cannedCanOpenURL = true - request.application = fakeApplication - - let parameters = request.parameters(with: configuration, universalLink: URL(string: "some-url")!) + let parameters = request.parameters(with: configuration, universalLink: URL(string: "some-url")!, isPayPalAppInstalled: true) XCTAssertEqual(parameters["launch_paypal_app"] as? Bool, true) XCTAssertTrue((parameters["os_version"] as! String).matches("\\d+\\.\\d+"))