judokit-react-native 4.1.3 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/JudoKit-ReactNative.podspec +42 -0
  2. package/LICENSE +1 -2
  3. package/README.md +106 -119
  4. package/android/build.gradle +65 -202
  5. package/android/gradle.properties +6 -1
  6. package/android/src/main/AndroidManifest.xml +2 -2
  7. package/android/src/main/AndroidManifestNew.xml +2 -0
  8. package/android/src/main/java/com/judopay/judokit/reactnative/Extensions.kt +382 -0
  9. package/android/src/main/java/com/judopay/judokit/reactnative/Helpers.kt +678 -0
  10. package/android/src/main/java/com/judopay/judokit/reactnative/JudoActivityEventListener.kt +50 -0
  11. package/android/src/main/java/com/judopay/judokit/reactnative/JudoKitReactNativeModule.kt +153 -0
  12. package/android/src/main/java/com/judopay/judokit/reactnative/JudoKitReactNativePackage.kt +16 -0
  13. package/ios/{Classes/Extensions → Extensions}/NSDictionary+JudoConvert.h +1 -1
  14. package/ios/{Classes/Extensions → Extensions}/NSDictionary+JudoConvert.m +2 -2
  15. package/ios/{Classes/Extensions → Extensions}/NSException+JudoValidationExceptions.h +1 -1
  16. package/ios/{Classes/Extensions → Extensions}/NSException+JudoValidationExceptions.m +1 -1
  17. package/ios/{Classes/Extensions → Extensions}/UIColor+RNAdditions.h +1 -1
  18. package/ios/{Classes/Extensions → Extensions}/UIColor+RNAdditions.m +3 -3
  19. package/ios/{Classes/RNJudo.h → JudoKitReactNative.h} +12 -6
  20. package/ios/{Classes/RNJudo.m → JudoKitReactNative.mm} +83 -81
  21. package/ios/{Classes/RNTypes.h → RNTypes.h} +8 -2
  22. package/ios/{Classes/Wrappers → Wrappers}/RNApplePayWrappers.h +1 -1
  23. package/ios/{Classes/Wrappers → Wrappers}/RNApplePayWrappers.m +105 -4
  24. package/ios/{Classes/Wrappers → Wrappers}/RNWrappers.h +14 -14
  25. package/ios/{Classes/Wrappers → Wrappers}/RNWrappers.m +46 -25
  26. package/lib/commonjs/index.js +274 -0
  27. package/lib/commonjs/index.js.map +1 -0
  28. package/lib/commonjs/judo-kit/index.js +212 -0
  29. package/lib/commonjs/judo-kit/index.js.map +1 -0
  30. package/lib/commonjs/types/index.js +273 -0
  31. package/lib/commonjs/types/index.js.map +1 -0
  32. package/lib/commonjs/types/judo-apple-pay-configuration.js +49 -0
  33. package/lib/commonjs/types/judo-apple-pay-configuration.js.map +1 -0
  34. package/lib/commonjs/types/judo-configuration.js +71 -0
  35. package/lib/commonjs/types/judo-configuration.js.map +1 -0
  36. package/lib/commonjs/types/judo-google-pay-configuration.js +28 -0
  37. package/lib/commonjs/types/judo-google-pay-configuration.js.map +1 -0
  38. package/lib/module/index.js +6 -0
  39. package/lib/module/index.js.map +1 -0
  40. package/lib/module/judo-kit/index.js +205 -0
  41. package/lib/module/judo-kit/index.js.map +1 -0
  42. package/lib/module/types/index.js +8 -0
  43. package/lib/module/types/index.js.map +1 -0
  44. package/lib/module/types/judo-apple-pay-configuration.js +43 -0
  45. package/lib/module/types/judo-apple-pay-configuration.js.map +1 -0
  46. package/lib/module/types/judo-configuration.js +65 -0
  47. package/lib/module/types/judo-configuration.js.map +1 -0
  48. package/lib/module/types/judo-google-pay-configuration.js +22 -0
  49. package/lib/module/types/judo-google-pay-configuration.js.map +1 -0
  50. package/lib/typescript/src/index.d.ts +4 -0
  51. package/lib/typescript/src/index.d.ts.map +1 -0
  52. package/lib/typescript/src/judo-kit/index.d.ts +86 -0
  53. package/lib/typescript/src/judo-kit/index.d.ts.map +1 -0
  54. package/lib/typescript/src/types/index.d.ts +4 -0
  55. package/lib/typescript/src/types/index.d.ts.map +1 -0
  56. package/lib/typescript/src/types/judo-apple-pay-configuration.d.ts +75 -0
  57. package/lib/typescript/src/types/judo-apple-pay-configuration.d.ts.map +1 -0
  58. package/lib/typescript/src/types/judo-configuration.d.ts +236 -0
  59. package/lib/typescript/src/types/judo-configuration.d.ts.map +1 -0
  60. package/lib/typescript/src/types/judo-google-pay-configuration.d.ts +42 -0
  61. package/lib/typescript/src/types/judo-google-pay-configuration.d.ts.map +1 -0
  62. package/package.json +158 -79
  63. package/src/index.tsx +51 -0
  64. package/src/judo-kit/index.ts +262 -0
  65. package/src/types/index.ts +54 -0
  66. package/src/types/judo-apple-pay-configuration.ts +85 -0
  67. package/src/types/judo-configuration.ts +263 -0
  68. package/src/types/judo-google-pay-configuration.ts +47 -0
  69. package/JudoPay.tsx +0 -334
  70. package/RNJudopay.podspec +0 -24
  71. package/android/src/main/java/com/reactlibrary/Extensions.kt +0 -372
  72. package/android/src/main/java/com/reactlibrary/Helpers.kt +0 -606
  73. package/android/src/main/java/com/reactlibrary/JudoReactNativeActivityEventListener.kt +0 -48
  74. package/android/src/main/java/com/reactlibrary/JudoReactNativeModule.kt +0 -257
  75. package/android/src/main/java/com/reactlibrary/JudoReactNativePBBAManager.kt +0 -52
  76. package/android/src/main/java/com/reactlibrary/JudoReactNativePackage.kt +0 -14
  77. package/components/JudoPBBAButton.ts +0 -2
  78. package/ios/.xcode.env +0 -11
  79. package/ios/Classes/Views/RNPBBAButtonManager.m +0 -42
  80. package/ios/Classes/Wrappers/RNPBBAWrappers.h +0 -40
  81. package/ios/Classes/Wrappers/RNPBBAWrappers.m +0 -57
  82. package/ios/Podfile +0 -44
  83. package/ios/Podfile.lock +0 -572
  84. package/ios/RNJudo.xcodeproj/project.pbxproj +0 -703
  85. package/ios/RNJudo.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  86. package/ios/RNJudo.xcodeproj/xcshareddata/xcschemes/RNJudo.xcscheme +0 -97
  87. package/ios/RNJudo.xcworkspace/contents.xcworkspacedata +0 -10
  88. package/ios/RNJudoTests/Info.plist +0 -22
  89. package/ios/RNJudoTests/MockConfiguration.json +0 -114
  90. package/ios/RNJudoTests/NSDictionaryConvertTests.m +0 -475
  91. package/ios/RNJudoTests/RNApplePayWrappersTests.m +0 -770
  92. package/ios/RNJudoTests/RNJudoTests.m +0 -37
  93. package/ios/RNJudoTests/RNMocks.h +0 -54
  94. package/ios/RNJudoTests/RNMocks.m +0 -55
  95. package/ios/RNJudoTests/RNPBBAWrappersTests.m +0 -121
  96. package/ios/RNJudoTests/RNThemeTests.m +0 -576
  97. package/ios/RNJudoTests/RNWrappersTests.m +0 -947
  98. package/types/JudoApplePayTypes.tsx +0 -59
  99. package/types/JudoGooglePayTypes.tsx +0 -47
  100. package/types/JudoPBBATypes.tsx +0 -7
  101. package/types/JudoTypes.tsx +0 -251
