Skip to content

Commit

Permalink
address pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
agedd committed Nov 12, 2024
1 parent 208840f commit b6f5382
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Sources/BraintreeThreeDSecure/BTThreeDSecureClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class BTThreeDSecureClient_Tests: XCTestCase {
accountType: .credit,
amount: 9.97,
billingAddress: billingAddress,
_cardAddChallenge: .requested,
cardAddChallengeRequested: true,
challengeRequested: true,
dataOnlyRequested: true,
Expand Down Expand Up @@ -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"
Expand All @@ -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()
}
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit b6f5382

Please sign in to comment.