Skip to content

Commit f5db1d0

Browse files
authored
Allow Merchant to Only Set Universal Links for Venmo (#1503)
* A bug was recently brought to the service channel where if a merchant trys to move from the deprecated BTAppContextSwitcher.sharedInstance.returnURLScheme for Venmo they get an error if only passing a universal link. We should allow merchants to only use universal links without needing to set both that and a returnURLScheme
1 parent 66377ac commit f5db1d0

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Braintree iOS SDK Release Notes
22

3+
## unreleased
4+
* BraintreeVenmo
5+
* Allow universal links to be set without a return URL scheme (fixes #1505)
6+
37
## 6.27.0 (2025-01-23)
48
* BraintreePayPal
59
* Add `BTContactInformation` request object

Sources/BraintreeVenmo/BTVenmoClient.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,20 @@ import BraintreeCore
8383
apiClient.sendAnalyticsEvent(BTVenmoAnalytics.tokenizeStarted, isVaultRequest: shouldVault, linkType: linkType)
8484
let returnURLScheme = BTAppContextSwitcher.sharedInstance._returnURLScheme
8585

86-
if returnURLScheme.isEmpty {
86+
if (universalLink?.absoluteString.isEmpty == true || universalLink?.absoluteString == nil) && returnURLScheme.isEmpty {
8787
NSLog(
88-
"%@ Venmo requires a return URL scheme to be configured via [BTAppContextSwitcher setReturnURLScheme:]",
88+
"%@ Venmo requires a return URL scheme or universal link to be configured.",
8989
BTLogLevelDescription.string(for: .critical)
9090
)
91-
notifyFailure(with: BTVenmoError.appNotAvailable, completion: completion)
91+
notifyFailure(
92+
with: BTVenmoError.invalidReturnURL("Venmo requires a return URL scheme or universal link to be configured."),
93+
completion: completion
94+
)
9295
return
93-
} else if let bundleIdentifier = bundle.bundleIdentifier, !returnURLScheme.hasPrefix(bundleIdentifier) {
96+
} else if
97+
let bundleIdentifier = bundle.bundleIdentifier,
98+
!returnURLScheme.hasPrefix(bundleIdentifier)
99+
&& (universalLink?.absoluteString.isEmpty == true || universalLink?.absoluteString == nil) {
94100
NSLog(
95101
// swiftlint:disable:next line_length
96102
"%@ Venmo requires [BTAppContextSwitcher setReturnURLScheme:] to be configured to begin with your app's bundle ID (%@). Currently, it is set to (%@)",

UnitTests/BraintreeVenmoTests/BTVenmoClient_Tests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ class BTVenmoClient_Tests: XCTestCase {
7878
let venmoClient = BTVenmoClient(apiClient: mockAPIClient)
7979
BTAppContextSwitcher.sharedInstance.returnURLScheme = ""
8080

81+
let expectation = expectation(description: "authorization callback")
82+
venmoClient.tokenize(venmoRequest) { venmoAccount, error in
83+
guard let error = error as NSError? else { return }
84+
XCTAssertEqual(error.domain, BTVenmoError.errorDomain)
85+
XCTAssertEqual(error.code, BTVenmoError.invalidReturnURL("").errorCode)
86+
expectation.fulfill()
87+
}
88+
89+
waitForExpectations(timeout: 2)
90+
}
91+
92+
func testTokenizeVenmoAccount_whenReturnURLSchemeAndUniversalLinkIsNil_andCallsBackWithError() {
93+
let venmoClient = BTVenmoClient(apiClient: mockAPIClient)
94+
8195
let expectation = expectation(description: "authorization callback")
8296
venmoClient.tokenize(venmoRequest) { venmoAccount, error in
8397
guard let error = error as NSError? else {return}

0 commit comments

Comments
 (0)