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

[RP1][iOS] Expose PayPal and Venmo App Installed for Merchants #1473

Merged
merged 10 commits into from
Dec 6, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public class BTShopperInsightsClient {
public init(apiClient: BTAPIClient) {
self.apiClient = apiClient
}

jaxdesmarais marked this conversation as resolved.
Show resolved Hide resolved

// 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.
Expand Down Expand Up @@ -121,7 +124,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}