From afedeac5aeb02dfd373da4d2505499029dd71d9b Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 13 Nov 2023 09:55:19 -0600 Subject: [PATCH 01/13] add BTThreeDSecureRenderTypes and BTThreeDSecureUIType --- Braintree.xcodeproj/project.pbxproj | 8 +++++++ .../BTThreeDSecureRenderTypes.swift | 22 +++++++++++++++++++ .../BTThreeDSecureUIType.swift | 14 ++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift create mode 100644 Sources/BraintreeThreeDSecure/BTThreeDSecureUIType.swift diff --git a/Braintree.xcodeproj/project.pbxproj b/Braintree.xcodeproj/project.pbxproj index 25b889de03..419054ca49 100644 --- a/Braintree.xcodeproj/project.pbxproj +++ b/Braintree.xcodeproj/project.pbxproj @@ -253,6 +253,8 @@ BEBC6F3329380B82004E25A0 /* BTExceptionCatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = BEBC6F3129380B82004E25A0 /* BTExceptionCatcher.m */; }; BEBD05222A1FE8BE0003C15C /* BTWebAuthenticationSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEBD05212A1FE8BE0003C15C /* BTWebAuthenticationSession.swift */; }; BEBD05242A1FEE150003C15C /* MockWebAuthenticationSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEBD05232A1FEE150003C15C /* MockWebAuthenticationSession.swift */; }; + BEBF0C202B02793B0079DA74 /* BTThreeDSecureUIType.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEBF0C1F2B02793B0079DA74 /* BTThreeDSecureUIType.swift */; }; + BEBF0C222B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift */; }; BEC3F11328A4401E0074DF0F /* BTHTTPError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEC3F11228A4401E0074DF0F /* BTHTTPError.swift */; }; BEC66DBE2901CC9E0030B6B2 /* BraintreeCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570B93AC285397520041BAFE /* BraintreeCore.framework */; }; BECBA0E62AEABC99002518AC /* BTCardClient_IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BECBA0E52AEABC99002518AC /* BTCardClient_IntegrationTests.swift */; }; @@ -858,6 +860,8 @@ BEBC6F3429380BA6004E25A0 /* BTExceptionCatcher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BTExceptionCatcher.h; sourceTree = ""; }; BEBD05212A1FE8BE0003C15C /* BTWebAuthenticationSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTWebAuthenticationSession.swift; sourceTree = ""; }; BEBD05232A1FEE150003C15C /* MockWebAuthenticationSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockWebAuthenticationSession.swift; sourceTree = ""; }; + BEBF0C1F2B02793B0079DA74 /* BTThreeDSecureUIType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureUIType.swift; sourceTree = ""; }; + BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureRenderTypes.swift; sourceTree = ""; }; BEC3F11228A4401E0074DF0F /* BTHTTPError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTHTTPError.swift; sourceTree = ""; }; BECA56C929C3F0A80098EC3C /* BTThreeDSecureV2UICustomization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureV2UICustomization.swift; sourceTree = ""; }; BECBA0E52AEABC99002518AC /* BTCardClient_IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTCardClient_IntegrationTests.swift; sourceTree = ""; }; @@ -1535,6 +1539,8 @@ BE01A83E29D32CA0000DFA24 /* BTThreeDSecureV2Provider.swift */, 80CD33FF2A6042FC009545F5 /* CardinalSessionTestable.swift */, 801A0A1725890DF200DAF851 /* V2UICustomization */, + BEBF0C1F2B02793B0079DA74 /* BTThreeDSecureUIType.swift */, + BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift */, ); path = BraintreeThreeDSecure; sourceTree = ""; @@ -2884,11 +2890,13 @@ buildActionMask = 2147483647; files = ( BE48CE4829D5DDA600F0825C /* BTThreeDSecureV2TextBoxCustomization.swift in Sources */, + BEBF0C222B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift in Sources */, 80D1638729E75CF1001D880E /* BTThreeDSecureClient.swift in Sources */, BEEBC3C129D5DD68009C7F77 /* BTThreeDSecureV2LabelCustomization.swift in Sources */, BEEBC3C029D5DD16009C7F77 /* BTThreeDSecureV2UICustomization.swift in Sources */, 80482F8029D39A1D007E5F50 /* BTThreeDSecureRequest.swift in Sources */, BE01A83D29D23833000DFA24 /* BTThreeDSecureAdditionalInformation.swift in Sources */, + BEBF0C202B02793B0079DA74 /* BTThreeDSecureUIType.swift in Sources */, BE01A83F29D32CA0000DFA24 /* BTThreeDSecureV2Provider.swift in Sources */, BE82E73F29C4A06B0059FE97 /* BTThreeDSecureV2ToolbarCustomization.swift in Sources */, BE01A84129D32CE1000DFA24 /* BTThreeDSecureAuthenticateJWT.swift in Sources */, diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift new file mode 100644 index 0000000000..36d922335c --- /dev/null +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift @@ -0,0 +1,22 @@ +import Foundation + +/// Render types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. +@objcMembers public class BTThreeDSecureRenderTypes: NSObject { + + public typealias StringValue = String + + /// OTP + public static let otp: StringValue = "CardinalSessionRenderTypeOTP" + + /// HTML + public static let html: StringValue = "CardinalSessionRenderTypeHTML" + + /// Single select + public static let singleSelect: StringValue = "CardinalSessionRenderTypeSingleSelect" + + /// Multi Select + public static let multiSelect: StringValue = "CardinalSessionRenderTypeMultiSelect" + + /// OOB + public static let oob: StringValue = "CardinalSessionRenderTypeOOB" +} diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureUIType.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureUIType.swift new file mode 100644 index 0000000000..68801576e4 --- /dev/null +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureUIType.swift @@ -0,0 +1,14 @@ +import Foundation + +/// The interface types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. +@objc public enum BTThreeDSecureUIType: Int { + + /// Native + case native + + /// HTML + case html + + /// Both + case both +} From 978291d4f5c12852892927e69a7e2b8e535f094c Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 13 Nov 2023 09:55:41 -0600 Subject: [PATCH 02/13] add uiType and renderTypes to BTThreeDSecureRequest --- .../BraintreeThreeDSecure/BTThreeDSecureRequest.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift index ad327b5fd6..0b91d88340 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift @@ -77,6 +77,17 @@ import BraintreeCore /// Optional. UI Customization for 3DS2 challenge views. public var v2UICustomization: BTThreeDSecureV2UICustomization? + /// Optional. Sets all UI types that the device supports for displaying specific challenge user interfaces in the 3D Secure challenge. + /// + /// Defaults to `.both` + public var uiType: BTThreeDSecureUIType = .both + + /// Optional. List of all the render types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. + /// + /// - Note: When using `BTThreeDSecureUIType.both` or `BTThreeDSecureUIType.html`, all `BTThreeDSecureRenderType` options must be set. + /// When using `BTThreeDSecureUIType.native`, all `BTThreeDSecureRenderType` options except `BTThreeDSecureRenderType.html` must be set. + public var renderTypes: [BTThreeDSecureRenderTypes.StringValue]? + /// A delegate for receiving information about the ThreeDSecure payment flow. public weak var threeDSecureRequestDelegate: BTThreeDSecureRequestDelegate? From c9f0d3706438dfb6d602c1791ffbf7026b7ee5b3 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 13 Nov 2023 09:56:09 -0600 Subject: [PATCH 03/13] sort files by name --- Braintree.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Braintree.xcodeproj/project.pbxproj b/Braintree.xcodeproj/project.pbxproj index 419054ca49..2f067f1e59 100644 --- a/Braintree.xcodeproj/project.pbxproj +++ b/Braintree.xcodeproj/project.pbxproj @@ -1531,16 +1531,16 @@ BE01A84229D32EA9000DFA24 /* BTThreeDSecureError.swift */, BE01A82C29CCCDE9000DFA24 /* BTThreeDSecureLookup.swift */, BE01A83429D1F7B9000DFA24 /* BTThreeDSecurePostalAddress.swift */, + BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift */, 80482F7F29D39A1D007E5F50 /* BTThreeDSecureRequest.swift */, 80482F8129D39BF5007E5F50 /* BTThreeDSecureRequestDelegate.swift */, 80482F8729D3A571007E5F50 /* BTThreeDSecureRequestedExemptionType.swift */, BE80C00229C549BE00793A6C /* BTThreeDSecureResult.swift */, 80482F8529D3A498007E5F50 /* BTThreeDSecureShippingMethod.swift */, + BEBF0C1F2B02793B0079DA74 /* BTThreeDSecureUIType.swift */, BE01A83E29D32CA0000DFA24 /* BTThreeDSecureV2Provider.swift */, 80CD33FF2A6042FC009545F5 /* CardinalSessionTestable.swift */, 801A0A1725890DF200DAF851 /* V2UICustomization */, - BEBF0C1F2B02793B0079DA74 /* BTThreeDSecureUIType.swift */, - BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift */, ); path = BraintreeThreeDSecure; sourceTree = ""; From a588e3b1c8ca530a975422d2ee1dfe178c97b809 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 13 Nov 2023 10:03:25 -0600 Subject: [PATCH 04/13] impliment logic for uiType and renderTypes --- .../BraintreeThreeDSecure/BTThreeDSecureUIType.swift | 12 ++++++++++++ .../BTThreeDSecureV2Provider.swift | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureUIType.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureUIType.swift index 68801576e4..2ec80c1cc5 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureUIType.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureUIType.swift @@ -1,4 +1,5 @@ import Foundation +import CardinalMobile /// The interface types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. @objc public enum BTThreeDSecureUIType: Int { @@ -11,4 +12,15 @@ import Foundation /// Both case both + + var cardinalValue: CardinalSessionUIType { + switch self { + case .native: + return .native + case .html: + return .HTML + case .both: + return .both + } + } } diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift index bea5542ba6..233a25b304 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift @@ -39,6 +39,12 @@ class BTThreeDSecureV2Provider { cardinalEnvironment = .production } + cardinalConfiguration.uiType = request.uiType.cardinalValue + + if let renderTypes = request.renderTypes { + cardinalConfiguration.renderType = renderTypes + } + guard let cardinalAuthenticationJWT = configuration.cardinalAuthenticationJWT else { completion(nil) return From 11627c7b1a0768983530faeed3a7eaa239a69c16 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 13 Nov 2023 10:16:57 -0600 Subject: [PATCH 05/13] add defaults to demo app --- .../Application/Features/ThreeDSecureViewController.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Demo/Application/Features/ThreeDSecureViewController.swift b/Demo/Application/Features/ThreeDSecureViewController.swift index 9bcbe62ea8..6cd8e73c54 100644 --- a/Demo/Application/Features/ThreeDSecureViewController.swift +++ b/Demo/Application/Features/ThreeDSecureViewController.swift @@ -98,6 +98,14 @@ class ThreeDSecureViewController: PaymentButtonBaseViewController { request.requestedExemptionType = .lowValue request.email = "test@example.com" request.shippingMethod = .sameDay + request.uiType = .both + request.renderTypes = [ + BTThreeDSecureRenderTypes.otp, + BTThreeDSecureRenderTypes.singleSelect, + BTThreeDSecureRenderTypes.multiSelect, + BTThreeDSecureRenderTypes.oob, + BTThreeDSecureRenderTypes.html + ] let billingAddress = BTThreeDSecurePostalAddress() billingAddress.givenName = "Jill" From ab933e6aecfaad09dc5f26a2a5147346c9656de6 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 13 Nov 2023 11:32:53 -0600 Subject: [PATCH 06/13] add request tests; update naming --- .../Features/ThreeDSecureViewController.swift | 10 ++--- .../BTThreeDSecureRenderTypes.swift | 2 +- .../BTThreeDSecureRequest.swift | 2 +- .../BTThreeDSecureRequest_Tests.swift | 45 +++++++++++++++++++ 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Demo/Application/Features/ThreeDSecureViewController.swift b/Demo/Application/Features/ThreeDSecureViewController.swift index 6cd8e73c54..40e194cea2 100644 --- a/Demo/Application/Features/ThreeDSecureViewController.swift +++ b/Demo/Application/Features/ThreeDSecureViewController.swift @@ -100,11 +100,11 @@ class ThreeDSecureViewController: PaymentButtonBaseViewController { request.shippingMethod = .sameDay request.uiType = .both request.renderTypes = [ - BTThreeDSecureRenderTypes.otp, - BTThreeDSecureRenderTypes.singleSelect, - BTThreeDSecureRenderTypes.multiSelect, - BTThreeDSecureRenderTypes.oob, - BTThreeDSecureRenderTypes.html + BTThreeDSecureRenderType.otp, + BTThreeDSecureRenderType.singleSelect, + BTThreeDSecureRenderType.multiSelect, + BTThreeDSecureRenderType.oob, + BTThreeDSecureRenderType.html ] let billingAddress = BTThreeDSecurePostalAddress() diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift index 36d922335c..31caa0c13e 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift @@ -1,7 +1,7 @@ import Foundation /// Render types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. -@objcMembers public class BTThreeDSecureRenderTypes: NSObject { +@objcMembers public class BTThreeDSecureRenderType: NSObject { public typealias StringValue = String diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift index 0b91d88340..407d93c917 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift @@ -86,7 +86,7 @@ import BraintreeCore /// /// - Note: When using `BTThreeDSecureUIType.both` or `BTThreeDSecureUIType.html`, all `BTThreeDSecureRenderType` options must be set. /// When using `BTThreeDSecureUIType.native`, all `BTThreeDSecureRenderType` options except `BTThreeDSecureRenderType.html` must be set. - public var renderTypes: [BTThreeDSecureRenderTypes.StringValue]? + public var renderTypes: [BTThreeDSecureRenderType.StringValue]? /// A delegate for receiving information about the ThreeDSecure payment flow. public weak var threeDSecureRequestDelegate: BTThreeDSecureRequestDelegate? diff --git a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift index 77bc099bc7..1f940eafb5 100644 --- a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift +++ b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift @@ -1,4 +1,5 @@ import XCTest +import CardinalMobile @testable import BraintreeTestShared @testable import BraintreeThreeDSecure @@ -114,4 +115,48 @@ class BTThreeDSecureRequest_Tests: XCTestCase { let request = BTThreeDSecureRequest() XCTAssertEqual(request.requestedExemptionType.stringValue, nil) } + + // MARK: - UIType + + func testUIType_whenUITypeNative_setsCardinalUITypeNative() { + let request = BTThreeDSecureRequest() + request.uiType = .native + XCTAssertEqual(request.uiType.cardinalValue, CardinalSessionUIType.native) + } + + func testUIType_whenUITypeHTML_setsCardinalUITypeHTML() { + let request = BTThreeDSecureRequest() + request.uiType = .html + XCTAssertEqual(request.uiType.cardinalValue, CardinalSessionUIType.HTML) + } + + func testUIType_whenUITypeBoth_setsCardinalUITypeBoth() { + let request = BTThreeDSecureRequest() + request.uiType = .native + XCTAssertEqual(request.uiType.cardinalValue, CardinalSessionUIType.both) + } + + // MARK: RenderTypes + + func testRenderTypes_whenAllRenderTypesAreSet_setsAllCardinalRenderTypes() { + let request = BTThreeDSecureRequest() + request.renderTypes = [ + BTThreeDSecureRenderType.otp, + BTThreeDSecureRenderType.singleSelect, + BTThreeDSecureRenderType.multiSelect, + BTThreeDSecureRenderType.oob, + BTThreeDSecureRenderType.html + ] + + XCTAssertEqual( + request.renderTypes, + [ + "CardinalSessionRenderTypeOTP", + "CardinalSessionRenderTypeSingleSelect", + "CardinalSessionRenderTypeMultiSelect", + "CardinalSessionRenderTypeOOB", + "CardinalSessionRenderTypeHTML" + ] + ) + } } From 6909deb70c4feee820ed640f3f994083c16d8230 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 13 Nov 2023 15:06:58 -0600 Subject: [PATCH 07/13] add CHANGELOG entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d86d3a493..37687a7eeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## unreleased * BraintreeThreeDSecure - * Add `cardAddChallengeRequested` to `BTThreeDSecureRequest` + * Add `cardAddChallengeRequested`, `uiType`, and `renderTypes` to `BTThreeDSecureRequest` * Deprecate `BTThreeDSecureRequest.cardAddChallenge` * Fix bug where defaults for `BTThreeDSecureRequest.accountType`, `BTThreeDSecureRequest.requestedExemptionType`, and `BTThreeDSecureRequest.dfReferenceID` were improperly returning an error if not passed into the request * BraintreeCard From e260990dae0c6bc50df4ac5d4830b805aa571de7 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Mon, 13 Nov 2023 15:22:10 -0600 Subject: [PATCH 08/13] goofed a unit test --- .../BTThreeDSecureRequest_Tests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift index 1f940eafb5..6824fd6865 100644 --- a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift +++ b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift @@ -132,7 +132,7 @@ class BTThreeDSecureRequest_Tests: XCTestCase { func testUIType_whenUITypeBoth_setsCardinalUITypeBoth() { let request = BTThreeDSecureRequest() - request.uiType = .native + request.uiType = .both XCTAssertEqual(request.uiType.cardinalValue, CardinalSessionUIType.both) } From 5911c551bbc829b3002f5f98941f1a248c97f988 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 14 Nov 2023 11:12:43 -0600 Subject: [PATCH 09/13] PR feedback: update renderTypes to use OptionSet --- Braintree.xcodeproj/project.pbxproj | 8 ++-- .../Features/ThreeDSecureViewController.swift | 8 +--- .../BTThreeDSecureRenderType.swift | 40 +++++++++++++++++++ .../BTThreeDSecureRenderTypes.swift | 22 ---------- .../BTThreeDSecureRequest.swift | 4 +- .../BTThreeDSecureV2Provider.swift | 2 +- .../BTThreeDSecureRequest_Tests.swift | 10 +---- 7 files changed, 50 insertions(+), 44 deletions(-) create mode 100644 Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift delete mode 100644 Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift diff --git a/Braintree.xcodeproj/project.pbxproj b/Braintree.xcodeproj/project.pbxproj index 2f067f1e59..8f5176f161 100644 --- a/Braintree.xcodeproj/project.pbxproj +++ b/Braintree.xcodeproj/project.pbxproj @@ -254,7 +254,7 @@ BEBD05222A1FE8BE0003C15C /* BTWebAuthenticationSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEBD05212A1FE8BE0003C15C /* BTWebAuthenticationSession.swift */; }; BEBD05242A1FEE150003C15C /* MockWebAuthenticationSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEBD05232A1FEE150003C15C /* MockWebAuthenticationSession.swift */; }; BEBF0C202B02793B0079DA74 /* BTThreeDSecureUIType.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEBF0C1F2B02793B0079DA74 /* BTThreeDSecureUIType.swift */; }; - BEBF0C222B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift */; }; + BEBF0C222B0279F10079DA74 /* BTThreeDSecureRenderType.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderType.swift */; }; BEC3F11328A4401E0074DF0F /* BTHTTPError.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEC3F11228A4401E0074DF0F /* BTHTTPError.swift */; }; BEC66DBE2901CC9E0030B6B2 /* BraintreeCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570B93AC285397520041BAFE /* BraintreeCore.framework */; }; BECBA0E62AEABC99002518AC /* BTCardClient_IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BECBA0E52AEABC99002518AC /* BTCardClient_IntegrationTests.swift */; }; @@ -861,7 +861,7 @@ BEBD05212A1FE8BE0003C15C /* BTWebAuthenticationSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTWebAuthenticationSession.swift; sourceTree = ""; }; BEBD05232A1FEE150003C15C /* MockWebAuthenticationSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockWebAuthenticationSession.swift; sourceTree = ""; }; BEBF0C1F2B02793B0079DA74 /* BTThreeDSecureUIType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureUIType.swift; sourceTree = ""; }; - BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureRenderTypes.swift; sourceTree = ""; }; + BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureRenderType.swift; sourceTree = ""; }; BEC3F11228A4401E0074DF0F /* BTHTTPError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTHTTPError.swift; sourceTree = ""; }; BECA56C929C3F0A80098EC3C /* BTThreeDSecureV2UICustomization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTThreeDSecureV2UICustomization.swift; sourceTree = ""; }; BECBA0E52AEABC99002518AC /* BTCardClient_IntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BTCardClient_IntegrationTests.swift; sourceTree = ""; }; @@ -1531,7 +1531,7 @@ BE01A84229D32EA9000DFA24 /* BTThreeDSecureError.swift */, BE01A82C29CCCDE9000DFA24 /* BTThreeDSecureLookup.swift */, BE01A83429D1F7B9000DFA24 /* BTThreeDSecurePostalAddress.swift */, - BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift */, + BEBF0C212B0279F10079DA74 /* BTThreeDSecureRenderType.swift */, 80482F7F29D39A1D007E5F50 /* BTThreeDSecureRequest.swift */, 80482F8129D39BF5007E5F50 /* BTThreeDSecureRequestDelegate.swift */, 80482F8729D3A571007E5F50 /* BTThreeDSecureRequestedExemptionType.swift */, @@ -2890,7 +2890,7 @@ buildActionMask = 2147483647; files = ( BE48CE4829D5DDA600F0825C /* BTThreeDSecureV2TextBoxCustomization.swift in Sources */, - BEBF0C222B0279F10079DA74 /* BTThreeDSecureRenderTypes.swift in Sources */, + BEBF0C222B0279F10079DA74 /* BTThreeDSecureRenderType.swift in Sources */, 80D1638729E75CF1001D880E /* BTThreeDSecureClient.swift in Sources */, BEEBC3C129D5DD68009C7F77 /* BTThreeDSecureV2LabelCustomization.swift in Sources */, BEEBC3C029D5DD16009C7F77 /* BTThreeDSecureV2UICustomization.swift in Sources */, diff --git a/Demo/Application/Features/ThreeDSecureViewController.swift b/Demo/Application/Features/ThreeDSecureViewController.swift index 40e194cea2..b64162da72 100644 --- a/Demo/Application/Features/ThreeDSecureViewController.swift +++ b/Demo/Application/Features/ThreeDSecureViewController.swift @@ -99,13 +99,7 @@ class ThreeDSecureViewController: PaymentButtonBaseViewController { request.email = "test@example.com" request.shippingMethod = .sameDay request.uiType = .both - request.renderTypes = [ - BTThreeDSecureRenderType.otp, - BTThreeDSecureRenderType.singleSelect, - BTThreeDSecureRenderType.multiSelect, - BTThreeDSecureRenderType.oob, - BTThreeDSecureRenderType.html - ] + request.renderTypes = [.otp, .singleSelect, .multiSelect, .oob, .html] let billingAddress = BTThreeDSecurePostalAddress() billingAddress.givenName = "Jill" diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift new file mode 100644 index 0000000000..c6861f0f5c --- /dev/null +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift @@ -0,0 +1,40 @@ +import Foundation + +/// Render types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. +@objcMembers public class BTThreeDSecureRenderType: NSObject, OptionSet { + + public let rawValue: Int + required public init(rawValue: Int) { self.rawValue = rawValue } + + /// OTP + public static let otp = BTThreeDSecureRenderType(rawValue: 1) + + /// HTML + public static let html = BTThreeDSecureRenderType(rawValue: 2) + + /// Single select + public static let singleSelect = BTThreeDSecureRenderType(rawValue: 3) + + /// Multi Select + public static let multiSelect = BTThreeDSecureRenderType(rawValue: 4) + + /// OOB + public static let oob = BTThreeDSecureRenderType(rawValue: 5) + + var stringValue: String { + switch self { + case .otp: + return "CardinalSessionRenderTypeOTP" + case .html: + return "CardinalSessionRenderTypeHTML" + case .singleSelect: + return "CardinalSessionRenderTypeSingleSelect" + case .multiSelect: + return "CardinalSessionRenderTypeMultiSelect" + case .oob: + return "CardinalSessionRenderTypeOOB" + default: + return "" + } + } +} diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift deleted file mode 100644 index 31caa0c13e..0000000000 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderTypes.swift +++ /dev/null @@ -1,22 +0,0 @@ -import Foundation - -/// Render types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. -@objcMembers public class BTThreeDSecureRenderType: NSObject { - - public typealias StringValue = String - - /// OTP - public static let otp: StringValue = "CardinalSessionRenderTypeOTP" - - /// HTML - public static let html: StringValue = "CardinalSessionRenderTypeHTML" - - /// Single select - public static let singleSelect: StringValue = "CardinalSessionRenderTypeSingleSelect" - - /// Multi Select - public static let multiSelect: StringValue = "CardinalSessionRenderTypeMultiSelect" - - /// OOB - public static let oob: StringValue = "CardinalSessionRenderTypeOOB" -} diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift index 407d93c917..403cbefc37 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRequest.swift @@ -85,8 +85,8 @@ import BraintreeCore /// Optional. List of all the render types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. /// /// - Note: When using `BTThreeDSecureUIType.both` or `BTThreeDSecureUIType.html`, all `BTThreeDSecureRenderType` options must be set. - /// When using `BTThreeDSecureUIType.native`, all `BTThreeDSecureRenderType` options except `BTThreeDSecureRenderType.html` must be set. - public var renderTypes: [BTThreeDSecureRenderType.StringValue]? + /// When using `BTThreeDSecureUIType.native`, all `BTThreeDSecureRenderType` options except `.html` must be set. + public var renderTypes: [BTThreeDSecureRenderType]? /// A delegate for receiving information about the ThreeDSecure payment flow. public weak var threeDSecureRequestDelegate: BTThreeDSecureRequestDelegate? diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift index 233a25b304..f00a114428 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift @@ -42,7 +42,7 @@ class BTThreeDSecureV2Provider { cardinalConfiguration.uiType = request.uiType.cardinalValue if let renderTypes = request.renderTypes { - cardinalConfiguration.renderType = renderTypes + cardinalConfiguration.renderType = renderTypes.compactMap { $0.stringValue } } guard let cardinalAuthenticationJWT = configuration.cardinalAuthenticationJWT else { diff --git a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift index 6824fd6865..559b5b820f 100644 --- a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift +++ b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift @@ -140,16 +140,10 @@ class BTThreeDSecureRequest_Tests: XCTestCase { func testRenderTypes_whenAllRenderTypesAreSet_setsAllCardinalRenderTypes() { let request = BTThreeDSecureRequest() - request.renderTypes = [ - BTThreeDSecureRenderType.otp, - BTThreeDSecureRenderType.singleSelect, - BTThreeDSecureRenderType.multiSelect, - BTThreeDSecureRenderType.oob, - BTThreeDSecureRenderType.html - ] + request.renderTypes = [.otp, .singleSelect, .multiSelect, .oob, .html] XCTAssertEqual( - request.renderTypes, + request.renderTypes?.compactMap { $0.stringValue }, [ "CardinalSessionRenderTypeOTP", "CardinalSessionRenderTypeSingleSelect", From 1b9fa41d3f7c380cf5e8bb357be4dda4f2f4c33e Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 14 Nov 2023 13:57:26 -0600 Subject: [PATCH 10/13] cleanup spacing --- Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift index c6861f0f5c..66b24d7ced 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift @@ -4,7 +4,10 @@ import Foundation @objcMembers public class BTThreeDSecureRenderType: NSObject, OptionSet { public let rawValue: Int - required public init(rawValue: Int) { self.rawValue = rawValue } + + required public init(rawValue: Int) { + self.rawValue = rawValue + } /// OTP public static let otp = BTThreeDSecureRenderType(rawValue: 1) From 388024faf9b23085889bada3c528a4904e067796 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 14 Nov 2023 14:07:44 -0600 Subject: [PATCH 11/13] update to use raw cardinal render types --- .../BTThreeDSecureRenderType.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift index 66b24d7ced..0d22eb3f17 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift @@ -1,4 +1,5 @@ import Foundation +import CardinalMobile /// Render types that the device supports for displaying specific challenge user interfaces within the 3D Secure challenge. @objcMembers public class BTThreeDSecureRenderType: NSObject, OptionSet { @@ -27,15 +28,15 @@ import Foundation var stringValue: String { switch self { case .otp: - return "CardinalSessionRenderTypeOTP" + return CardinalSessionRenderTypeOTP case .html: - return "CardinalSessionRenderTypeHTML" + return CardinalSessionRenderTypeHTML case .singleSelect: - return "CardinalSessionRenderTypeSingleSelect" + return CardinalSessionRenderTypeSingleSelect case .multiSelect: - return "CardinalSessionRenderTypeMultiSelect" + return CardinalSessionRenderTypeMultiSelect case .oob: - return "CardinalSessionRenderTypeOOB" + return CardinalSessionRenderTypeOOB default: return "" } From 4bff6faac1a778169e337e8f3c345bf345481ea8 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 14 Nov 2023 14:08:37 -0600 Subject: [PATCH 12/13] update stringValue to cardinalValue --- Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift | 2 +- Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift | 2 +- .../BTThreeDSecureRequest_Tests.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift index 0d22eb3f17..86e31573f5 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureRenderType.swift @@ -25,7 +25,7 @@ import CardinalMobile /// OOB public static let oob = BTThreeDSecureRenderType(rawValue: 5) - var stringValue: String { + var cardinalValue: String { switch self { case .otp: return CardinalSessionRenderTypeOTP diff --git a/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift b/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift index f00a114428..794af534f0 100644 --- a/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift +++ b/Sources/BraintreeThreeDSecure/BTThreeDSecureV2Provider.swift @@ -42,7 +42,7 @@ class BTThreeDSecureV2Provider { cardinalConfiguration.uiType = request.uiType.cardinalValue if let renderTypes = request.renderTypes { - cardinalConfiguration.renderType = renderTypes.compactMap { $0.stringValue } + cardinalConfiguration.renderType = renderTypes.compactMap { $0.cardinalValue } } guard let cardinalAuthenticationJWT = configuration.cardinalAuthenticationJWT else { diff --git a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift index 559b5b820f..157ef7a255 100644 --- a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift +++ b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift @@ -143,7 +143,7 @@ class BTThreeDSecureRequest_Tests: XCTestCase { request.renderTypes = [.otp, .singleSelect, .multiSelect, .oob, .html] XCTAssertEqual( - request.renderTypes?.compactMap { $0.stringValue }, + request.renderTypes?.compactMap { $0.cardinalValue }, [ "CardinalSessionRenderTypeOTP", "CardinalSessionRenderTypeSingleSelect", From ec328015a986554027e6744d8c8587f730515676 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 14 Nov 2023 14:23:49 -0600 Subject: [PATCH 13/13] update UnitTest to use raw cardinal render type --- .../BTThreeDSecureRequest_Tests.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift index 157ef7a255..1e08a285fb 100644 --- a/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift +++ b/UnitTests/BraintreeThreeDSecureTests/BTThreeDSecureRequest_Tests.swift @@ -145,11 +145,11 @@ class BTThreeDSecureRequest_Tests: XCTestCase { XCTAssertEqual( request.renderTypes?.compactMap { $0.cardinalValue }, [ - "CardinalSessionRenderTypeOTP", - "CardinalSessionRenderTypeSingleSelect", - "CardinalSessionRenderTypeMultiSelect", - "CardinalSessionRenderTypeOOB", - "CardinalSessionRenderTypeHTML" + CardinalSessionRenderTypeOTP, + CardinalSessionRenderTypeSingleSelect, + CardinalSessionRenderTypeMultiSelect, + CardinalSessionRenderTypeOOB, + CardinalSessionRenderTypeHTML ] ) }