judokit-react-native 4.1.3 → 4.2.0

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 +653 -0
  10. package/android/src/main/java/com/judopay/judokit/reactnative/JudoActivityEventListener.kt +49 -0
  11. package/android/src/main/java/com/judopay/judokit/reactnative/JudoKitReactNativeModule.kt +238 -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 +268 -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 +267 -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 +50 -0
  64. package/src/judo-kit/index.ts +262 -0
  65. package/src/types/index.ts +53 -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
@@ -0,0 +1,238 @@
1
+ package com.judopay.judokit.reactnative
2
+
3
+ import androidx.fragment.app.FragmentActivity
4
+ import com.facebook.react.bridge.Promise
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
7
+ import com.facebook.react.bridge.ReactMethod
8
+ import com.facebook.react.bridge.ReadableMap
9
+ import com.judopay.judokit.android.Judo
10
+ import com.judopay.judokit.android.api.factory.JudoApiServiceFactory
11
+ import com.judopay.judokit.android.api.model.response.JudoApiCallResult
12
+ import com.judopay.judokit.android.api.model.response.Receipt
13
+ import com.judopay.judokit.android.api.model.response.toJudoResult
14
+ import com.judopay.judokit.android.model.JudoPaymentResult
15
+ import com.judopay.judokit.android.model.PaymentWidgetType
16
+ import com.judopay.judokit.android.model.TransactionDetails
17
+ import com.judopay.judokit.android.service.CardTransactionManager
18
+ import com.judopay.judokit.android.service.CardTransactionManagerResultListener
19
+ import retrofit2.Call
20
+ import retrofit2.Callback
21
+ import retrofit2.Response
22
+
23
+ const val REQUEST_FAILED_MESSAGE = "The request was unsuccessful."
24
+ const val MODULE_NAME = "JudoKitReactNative"
25
+
26
+ class JudoKitReactNativeModule internal constructor(private val reactContext: ReactApplicationContext) :
27
+ ReactContextBaseJavaModule(reactContext), CardTransactionManagerResultListener {
28
+ override fun getName() = MODULE_NAME
29
+
30
+ private val listener = JudoActivityEventListener()
31
+ private var transactionPromise: Promise? = null
32
+ private var isSubscribedToCardTransactionResults = false
33
+
34
+ init {
35
+ reactContext.addActivityEventListener(listener)
36
+ }
37
+
38
+ @ReactMethod
39
+ fun invokeTransaction(
40
+ options: ReadableMap,
41
+ promise: Promise,
42
+ ) {
43
+ try {
44
+ val judo = getTransactionConfiguration(options)
45
+ startJudoActivity(judo, promise)
46
+ } catch (error: Exception) {
47
+ promise.reject(JUDO_PROMISE_REJECTION_CODE, error.localizedMessage, error)
48
+ }
49
+ }
50
+
51
+ @ReactMethod
52
+ fun invokeGooglePay(
53
+ options: ReadableMap,
54
+ promise: Promise,
55
+ ) {
56
+ try {
57
+ val judo = getGoogleTransactionConfiguration(options)
58
+ startJudoActivity(judo, promise)
59
+ } catch (error: Exception) {
60
+ promise.reject(JUDO_PROMISE_REJECTION_CODE, error.localizedMessage, error)
61
+ }
62
+ }
63
+
64
+ @ReactMethod
65
+ fun invokePaymentMethodScreen(
66
+ options: ReadableMap,
67
+ promise: Promise,
68
+ ) {
69
+ try {
70
+ val judo = getPaymentMethodsConfiguration(options)
71
+ startJudoActivity(judo, promise)
72
+ } catch (error: Exception) {
73
+ promise.reject(JUDO_PROMISE_REJECTION_CODE, error.localizedMessage, error)
74
+ }
75
+ }
76
+
77
+ @ReactMethod
78
+ fun performTokenTransaction(
79
+ options: ReadableMap,
80
+ promise: Promise,
81
+ ) {
82
+ try {
83
+ ensureIsSubscribedToCardTransactionResults()
84
+
85
+ val activity = reactContext.currentActivity as FragmentActivity
86
+ val manager = CardTransactionManager.getInstance(activity)
87
+
88
+ val judo = getTokenTransactionConfiguration(options)
89
+ val cardToken = options.cardToken
90
+
91
+ if (cardToken == null) {
92
+ promise.reject(JUDO_PROMISE_REJECTION_CODE, "No card token found")
93
+ return
94
+ }
95
+
96
+ manager.configureWith(judo)
97
+
98
+ val details =
99
+ TransactionDetails.Builder()
100
+ .setCardHolderName(options.cardholderName)
101
+ .setSecurityNumber(options.securityCode)
102
+ .setCardType(options.cardType)
103
+ .setCardToken(cardToken)
104
+ .setEmail(judo.emailAddress)
105
+ .setCountryCode(judo.address?.countryCode.toString())
106
+ .setPhoneCountryCode(judo.phoneCountryCode)
107
+ .setMobileNumber(judo.mobileNumber)
108
+ .setAddressLine1(judo.address?.line1)
109
+ .setAddressLine2(judo.address?.line2)
110
+ .setAddressLine3(judo.address?.line3)
111
+ .setCity(judo.address?.town)
112
+ .setPostalCode(judo.address?.postCode)
113
+ .build()
114
+
115
+ transactionPromise = promise
116
+
117
+ when (judo.paymentWidgetType) {
118
+ PaymentWidgetType.CARD_PAYMENT -> manager.paymentWithToken(details, JudoKitReactNativeModule::class.java.name)
119
+ PaymentWidgetType.PRE_AUTH -> manager.preAuthWithToken(details, JudoKitReactNativeModule::class.java.name)
120
+ else ->
121
+ promise.reject(
122
+ JUDO_PROMISE_REJECTION_CODE,
123
+ "${judo.paymentWidgetType.name} payment widget type is not valid for token transactions",
124
+ )
125
+ }
126
+ } catch (exception: Exception) {
127
+ promise.reject(exception)
128
+ }
129
+ }
130
+
131
+ @ReactMethod
132
+ fun fetchTransactionDetails(
133
+ options: ReadableMap,
134
+ promise: Promise,
135
+ ) {
136
+ try {
137
+ val judo = getJudoConfigurationForApiService(options)
138
+ val receiptId = options.receiptId ?: ""
139
+
140
+ val service = JudoApiServiceFactory.create(reactContext, judo)
141
+
142
+ val fetchTransactionDetailsCallback =
143
+ object : Callback<JudoApiCallResult<Receipt>> {
144
+ override fun onResponse(
145
+ call: Call<JudoApiCallResult<Receipt>>,
146
+ response: Response<JudoApiCallResult<Receipt>>,
147
+ ) {
148
+ when (val result = response.body()) {
149
+ is JudoApiCallResult.Success -> {
150
+ val receipt = result.data
151
+ if (receipt != null) {
152
+ val judoResult = receipt.toJudoResult()
153
+ promise.resolve(getMappedResult(judoResult))
154
+ } else {
155
+ promise.reject(JUDO_PROMISE_REJECTION_CODE, REQUEST_FAILED_MESSAGE)
156
+ }
157
+ }
158
+ is JudoApiCallResult.Failure -> {
159
+ val message = result.error?.message ?: REQUEST_FAILED_MESSAGE
160
+ promise.reject(JUDO_PROMISE_REJECTION_CODE, message)
161
+ }
162
+ else -> {
163
+ promise.reject(JUDO_PROMISE_REJECTION_CODE, REQUEST_FAILED_MESSAGE)
164
+ }
165
+ }
166
+ }
167
+
168
+ override fun onFailure(
169
+ call: Call<JudoApiCallResult<Receipt>>,
170
+ throwable: Throwable,
171
+ ) {
172
+ promise.reject(JUDO_PROMISE_REJECTION_CODE, throwable.localizedMessage, throwable)
173
+ }
174
+ }
175
+
176
+ service
177
+ .fetchTransactionWithReceiptId(receiptId)
178
+ .enqueue(fetchTransactionDetailsCallback)
179
+ } catch (error: Exception) {
180
+ promise.reject(JUDO_PROMISE_REJECTION_CODE, error.localizedMessage, error)
181
+ }
182
+ }
183
+
184
+ private fun ensureIsSubscribedToCardTransactionResults() {
185
+ if (isSubscribedToCardTransactionResults) {
186
+ return
187
+ }
188
+
189
+ val activity = reactContext.currentActivity
190
+ activity?.let {
191
+ isSubscribedToCardTransactionResults = true
192
+ CardTransactionManager.getInstance(activity as FragmentActivity).registerResultListener(this)
193
+ }
194
+ }
195
+
196
+ private fun unsubscribeFromCardTransactionResults() {
197
+ val activity = reactContext.currentActivity
198
+ activity?.let {
199
+ isSubscribedToCardTransactionResults = false
200
+ CardTransactionManager.getInstance(activity as FragmentActivity).unRegisterResultListener(this)
201
+ }
202
+ }
203
+
204
+ override fun initialize() {
205
+ super.initialize()
206
+ ensureIsSubscribedToCardTransactionResults()
207
+ }
208
+
209
+ override fun invalidate() {
210
+ super.invalidate()
211
+ unsubscribeFromCardTransactionResults()
212
+ }
213
+
214
+ override fun onCardTransactionResult(result: JudoPaymentResult) {
215
+ transactionPromise?.let {
216
+ if (result is JudoPaymentResult.Success) {
217
+ it.resolve(getMappedResult(result.result))
218
+ } else {
219
+ val message =
220
+ when (result) {
221
+ is JudoPaymentResult.Error -> result.error.message
222
+ is JudoPaymentResult.UserCancelled -> result.error.message
223
+ else -> "The transaction was unsuccessful"
224
+ }
225
+ it.reject(JUDO_PROMISE_REJECTION_CODE, message)
226
+ }
227
+ }
228
+ }
229
+
230
+ private fun startJudoActivity(
231
+ configuration: Judo,
232
+ promise: Promise,
233
+ ) = currentActivity?.let {
234
+ listener.transactionPromise = promise
235
+ val intent = configuration.toJudoActivityIntent(it)
236
+ it.startActivityForResult(intent, JUDO_PAYMENT_WIDGET_REQUEST_CODE)
237
+ }
238
+ }
@@ -0,0 +1,16 @@
1
+ package com.judopay.judokit.reactnative
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+ class JudoKitReactNativePackage : ReactPackage {
9
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
+ return listOf(JudoKitReactNativeModule(reactContext))
11
+ }
12
+
13
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
14
+ return emptyList()
15
+ }
16
+ }
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // NSDictionary+JudoConvert.h
3
- // RNJudo
3
+ // JudoKitReactNative
4
4
  //
