Skip to content

Commit

Permalink
pass isPayPalAppInstalled into parameters; update tests; remove appli…
Browse files Browse the repository at this point in the history
…cation from VaultRequest
  • Loading branch information
jaxdesmarais committed Aug 7, 2024
1 parent e4f4484 commit 893d736
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Sources/BraintreePayPal/BTPayPalCheckoutRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion Sources/BraintreePayPal/BTPayPalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/BraintreePayPal/BTPayPalRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/BraintreePayPal/BTPayPalVaultBaseRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
7 changes: 2 additions & 5 deletions Sources/BraintreePayPal/BTPayPalVaultRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions UnitTests/BraintreePayPalTests/BTPayPalClient_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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+"))
Expand Down

0 comments on commit 893d736

Please sign in to comment.