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/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift index e5dc83a6c..c40368229 100644 --- a/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift +++ b/Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift @@ -25,6 +25,8 @@ public class BTShopperInsightsClient { self.apiClient = apiClient } + // MARK: - Public Methods + /// This method confirms if the customer is a user of PayPal services using their email and phone number. /// - Parameters: /// - request: Required: A `BTShopperInsightsRequest` containing the buyer's user information. @@ -121,7 +123,19 @@ public class BTShopperInsightsClient { public func sendVenmoSelectedEvent() { apiClient.sendAnalyticsEvent(BTShopperInsightsAnalytics.venmoSelected) } - + + /// 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() + } + // MARK: - Analytics Helper Methods private func notifySuccess(with result: BTShopperInsightsResult, for experiment: String?) -> BTShopperInsightsResult { diff --git a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift index 168e28213..a8019bbdf 100644 --- a/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift +++ b/UnitTests/BraintreeShopperInsightsTests/BTShopperInsightsClient_Tests.swift @@ -227,4 +227,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() + fakeApplication.cannedCanOpenURL = false + + XCTAssertFalse(sut.isPayPalAppInstalled()) + } + + func testIsPayPalAppInstalled_whenPayPalAppIsInstalled_returnsTrue() { + let fakeApplication = FakeApplication() + fakeApplication.cannedCanOpenURL = true + fakeApplication.canOpenURLWhitelist.append(URL(string: "paypal-app-switch-checkout://x-callback-url/path")!) + sut.application = fakeApplication + + XCTAssertTrue(sut.isPayPalAppInstalled()) + } + + func testIsVenmoAppInstalled_whenVenmoAppNotInstalled_returnsFalse() { + let fakeApplication = FakeApplication() + fakeApplication.cannedCanOpenURL = false + + XCTAssertFalse(sut.isVenmoAppInstalled()) + } + + func testIsVenmoAppInstalled_whenVenmoAppIsInstalled_returnsTrue() { + let fakeApplication = FakeApplication() + fakeApplication.cannedCanOpenURL = true + fakeApplication.canOpenURLWhitelist.append(URL(string: "com.venmo.touch.v2://x-callback-url/path")!) + sut.application = fakeApplication + + XCTAssertTrue(sut.isVenmoAppInstalled()) + } }