5
5
  // Copyright (c) 2020 Alternative Payments Ltd
6
6
  //
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // NSDictionary+JudoConvert.m
3
- // RNJudo
3
+ // JudoKitReactNative
4
4
  //
5
5
  // Copyright (c) 2020 Alternative Payments Ltd
6
6
  //
@@ -97,7 +97,7 @@
97
97
 
98
98
  - (nonnull NSString *)hexColorForKey:(nonnull NSString *)key {
99
99
  id object = [self stringForKey:key];
100
-
100
+
101
101
  NSString *regexPattern = @"#[A-Fa-f0-9]{6}$";
102
102
  NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexPattern options:0 error:nil];
103
103
  if ([regex matchesInString:object options:NSMatchingAnchored range:NSMakeRange(0, [object length])].count) {
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // NSException+JudoValidationExceptions.h
3
- // RNJudo
3
+ // JudoKitReactNative
4
4
  //
5
5
  // Copyright (c) 2020 Alternative Payments Ltd
6
6
  //
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // NSException+JudoValidationExceptions.h
3
- // RNJudo
3
+ // JudoKitReactNative
4
4
  //
5
5
  // Copyright (c) 2020 Alternative Payments Ltd
6
6
  //
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // UIColor+Additions.m
3
- // RNJudo
3
+ // JudoKitReactNative
4
4
  //
5
5
  // Copyright (c) 2020 Alternative Payments Ltd
6
6
  //
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // UIColor+Additions.m
3
- // RNJudo
3
+ // JudoKitReactNative
4
4
  //
5
5
  // Copyright (c) 2020 Alternative Payments Ltd
6
6
  //
@@ -22,8 +22,8 @@
22
22
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  // SOFTWARE.
24
24
 
25
- #import <UIKit/UIKit.h>
26
25
  #import "UIColor+RNAdditions.h"
26
+ #import <UIKit/UIKit.h>
27
27
 
28
28
  @implementation UIColor (RNAdditions)
29
29
 
@@ -35,7 +35,7 @@
35
35
  NSScanner *scanner = [NSScanner scannerWithString:hexString];
36
36
  [scanner setScanLocation:1]; // bypass '#' character
37
37
  [scanner scanHexInt:&rgbValue];
38
- return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
38
+ return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 green:((rgbValue & 0xFF00) >> 8) / 255.0 blue:(rgbValue & 0xFF) / 255.0 alpha:1.0];
39
39
  }
