diff --git a/CHANGELOG.md b/CHANGELOG.md index bcea2b24e..c563b4664 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Braintree iOS SDK Release Notes ## unreleased +* BraintreeVenmo + * Allow universal links to be set without a return URL scheme (fixes #1505) * BraintreeCore * Update to use `NSSecureCoding` protocol (fixes #1508) diff --git a/Sources/BraintreeVenmo/BTVenmoClient.swift b/Sources/BraintreeVenmo/BTVenmoClient.swift index 7193bb875..52546b78a 100644 --- a/Sources/BraintreeVenmo/BTVenmoClient.swift +++ b/Sources/BraintreeVenmo/BTVenmoClient.swift @@ -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 (%@)", diff --git a/UnitTests/BraintreeVenmoTests/BTVenmoClient_Tests.swift b/UnitTests/BraintreeVenmoTests/BTVenmoClient_Tests.swift index e9101a438..11eb0f6a9 100644 --- a/UnitTests/BraintreeVenmoTests/BTVenmoClient_Tests.swift +++ b/UnitTests/BraintreeVenmoTests/BTVenmoClient_Tests.swift @@ -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}