diff --git a/CHANGELOG.md b/CHANGELOG.md index 156f06052..4ffda6028 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ * Add `BTPayPalRequest.userPhoneNumber` optional property * BraintreeVenmo * Send `url` in `event_params` for App Switch events to PayPal's analytics service (FPTI) +* BraintreeShopperInsights (BETA) + * Add `isPayPalAppInstalled()` and/or `isVenmoAppInstalled()` ## 6.24.0 (2024-10-15) * BraintreePayPal diff --git a/Podfile.lock b/Podfile.lock index 53baaccb0..086a065f0 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -37,4 +37,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 224cc2d6666b79d3d6adb45cccd6dfbc6fe74d18 -COCOAPODS: 1.15.2 +COCOAPODS: 1.14.3 diff --git a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift index e5dc83a6c..a7eec363f 100644 --- a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift +++ b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift @@ -140,4 +140,18 @@ public class BTShopperInsightsClient { ) return error } + + // MARK: - Public Methods + + /// Indicates whether the PayPal App is installed. + /// - Warning: This method is currently in beta and may change or be removed in future releases. + public func isPayPalAppInstalled() -> Bool { + application.isPayPalAppInstalled() + } + + /// Indicates whether the Venmo App is installed. + /// - Warning: This method is currently in beta and may change or be removed in future releases. + public func isVenmoAppInstalled() -> Bool { + application.isVenmoAppInstalled() + } } diff --git a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift index 168e28213..f19dccc3e 100644 --- a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift +++ b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift @@ -1,5 +1,6 @@ import Foundation import XCTest +@testable import BraintreePayPal @testable import BraintreeTestShared @testable import BraintreeShopperInsights @testable import BraintreeCore @@ -8,7 +9,9 @@ class BTShopperInsightsClient_Tests: XCTestCase { let clientToken = TestClientTokenFactory.token(withVersion: 3) var mockAPIClient: MockAPIClient! + var payPalClient: BTPayPalClient! var sut: BTShopperInsightsClient! + var mockWebAuthenticationSession: MockWebAuthenticationSession! let request = BTShopperInsightsRequest( email: "my-email", @@ -33,6 +36,9 @@ class BTShopperInsightsClient_Tests: XCTestCase { super.setUp() mockAPIClient = MockAPIClient(authorization: clientToken) sut = BTShopperInsightsClient(apiClient: mockAPIClient!) + payPalClient = BTPayPalClient(apiClient: mockAPIClient, universalLink: URL(string: "https://www.paypal.com")!) + mockWebAuthenticationSession = MockWebAuthenticationSession() + payPalClient.webAuthenticationSession = mockWebAuthenticationSession } // MARK: - getRecommendedPaymentMethods() @@ -227,4 +233,38 @@ class BTShopperInsightsClient_Tests: XCTestCase { sut.sendVenmoSelectedEvent() XCTAssertEqual(mockAPIClient.postedAnalyticsEvents.first, "shopper-insights:venmo-selected") } + + // MARK: - App Installed Methods + + func testIsPayPalAppInstalled_whenPayPalAppNotInstalled_returnsFalse() { + let fakeApplication = FakeApplication() + payPalClient.application = fakeApplication + fakeApplication.cannedCanOpenURL = false + + XCTAssertFalse(payPalClient.application.isPayPalAppInstalled()) + } + + func testIsPayPalAppInstalled_whenPayPalAppIsInstalled_returnsTrue() { + let fakeApplication = FakeApplication() + payPalClient.application = fakeApplication + fakeApplication.cannedCanOpenURL = true + + XCTAssertTrue(payPalClient.application.isPayPalAppInstalled()) + } + + func testIsVenmoAppInstalled_whenVenmoAppNotInstalled_returnsFalse() { + let fakeApplication = FakeApplication() + payPalClient.application = fakeApplication + fakeApplication.cannedCanOpenURL = false + + XCTAssertFalse(payPalClient.application.isVenmoAppInstalled()) + } + + func testIsVenmoAppInstalled_whenVenmoAppIsInstalled_returnsTrue() { + let fakeApplication = FakeApplication() + payPalClient.application = fakeApplication + fakeApplication.cannedCanOpenURL = true + + XCTAssertTrue(payPalClient.application.isVenmoAppInstalled()) + } }