40
40
 
41
41
  @end
@@ -1,8 +1,8 @@
1
1
  //
2
- // RNJudo.h
3
- // RNJudo
2
+ // JudoKitReactNative.h
3
+ // JudoKitReactNative
4
4
  //
5
- // Copyright (c) 2020 Alternative Payments Ltd
5
+ // Copyright (c) 2024 Alternative Payments Ltd
6
6
  //
7
7
  // Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  // of this software and associated documentation files (the "Software"), to deal
@@ -22,10 +22,16 @@
22
22
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  // SOFTWARE.
24
24
 
25
- #import <React/RCTBridgeModule.h>
26
-
27
25
  static const NSErrorDomain _Nonnull RNJudoErrorDomain = @"com.judopay.react-native.error-domain";
28
26
 
29
- @interface RNJudo : NSObject <RCTBridgeModule>
27
+ #ifdef RCT_NEW_ARCH_ENABLED
28
+ #import "RNJudoKitReactNativeSpec.h"
29
+
30
+ @interface JudoKitReactNative : NSObject <NativeJudoKitReactNativeSpec>
31
+ #else
32
+ #import <React/RCTBridgeModule.h>
33
+
34
+ @interface JudoKitReactNative : NSObject <RCTBridgeModule>
35
+ #endif
30
36
 