@@ -1,606 +0,0 @@
1
- package com.reactlibrary
2
-
3
- import android.net.Uri
4
- import android.os.Bundle
5
- import com.facebook.react.bridge.Arguments
6
- import com.facebook.react.bridge.ReadableMap
7
- import com.facebook.react.bridge.WritableMap
8
- import com.judopay.judo3ds2.customization.ButtonCustomization
9
- import com.judopay.judo3ds2.customization.LabelCustomization
10
- import com.judopay.judo3ds2.customization.TextBoxCustomization
11
- import com.judopay.judo3ds2.customization.ToolbarCustomization
12
- import com.judopay.judo3ds2.customization.UiCustomization
13
- import com.judopay.judokit.android.Judo
14
- import com.judopay.judokit.android.api.model.Authorization
15
- import com.judopay.judokit.android.api.model.BasicAuthorization
16
- import com.judopay.judokit.android.api.model.PaymentSessionAuthorization
17
- import com.judopay.judokit.android.api.model.request.Address
18
- import com.judopay.judokit.android.model.*
19
- import com.judopay.judokit.android.model.googlepay.*
20
-
21
- // For consistency with:
22
- // https://github.com/Judopay/JudoKit-iOS/blob/master/Source/Models/Response/JPResponse.m#L36
23
- private const val TRANSACTION_TYPE_PAYMENT = "payment"
24
- private const val TRANSACTION_TYPE_PRE_AUTH = "preauth"
25
- private const val TRANSACTION_TYPE_REGISTER = "register"
26
- private const val TRANSACTION_TYPE_REGISTER_CARD = "registercard"
27
- private const val TRANSACTION_TYPE_SAVE_CARD = "save"
28
- private const val TRANSACTION_TYPE_CHECK_CARD = "checkcard"
29
-
30
- // For consistency with:
31
- // https://github.com/Judopay/JudoKit-iOS/blob/master/Source/Models/Transaction/JPTransactionType.h#L30
32
- private enum class TransactionType(val value: Int, val typeAsStrings: List<String>? = null) {
33
- PAYMENT(1, listOf(TRANSACTION_TYPE_PAYMENT)),
34
- PRE_AUTH(2, listOf(TRANSACTION_TYPE_PRE_AUTH)),
35
- REGISTER_CARD(3, listOf(TRANSACTION_TYPE_REGISTER, TRANSACTION_TYPE_REGISTER_CARD)),
36
- CHECK_CARD(4, listOf(TRANSACTION_TYPE_CHECK_CARD)),
37
- SAVE_CARD(5, listOf(TRANSACTION_TYPE_SAVE_CARD)),
38
- UNKNOWN(-1)
39
- }
40
-
41
- // For consistency with:
42
- // https://github.com/Judopay/JudoKit-iOS/blob/master/Source/Models/Response/JPResponse.m#L32
43
- private const val STATUS_DECLINED = "declined"
44
- private const val STATUS_SUCCESS = "success"
45
- private const val STATUS_ERROR = "error"
46
-
47
- // For consistency with:
48
- // https://github.com/Judopay/JudoKit-iOS/blob/abd34bbfe4784fb5f074ed30f93d6743ba295622/Source/Models/Transaction/JPTransactionResult.h#L27
49
- private enum class TransactionResult(val value: Int, val status: String? = null) {
50
- ERROR(0, STATUS_ERROR),
51
- SUCCESS(1, STATUS_SUCCESS),
52
- DECLINED(2, STATUS_DECLINED),
53
- UNKNOWN(-1)
54
- }
55
-
56
- internal fun getTransactionConfiguration(options: ReadableMap): Judo {
57
- val widgetType = getTransactionTypeWidget(options)
58
- return getJudoConfiguration(widgetType, options)
59
- }
60
-
61
- internal fun getTokenTransactionConfiguration(options: ReadableMap): Judo {
62
- val widgetType = getTransactionModeWidget(options)
63
- return getJudoConfiguration(widgetType, options)
64
- }
65
-
66
- internal fun getGoogleTransactionConfiguration(options: ReadableMap): Judo {
67
- val type = when (options.transactionMode) {
68
- 0 -> PaymentWidgetType.GOOGLE_PAY
69
- else -> PaymentWidgetType.PRE_AUTH_GOOGLE_PAY
70
- }
71
- return getJudoConfiguration(type, options)
72
- }
73
-
74
- internal fun getPaymentMethodsConfiguration(options: ReadableMap): Judo {
75
- val type = when (options.transactionMode) {
76
- 0 -> PaymentWidgetType.PAYMENT_METHODS
77
- 1 -> PaymentWidgetType.PRE_AUTH_PAYMENT_METHODS
78
- 2 -> PaymentWidgetType.SERVER_TO_SERVER_PAYMENT_METHODS
79
- else -> PaymentWidgetType.PAYMENT_METHODS
80
- }
81
- return getJudoConfiguration(type, options)
82
- }
83
-
84
- internal fun getMappedType(type: String?): Int {
85
- val typeInLowercase = type?.lowercase()
86
- val typeValue = TransactionType.values().firstOrNull { it.typeAsStrings?.contains(typeInLowercase) ?: false }
87
-
88
- return typeValue?.value ?: TransactionType.UNKNOWN.value
89
- }
90
-
91
- // consistent with:
92
- // https://github.com/Judopay/JudoKit-iOS/blob/master/Source/Models/Response/JPResponse.m#L125
93
- internal fun getMappedResult(result: String?): Int {
94
- val resultInLowercase = result?.lowercase()
95
- val resultValue = TransactionResult.values().firstOrNull { it.status == resultInLowercase }
96
-
97
- return resultValue?.value ?: TransactionResult.UNKNOWN.value
98
- }
99
-
100
- internal fun getMappedResult(result: JudoResult?): WritableMap {
101
- val map = Arguments.createMap()
102
- map.putString("receiptId", result?.receiptId)
103
- map.putString("yourPaymentReference", result?.yourPaymentReference)
104
- map.putInt("type", getMappedType(result?.type))
105
- map.putString("createdAt", result?.createdAt.toString())
106
- map.putInt("result", getMappedResult(result?.result))
107
- map.putString("message", result?.message)
108
- map.putString("judoId", result?.judoId)
109
- map.putString("merchantName", result?.merchantName)
110
- map.putString("appearsOnStatementAs", result?.appearsOnStatementAs)
111
- map.putString("originalAmount", result?.originalAmount.toString())
112
- map.putString("netAmount", result?.netAmount.toString())
113
- map.putString("amount", result?.amount.toString())
114
- map.putString("currency", result?.currency)
115
-
116
- val cardDetailsMap = Arguments.createMap()
117
- cardDetailsMap.putString("cardLastFour", result?.cardDetails?.lastFour)
118
- cardDetailsMap.putString("endDate", result?.cardDetails?.endDate)
119
- cardDetailsMap.putString("cardToken", result?.cardDetails?.token)
120
- result?.cardDetails?.type?.let { cardDetailsMap.putInt("cardNetwork", it) }
121
- cardDetailsMap.putString("bank", result?.cardDetails?.bank)
122
- cardDetailsMap.putString("cardCategory", result?.cardDetails?.category)
123
- cardDetailsMap.putString("cardCountry", result?.cardDetails?.country)
124
- cardDetailsMap.putString("cardFunding", result?.cardDetails?.funding)
125
- cardDetailsMap.putString("cardScheme", result?.cardDetails?.scheme)
126
- cardDetailsMap.putString("cardHolderName", result?.cardDetails?.cardHolderName)
127
-
128
- map.putMap("cardDetails", cardDetailsMap)
129
-
130
- val consumerMap = Arguments.createMap()
131
- consumerMap.putString("consumerToken", result?.consumer?.consumerToken)
132
- consumerMap.putString("consumerReference", result?.consumer?.yourConsumerReference)
133
-
134
- map.putMap("consumer", consumerMap)
135
-
136
- return map
137
- }
138
-
139
- internal fun getJudoConfigurationForApiService(options: ReadableMap): Judo {
140
- val authorization = getAuthorization(options)
141
-
142
- val amount = Amount.Builder()
143
- .setAmount("0.00")
144
- .setCurrency(Currency.GBP)
145
- .build()
146
-
147
- val reference = Reference.Builder()
148
- .setConsumerReference("reference")
149
- .build()
150
-
151
- return Judo.Builder(PaymentWidgetType.CARD_PAYMENT)
152
- .setIsSandboxed(options.isSandboxed)
153
- .setJudoId("000000")
154
- .setAuthorization(authorization)
155
- .setAmount(amount)
156
- .setReference(reference)
157
- .setSubProductInfo(getSubProductInfo(options))
158
- .build()
159
- }
160
-
161
- internal fun getJudoConfiguration(type: PaymentWidgetType, options: ReadableMap): Judo {
162
- val authorization = getAuthorization(options)
163
- val amount = getAmount(options)
164
- val reference = getReference(options)
165
- val cardNetworks = getCardNetworks(options)
166
- val paymentMethods = getPaymentMethods(options)
167
- val uiConfiguration = getUIConfiguration(options)
168
- val primaryAccountDetails = getPrimaryAccountDetails(options)
169
- val googlePayConfiguration = getGooglePayConfiguration(options)
170
- val pbbaConfiguration = getPBBAConfiguration(options)
171
- val timeouts = getNetworkTimeout(options)
172
- val challengeRequestIndicator = getChallengeRequestIndicator(options)
173
- val scaExemption = getScaExemption(options)
174
- val address = getAddress(options)
175
-
176
- return Judo.Builder(type)
177
- .setAuthorization(authorization)
178
- .setIsSandboxed(options.isSandboxed)
179
- .setJudoId(options.judoId)
180
- .setAmount(amount)
181
- .setReference(reference)
182
- .setSupportedCardNetworks(cardNetworks)
183
- .setPaymentMethods(paymentMethods)
184
- .setUiConfiguration(uiConfiguration)
185
- .setPrimaryAccountDetails(primaryAccountDetails)
186
- .setGooglePayConfiguration(googlePayConfiguration)
187
- .setPBBAConfiguration(pbbaConfiguration)
188
- .setInitialRecurringPayment(options.isInitialRecurringPayment)
189
- .setDelayedAuthorisation(options.isDelayedAuthorisation)
190
- .setNetworkTimeout(timeouts)
191
- .setChallengeRequestIndicator(challengeRequestIndicator)
192
- .setScaExemption(scaExemption)
193
- .setMobileNumber(options.mobileNumber)
194
- .setEmailAddress(options.emailAddress)
195
- .setThreeDSTwoMaxTimeout(options.threeDSTwoMaxTimeout)
196
- .setThreeDSTwoMessageVersion(options.threeDSTwoMessageVersion)
197
- .setPhoneCountryCode(options.phoneCountryCode)
198
- .setAddress(address)
199
- .setSubProductInfo(getSubProductInfo(options))
200
- .build()
201
- }
202
-
203
- internal fun getAddress(options: ReadableMap): Address? {
204
- if (options.cardAddress != null) {
205
- return Address.Builder()
206
- .setLine1(options.cardAddressLine1)
207
- .setLine2(options.cardAddressLine2)
208
- .setLine3(options.cardAddressLine3)
209
- .setTown(options.cardAddressTown)
210
- .setPostCode(options.cardAddressPostCode)
211
- .setCountryCode(options.cardAddressCountryCode)
212
- .setState(options.cardAddressState)
213
- .build()
214
- }
215
- return null
216
- }
217
-
218
- internal fun getNetworkTimeout(options: ReadableMap): NetworkTimeout? {
219
- val networkTimeout = options.networkTimeout
220
- if (networkTimeout != null) {
221
- return NetworkTimeout.Builder()
222
- .setConnectTimeout(options.networkConnectTimeout)
223
- .setReadTimeout(options.networkReadTimeout)
224
- .setWriteTimeout(options.networkWriteTimeout)
225
- .build()
226
- }
227
- return null
228
- }
229
-
230
- internal fun getChallengeRequestIndicator(options: ReadableMap): ChallengeRequestIndicator? = ChallengeRequestIndicator.values().firstOrNull { it.value == options.challengeRequestIndicator }
231
-
232
- internal fun getScaExemption(options: ReadableMap): ScaExemption? = ScaExemption.values().firstOrNull { it.value == options.scaExemption }
233
-
234
- internal fun getAuthorization(options: ReadableMap): Authorization {
235
- val token = options.token
236
-
237
- options.secret?.let { secret ->
238
- return BasicAuthorization.Builder()
239
- .setApiToken(token)
240
- .setApiSecret(secret)
241
- .build()
242
- }
243
-
244
- options.paymentSession?.let { paymentSession ->
245
- return PaymentSessionAuthorization.Builder()
246
- .setApiToken(token)
247
- .setPaymentSession(paymentSession)
248
- .build()
249
- }
250
-
251
- throw IllegalArgumentException("No secret or payment session in the authorization")
252
- }
253
-
254
- internal fun getTransactionTypeWidget(options: ReadableMap) = when (options.getInt("transactionType")) {
255
- 1 -> PaymentWidgetType.CARD_PAYMENT
256
- 2 -> PaymentWidgetType.PRE_AUTH
257
- 3 -> PaymentWidgetType.REGISTER_CARD
258
- 4 -> PaymentWidgetType.CHECK_CARD
259
- 5 -> PaymentWidgetType.CREATE_CARD_TOKEN
260
- else -> throw IllegalArgumentException("Unknown transaction type")
261
- }
262
-
263
- internal fun getTransactionModeWidget(options: ReadableMap) = when (options.getInt("transactionMode")) {
264
- 1 -> PaymentWidgetType.PRE_AUTH
265
- else -> PaymentWidgetType.CARD_PAYMENT
266
- }
267
-
268
- internal fun getAmount(options: ReadableMap): Amount {
269
- val currency = when (val currencyValue = options.currencyValue) {
270
- null -> Currency.GBP
271
- else -> Currency.valueOf(currencyValue)
272
- }
273
- return Amount.Builder()
274
- .setAmount(options.amountValue)
275
- .setCurrency(currency)
276
- .build()
277
- }
278
-
279
- internal fun getSubProductInfo(options: ReadableMap): SubProductInfo {
280
- val version = options.packageVersion ?: ""
281
- return SubProductInfo.ReactNative(version)
282
- }
283
-
284
- internal fun getReference(options: ReadableMap): Reference? {
285
-
286
- var builder = Reference.Builder()
287
- .setConsumerReference(options.consumerReference)
288
- .setPaymentReference(options.paymentReference)
289
-
290
- val metadataMap = options.metadata
291
- metadataMap?.let {
292
- val bundle = Bundle()
293
- metadataMap.toHashMap().forEach {
294
- bundle.putString(it.key, it.value.toString())
295
- }
296
- builder = builder.setMetaData(bundle)
297
- }
298
-
299
- return builder.build()
300
- }
301
-
302
- internal fun getCardNetworks(options: ReadableMap): Array<CardNetwork>? {
303
-
304
- val cardVisa = 1
305
- val cardMastercard = 1 shl 1
306
- val cardMaestro = 1 shl 2
307
- val cardAmex = 1 shl 3
308
- val cardChinaUnionPay = 1 shl 4
309
- val cardJcb = 1 shl 5
310
- val cardDiscover = 1 shl 6
311
- val cardDinersClub = 1 shl 7
312
- val cardsAll = 1 shl 8
313
-
314
- var supportedNetworks: MutableList<CardNetwork>? = null
315
-
316
- val cardValue = options.cardNetworkValue
317
- cardValue?.let {
318
-
319
- supportedNetworks = ArrayList()
320
-
321
- if (cardValue and cardVisa == cardVisa) {
322
- supportedNetworks?.add(CardNetwork.VISA)
323
- }
324
-
325
- if (cardValue and cardMastercard == cardMastercard) {
326
- supportedNetworks?.add(CardNetwork.MASTERCARD)
327
- }
328
-
329
- if (cardValue and cardMaestro == cardMaestro) {
330
- supportedNetworks?.add(CardNetwork.MAESTRO)
331
- }
332
-
333
- if (cardValue and cardAmex == cardAmex) {
334
- supportedNetworks?.add(CardNetwork.AMEX)
335
- }
336
-
337
- if (cardValue and cardChinaUnionPay == cardChinaUnionPay) {
338
- supportedNetworks?.add(CardNetwork.CHINA_UNION_PAY)
339
- }
340
-
341
- if (cardValue and cardJcb == cardJcb) {
342
- supportedNetworks?.add(CardNetwork.JCB)
343
- }
344
-
345
- if (cardValue and cardDiscover == cardDiscover) {
346
- supportedNetworks?.add(CardNetwork.DISCOVER)
347
- }
348
-
349
- if (cardValue and cardDinersClub == cardDinersClub) {
350
- supportedNetworks?.add(CardNetwork.DINERS_CLUB)
351
- }
352
-
353
- if (cardValue and cardsAll == cardsAll) {
354
- return CardNetwork.values()
355
- }
356
- }
357
- return supportedNetworks?.toTypedArray()
358
- }
359
-
360
- internal fun getPaymentMethods(options: ReadableMap): Array<PaymentMethod>? {
361
-
362
- var paymentMethods: ArrayList<PaymentMethod>? = null
363
-
364
- val cardPaymentValue = 1
365
- val googlePaymentValue = 1 shl 2
366
- val idealPaymentValue = 1 shl 3
367
- val allPaymentValues = 1 shl 4
368
-
369
- options.paymentMethodValue?.let {
370
-
371
- paymentMethods = arrayListOf()
372
-
373
- if (it and cardPaymentValue == cardPaymentValue) {
374
- paymentMethods?.add(PaymentMethod.CARD)
375
- }
376
-
377
- if (it and googlePaymentValue == googlePaymentValue) {
378
- paymentMethods?.add(PaymentMethod.GOOGLE_PAY)
379
- }
380
-
381
- if (it and idealPaymentValue == idealPaymentValue) {
382
- paymentMethods?.add(PaymentMethod.IDEAL)
383
- }
384
-
385
- if (it and allPaymentValues == allPaymentValues) {
386
- return PaymentMethod.values()
387
- }
388
- }
389
-
390
- return paymentMethods?.toTypedArray()
391
- }
392
-
393
- internal fun getUIConfiguration(options: ReadableMap): UiConfiguration? {
394
- return if (options.uiConfiguration != null) {
395
- UiConfiguration.Builder()
396
- .setAvsEnabled(options.isAVSEnabled)
397
- .setShouldPaymentMethodsDisplayAmount(options.shouldPaymentMethodsDisplayAmount)
398
- .setShouldPaymentButtonDisplayAmount(options.shouldPaymentButtonDisplayAmount)
399
- .setShouldPaymentMethodsVerifySecurityCode(options.shouldPaymentMethodsVerifySecurityCode)
400
- .setShouldAskForBillingInformation(options.shouldAskForBillingInformation)
401
- .setThreeDSUiCustomization(getThreeDSUiCustomization(options))
402
- .build()
403
- } else {
404
- null
405
- }
406
- }
407
-
408
- internal fun getThreeDSUiCustomization(options: ReadableMap): UiCustomization? {
409
- return if (options.threeDSUIConfiguration != null) {
410
-
411
- val uiCustomization = UiCustomization()
412
-
413
- options.threeDSUIToolbarCustomization?.let {
414
- uiCustomization.setToolbarCustomization(ToolbarCustomization().apply {
415
- setTextFontName(it.textFontName)
416
- setTextColor(it.textColor)
417
- setTextFontSize(it.textFontSize)
418
- setBackgroundColor(it.backgroundColor)
419
- setHeaderText(it.headerText)
420
- setButtonText(it.buttonText)
421
- })
422
- }
423
-
424
- options.threeDSUILabelCustomization?.let {
425
- uiCustomization.setLabelCustomization(LabelCustomization().apply {
426
- setTextFontName(it.textFontName)
427
- setTextColor(it.textColor)
428
- setTextFontSize(it.textFontSize)
429
- setHeadingTextFontName(it.headingTextFontName)
430
- setHeadingTextColor(it.headingTextColor)
431
- setHeadingTextFontSize(it.headingTextFontSize)
432
- })
433
- }
434
-
435
- options.threeDSUITextBoxCustomization?.let {
436
- uiCustomization.setTextBoxCustomization(TextBoxCustomization().apply {
437
- setTextFontName(it.textFontName)
438
- setTextColor(it.textColor)
439
- setTextFontSize(it.textFontSize)
440
- setBorderWidth(it.borderWidth)
441
- setBorderColor(it.borderColor)
442
- setCornerRadius(it.cornerRadius)
443
- })
444
- }
445
-
446
- if (options.threeDSUIButtonCustomizations != null) {
447
-
448
- options.threeDSUISubmitButtonCustomization?.let {
449
- uiCustomization.setButtonCustomization(ButtonCustomization().apply {
450
- setTextFontName(it.textFontName)
451
- setTextColor(it.textColor)
452
- setTextFontSize(it.textFontSize)
453
- setBackgroundColor(it.backgroundColor)
454
- setCornerRadius(it.cornerRadius)
455
- }, UiCustomization.ButtonType.SUBMIT)
456
- }
457
-
458
- options.threeDSUINextButtonCustomization?.let {
459
- uiCustomization.setButtonCustomization(ButtonCustomization().apply {
460
- setTextFontName(it.textFontName)
461
- setTextColor(it.textColor)
462
- setTextFontSize(it.textFontSize)
463
- setBackgroundColor(it.backgroundColor)
464
- setCornerRadius(it.cornerRadius)
465
- }, UiCustomization.ButtonType.NEXT)
466
- }
467
-
468
- options.threeDSUIContinueButtonCustomization?.let {
469
- uiCustomization.setButtonCustomization(ButtonCustomization().apply {
470
- setTextFontName(it.textFontName)
471
- setTextColor(it.textColor)
472
- setTextFontSize(it.textFontSize)
473
- setBackgroundColor(it.backgroundColor)
474
- setCornerRadius(it.cornerRadius)
475
- }, UiCustomization.ButtonType.CONTINUE)
476
- }
477
-
478
- options.threeDSUICancelButtonCustomization?.let {
479
- uiCustomization.setButtonCustomization(ButtonCustomization().apply {
480
- setTextFontName(it.textFontName)
481
- setTextColor(it.textColor)
482
- setTextFontSize(it.textFontSize)
483
- setBackgroundColor(it.backgroundColor)
484
- setCornerRadius(it.cornerRadius)
485
- }, UiCustomization.ButtonType.CANCEL)
486
- }
487
-
488
- options.threeDSUIResendButtonCustomization?.let {
489
- uiCustomization.setButtonCustomization(ButtonCustomization().apply {
490
- setTextFontName(it.textFontName)
491
- setTextColor(it.textColor)
492
- setTextFontSize(it.textFontSize)
493
- setBackgroundColor(it.backgroundColor)
494
- setCornerRadius(it.cornerRadius)
495
- }, UiCustomization.ButtonType.RESEND)
496
- }
497
- }
498
-
499
- uiCustomization
500
- } else {
501
- null
502
- }
503
- }
504
-
505
- internal fun getPrimaryAccountDetails(options: ReadableMap): PrimaryAccountDetails? {
506
- return if (options.primaryAccountDetails != null) {
507
- PrimaryAccountDetails.Builder()
508
- .setName(options.name)
509
- .setAccountNumber(options.accountNumber)
510
- .setDateOfBirth(options.dateOfBirth)
511
- .setPostCode(options.postCode)
512
- .build()
513
- } else {
514
- null
515
- }
516
- }
517
-
518
- internal fun getGooglePayConfiguration(options: ReadableMap): GooglePayConfiguration? {
519
-
520
- val environment = when (options.environmentValue) {
521
- 0 -> GooglePayEnvironment.TEST
522
- else -> GooglePayEnvironment.PRODUCTION
523
- }
524
- val totalPriceStatus = when (options.totalPriceStatus) {
525
- 0 -> GooglePayPriceStatus.FINAL
526
- 1 -> GooglePayPriceStatus.ESTIMATED
527
- 2 -> GooglePayPriceStatus.NOT_CURRENTLY_KNOWN
528
- else -> null
529
- }
530
-
531
- val checkoutOption = when (options.checkoutOption) {
532
- 0 -> GooglePayCheckoutOption.DEFAULT
533
- 1 -> GooglePayCheckoutOption.COMPLETE_IMMEDIATE_PURCHASE
534
- else -> null
535
- }
536
-
537
- val billingParameters = getBillingParameters(options)
538
- val shippingParameters = getShippingParameters(options)
539
-
540
- return if (options.googlePayConfiguration != null) {
541
- GooglePayConfiguration.Builder()
542
- .setEnvironment(environment)
543
- .setMerchantName(options.merchantName)
544
- .setTransactionCountryCode(options.countryCode)
545
- .setTransactionId(options.transactionId)
546
- .setTotalPriceStatus(totalPriceStatus)
547
- .setTotalPriceLabel(options.totalPriceLabel)
548
- .setCheckoutOption(checkoutOption)
549
- .setIsEmailRequired(options.isEmailRequired)
550
- .setIsBillingAddressRequired(options.isBillingAddressRequired)
551
- .setBillingAddressParameters(billingParameters)
552
- .setIsShippingAddressRequired(options.isShippingAddressRequired)
553
- .setShippingAddressParameters(shippingParameters)
554
- .setAllowPrepaidCards(options.allowPrepaidCards)
555
- .setAllowCreditCards(options.allowCreditCards)
556
- .build()
557
- } else {
558
- null
559
- }
560
- }
561
-
562
- internal fun getBillingParameters(options: ReadableMap): GooglePayBillingAddressParameters? {
563
- val addressFormat = when (options.addressFormat) {
564
- 0 -> GooglePayAddressFormat.MIN
565
- else -> GooglePayAddressFormat.FULL
566
- }
567
- return GooglePayBillingAddressParameters(
568
- addressFormat,
569
- options.isBillingPhoneNumberRequired
570
- )
571
- }
572
-
573
- internal fun getShippingParameters(options: ReadableMap): GooglePayShippingAddressParameters? {
574
-
575
- var allowedCountryCodes: Array<String>? = null
576
- val allowedCountryArray = options.allowedCountryCodeList
577
-
578
- allowedCountryArray?.let {
579
- val countryList = allowedCountryArray.toArrayList().mapNotNull { it as String }
580
- allowedCountryCodes = countryList.toTypedArray()
581
- }
582
-
583
- return GooglePayShippingAddressParameters(
584
- allowedCountryCodes,
585
- options.isShippingPhoneNumberRequired
586
- )
587
- }
588
-
589
- internal fun getPBBAConfiguration(options: ReadableMap): PBBAConfiguration? {
590
- return if (options.pbbaConfiguration != null) {
591
- val deeplinkUri = if (options.deeplinkURL.isNullOrBlank()) {
592
- null
593
- } else {
594
- Uri.parse(options.deeplinkURL)
595
- }
596
-
597
- PBBAConfiguration.Builder()
598
- .setMobileNumber(options.pbbaMobileNumber)
599
- .setEmailAddress(options.pbbaEmailAddress)
600
- .setDeepLinkURL(deeplinkUri)
601
- .setDeepLinkScheme(options.deeplinkScheme)
602
- .build()
603
- } else {
604
- null
605
- }
606
- }
@@ -1,48 +0,0 @@
1
- package com.reactlibrary
2
-
3
- import android.app.Activity
4
- import android.app.Activity.RESULT_CANCELED
5
- import android.content.Intent
6
- import com.facebook.react.bridge.BaseActivityEventListener
7
- import com.facebook.react.bridge.Promise
8
- import com.judopay.judokit.android.JUDO_ERROR
9
- import com.judopay.judokit.android.JUDO_RESULT
10
- import com.judopay.judokit.android.PAYMENT_ERROR
11
- import com.judopay.judokit.android.PAYMENT_CANCELLED
12
- import com.judopay.judokit.android.PAYMENT_SUCCESS
13
- import com.judopay.judokit.android.model.JudoError
14
- import com.judopay.judokit.android.model.JudoResult
15
-
16
- class JudoReactNativeActivityEventListener : BaseActivityEventListener() {
17
-
18
- internal var transactionPromise: Promise? = null
19
-
20
- override fun onActivityResult(
21
- activity: Activity?,
22
- requestCode: Int,
23
- resultCode: Int,
24
- data: Intent?
25
- ) {
26
-
27
- if (data == null || resultCode == RESULT_CANCELED || requestCode != JUDO_PAYMENT_WIDGET_REQUEST_CODE) {
28
- return
29
- }
30
-
31
- try {
32
- when (resultCode) {
33
- PAYMENT_ERROR, PAYMENT_CANCELLED -> {
34
- val error = data.getParcelableExtra<JudoError>(JUDO_ERROR)
35
- transactionPromise?.reject(JUDO_PROMISE_REJECTION_CODE, error?.message)
36
- }
37
- PAYMENT_SUCCESS -> {
38
- val result = data.getParcelableExtra<JudoResult>(JUDO_RESULT)
39
- transactionPromise?.resolve(getMappedResult(result))
40
- }
41
- }
42
- } catch (throwable: Throwable) {
43
- transactionPromise?.reject(JUDO_PROMISE_REJECTION_CODE, throwable.message)
44
- }
45
-
46
- transactionPromise = null
47
- }
48
- }