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

[v7] Remove cardAddChallenge #1487

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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: 0 additions & 4 deletions Braintree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@
BE01A83F29D32CA0000DFA24 /* BTThreeDSecureV2Provider.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE01A83E29D32CA0000DFA24 /* BTThreeDSecureV2Provider.swift */; };
BE01A84129D32CE1000DFA24 /* BTThreeDSecureAuthenticateJWT.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE01A84029D32CE1000DFA24 /* BTThreeDSecureAuthenticateJWT.swift */; };
BE01A84329D32EA9000DFA24 /* BTThreeDSecureError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE01A84229D32EA9000DFA24 /* BTThreeDSecureError.swift */; };
BE01A84929D4C529000DFA24 /* BTThreeDSecureCardAddChallenge.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE01A84829D4C529000DFA24 /* BTThreeDSecureCardAddChallenge.swift */; };
BE0AF6B929AFD50500245C2C /* BTVenmoAppSwitchReturnURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE0AF6B829AFD50500245C2C /* BTVenmoAppSwitchReturnURL.swift */; };
BE0AF6BB29AFD53300245C2C /* BTVenmoError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE0AF6BA29AFD53300245C2C /* BTVenmoError.swift */; };
BE0AF6BD29AFDCD100245C2C /* BTVenmoAppSwitchRedirectURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE0AF6BC29AFDCD100245C2C /* BTVenmoAppSwitchRedirectURL.swift */; };
Expand Down Expand Up @@ -896,7 +895,6 @@
BE01A83E29D32CA0000DFA24 /* BTThreeDSecureV2Provider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureV2Provider.swift; sourceTree = "<group>"; };
BE01A84029D32CE1000DFA24 /* BTThreeDSecureAuthenticateJWT.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureAuthenticateJWT.swift; sourceTree = "<group>"; };
BE01A84229D32EA9000DFA24 /* BTThreeDSecureError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureError.swift; sourceTree = "<group>"; };
BE01A84829D4C529000DFA24 /* BTThreeDSecureCardAddChallenge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureCardAddChallenge.swift; sourceTree = "<group>"; };
BE0AF6B829AFD50500245C2C /* BTVenmoAppSwitchReturnURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTVenmoAppSwitchReturnURL.swift; sourceTree = "<group>"; };
BE0AF6BA29AFD53300245C2C /* BTVenmoError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTVenmoError.swift; sourceTree = "<group>"; };
BE0AF6BC29AFDCD100245C2C /* BTVenmoAppSwitchRedirectURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTVenmoAppSwitchRedirectURL.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1793,7 +1791,6 @@
BE01A83C29D23833000DFA24 /* BTThreeDSecureAdditionalInformation.swift */,
3BEB03C429FD55CA001133D5 /* BTThreeDSecureAnalytics.swift */,
BE01A84029D32CE1000DFA24 /* BTThreeDSecureAuthenticateJWT.swift */,
BE01A84829D4C529000DFA24 /* BTThreeDSecureCardAddChallenge.swift */,
80D1638529E75766001D880E /* BTThreeDSecureClient.swift */,
BE01A84229D32EA9000DFA24 /* BTThreeDSecureError.swift */,
BE01A82C29CCCDE9000DFA24 /* BTThreeDSecureLookup.swift */,
Expand Down Expand Up @@ -3325,7 +3322,6 @@
BE80C00129C4BFD700793A6C /* BTThreeDSecureV2BaseCustomization.swift in Sources */,
80482F8429D3A1D9007E5F50 /* BTThreeDSecureAccountType.swift in Sources */,
80482F8629D3A498007E5F50 /* BTThreeDSecureShippingMethod.swift in Sources */,
BE01A84929D4C529000DFA24 /* BTThreeDSecureCardAddChallenge.swift in Sources */,
80482F8829D3A571007E5F50 /* BTThreeDSecureRequestedExemptionType.swift in Sources */,
BE01A84329D32EA9000DFA24 /* BTThreeDSecureError.swift in Sources */,
3BEB03C529FD55CA001133D5 /* BTThreeDSecureAnalytics.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* BraintreeThreeDSecure
* Update `BTThreeDSecureRequest` to make all properties accessible on the initializer only vs via the dot syntax.
* Update `BTThreeDSecureRequest.amount` to be a `String`
* Remove `cardAddChallenge` - use `cardAddChallengeRequested` instead
* BraintreeCore
* Remove `fetchPaymentMethodNonces` methods and parser
* BraintreePayPal
Expand Down

This file was deleted.

4 changes: 1 addition & 3 deletions Sources/BraintreeThreeDSecure/BTThreeDSecureClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,8 @@ import BraintreeCore
requestParameters["customFields"] = customFields
}

if request._cardAddChallenge == .requested || request.cardAddChallengeRequested == true {
if request.cardAddChallengeRequested == true {
jaxdesmarais marked this conversation as resolved.
Show resolved Hide resolved
requestParameters["cardAdd"] = true
} else if request._cardAddChallenge == .notRequested {
requestParameters["cardAdd"] = false
}

var additionalInformation: [String: String?] = [
Expand Down
67 changes: 23 additions & 44 deletions Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,32 @@ import BraintreeCore

/// Used to initialize a 3D Secure payment flow
@objcMembers public class BTThreeDSecureRequest: NSObject {

// MARK: - Internal Properties

var amount: String
var nonce: String
var accountType: BTThreeDSecureAccountType
var additionalInformation: BTThreeDSecureAdditionalInformation?
var billingAddress: BTThreeDSecurePostalAddress?
var cardAddChallengeRequested: Bool
var challengeRequested: Bool
var customFields: [String: String]?
var dataOnlyRequested: Bool
var dfReferenceID: String?
var email: String?
var exemptionRequested: Bool
var mobilePhoneNumber: String?
var renderTypes: [BTThreeDSecureRenderType]?
var requestedExemptionType: BTThreeDSecureRequestedExemptionType
var shippingMethod: BTThreeDSecureShippingMethod
var uiType: BTThreeDSecureUIType
var v2UICustomization: BTThreeDSecureV2UICustomization?

// NEXT_MAJOR_VERSION remove cardAddChallenge in favor of cardAddChallengeRequested
/// Optional. An authentication created using this property should only be used for adding a payment method to the merchant's vault and not for creating transactions.
///
/// Defaults to `.unspecified.`
///
/// If set to `.challengeRequested`, the authentication challenge will be requested from the issuer to confirm adding new card to the merchant's vault.
/// If set to `.notRequested` the authentication challenge will not be requested from the issuer.
/// If set to `.unspecified`, when the amount is 0, the authentication challenge will be requested from the issuer.
/// If set to `.unspecified`, when the amount is greater than 0, the authentication challenge will not be requested from the issuer.
@available(*, deprecated, renamed: "cardAddChallengeRequested", message: "Use the `cardAddChallengeRequested` boolean property instead")
public var cardAddChallenge: BTThreeDSecureCardAddChallenge {
get { _cardAddChallenge }
set { _cardAddChallenge = newValue }
}

// swiftlint:disable identifier_name
/// Internal property for `cardAddChallenge`. Created to avoid deprecation warnings upon accessing
/// `cardAddChallenge` directly within our SDK. Use this value internally instead.
var _cardAddChallenge: BTThreeDSecureCardAddChallenge = .unspecified


/// A delegate for receiving information about the ThreeDSecure payment flow.
public weak var threeDSecureRequestDelegate: BTThreeDSecureRequestDelegate?

// MARK: - Internal Properties

let amount: String
let nonce: String
let accountType: BTThreeDSecureAccountType
let additionalInformation: BTThreeDSecureAdditionalInformation?
let billingAddress: BTThreeDSecurePostalAddress?
let cardAddChallengeRequested: Bool
let challengeRequested: Bool
let customFields: [String: String]?
let dataOnlyRequested: Bool
let email: String?
let exemptionRequested: Bool
let mobilePhoneNumber: String?
let renderTypes: [BTThreeDSecureRenderType]?
let requestedExemptionType: BTThreeDSecureRequestedExemptionType
let shippingMethod: BTThreeDSecureShippingMethod
let uiType: BTThreeDSecureUIType
let v2UICustomization: BTThreeDSecureV2UICustomization?

var dfReferenceID: String?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only property that should need to be a var according to our logic. Updated these and the unit tests with this change. Also confirmed in the demo app things are still appearing as expected.


// MARK: - Initializer

/// Creates a `BTThreeDSecureRequest`
Expand Down Expand Up @@ -79,7 +60,6 @@ import BraintreeCore
accountType: BTThreeDSecureAccountType = .unspecified,
additionalInformation: BTThreeDSecureAdditionalInformation? = nil,
billingAddress: BTThreeDSecurePostalAddress? = nil,
_cardAddChallenge: BTThreeDSecureCardAddChallenge = .unspecified,
cardAddChallengeRequested: Bool = false,
challengeRequested: Bool = false,
customFields: [String: String]? = nil,
Expand All @@ -99,7 +79,6 @@ import BraintreeCore
self.accountType = accountType
self.additionalInformation = additionalInformation
self.billingAddress = billingAddress
self._cardAddChallenge = _cardAddChallenge
self.cardAddChallengeRequested = cardAddChallengeRequested
self.challengeRequested = challengeRequested
self.customFields = customFields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class BTThreeDSecureClient_Tests: XCTestCase {
nonce: "fake-card-nonce",
accountType: .credit,
billingAddress: billingAddress,
_cardAddChallenge: .requested,
cardAddChallengeRequested: true,
challengeRequested: true,
dataOnlyRequested: true,
Expand Down Expand Up @@ -92,8 +91,7 @@ class BTThreeDSecureClient_Tests: XCTestCase {
func testPerformThreeDSecureLookup_whenDefaultsArePassed_buildsRequestWithNilValues() {
let expectation = expectation(description: "willCallCompletion")

threeDSecureRequest.nonce = "fake-card-nonce"
threeDSecureRequest.amount = "9.99"
let threeDSecureRequest = BTThreeDSecureRequest(amount: "9.99", nonce: "fake-card-nonce")

client.performThreeDSecureLookup(threeDSecureRequest) { _, _ in
XCTAssertEqual(self.mockAPIClient.lastPOSTParameters!["amount"] as! String, "9.99")
Expand All @@ -108,26 +106,6 @@ class BTThreeDSecureClient_Tests: XCTestCase {
waitForExpectations(timeout: 1)
}

func testPerformThreeDSecureLookup_whenCardAddChallengeNotRequested_sendsCardAddFalse() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was specific to this removed logic in the client:

} else if request._cardAddChallenge == .notRequested {
            requestParameters["cardAdd"] = false
}

let expectation = self.expectation(description: "willCallCompletion")

threeDSecureRequest = BTThreeDSecureRequest(
amount: "9.97",
nonce: "fake-card-nonce",
_cardAddChallenge: .notRequested,
cardAddChallengeRequested: false,
dfReferenceID: "df-reference-id"
)

client.performThreeDSecureLookup(threeDSecureRequest) { (lookup, error) in
XCTAssertFalse(self.mockAPIClient.lastPOSTParameters!["cardAdd"] as! Bool)

expectation.fulfill()
}

waitForExpectations(timeout: 1, handler: nil)
}

func testPerformThreeDSecureLookup_whenCardAddChallengeRequestedNotSet_doesNotSendCardAddParameter() {
let expectation = self.expectation(description: "willCallCompletion")

Expand Down Expand Up @@ -285,12 +263,10 @@ class BTThreeDSecureClient_Tests: XCTestCase {
func testStartPaymentFlow_whenAmountIsEmpty_throwsError() {
mockAPIClient.cannedConfigurationResponseBody = mockConfiguration

let request = BTThreeDSecureRequest(amount: "10.00", nonce: "fake-card-nonce")
request.amount = ""

let expectation = self.expectation(description: "Callback envoked")
threeDSecureRequest = BTThreeDSecureRequest(amount: "", nonce: "fake-card-nonce")
let expectation = self.expectation(description: "Callback invoked")

client.startPaymentFlow(request) { result, error in
client.startPaymentFlow(threeDSecureRequest) { result, error in
XCTAssertNil(result)
XCTAssertEqual(error?.localizedDescription, "BTThreeDSecureRequest amount can not be nil or NaN.")
expectation.fulfill()
Expand Down Expand Up @@ -640,7 +616,6 @@ class BTThreeDSecureClient_Tests: XCTestCase {
mockAPIClient.cannedConfigurationResponseBody = mockConfiguration
let expectation = expectation(description: "willCallCompletion")

threeDSecureRequest.nonce = "fake-card-nonce"
threeDSecureRequest.dfReferenceID = "fake-df-reference-id"

client.prepareLookup(threeDSecureRequest) { clientData, error in
Expand Down Expand Up @@ -668,7 +643,6 @@ class BTThreeDSecureClient_Tests: XCTestCase {
let client = BTThreeDSecureClient(apiClient: MockAPIClient(authorization: "sandbox_9dbg82cq_dcpspy2brwdjr3qn")!)
let expectation = expectation(description: "willCallCompletion")

threeDSecureRequest.nonce = "fake-card-nonce"
threeDSecureRequest.dfReferenceID = "fake-df-reference-id"

client.prepareLookup(threeDSecureRequest) { _, error in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ class BTThreeDSecureRequest_Tests: XCTestCase {

// MARK: - accountTypeAsString

func testCustomFields_notNil() {
let request = BTThreeDSecureRequest(amount: "10.0", nonce: "fake-nonce")
XCTAssertNil(request.customFields)

request.customFields = ["test": "test"]
func testCustomFields_whenCustomFieldsExist_notNil() {
let request = BTThreeDSecureRequest(amount: "10.0", nonce: "fake-nonce", customFields: ["test": "test"])
XCTAssertNotNil(request.customFields)
}

Expand Down