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