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

Create threeDSecure encodable #1515

Merged
merged 30 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b6c1597
Add post body encodable
warmkesselj Jan 23, 2025
18b7cf0
Add init to post body
warmkesselj Feb 3, 2025
767a767
Track given and surname
warmkesselj Feb 4, 2025
268de91
Update to encodable
warmkesselj Feb 4, 2025
2b29623
AdditionalInfo alphabetical order
warmkesselj Feb 4, 2025
c6d8d03
Alphabetical order BTThreeDSecurePostBody
warmkesselj Feb 4, 2025
8cccab8
swiftlint
warmkesselj Feb 4, 2025
a0a8338
Update BTThreeDSecureclient to use encodable object
warmkesselj Feb 4, 2025
68c2b18
Add missing coding keys
warmkesselj Feb 5, 2025
4a4ef7b
Updates to alphabetize and refactor
warmkesselj Feb 5, 2025
a45ddc6
Merge branch 'v7' of https://github.com/braintree/braintree_ios into …
warmkesselj Feb 5, 2025
929f9fa
Update project file
warmkesselj Feb 5, 2025
0bc888d
Pr comments
warmkesselj Feb 6, 2025
dbe458c
PR comments
warmkesselj Feb 6, 2025
5019d7a
Remove BT prefix
warmkesselj Feb 10, 2025
9abc347
Passing fake data to ThreeDS
warmkesselj Feb 11, 2025
088cf18
Update PostBody
warmkesselj Feb 11, 2025
e220eb6
Remove unnecessary unit tests
warmkesselj Feb 11, 2025
c324282
Remove unnecessary unit tests
warmkesselj Feb 12, 2025
87e1c9b
PR comments
warmkesselj Feb 12, 2025
744e063
Unit test for additional info
warmkesselj Feb 14, 2025
39a6126
Update unit tests to check keys
warmkesselj Feb 25, 2025
f082677
Update to accountID from accountId adding coding keys
warmkesselj Feb 25, 2025
1364339
Test billing properties
warmkesselj Feb 25, 2025
573dee4
Swift lint issues
warmkesselj Feb 25, 2025
cb47ee7
Merge branch 'v7' into create-encodable-three_d_secure-encodable
warmkesselj Feb 25, 2025
e34e3a1
Update unit test
warmkesselj Feb 26, 2025
c014988
Merge branch 'v7' into create-encodable-three_d_secure-encodable
warmkesselj Feb 26, 2025
6118c27
Update name
warmkesselj Mar 3, 2025
7a021ae
Re-add line
warmkesselj Mar 3, 2025
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: 4 additions & 0 deletions Braintree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
A9E80A9C24FEF37C00196BD3 /* MockDelegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42D79395233A65EB001FDD89 /* MockDelegates.swift */; };
A9E80A9F24FEF40C00196BD3 /* BraintreeTestShared.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A903E1A624F9D34000C314E1 /* BraintreeTestShared.framework */; };
A9E80AA324FEF4D800196BD3 /* MockLocalPaymentRequestDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9E80AA224FEF4D800196BD3 /* MockLocalPaymentRequestDelegate.swift */; };
B87B26242D54176F0002225F /* BTThreeDSecurePostBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = B87B26232D54176F0002225F /* BTThreeDSecurePostBody.swift */; };
B8BA342E2D4811560030423C /* BTContactInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BA342D2D4811560030423C /* BTContactInformation.swift */; };
BC17F9B428D23C5C004B18CC /* BTGraphQLMultiErrorNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC17F9B328D23C5C004B18CC /* BTGraphQLMultiErrorNode.swift */; };
BC17F9BC28D24C9E004B18CC /* BTGraphQLErrorTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC17F9BB28D24C9E004B18CC /* BTGraphQLErrorTree.swift */; };
Expand Down Expand Up @@ -895,6 +896,7 @@
A9E5C22424FD6D0800EE691F /* BraintreeCoreTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BraintreeCoreTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A9E5C22824FD6D0800EE691F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A9E80AA224FEF4D800196BD3 /* MockLocalPaymentRequestDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockLocalPaymentRequestDelegate.swift; sourceTree = "<group>"; };
B87B26232D54176F0002225F /* BTThreeDSecurePostBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecurePostBody.swift; sourceTree = "<group>"; };
B8BA342D2D4811560030423C /* BTContactInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTContactInformation.swift; sourceTree = "<group>"; };
BC17F9B328D23C5C004B18CC /* BTGraphQLMultiErrorNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTGraphQLMultiErrorNode.swift; sourceTree = "<group>"; };
BC17F9BB28D24C9E004B18CC /* BTGraphQLErrorTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTGraphQLErrorTree.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1819,6 +1821,7 @@
3BEB03C429FD55CA001133D5 /* BTThreeDSecureAnalytics.swift */,
BE01A84029D32CE1000DFA24 /* BTThreeDSecureAuthenticateJWT.swift */,
80D1638529E75766001D880E /* BTThreeDSecureClient.swift */,
B87B26232D54176F0002225F /* BTThreeDSecurePostBody.swift */,
BE01A84229D32EA9000DFA24 /* BTThreeDSecureError.swift */,
BE01A82C29CCCDE9000DFA24 /* BTThreeDSecureLookup.swift */,
BE01A83429D1F7B9000DFA24 /* BTThreeDSecurePostalAddress.swift */,
Expand Down Expand Up @@ -3355,6 +3358,7 @@
BE80C00129C4BFD700793A6C /* BTThreeDSecureV2BaseCustomization.swift in Sources */,
80482F8429D3A1D9007E5F50 /* BTThreeDSecureAccountType.swift in Sources */,
80482F8629D3A498007E5F50 /* BTThreeDSecureShippingMethod.swift in Sources */,
B87B26242D54176F0002225F /* BTThreeDSecurePostBody.swift in Sources */,
80482F8829D3A571007E5F50 /* BTThreeDSecureRequestedExemptionType.swift in Sources */,
BE01A84329D32EA9000DFA24 /* BTThreeDSecureError.swift in Sources */,
3BEB03C529FD55CA001133D5 /* BTThreeDSecureAnalytics.swift in Sources */,
Expand Down
6 changes: 3 additions & 3 deletions Sources/BraintreeThreeDSecure/BTThreeDSecureClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ import BraintreeCore
return
}

