Skip to content

Commit

Permalink
Allow Merchant to Only Set Universal Links for Venmo (#1503)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jaxdesmarais authored Jan 31, 2025
1 parent 66377ac commit f5db1d0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Braintree iOS SDK Release Notes

## unreleased
* BraintreeVenmo
* Allow universal links to be set without a return URL scheme (fixes #1505)

## 6.27.0 (2025-01-23)
* BraintreePayPal
* Add `BTContactInformation` request object
Expand Down
14 changes: 10 additions & 4 deletions Sources/BraintreeVenmo/BTVenmoClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,20 @@ import BraintreeCore
apiClient.sendAnalyticsEvent(BTVenmoAnalytics.tokenizeStarted, isVaultRequest: shouldVault, linkType: linkType)
let returnURLScheme = BTAppContextSwitcher.sharedInstance._returnURLScheme

if returnURLScheme.isEmpty {
if (universalLink?.absoluteString.isEmpty == true || universalLink?.absoluteString == nil) && returnURLScheme.isEmpty {
NSLog(
"%@ Venmo requires a return URL scheme to be configured via [BTAppContextSwitcher setReturnURLScheme:]",
"%@ Venmo requires a return URL scheme or universal link to be configured.",
BTLogLevelDescription.string(for: .critical)
)
notifyFailure(with: BTVenmoError.appNotAvailable, completion: completion)
notifyFailure(
with: BTVenmoError.invalidReturnURL("Venmo requires a return URL scheme or universal link to be configured."),
completion: completion
)
return
} else if let bundleIdentifier = bundle.bundleIdentifier, !returnURLScheme.hasPrefix(bundleIdentifier) {
} else if
let bundleIdentifier = bundle.bundleIdentifier,
!returnURLScheme.hasPrefix(bundleIdentifier)
&& (universalLink?.absoluteString.isEmpty == true || universalLink?.absoluteString == nil) {
NSLog(
// swiftlint:disable:next line_length
"%@ Venmo requires [BTAppContextSwitcher setReturnURLScheme:] to be configured to begin with your app's bundle ID (%@). Currently, it is set to (%@)",
Expand Down
14 changes: 14 additions & 0 deletions UnitTests/BraintreeVenmoTests/BTVenmoClient_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ class BTVenmoClient_Tests: XCTestCase {
let venmoClient = BTVenmoClient(apiClient: mockAPIClient)
BTAppContextSwitcher.sharedInstance.returnURLScheme = ""

let expectation = expectation(description: "authorization callback")
venmoClient.tokenize(venmoRequest) { venmoAccount, error in
guard let error = error as NSError? else { return }
XCTAssertEqual(error.domain, BTVenmoError.errorDomain)
XCTAssertEqual(error.code, BTVenmoError.invalidReturnURL("").errorCode)
expectation.fulfill()
}

waitForExpectations(timeout: 2)
}

func testTokenizeVenmoAccount_whenReturnURLSchemeAndUniversalLinkIsNil_andCallsBackWithError() {
let venmoClient = BTVenmoClient(apiClient: mockAPIClient)

let expectation = expectation(description: "authorization callback")
venmoClient.tokenize(venmoRequest) { venmoAccount, error in
guard let error = error as NSError? else {return}
Expand Down

0 comments on commit f5db1d0

Please sign in to comment.