judokit-react-native 3.5.0 → 4.1.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.
@@ -16,10 +16,42 @@ import com.judopay.judokit.android.api.model.BasicAuthorization
16
16
  import com.judopay.judokit.android.api.model.PaymentSessionAuthorization
17
17
  import com.judopay.judokit.android.api.model.request.Address
18
18
  import com.judopay.judokit.android.model.*
19
- import com.judopay.judokit.android.model.googlepay.GooglePayAddressFormat
20
- import com.judopay.judokit.android.model.googlepay.GooglePayBillingAddressParameters
21
- import com.judopay.judokit.android.model.googlepay.GooglePayEnvironment
22
- import com.judopay.judokit.android.model.googlepay.GooglePayShippingAddressParameters
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
+ }
23
55
 
24
56
  internal fun getTransactionConfiguration(options: ReadableMap): Judo {
25
57
  val widgetType = getTransactionTypeWidget(options)
@@ -50,20 +82,19 @@ internal fun getPaymentMethodsConfiguration(options: ReadableMap): Judo {
50
82
  }
51
83
 
52
84
  internal fun getMappedType(type: String?): Int {
53
- return when (type) {
54
- "PreAuth" -> 1
55
- "RegisterCard" -> 2
56
- "CheckCard" -> 3
57
- "Save" -> 4
58
- else -> 0
59
- }
85
+ val typeInLowercase = type?.lowercase()
86
+ val typeValue = TransactionType.values().firstOrNull { it.typeAsStrings?.contains(typeInLowercase) ?: false }
87
+
88
+ return typeValue?.value ?: TransactionType.UNKNOWN.value
60
89
  }
61
90
 
91
+ // consistent with:
92
+ // https://github.com/Judopay/JudoKit-iOS/blob/master/Source/Models/Response/JPResponse.m#L125
62
93
  internal fun getMappedResult(result: String?): Int {
63
- return when (result) {
64
- "Declined" -> 1
65
- else -> 0
66
- }
94
+ val resultInLowercase = result?.lowercase()
95
+ val resultValue = TransactionResult.values().firstOrNull { it.status == resultInLowercase }
96
+
97
+ return resultValue?.value ?: TransactionResult.UNKNOWN.value
67
98
  }
68
99
 
69
100
  internal fun getMappedResult(result: JudoResult?): WritableMap {
@@ -123,6 +154,7 @@ internal fun getJudoConfigurationForApiService(options: ReadableMap): Judo {
123
154
  .setAuthorization(authorization)
124
155
  .setAmount(amount)
125
156
  .setReference(reference)
157
+ .setSubProductInfo(getSubProductInfo(options))
126
158
  .build()
127
159
  }
128
160
 
@@ -164,6 +196,7 @@ internal fun getJudoConfiguration(type: PaymentWidgetType, options: ReadableMap)
164
196
  .setThreeDSTwoMessageVersion(options.threeDSTwoMessageVersion)
165
197
  .setPhoneCountryCode(options.phoneCountryCode)
166
198
  .setAddress(address)
199
+ .setSubProductInfo(getSubProductInfo(options))
167
200
  .build()
168
201
  }
169
202
 
@@ -219,11 +252,12 @@ internal fun getAuthorization(options: ReadableMap): Authorization {
219
252
  }
220
253
 
221
254
  internal fun getTransactionTypeWidget(options: ReadableMap) = when (options.getInt("transactionType")) {
222
- 1 -> PaymentWidgetType.PRE_AUTH
223
- 2 -> PaymentWidgetType.REGISTER_CARD
224
- 3 -> PaymentWidgetType.CHECK_CARD
225
- 4 -> PaymentWidgetType.CREATE_CARD_TOKEN
226
- else -> PaymentWidgetType.CARD_PAYMENT
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")
227
261
  }
228
262
 
229
263
  internal fun getTransactionModeWidget(options: ReadableMap) = when (options.getInt("transactionMode")) {
@@ -242,6 +276,11 @@ internal fun getAmount(options: ReadableMap): Amount {
242
276
  .build()
243
277
  }
244
278
 
279
+ internal fun getSubProductInfo(options: ReadableMap): SubProductInfo {
280
+ val version = options.packageVersion ?: ""
281
+ return SubProductInfo.ReactNative(version)
282
+ }
283
+
245
284
  internal fun getReference(options: ReadableMap): Reference? {
246
285
 
247
286
  var builder = Reference.Builder()
@@ -482,19 +521,38 @@ internal fun getGooglePayConfiguration(options: ReadableMap): GooglePayConfigura
482
521
  0 -> GooglePayEnvironment.TEST
483
522
  else -> GooglePayEnvironment.PRODUCTION
484
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
+ }
485
536
 
486
537
  val billingParameters = getBillingParameters(options)
487
538
  val shippingParameters = getShippingParameters(options)
488
539
 
489
540
  return if (options.googlePayConfiguration != null) {
490
541
  GooglePayConfiguration.Builder()
491
- .setTransactionCountryCode(options.countryCode)
492
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)
493
549
  .setIsEmailRequired(options.isEmailRequired)
494
550
  .setIsBillingAddressRequired(options.isBillingAddressRequired)
495
551
  .setBillingAddressParameters(billingParameters)
496
552
  .setIsShippingAddressRequired(options.isShippingAddressRequired)
497
553
  .setShippingAddressParameters(shippingParameters)
554
+ .setAllowPrepaidCards(options.allowPrepaidCards)
555
+ .setAllowCreditCards(options.allowCreditCards)
498
556
  .build()
499
557
  } else {
500
558
  null
package/ios/.xcode.env ADDED
@@ -0,0 +1,11 @@
1
+ # This `.xcode.env` file is versioned and is used to source the environment
2
+ # used when running script phases inside Xcode.
3
+ # To customize your local environment, you can create an `.xcode.env.local`
4
+ # file that is not versioned.
5
+
6
+ # NODE_BINARY variable contains the PATH to the node executable.
7
+ #
8
+ # Customize the NODE_BINARY variable here.
9
+ # For example, to use nvm with brew, add the following line
10
+ # . "$(brew --prefix nvm)/nvm.sh" --no-use
11
+ export NODE_BINARY=$(command -v node)
@@ -112,7 +112,7 @@ RCT_REMAP_METHOD(performTokenTransaction,
112
112
 
113
113
  JPCardTransactionDetails *details = [[JPCardTransactionDetails new] initWithConfiguration:configuration];
114
114
  details.cardToken = [RNWrappers cardTokenFromProperties:properties];
115
- details.secureCode = [RNWrappers securityCodeFromProperties:properties];
115
+ details.securityCode = [RNWrappers securityCodeFromProperties:properties];
116
116
  details.cardholderName = [RNWrappers cardholderNameFromProperties:properties];
117
117
  details.cardType = [RNWrappers cardTypeFromProperties:properties];
118
118
 
@@ -44,6 +44,8 @@ static NSString *const kCardSchemeAMEX = @"amex";
44
44
  id<JPAuthorization> authorization = [RNWrappers authorizationFromProperties:properties];
45
45
  JudoKit *judoKit = [[JudoKit alloc] initWithAuthorization:authorization];
46
46
  judoKit.isSandboxed = [RNWrappers isSandboxedFromProperties:properties];
47
+ judoKit.subProductInfo = [RNWrappers subProductInfoFromProperties:properties];
48
+
47
49
  return judoKit;
48
50
  }
49
51
 
@@ -73,6 +75,11 @@ static NSString *const kCardSchemeAMEX = @"amex";
73
75
  return isSandboxed.boolValue;
74
76
  }
75
77
 
78
+ + (JPSubProductInfo *)subProductInfoFromProperties:(NSDictionary *)properties {
79
+ NSString *version = [properties optionalStringForKey:@"packageVersion"];;
80
+ return [[JPSubProductInfo alloc] initWithSubProductType:JPSubProductTypeReactNative andVersion:version];
81
+ }
82
+
76
83
  + (JPCardTransactionService *)cardTransactionServiceFromProperties:(NSDictionary *)properties {
77
84
  BOOL isSandboxed = [RNWrappers isSandboxedFromProperties:properties];
78
85
  id<JPAuthorization> authorization = [RNWrappers authorizationFromProperties:properties];
@@ -86,15 +93,20 @@ static NSString *const kCardSchemeAMEX = @"amex";
86
93
  + (JPTransactionType)transactionTypeFromProperties:(NSDictionary *)properties {
87
94
  int type = [properties numberForKey:@"transactionType"].intValue;
88
95
 
89
- NSArray<NSNumber *> *availableTypes = @[
90
- @(JPTransactionTypePayment),
91
- @(JPTransactionTypePreAuth),
92
- @(JPTransactionTypeRegisterCard),
93
- @(JPTransactionTypeCheckCard),
94
- @(JPTransactionTypeSaveCard)
95
- ];
96
-
97
- return availableTypes[type].intValue;
96
+ switch (type) {
97
+ case 1:
98
+ return JPTransactionTypePayment;
99
+ case 2:
100
+ return JPTransactionTypePreAuth;
101
+ case 3:
102
+ return JPTransactionTypeRegisterCard;
103
+ case 4:
104
+ return JPTransactionTypeCheckCard;
105
+ case 5:
106
+ return JPTransactionTypeSaveCard;
107
+ default:
108
+ return JPTransactionTypeUnknown;
109
+ }
98
110
  }
99
111
 
100
112
  + (JPTransactionMode)transactionModeFromProperties:(NSDictionary *)properties {
@@ -745,35 +757,12 @@ static NSString *const kCardSchemeAMEX = @"amex";
745
757
  + (NSDictionary *)dictionaryFromResponse:(JPResponse *)response {
746
758
 
747
759
  NSMutableDictionary *mappedResponse = [NSMutableDictionary new];
748
-
749
- // TODO: remove this ASAP when this https://github.com/Judopay/JudoKit-ReactNative/pull/138
750
- // will go to master (mimics the android wrapper behaviour: https://github.com/Judopay/JudoKit-ReactNative/blob/master/android/src/main/java/com/reactlibrary/Helpers.kt#L57)
751
- NSNumber *result = @0;
752
- if (response.result == JPTransactionResultDeclined) {
753
- result = @1;
754
- }
755
-
756
- NSNumber *type = @0;
757
-
758
- switch (response.type) {
759
- case JPTransactionTypePreAuth:
760
- type = @1;
761
- break;
762
- case JPTransactionTypeCheckCard:
763
- type = @3;
764
- break;
765
- case JPTransactionTypeSaveCard:
766
- type = @4;
767
- break;
768
- default:
769
- break;
770
- }
771
760
 
772
761
  [mappedResponse setValue:response.receiptId forKey:@"receiptId"];
773
762
  [mappedResponse setValue:response.paymentReference forKey:@"yourPaymentReference"];
774
- [mappedResponse setValue:type forKey:@"type"];
763
+ [mappedResponse setValue:@(response.type) forKey:@"type"];
775
764
  [mappedResponse setValue:response.createdAt forKey:@"createdAt"];
776
- [mappedResponse setValue:result forKey:@"result"];
765
+ [mappedResponse setValue:@(response.result) forKey:@"result"];
777
766
  [mappedResponse setValue:response.message forKey:@"message"];
778
767
  [mappedResponse setValue:response.judoId forKey:@"judoId"];
779
768
  [mappedResponse setValue:response.merchantName forKey:@"merchantName"];
package/ios/Podfile CHANGED
@@ -1,74 +1,44 @@
1
+ require_relative '../node_modules/react-native/scripts/react_native_pods'
1
2
  require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
2
- platform :ios, '11.0'
3
3
 
4
- pre_install do |installer|
5
- puts("Image fix for ios14: remove this when upgradeing to >= 0.63.3")
6
- find = "_currentFrame.CGImage;"
7
- replace = "_currentFrame.CGImage ;} else { [super displayLayer:layer];"
8
- op = `sed -ie "s/#{find}/#{replace}/" ../node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m`
9
- puts("Image fix for ios14 done")
4
+ platform :ios, '12.4'
5
+ install! 'cocoapods', :deterministic_uuids => false
10
6
 
11
- ## Fix for XCode 12.5
12
- find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
13
- "_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")
14
- find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
15
- "RCTBridgeModuleNameForClass(module))", "RCTBridgeModuleNameForClass(Class(module)))")
16
- end
7
+ production = ENV["PRODUCTION"] == "1"
17
8
 
18
9
  target 'RNJudo' do
19
- # use_frameworks!
10
+ config = use_native_modules!
11
+
12
+ # Flags change depending on the env values.
13
+ flags = get_default_flags()
14
+
15
+ use_react_native!(
16
+ :path => config[:reactNativePath],
17
+ # to enable hermes on iOS, change `false` to `true` and then install pods
18
+ :production => production,
19
+ :hermes_enabled => flags[:hermes_enabled],
20
+ :fabric_enabled => flags[:fabric_enabled],
21
+ :flipper_configuration => FlipperConfiguration.enabled,
22
+ # An absolute path to your application root.
23
+ :app_path => "#{Pod::Config.instance.installation_root}/.."
24
+ )
20
25
 
21
26
  # Pods for RNJudo
22
- pod "JudoKit-iOS", "3.1.10"
23
- pod "Judo3DS2_iOS", "1.1.3"
24
-
25
- pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
26
- pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
27
- pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
28
- pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
29
- pod 'React', :path => '../node_modules/react-native/'
30
- pod 'React-Core', :path => '../node_modules/react-native/'
31
- pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
32
- pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
33
- pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
34
- pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
35
- pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
36
- pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
37
- pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
38
- pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
39
- pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
40
- pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
41
- pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
42
- pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
43
-
44
- pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
45
- pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
46
- pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
47
- pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
48
- pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
49
- pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
50
- pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
51
- pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
52
- pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
53
- pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
27
+ pod "JudoKit-iOS", "3.2.2"
54
28
 
55
29
  target 'RNJudoTests' do
30
+ inherit! :complete
31
+ requires_app_host = true
56
32
  # Pods for testing
57
33
  end
58
34
 
59
- use_native_modules!
60
- end
35
+ post_install do |installer|
36
+ react_native_post_install(installer)
37
+ __apply_Xcode_12_5_M1_post_install_workaround(installer)
61
38
 
62
- ## Fix for XCode 12.5
63
- def find_and_replace(dir, findstr, replacestr)
64
- Dir[dir].each do |name|
65
- text = File.read(name)
66
- replace = text.gsub(findstr,replacestr)
67
- if text != replace
68
- puts "Fix: " + name
69
- File.open(name, "w") { |file| file.puts replace }
70
- STDOUT.flush
39
+ installer.pods_project.build_configurations.each do |config|
40
+ # https://khushwanttanwar.medium.com/xcode-12-compilation-errors-while-running-with-ios-14-simulators-5731c91326e9
41
+ config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
71
42
  end
72
43
  end
73
- Dir[dir + '*/'].each(&method(:find_and_replace))
74
44
  end