31
37
  @end
@@ -1,8 +1,8 @@
1
1
  //
2
- // RNJudo.m
3
- // RNJudo
2
+ // JudoKitReactNative.m
3
+ // JudoKitReactNative
4
4
  //
5
- // Copyright (c) 2020 Alternative Payments Ltd
5
+ // Copyright (c) 2024 Alternative Payments Ltd
6
6
  //
7
7
  // Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  // of this software and associated documentation files (the "Software"), to deal
@@ -22,112 +22,89 @@
22
22
  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  // SOFTWARE.
24
24
 
25
- #import <JudoKit-iOS/JudoKit_iOS.h>
26
- #import <JudoKit-iOS/JPError+Additions.h>
27
-
28
- #import "RNJudo.h"
29
- #import "RNWrappers.h"
25
+ #import "JudoKitReactNative.h"
30
26
  #import "RNApplePayWrappers.h"
27
+ #import "RNWrappers.h"
28
+ #import <JudoKit-iOS/JPError+Additions.h>
29
+ #import <JudoKit-iOS/JudoKit_iOS.h>
31
30
 
32
31
  static NSString *kJudoPromiseRejectionCode = @"JUDO_ERROR";
33
32
 
34
33
  typedef NS_ENUM(NSUInteger, JudoSDKInvocationType) {
35
34
  JudoSDKInvocationTypeTransaction,
36
35
  JudoSDKInvocationTypeApplePay,
37
- JudoSDKInvocationTypePBBA,
38
- JudoSDKInvocationTypePaymentMethods
36
+ JudoSDKInvocationTypePaymentMethods,
37
+ JudoSDKInvocationTypeTokenTransaction
39
38
  };
40
39
 
41
- @interface RNJudo ()
40
+ @interface JudoKitReactNative ()
42
41
 
43
42
  @property (nonatomic, strong) JudoKit *judoKit;
44
43
  @property (nonatomic, strong) JPApiService *apiService;
45
- @property (nonatomic, strong) JPCardTransactionService *transactionService;
46
44
  @property (nonatomic, strong) JPCompletionBlock completionBlock;
47
45
 
48
46
  @end
49
47
 
50
- @implementation RNJudo
51
-
52
- RCT_EXPORT_MODULE();
48
+ @implementation JudoKitReactNative
49
+ RCT_EXPORT_MODULE()
53
50
 
54
51
  //----------------------------------------------
55
52
  // MARK: - SDK Methods
56
53
  //----------------------------------------------
57
54
 
