@sumup/react-native-checkout 0.0.0-alpha.2 → 0.0.0-alpha.3

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.
@@ -5,7 +5,7 @@ buildscript {
5
5
  }
6
6
 
7
7
  dependencies {
8
- classpath "com.android.tools.build:gradle:7.2.1"
8
+ classpath "com.android.tools.build:gradle:8.6.1"
9
9
  }
10
10
  }
11
11
 
@@ -15,9 +15,6 @@ def isNewArchitectureEnabled() {
15
15
 
16
16
  apply plugin: "com.android.library"
17
17
 
18
-
19
- def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
20
-
21
18
  if (isNewArchitectureEnabled()) {
22
19
  apply plugin: "com.facebook.react"
23
20
  }
@@ -30,12 +27,25 @@ def getExtOrIntegerDefault(name) {
30
27
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["SumupReactNative_" + name]).toInteger()
31
28
  }
32
29
 
30
+ def getReactNativeAndroidDependency() {
31
+ if (rootProject.ext.has("reactNativeVersion")) {
32
+ return "com.facebook.react:react-android:${rootProject.ext.get("reactNativeVersion")}"
33
+ }
34
+ if (project.hasProperty("reactNativeVersion")) {
35
+ return "com.facebook.react:react-android:${project.property("reactNativeVersion")}"
36
+ }
37
+ // Fallback for older hosts still exposing only react-native:+ from local maven.
38
+ return "com.facebook.react:react-native:+"
39
+ }
40
+
33
41
  android {
34
- compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
42
+ namespace "com.sumupreactnative"
43
+ compileSdk getExtOrIntegerDefault("compileSdkVersion")
44
+ ndkVersion getExtOrDefault("ndkversion")
35
45
 
36
46
  defaultConfig {
37
- minSdkVersion getExtOrIntegerDefault("minSdkVersion")
38
- targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
47
+ minSdk getExtOrIntegerDefault("minSdkVersion")
48
+ targetSdk getExtOrIntegerDefault("targetSdkVersion")
39
49
  buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
40
50
  }
41
51
  buildTypes {
@@ -44,13 +54,13 @@ android {
44
54
  }
45
55
  }
46
56
 
47
- lintOptions {
57
+ lint {
48
58
  disable "GradleCompatible"
49
59
  }
50
60
 
51
61
  compileOptions {
52
- sourceCompatibility JavaVersion.VERSION_1_8
53
- targetCompatibility JavaVersion.VERSION_1_8
62
+ sourceCompatibility JavaVersion.VERSION_17
63
+ targetCompatibility JavaVersion.VERSION_17
54
64
  }
55
65
 
56
66
  }
@@ -62,10 +72,7 @@ repositories {
62
72
 
63
73
 
64
74
  dependencies {
65
- // For < 0.71, this will be from the local maven repo
66
- // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
67
- //noinspection GradleDynamicVersion
68
- implementation "com.facebook.react:react-native:+"
75
+ implementation getReactNativeAndroidDependency()
69
76
  implementation 'com.google.android.gms:play-services-wallet:19.1.0'
70
77
  }
71
78
 
@@ -1,5 +1,5 @@
1
1
  SumupReactNative_kotlinVersion=1.7.0
2
- SumupReactNative_minSdkVersion=21
3
- SumupReactNative_targetSdkVersion=31
4
- SumupReactNative_compileSdkVersion=31
5
- SumupReactNative_ndkversion=21.4.7075529
2
+ SumupReactNative_minSdkVersion=23
3
+ SumupReactNative_targetSdkVersion=35
4
+ SumupReactNative_compileSdkVersion=35
5
+ SumupReactNative_ndkversion=26.1.10909125
@@ -60,6 +60,10 @@ public class SumupReactNativeModule extends ReactContextBaseJavaModule {
60
60
  private final ActivityEventListener activityEventListener = new BaseActivityEventListener() {
61
61
  @Override
62
62
  public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
63
+ if (requestPaymentPromise == null) {
64
+ return;
65
+ }
66
+
63
67
  switch (requestCode) {
64
68
  // value passed in AutoResolveHelper
65
69
  case LOAD_PAYMENT_DATA_REQUEST_CODE:
@@ -81,6 +85,7 @@ public class SumupReactNativeModule extends ReactContextBaseJavaModule {
81
85
  default:
82
86
  // Do nothing.
83
87
  }
88
+ requestPaymentPromise = null;
84
89
  break;
85
90
  }
86
91
  }
@@ -114,6 +119,11 @@ public class SumupReactNativeModule extends ReactContextBaseJavaModule {
114
119
  promise.resolve(false);
115
120
  return;
116
121
  }
122
+ if (mPaymentsClient == null) {
123
+ Log.w(NAME, "[GooglePay] payments client is not initialized");
124
+ promise.resolve(false);
125
+ return;
126
+ }
117
127
 
118
128
  final JSONObject isReadyToPayJson = PaymentUtil.getIsReadyToPayRequest(allowedCardNetworks.toArrayList(), allowedCardAuthMethods.toArrayList());
119
129
  if (isReadyToPayJson == null) {
@@ -158,6 +168,11 @@ public class SumupReactNativeModule extends ReactContextBaseJavaModule {
158
168
  promise.reject("NO_ACTIVITY", "activity is null");
159
169
  return;
160
170
  }
171
+ if (mPaymentsClient == null) {
172
+ Log.w(NAME, "[GooglePay] payments client is not initialized");
173
+ promise.reject("NO_PAYMENTS_CLIENT", "payments client is not initialized");
174
+ return;
175
+ }
161
176
 
162
177
  JSONObject paymentDataRequestJson = PaymentUtil.getPaymentDataRequest(requestData);
163
178
  if (paymentDataRequestJson == null) {
@@ -1,31 +1,34 @@
1
1
  import PassKit
2
+ import UIKit
2
3
 
3
4
  @objc(SumupReactNative)
4
- class SumupReactNative: UIViewController {
5
+ class SumupReactNative: NSObject {
5
6
 
6
7
  private var request: PKPaymentRequest = PKPaymentRequest()
7
8
  private var resolve: RCTPromiseResolveBlock?
9
+ private var reject: RCTPromiseRejectBlock?
8
10
  private var paymentNetworks: [PKPaymentNetwork]?
11
+ private var didResolvePayment = false
9
12
 
10
13
  @objc(configure:details:)
11
- private func configure(withMethod method: NSDictionary, details: NSDictionary) -> Void {
12
-
13
- self.paymentNetworks = method["supportedNetworks"] as? [PKPaymentNetwork]
14
+ func configure(withMethod method: NSDictionary, details: NSDictionary) -> Void {
15
+ self.paymentNetworks = parseSupportedNetworks(from: method)
16
+ self.request = PKPaymentRequest()
14
17
 
15
18
  guard let paymentNetworks = paymentNetworks,
16
19
  PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks),
17
20
  let total = details["total"] as? NSDictionary,
18
21
  let label = total["label"] as? String,
19
- let amount = total["amount"] as? Double,
22
+ let amountNumber = total["amount"] as? NSNumber,
20
23
  let currencyCode = method["currencyCode"] as? String,
21
24
  let countryCode = method["countryCode"] as? String,
22
25
  let merchantIdentifier = method["merchantIdentifier"] as? String else {
23
- print("SumupReactNative: params are not valid")
26
+ NSLog("SumupReactNative: invalid Apple Pay configuration")
24
27
  return
25
28
  }
26
29
 
27
30
  let paymentItem = PKPaymentSummaryItem.init(label: label,
28
- amount: NSDecimalNumber(value: amount))
31
+ amount: NSDecimalNumber(decimal: amountNumber.decimalValue))
29
32
  request.currencyCode = currencyCode
30
33
  request.countryCode = countryCode
31
34
  request.merchantIdentifier = merchantIdentifier
@@ -35,31 +38,30 @@ class SumupReactNative: UIViewController {
35
38
  }
36
39
 
37
40
  @objc(presentApplePay:withRejecter:)
38
- func presentApplePay(resolve: @escaping RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void {
41
+ func presentApplePay(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
42
+ self.resolve = resolve
43
+ self.reject = reject
44
+ self.didResolvePayment = false
45
+
39
46
  guard let paymentNetworks = paymentNetworks,
40
47
  PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) else {
41
- print("SumupReactNative: Can not make payment")
48
+ reject("PAYMENT_NOT_AVAILABLE", "Apple Pay is not available for the configured networks", nil)
42
49
  return
43
50
  }
44
-
45
- self.resolve = resolve
46
-
47
- if let controller = PKPaymentAuthorizationViewController(paymentRequest: request) {
48
- controller.delegate = self
49
51
 
50
- DispatchQueue.main.async {
51
- var rootViewController = UIApplication.shared.keyWindow?.rootViewController
52
- if let presentedViewController = rootViewController?.presentedViewController {
53
- rootViewController = presentedViewController
54
- }
55
-
56
- guard let rootViewController = rootViewController else {
57
- print("SumupReactNative: unable to find rootViewController")
58
- return
59
- }
52
+ guard let controller = PKPaymentAuthorizationViewController(paymentRequest: request) else {
53
+ reject("PRESENTATION_ERROR", "Unable to create Apple Pay authorization controller", nil)
54
+ return
55
+ }
56
+ controller.delegate = self
60
57
 
61
- rootViewController.present(controller, animated: true, completion: nil)
58
+ DispatchQueue.main.async {
59
+ guard let rootViewController = self.topViewController() else {
60
+ self.reject?("NO_ROOT_VIEW_CONTROLLER", "Unable to find active root view controller", nil)
61
+ return
62
62
  }
63
+
64
+ rootViewController.present(controller, animated: true, completion: nil)
63
65
  }
64
66
  }
65
67
 
@@ -72,15 +74,44 @@ class SumupReactNative: UIViewController {
72
74
  resolve(false)
73
75
  }
74
76
  }
77
+
78
+ private func parseSupportedNetworks(from method: NSDictionary) -> [PKPaymentNetwork]? {
79
+ guard let networks = method["supportedNetworks"] as? [String] else {
80
+ return nil
81
+ }
82
+ let parsedNetworks = networks.compactMap { PKPaymentNetwork(rawValue: $0) }
83
+ return parsedNetworks.isEmpty ? nil : parsedNetworks
84
+ }
85
+
86
+ private func topViewController() -> UIViewController? {
87
+ let foregroundScene = UIApplication.shared.connectedScenes
88
+ .compactMap { $0 as? UIWindowScene }
89
+ .first { $0.activationState == .foregroundActive }
90
+
91
+ let keyWindow = foregroundScene?.windows.first(where: { $0.isKeyWindow })
92
+ var root = keyWindow?.rootViewController
93
+
94
+ while let presented = root?.presentedViewController {
95
+ root = presented
96
+ }
97
+
98
+ return root
99
+ }
75
100
  }
76
101
 
77
102
  extension SumupReactNative: PKPaymentAuthorizationViewControllerDelegate {
78
103
  func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
79
104
  controller.dismiss(animated: true, completion: nil)
105
+ if !didResolvePayment {
106
+ reject?("PAYMENT_RESULT_CANCELED", "Payment has been canceled", nil)
107
+ }
108
+ resolve = nil
109
+ reject = nil
80
110
  }
81
111
 
82
112
  func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
83
113
 
114
+ didResolvePayment = true
84
115
  self.resolve?(payment.toDictionary())
85
116
  completion(.success)
86
117
  }
@@ -132,8 +163,15 @@ extension PKPaymentMethod {
132
163
  extension PKPaymentMethodType {
133
164
 
134
165
  func toString() -> String {
135
- let arr = ["unknown", "debit", "credit", "prepaid", "store", "eMoney"]
136
- return arr[Int(self.rawValue)]
166
+ let namesByRawValue: [Int: String] = [
167
+ 0: "unknown",
168
+ 1: "debit",
169
+ 2: "credit",
170
+ 3: "prepaid",
171
+ 4: "store",
172
+ 5: "eMoney",
173
+ ]
174
+ return namesByRawValue[Int(self.rawValue)] ?? "unknown"
137
175
  }
138
176
  }
139
177
 
@@ -153,12 +191,13 @@ extension PKPaymentPass {
153
191
  extension PKPaymentPassActivationState {
154
192
 
155
193
  func toString() -> String {
156
- let arr = ["PKPaymentPassActivationStateActivated",
157
- "PKPaymentPassActivationStateRequiresActivation",
158
- "PKPaymentPassActivationStateActivating",
159
- "PKPaymentPassActivationStateSuspended",
160
- "PKPaymentPassActivationStateDeactivated"]
161
-
162
- return arr[Int(self.rawValue)]
194
+ let namesByRawValue: [Int: String] = [
195
+ 0: "PKPaymentPassActivationStateActivated",
196
+ 1: "PKPaymentPassActivationStateRequiresActivation",
197
+ 2: "PKPaymentPassActivationStateActivating",
198
+ 3: "PKPaymentPassActivationStateSuspended",
199
+ 4: "PKPaymentPassActivationStateDeactivated",
200
+ ]
201
+ return namesByRawValue[Int(self.rawValue)] ?? "PKPaymentPassActivationStateActivated"
163
202
  }
164
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sumup/react-native-checkout",
3
- "version": "0.0.0-alpha.2",
3
+ "version": "0.0.0-alpha.3",
4
4
  "description": "Official SumUp React Native SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -63,7 +63,7 @@
63
63
  "@evilmartians/lefthook": "^1.2.2",
64
64
  "@react-native-community/eslint-config": "^3.0.2",
65
65
  "@react-native-community/netinfo": "^11.5.2",
66
- "@react-native/babel-preset": "^0.74.87",
66
+ "@react-native/babel-preset": "^0.74.89",
67
67
  "@testing-library/react-native": "^13.3.3",
68
68
  "@types/jest": "^29.5.1",
69
69
  "@types/react": "^18.2.6",
@@ -78,7 +78,7 @@
78
78
  "react": "18.2.0",
79
79
  "react-native": "0.74.5",
80
80
  "react-native-builder-bob": "^0.20.0",
81
- "react-native-localization": "^2.3.1",
81
+ "react-native-localization": "^2.3.2",
82
82
  "react-native-webview": "^13.16.0",
83
83
  "react-test-renderer": "^18.2.0",
84
84
  "typescript": "^5.9.3"
@@ -159,6 +159,6 @@
159
159
  "mobx-react-lite": "^4.1.1",
160
160
  "react-native-modal": "^13.0.1",
161
161
  "react-native-spacing-system": "^2.0.0-rc.0",
162
- "react-native-uuid": "^2.0.1"
162
+ "react-native-uuid": "^2.0.3"
163
163
  }
164
164
  }
@@ -13,8 +13,8 @@ Pod::Spec.new do |s|
13
13
  s.license = package["license"]
14
14
  s.authors = package["author"]
15
15
 
16
- s.platforms = { :ios => "11.0" }
17
- s.source = { :git => "https://github.com/sumup/sumup-react-native-checkout-sdk.git", :tag => package["version"] }
16
+ s.platforms = { :ios => "13.4" }
17
+ s.source = { :git => "https://github.com/sumup/sumup-react-native-checkout-sdk.git", :tag => "#{s.version}" }
18
18
 
19
19
  s.source_files = "ios/**/*.{h,m,mm,swift}"
20
20