@@ -15,14 +15,20 @@ class CardDataConverter {
1515
1616 companion object {
1717
18+ /* *
19+ * Converts a basic CardNonce into a WritableMap for React Native.
20+ */
1821 fun createTokenizeCardDataNonce (cardNonce : CardNonce ): WritableMap {
1922 val result: WritableMap = Arguments .createMap()
2023 result.putString(" nonce" , cardNonce.string)
24+
25+ // Handling unknown card types for consistent JS reporting
2126 if (cardNonce.cardType == " Unknown" ) {
2227 result.putString(" cardNetwork" , " " )
2328 } else {
2429 result.putString(" cardNetwork" , cardNonce.cardType)
2530 }
31+
2632 result.putString(" lastFour" , cardNonce.lastFour)
2733 result.putString(" lastTwo" , cardNonce.lastTwo)
2834 result.putString(" expirationMonth" , cardNonce.expirationMonth)
@@ -32,7 +38,7 @@ class CardDataConverter {
3238
3339 /* *
3440 * Converts the 3D Secure result nonce into a WritableMap to be sent back to JavaScript.
35- * This includes card details and the critical threeDSecureInfo object .
41+ * Includes liability shift details required for security checks .
3642 */
3743 fun createThreeDSecureDataNonce (cardNonce : ThreeDSecureNonce ): WritableMap {
3844 val result: WritableMap = Arguments .createMap()
@@ -53,18 +59,20 @@ class CardDataConverter {
5359 val infoMap: WritableMap = Arguments .createMap()
5460 val info = cardNonce.threeDSecureInfo
5561
56- if (info != null ) {
57- infoMap.putBoolean(" liabilityShifted" , info.liabilityShifted)
58- infoMap.putBoolean(" liabilityShiftPossible" , info.liabilityShiftPossible)
59- infoMap.putString(" status" , info.status)
60- infoMap.putBoolean(" wasVerified" , info.wasVerified)
61- }
62+ // REMOVED: if (info != null) check because threeDSecureInfo is NonNull in SDK v5+
63+ infoMap.putBoolean(" liabilityShifted" , info.liabilityShifted)
64+ infoMap.putBoolean(" liabilityShiftPossible" , info.liabilityShiftPossible)
65+ infoMap.putString(" status" , info.status)
66+ infoMap.putBoolean(" wasVerified" , info.wasVerified)
6267
6368 result.putMap(" threeDSecureInfo" , infoMap)
6469
6570 return result
6671 }
6772
73+ /* *
74+ * Creates a Card object from JS options for basic tokenization.
75+ */
6876 fun createTokenizeCardRequest (options : ReadableMap ): Card {
6977 val card: Card = Card ()
7078 if (options.hasKey(" number" )) {
@@ -85,29 +93,30 @@ class CardDataConverter {
8593 return card
8694 }
8795
96+ /* *
97+ * Maps JS options to a ThreeDSecureRequest.
98+ * Includes address mapping to satisfy 3DS 2.0 risk assessment requirements.
99+ */
88100 fun create3DSecureRequest (options : ReadableMap ): ThreeDSecureRequest {
89101 val address = ThreeDSecurePostalAddress ()
90102
91- // Map personal names - Note: Braintree v6 uses givenName and surname
103+ // Personal details mapping
92104 if (options.hasKey(" givenName" )) {
93105 address.givenName = options.getString(" givenName" )
94106 }
95107 if (options.hasKey(" surName" )) {
96108 address.surname = options.getString(" surName" )
97109 }
98110
99- // Map contact details
100111 if (options.hasKey(" phoneNumber" )) {
101112 address.phoneNumber = options.getString(" phoneNumber" )
102113 }
103114
104- // CRITICAL: countryCodeAlpha2 MUST be provided if 'region' is present.
105- // This prevents the "The region cannot be provided without a corresponding country code" (422) error.
115+ // Required by Braintree to avoid 422 errors if region is provided
106116 if (options.hasKey(" countryCodeAlpha2" )) {
107117 address.countryCodeAlpha2 = options.getString(" countryCodeAlpha2" )
108118 }
109119
110- // Map geographic location details
111120 if (options.hasKey(" city" )) {
112121 address.locality = options.getString(" city" )
113122 }
@@ -124,21 +133,18 @@ class CardDataConverter {
124133 address.extendedAddress = options.getString(" streetAddress2" )
125134 }
126135
127- // 3D Secure 2.0 requires additional info for better risk assessment
128136 val additionalInformation = ThreeDSecureAdditionalInformation ()
129137 additionalInformation.shippingAddress = address
130138
131139 val threeDSecureRequest = ThreeDSecureRequest ()
132- // Use elvis operator to ensure non-null values for the SDK
133140 threeDSecureRequest.nonce = options.getString(" nonce" ) ? : " "
134141 threeDSecureRequest.email = options.getString(" email" ) ? : " "
135142 threeDSecureRequest.amount = options.getString(" amount" ) ? : " 0.00"
136143
137- // Attach the objects to the main request
138144 threeDSecureRequest.billingAddress = address
139145 threeDSecureRequest.additionalInformation = additionalInformation
140146
141147 return threeDSecureRequest
142148 }
143149 }
144- }
150+ }
0 commit comments