58
- RCT_REMAP_METHOD(isBankingAppAvailable,
59
- isBankingAppAvailableWithResolver:(RCTPromiseResolveBlock)resolve
60
- rejecter:(RCTPromiseRejectBlock)reject) {
61
- NSNumber *boolValue = [NSNumber numberWithBool:[JudoKit isBankingAppAvailable]];
62
- resolve(boolValue);
63
- }
64
-
65
55
  RCT_REMAP_METHOD(isApplePayAvailableWithConfiguration,
66
- properties:(NSDictionary *)properties
67
- isApplePayAvailableWithResolver:(RCTPromiseResolveBlock)resolve
68
- rejecter:(RCTPromiseRejectBlock)reject) {
56
+ properties : (NSDictionary *)properties
57
+ isApplePayAvailableWithResolver : (RCTPromiseResolveBlock)resolve
58
+ rejecter : (RCTPromiseRejectBlock)reject) {
69
59
  JPConfiguration *configuration = [RNWrappers configurationFromProperties:properties];
70
60
  NSNumber *boolValue = [NSNumber numberWithBool:[JudoKit isApplePayAvailableWithConfiguration:configuration]];
71
61
  resolve(boolValue);
72
62
  }
73
63
 
74
64
  RCT_REMAP_METHOD(invokeTransaction,
75
- properties:(NSDictionary *)properties
76
- invokePaymentWithResolver:(RCTPromiseResolveBlock)resolve
77
- rejecter:(RCTPromiseRejectBlock)reject) {
78
- [self invokeSDKWithType:JudoSDKInvocationTypeTransaction withProperties:properties resolver:resolve andRejecter:reject];
65
+ properties : (NSDictionary *)properties
66
+ invokePaymentWithResolver : (RCTPromiseResolveBlock)resolve
67
+ rejecter : (RCTPromiseRejectBlock)reject) {
68
+ [self invokeSDKWithType:JudoSDKInvocationTypeTransaction
69
+ withProperties:properties
70
+ resolver:resolve
71
+ andRejecter:reject];
79
72
  }
80
73
 
81
74
  RCT_REMAP_METHOD(invokeApplePay,
82
- properties:(NSDictionary *)properties
83
- invokeApplePayWithResolver:(RCTPromiseResolveBlock)resolve
84
- rejecter:(RCTPromiseRejectBlock)reject) {
85
- [self invokeSDKWithType:JudoSDKInvocationTypeApplePay withProperties:properties resolver:resolve andRejecter:reject];
86
- }
87
-
88
- RCT_REMAP_METHOD(invokePayByBankApp,
89
- properties:(NSDictionary *)properties
90
- invokePayByBankAppWithResolver:(RCTPromiseResolveBlock)resolve
91
- rejecter:(RCTPromiseRejectBlock)reject) {
92
- [self invokeSDKWithType:JudoSDKInvocationTypePBBA withProperties:properties resolver:resolve andRejecter:reject];
75
+ properties : (NSDictionary *)properties
76
+ invokeApplePayWithResolver : (RCTPromiseResolveBlock)resolve
77
+ rejecter : (RCTPromiseRejectBlock)reject) {
78
+ [self invokeSDKWithType:JudoSDKInvocationTypeApplePay
79
+ withProperties:properties
80
+ resolver:resolve
81
+ andRejecter:reject];
93
82
  }
94
83
 
95
84
  RCT_REMAP_METHOD(invokePaymentMethodScreen,
96
- properties:(NSDictionary *)properties
97
- invokePaymentMethodScreenWithResolver:(RCTPromiseResolveBlock)resolve
98
- rejecter:(RCTPromiseRejectBlock)reject) {
99
- [self invokeSDKWithType:JudoSDKInvocationTypePaymentMethods withProperties:properties resolver:resolve andRejecter:reject];
85
+ properties : (NSDictionary *)properties
86
+ invokePaymentMethodScreenWithResolver : (RCTPromiseResolveBlock)resolve
87
+ rejecter : (RCTPromiseRejectBlock)reject) {
88
+ [self invokeSDKWithType:JudoSDKInvocationTypePaymentMethods
89
+ withProperties:properties
90
+ resolver:resolve
91
+ andRejecter:reject];
100
92
  }
101
93
 
