Skip to content

Commit

Permalink
[RP1][iOS] Expose PayPal and Venmo App Installed for Merchants (#1473)
Browse files Browse the repository at this point in the history
* Added `isPayPalAppInstalled`, `isVenmoAppInstalled` methods

* Moved methods to Shopper Insights

* Fixed failing unit tests. Added to CHANGELOG

* Addressed PR comment

* Update Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift
  • Loading branch information
stechiu authored Dec 6, 2024
1 parent 8941506 commit 6b3450b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
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
16 changes: 15 additions & 1 deletion Sources/BraintreeShopperInsights/BTShopperInsightsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
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())
}
}

0 comments on commit 6b3450b

Please sign in to comment.