From b6f5382aefb7dc7a3467a891735988bba0a80a0d Mon Sep 17 00:00:00 2001 From: ageddam Date: Tue, 12 Nov 2024 12:44:26 -0600 Subject: [PATCH] address pr feedback --- .../BTThreeDSecureClient.swift | 2 +- .../BTThreeDSecureRequest.swift | 16 ++++++----- .../BTThreeDSecureClient_Tests.swift | 27 ++++--------------- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureClient.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureClient.swift index 75c3316b44..b57146958c 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureClient.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureClient.swift @@ -59,7 +59,7 @@ import BraintreeCore return } - if request.amount?.decimalValue.isNaN == true || request.amount == nil { + if request.amount.decimalValue.isNaN == true { NSLog("%@ BTThreeDSecureRequest amount can not be nil or NaN.", BTLogLevelDescription.string(for: .critical)) let error = BTThreeDSecureError.configuration("BTThreeDSecureRequest amount can not be nil or NaN.") notifyFailure(with: error, completion: completion) diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift index 36cfe1d6fd..59d31849a8 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift @@ -11,7 +11,7 @@ import BraintreeCore var accountType: BTThreeDSecureAccountType var additionalInformation: BTThreeDSecureAdditionalInformation? - var amount: NSDecimalNumber? + var amount: NSDecimalNumber var billingAddress: BTThreeDSecurePostalAddress? var cardAddChallengeRequested: Bool var challengeRequested: Bool @@ -57,17 +57,17 @@ import BraintreeCore /// - Parameters: /// - accountType: Optional. The account type selected by the cardholder. Some cards can be processed using either a credit or debit account and cardholders have the option to choose which account to use. /// - additionalInformation: Optional. The additional information used for verification. - /// - amount: The amount for the transaction. + /// - amount: Required. The amount for the transaction. /// - billingAddress: Optional. The billing address used for verification /// - cardAddChallengeRequested: Optional. An authentication created using this flag should only be used for vaulting operations (creation of customers' credit cards or payment methods) and not for creating transactions. If set to `true`, a card-add challenge will be requested from the issuer. If set to `false`, a card-add challenge will not be requested. If the parameter is missing, a card-add challenge will only be requested for $0 amount. /// - challengeRequested: Optional. If set to true, an authentication challenge will be forced if possible. - /// - customFields: Object where each key is the name of a custom field which has been configured in the Control Panel. In the Control Panel you can configure 3D Secure Rules which trigger on certain values. + /// - customFields: Optional. Object where each key is the name of a custom field which has been configured in the Control Panel. In the Control Panel you can configure 3D Secure Rules which trigger on certain values. /// - dataOnlyRequested: Optional. Indicates whether to use the data only flow. In this flow, frictionless 3DS is ensured for Mastercard cardholders as the card scheme provides a risk score for the issuer to determine whether to approve. If data only is not supported by the processor, a validation error will be raised. Non-Mastercard cardholders will fallback to a normal 3DS flow. - /// - dfReferenceID: The dfReferenceID for the session. Exposed for testing. + /// - dfReferenceID: Optional. The dfReferenceID for the session, particularly useful for merchants peforming 3DS lookup. Exposed for testing. /// - email: Optional. The email used for verification. /// - exemptionRequested: Optional. If set to true, an exemption to the authentication challenge will be requested. /// - mobilePhoneNumber: Optional. The mobile phone number used for verification. Only numbers. Remove dashes, parentheses and other characters. - /// - nonce: A nonce to be verified by ThreeDSecure + /// - nonce: Optional. A nonce to be verified by ThreeDSecure /// - renderTypes: Optional: List of all the render types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. When using `BTThreeDSecureUIType.both` or `BTThreeDSecureUIType.html`, all `BTThreeDSecureRenderType` options must be set. When using `BTThreeDSecureUIType.native`, all `BTThreeDSecureRenderType` options except `.html` must be set. /// - requestedExemptionType: Optional. The exemption type to be requested. If an exemption is requested and the exemption's conditions are satisfied, then it will be applied. /// - shippingMethod: Optional. The shipping method chosen for the transaction @@ -76,11 +76,12 @@ import BraintreeCore public init( accountType: BTThreeDSecureAccountType = .unspecified, additionalInformation: BTThreeDSecureAdditionalInformation? = nil, - amount: NSDecimalNumber? = 0, + amount: NSDecimalNumber = 0, billingAddress: BTThreeDSecurePostalAddress? = nil, + _cardAddChallenge: BTThreeDSecureCardAddChallenge = .unspecified, cardAddChallengeRequested: Bool = false, challengeRequested: Bool = false, - customFields: [String : String]? = nil, + customFields: [String: String]? = nil, dataOnlyRequested: Bool = false, dfReferenceID: String? = nil, email: String? = nil, @@ -97,6 +98,7 @@ import BraintreeCore self.additionalInformation = additionalInformation self.amount = amount self.billingAddress = billingAddress + self._cardAddChallenge = _cardAddChallenge self.cardAddChallengeRequested = cardAddChallengeRequested self.challengeRequested = challengeRequested self.customFields = customFields diff --git a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureClient_Tests.swift b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureClient_Tests.swift index 7cac080c93..c32567be3e 100644 --- a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureClient_Tests.swift +++ b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureClient_Tests.swift @@ -45,6 +45,7 @@ class BTThreeDSecureClient_Tests: XCTestCase { accountType: .credit, amount: 9.97, billingAddress: billingAddress, + _cardAddChallenge: .requested, cardAddChallengeRequested: true, challengeRequested: true, dataOnlyRequested: true, @@ -112,6 +113,7 @@ class BTThreeDSecureClient_Tests: XCTestCase { threeDSecureRequest = BTThreeDSecureRequest( amount: 9.97, + _cardAddChallenge: .notRequested, cardAddChallengeRequested: false, dfReferenceID: "df-reference-id", nonce: "fake-card-nonce" @@ -136,7 +138,7 @@ class BTThreeDSecureClient_Tests: XCTestCase { ) client.performThreeDSecureLookup(threeDSecureRequest) { (lookup, error) in - XCTAssertFalse(self.mockAPIClient.lastPOSTParameters!["cardAdd"] as! Bool) + XCTAssertNil(self.mockAPIClient.lastPOSTParameters!["cardAdd"]) expectation.fulfill() } @@ -283,7 +285,7 @@ class BTThreeDSecureClient_Tests: XCTestCase { func testStartPaymentFlow_whenAmountIsNotANumber_throwsError() { mockAPIClient.cannedConfigurationResponseBody = mockConfiguration - let request = BTThreeDSecureRequest() + let request = BTThreeDSecureRequest(nonce: "fake-card-nonce") request.amount = NSDecimalNumber.notANumber let expectation = self.expectation(description: "Callback envoked") @@ -297,28 +299,9 @@ class BTThreeDSecureClient_Tests: XCTestCase { waitForExpectations(timeout: 1) XCTAssertTrue(mockAPIClient.postedAnalyticsEvents.contains(BTThreeDSecureAnalytics.verifyFailed)) } - - func testStartPaymentFlow_whenAmountIsNil_throwsError() { - mockAPIClient.cannedConfigurationResponseBody = mockConfiguration - - let request = BTThreeDSecureRequest() - request.amount = nil - - let expectation = expectation(description: "Callback envoked") - - client.startPaymentFlow(request) { result, error in - XCTAssertNil(result) - XCTAssertEqual(error?.localizedDescription, "BTThreeDSecureRequest amount can not be nil or NaN.") - expectation.fulfill() - } - - waitForExpectations(timeout: 1) - XCTAssertTrue(mockAPIClient.postedAnalyticsEvents.contains(BTThreeDSecureAnalytics.verifyFailed)) - } func testStartPayment_whenNoBodyReturned_returnsAnError() { - threeDSecureRequest = BTThreeDSecureRequest() - threeDSecureRequest.nonce = "fake-card-nonce" + threeDSecureRequest = BTThreeDSecureRequest(nonce: "fake-card-nonce") threeDSecureRequest.threeDSecureRequestDelegate = mockThreeDSecureRequestDelegate let expectation = expectation(description: "willCallCompletion")