102
94
  RCT_REMAP_METHOD(performTokenTransaction,
103
- properties:(NSDictionary *)properties
104
- performTokenTransactionWithResolver:(RCTPromiseResolveBlock)resolve
105
- rejecter:(RCTPromiseRejectBlock)reject) {
106
-
107
- self.transactionService = [RNWrappers cardTransactionServiceFromProperties:properties];
108
- self.completionBlock = [self completionBlockWithResolve:resolve andReject:reject];
109
-
110
- JPTransactionMode transactionMode = [RNWrappers transactionModeFromProperties:properties];
111
- JPConfiguration *configuration = [RNWrappers configurationFromProperties:properties];
112
-
113
- JPCardTransactionDetails *details = [[JPCardTransactionDetails new] initWithConfiguration:configuration];
114
- details.cardToken = [RNWrappers cardTokenFromProperties:properties];
115
- details.securityCode = [RNWrappers securityCodeFromProperties:properties];
116
- details.cardholderName = [RNWrappers cardholderNameFromProperties:properties];
117
- details.cardType = [RNWrappers cardTypeFromProperties:properties];
118
-
119
- if (transactionMode == JPTransactionModePreAuth) {
120
- [self.transactionService invokePreAuthTokenPaymentWithDetails:details andCompletion:self.completionBlock];
121
- return;
122
- }
123
-
124
- [self.transactionService invokeTokenPaymentWithDetails:details andCompletion:self.completionBlock];
95
+ properties : (NSDictionary *)properties
96
+ performTokenTransactionWithResolver : (RCTPromiseResolveBlock)resolve
97
+ rejecter : (RCTPromiseRejectBlock)reject) {
98
+ [self invokeSDKWithType:JudoSDKInvocationTypeTokenTransaction
99
+ withProperties:properties
100
+ resolver:resolve
101
+ andRejecter:reject];
125
102
  }
126
103
 
