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

Bug Fix: Handle Missing 3DS dfReferenceId #1499

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Braintree iOS SDK Release Notes

## unreleased
## unreleased
* BraintreePayPal
* Fix bug to ensure that `BTPayPalVaultRequest.userAuthenticationEmail` is not sent as an empty string
* BraintreeThreeDSecure
* Return error if no `dfReferenceId` is returned in the 3D Secure flow

## 6.25.0 (2024-12-11)
* BraintreePayPal
Expand Down
11 changes: 9 additions & 2 deletions Sources/BraintreeThreeDSecure/BTThreeDSecureClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,16 @@ import BraintreeCore
request: request,
cardinalSession: cardinalSession
) { lookupParameters in
if let dfReferenceID = lookupParameters?["dfReferenceId"] {
request.dfReferenceID = dfReferenceID
guard let dfReferenceID = lookupParameters?["dfReferenceId"], !dfReferenceID.isEmpty else {
completion(
BTThreeDSecureError.failedLookup(
[NSLocalizedDescriptionKey: "There was an error retrieving the dfReferenceId."]
)
)
return
}

request.dfReferenceID = dfReferenceID
completion(nil)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class BTThreeDSecureClient_Tests: XCTestCase {
var threeDSecureRequest = BTThreeDSecureRequest()
var client: BTThreeDSecureClient!
var mockThreeDSecureRequestDelegate : MockThreeDSecureRequestDelegate!


let mockCardinalSession = MockCardinalSession()

let mockConfiguration = BTJSON(value: [
"threeDSecure": ["cardinalAuthenticationJWT": "FAKE_JWT"],
"assetsUrl": "http://assets.example.com"
Expand All @@ -21,7 +23,7 @@ class BTThreeDSecureClient_Tests: XCTestCase {
threeDSecureRequest.amount = 10.0
threeDSecureRequest.nonce = "fake-card-nonce"
client = BTThreeDSecureClient(apiClient: mockAPIClient)
client.cardinalSession = MockCardinalSession()
client.cardinalSession = mockCardinalSession
mockThreeDSecureRequestDelegate = MockThreeDSecureRequestDelegate()
}

Expand Down Expand Up @@ -689,4 +691,20 @@ class BTThreeDSecureClient_Tests: XCTestCase {

waitForExpectations(timeout: 1)
}

func testPrepareLookup_whenDfReferenceIDEmpty_throwsError() {
mockAPIClient.cannedConfigurationResponseBody = mockConfiguration
mockCardinalSession.dfReferenceID = ""

let expectation = expectation(description: "willCallCompletion")

threeDSecureRequest.nonce = "fake-card-nonce"

client.prepareLookup(threeDSecureRequest) { _, error in
XCTAssertEqual(error?.localizedDescription, "There was an error retrieving the dfReferenceId.")
expectation.fulfill()
}

waitForExpectations(timeout: 1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import CardinalMobile
@testable import BraintreeThreeDSecure

class MockCardinalSession: CardinalSessionTestable {


var dfReferenceID = "fake-df-reference-id"

func configure(_ sessionConfig: CardinalSessionConfiguration) {
// do nothing
}
Expand All @@ -13,7 +15,7 @@ class MockCardinalSession: CardinalSessionTestable {
completed didCompleteHandler: @escaping CardinalSessionSetupDidCompleteHandler,
validated didValidateHandler: @escaping CardinalSessionSetupDidValidateHandler
) {
didCompleteHandler("fake-df-reference-id")
didCompleteHandler(dfReferenceID)
}

func continueWith(transactionId: String, payload: String, validationDelegate: CardinalValidationDelegate) {
Expand Down