let requestParameters = self.buildRequestDictionary(with: request)
let requestParameters = BTThreeDSecurePostBody(request: request)
guard let urlSafeNonce = request.nonce.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
self.apiClient.sendAnalyticsEvent(BTThreeDSecureAnalytics.lookupFailed)
self.notifyFailure(
Expand All @@ -364,7 +364,7 @@ import BraintreeCore

self.apiClient.post(
"v1/payment_methods/\(urlSafeNonce)/three_d_secure/lookup",
parameters: requestParameters as [String: Any]
parameters: requestParameters
) { body, _, error in
if let error = error as NSError? {
// Provide more context for card validation error when status code 422
Expand Down Expand Up @@ -411,7 +411,7 @@ import BraintreeCore
}
}
}

private func buildRequestDictionary(with request: BTThreeDSecureRequest) -> [String: Any?] {
let customer: [String: String] = [:]

Expand Down
96 changes: 96 additions & 0 deletions Sources/BraintreeThreeDSecure/BTThreeDSecurePostBody.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import Foundation

// MARK: - BTThreeDSecurePostBody
struct BTThreeDSecurePostBody: Encodable {

let accountType: String?
let additionalInfo: AdditionalInfo
let amount: String
let cardAdd: Bool?
let challengeRequested: Bool
let customFields: [String: String]?
let customer: Customer
let dataOnlyRequested: Bool
let dfReferenceID: String?
let exemptionRequested: Bool
let requestedExemptionType: String?
let requestedThreeDSecureVersion: String?

init(request: BTThreeDSecureRequest) {
self.requestedExemptionType = request.requestedExemptionType.stringValue
self.requestedThreeDSecureVersion = "2"
self.accountType = request.accountType.stringValue
self.dfReferenceID = request.dfReferenceID
self.dataOnlyRequested = request.dataOnlyRequested
self.challengeRequested = request.challengeRequested
self.amount = request.amount
self.exemptionRequested = request.exemptionRequested

if let customFields = request.customFields {
self.customFields = customFields
} else {
self.customFields = nil
}

if request.cardAddChallengeRequested {
self.cardAdd = true
} else {
self.cardAdd = nil
}

self.additionalInfo = AdditionalInfo(request: request)
self.customer = Customer()
}

enum CodingKeys: String, CodingKey {
case accountType
case additionalInfo
case amount
case cardAdd
case challengeRequested
case customFields
case customer
case dataOnlyRequested
case dfReferenceID = "dfReferenceId"
case exemptionRequested
case requestedExemptionType
case requestedThreeDSecureVersion
}

// MARK: - AdditionalInfo
struct AdditionalInfo: Codable {

let billingCity: String?
let billingCountryCode: String?
let billingGivenName: String?
let billingLine1: String?
let billingLine2: String?
let billingLine3: String?
let billingPhoneNumber: String?
let billingPostalCode: String?
let billingState: String?
let billingSurname: String?
let email: String?
let mobilePhoneNumber: String?
let shippingMethod: String?

init(request: BTThreeDSecureRequest) {
self.billingCity = request.billingAddress?.locality
self.billingCountryCode = request.billingAddress?.countryCodeAlpha2
self.billingGivenName = request.billingAddress?.givenName
self.billingLine1 = request.billingAddress?.streetAddress
self.billingLine2 = request.billingAddress?.extendedAddress
self.billingLine3 = request.billingAddress?.line3
self.billingPhoneNumber = request.billingAddress?.phoneNumber
self.billingPostalCode = request.billingAddress?.postalCode
self.billingState = request.billingAddress?.region
self.billingSurname = request.billingAddress?.surname
self.email = request.email
self.mobilePhoneNumber = request.mobilePhoneNumber
self.shippingMethod = request.shippingMethod.stringValue
}
}

// MARK: - Customer
struct Customer: Codable {}
}
Loading