127
104
  RCT_REMAP_METHOD(fetchTransactionDetails,
128
- properties:(NSDictionary *)properties
129
- fetchTransactionDetailsWithResolver:(RCTPromiseResolveBlock)resolve
130
- rejecter:(RCTPromiseRejectBlock)reject) {
105
+ properties : (NSDictionary *)properties
106
+ fetchTransactionDetailsWithResolver : (RCTPromiseResolveBlock)resolve
107
+ rejecter : (RCTPromiseRejectBlock)reject) {
131
108
  @try {
132
109
  self.apiService = [RNWrappers apiServiceFromProperties:properties];
133
110
  self.completionBlock = [self completionBlockWithResolve:resolve andReject:reject];
@@ -160,24 +137,37 @@ RCT_REMAP_METHOD(fetchTransactionDetails,
160
137
  switch (invocationType) {
161
138
  case JudoSDKInvocationTypeTransaction: {
162
139
  JPTransactionType type = [RNWrappers transactionTypeFromProperties:properties];
163
- [self.judoKit invokeTransactionWithType:type configuration:configuration completion:self.completionBlock];
140
+ [self.judoKit invokeTransactionWithType:type
141
+ configuration:configuration
142
+ completion:self.completionBlock];
164
143
  break;
165
144
  }
166
145
 
167
146
  case JudoSDKInvocationTypeApplePay: {
168
147
  JPTransactionMode mode = [RNWrappers transactionModeFromProperties:properties];
169
- [self.judoKit invokeApplePayWithMode:mode configuration:configuration completion:self.completionBlock];
148
+ [self.judoKit invokeApplePayWithMode:mode
149
+ configuration:configuration
150
+ completion:self.completionBlock];
170
151
  break;
171
152
  }
172
153
 
173
- case JudoSDKInvocationTypePBBA: {
174
- [self.judoKit invokePBBAWithConfiguration:configuration completion:self.completionBlock];
154
+ case JudoSDKInvocationTypePaymentMethods: {
155
+ JPTransactionMode mode = [RNWrappers transactionModeFromProperties:properties];
156
+ [self.judoKit invokePaymentMethodScreenWithMode:mode
157
+ configuration:configuration
158
+ completion:self.completionBlock];
175
159
  break;
176
160
  }
177
161
 
178
- case JudoSDKInvocationTypePaymentMethods: {
162
+ case JudoSDKInvocationTypeTokenTransaction: {
163
+ JPCardTransactionDetails *details = [self transactionDetailsFromProperties:properties];
179
164
  JPTransactionMode mode = [RNWrappers transactionModeFromProperties:properties];
180
- [self.judoKit invokePaymentMethodScreenWithMode:mode configuration:configuration completion:self.completionBlock];
165
+ JPTransactionType type = mode == JPTransactionModePayment ? JPTransactionTypePayment : JPTransactionTypePreAuth;
166
+
167
+ [self.judoKit invokeTokenTransactionWithType:type
168
+ configuration:configuration
169
+ details:details
170
+ completion:self.completionBlock];
181
171
  break;
182
172
  }
183
173
 
@@ -194,22 +184,35 @@ RCT_REMAP_METHOD(fetchTransactionDetails,
194
184
  }
195
185
  }
196
186
 
187
+ - (JPCardTransactionDetails *)transactionDetailsFromProperties:(NSDictionary *)properties {
188
+ JPConfiguration *configuration = [RNWrappers configurationFromProperties:properties];
189
+
190
+ JPCardTransactionDetails *details = [[JPCardTransactionDetails new] initWithConfiguration:configuration];
191
+
192
+ details.cardToken = [RNWrappers cardTokenFromProperties:properties];
193
+ details.securityCode = [RNWrappers securityCodeFromProperties:properties];
194
+ details.cardholderName = [RNWrappers cardholderNameFromProperties:properties];
195
+ details.cardType = [RNWrappers cardTypeFromProperties:properties];
196
+
197
+ return details;
198
+ }
199
+
197
200
  - (JPCompletionBlock)completionBlockWithResolve:(RCTPromiseResolveBlock)resolve
198
201
  andReject:(RCTPromiseRejectBlock)reject {
199
202
  return ^(JPResponse *response, NSError *error) {
200
203
  if (error) {
201
204
  if (error.code == JPError.userDidCancelError.code) {
202
- reject(kJudoPromiseRejectionCode, @"Transaction cancelled", error);
205
+ reject(kJudoPromiseRejectionCode, @"Transaction cancelled", error);
203
206
  return;
204
207
  }
205
-
208
+
206
209
  NSString *description = error.userInfo[NSLocalizedDescriptionKey];
207
210
  NSString *message = @"Transaction failed";
208
-
211
+
209
212
  if (description && description.length > 0) {
210
213
  message = description;
211
214
  }
212
-
215
+
213
216
  // TODO: RCTJSErrorFromCodeMessageAndNSError expects an NSError instane in userInfo[NSUnderlyingErrorKey]
214
217
  // which in case of a 3DS SDK error is a NSString ('JP3DSSDKRuntimeException') - so it crashes
215
218
  // ! this should be fixed in JudoKit-iOS, and the folowing workaround removed ASAP
@@ -218,8 +221,7 @@ RCT_REMAP_METHOD(fetchTransactionDetails,
218
221
  NSError *myError = [[NSError alloc] initWithDomain:error.domain
219
222
  code:error.code
220
223
  userInfo:[NSDictionary dictionaryWithDictionary:userInfo]];
221
-
222
-
224
+
223
225
  reject(kJudoPromiseRejectionCode, message, myError);
224
226
  } else {
225
227
  NSDictionary *mappedResponse = [RNWrappers dictionaryFromResponse:response];
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // RNTypes.h
3
- // RNJudo
3
+ // JudoKitReactNative
4
4
  //
5
5
  // Copyright (c) 2020 Alternative Payments Ltd
6
6
  //
@@ -28,7 +28,6 @@ typedef NS_OPTIONS(NSUInteger, IOSPaymentMethod) {
28
28
  IOSPaymentMethodCard = 1 << 0,
29
29
  IOSPaymentMethodApplePay = 1 << 1,
30
30
  IOSPaymentMethodIDEAL = 1 << 3,
31
- IOSPaymentMethodPBBA = 1 << 4,
32
31
  IOSPaymentMethodAll = 1 << 5,
33
32
  };
34
33
 
@@ -73,3 +72,10 @@ typedef NS_ENUM(NSUInteger, IOSShippingType) {
73
72
  IOSShippingTypeServicePickup,
74
73
  };
75
74
 
75
+ typedef NS_ENUM(NSUInteger, IOSCalendarUnit) {
76
+ IOSCalendarUnitYear = 1,
77
+ IOSCalendarUnitMonth,
78
+ IOSCalendarUnitDay,
79
+ IOSCalendarUnitHour,
80
+ IOSCalendarUnitMinute,
81
+ };
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // RNApplePayWrappers.h
3
- // RNJudo
3
+ // JudoKitReactNative
4
4
  //
5
5
  // Copyright (c) 2020 Alternative Payments Ltd
6
6
  //