@primer-io/react-native 2.2.0 → 2.4.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.
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/primerioreactnative/PrimerRN.kt +1 -20
- package/android/src/main/java/com/primerioreactnative/PrimerRNHeadlessUniversalCheckout.kt +6 -25
- package/android/src/main/java/com/primerioreactnative/PrimerRNHeadlessUniversalCheckoutListener.kt +5 -6
- package/android/src/main/java/com/primerioreactnative/datamodels/PrimerPaymentMethodDataRN.kt +1 -3
- package/ios/Headless Universal Checkout/RNTPrimerHeadlessUniversalCheckout.swift +20 -57
- package/ios/RNTPrimer.m +1 -1
- package/ios/RNTPrimer.swift +2 -9
- package/package.json +1 -1
- package/primer-io-react-native.podspec +1 -1
package/android/build.gradle
CHANGED
|
@@ -137,5 +137,5 @@ dependencies {
|
|
|
137
137
|
api 'com.facebook.react:react-native:+'
|
|
138
138
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
139
139
|
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3"
|
|
140
|
-
implementation 'io.primer:android:2.
|
|
140
|
+
implementation 'io.primer:android:2.4.0'
|
|
141
141
|
}
|
|
@@ -9,7 +9,6 @@ import com.primerioreactnative.utils.convertJsonToMap
|
|
|
9
9
|
import com.primerioreactnative.utils.errorTo
|
|
10
10
|
import io.primer.android.Primer
|
|
11
11
|
import io.primer.android.PrimerSessionIntent
|
|
12
|
-
import io.primer.android.data.configuration.models.PrimerPaymentMethodType
|
|
13
12
|
import io.primer.android.data.settings.PrimerSettings
|
|
14
13
|
import kotlinx.serialization.decodeFromString
|
|
15
14
|
import kotlinx.serialization.encodeToString
|
|
@@ -92,22 +91,12 @@ class PrimerRN(private val reactContext: ReactApplicationContext, private val js
|
|
|
92
91
|
promise.reject(exception.errorId, exception.description, e)
|
|
93
92
|
return
|
|
94
93
|
}
|
|
95
|
-
val paymentMethod: PrimerPaymentMethodType
|
|
96
|
-
try {
|
|
97
|
-
paymentMethod = getPrimerPaymentMethod(paymentMethodTypeStr)
|
|
98
|
-
} catch (e: Exception) {
|
|
99
|
-
val exception =
|
|
100
|
-
ErrorTypeRN.NativeBridgeFailed errorTo "Payment method type $paymentMethodTypeStr is not valid."
|
|
101
|
-
onError(exception)
|
|
102
|
-
promise.reject(exception.errorId, exception.description, e)
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
94
|
|
|
106
95
|
try {
|
|
107
96
|
Primer.instance.showPaymentMethod(
|
|
108
97
|
reactApplicationContext.applicationContext,
|
|
109
98
|
clientToken,
|
|
110
|
-
|
|
99
|
+
paymentMethodTypeStr,
|
|
111
100
|
intent
|
|
112
101
|
)
|
|
113
102
|
promise.resolve(null)
|
|
@@ -236,14 +225,6 @@ class PrimerRN(private val reactContext: ReactApplicationContext, private val js
|
|
|
236
225
|
private fun prepareData(data: JSONObject?): WritableMap {
|
|
237
226
|
return data?.let { convertJsonToMap(data) } ?: Arguments.createMap()
|
|
238
227
|
}
|
|
239
|
-
|
|
240
|
-
private fun getPrimerPaymentMethod(paymentMethodTypeStr: String): PrimerPaymentMethodType {
|
|
241
|
-
if (PrimerPaymentMethodType.PAYMENT_CARD.name == paymentMethodTypeStr) {
|
|
242
|
-
return PrimerPaymentMethodType.PAYMENT_CARD
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return PrimerPaymentMethodType.valueOf(paymentMethodTypeStr)
|
|
246
|
-
}
|
|
247
228
|
}
|
|
248
229
|
|
|
249
230
|
internal object Keys {
|
|
@@ -15,8 +15,6 @@ import com.primerioreactnative.utils.errorTo
|
|
|
15
15
|
import io.primer.android.ExperimentalPrimerApi
|
|
16
16
|
import io.primer.android.components.PrimerHeadlessUniversalCheckout
|
|
17
17
|
import io.primer.android.components.ui.assets.ImageType
|
|
18
|
-
import io.primer.android.data.configuration.models.PaymentMethodType
|
|
19
|
-
import io.primer.android.data.configuration.models.PrimerPaymentMethodType
|
|
20
18
|
import kotlinx.serialization.decodeFromString
|
|
21
19
|
import kotlinx.serialization.encodeToString
|
|
22
20
|
import kotlinx.serialization.json.Json
|
|
@@ -72,19 +70,11 @@ class PrimerRNHeadlessUniversalCheckout(
|
|
|
72
70
|
|
|
73
71
|
@ReactMethod
|
|
74
72
|
fun showPaymentMethod(paymentMethodTypeStr: String, promise: Promise) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
promise.reject(exception.errorId, exception.description)
|
|
81
|
-
} else {
|
|
82
|
-
PrimerHeadlessUniversalCheckout.current.showPaymentMethod(
|
|
83
|
-
reactContext,
|
|
84
|
-
primerPaymentMethodType
|
|
85
|
-
)
|
|
86
|
-
promise.resolve(null)
|
|
87
|
-
}
|
|
73
|
+
PrimerHeadlessUniversalCheckout.current.showPaymentMethod(
|
|
74
|
+
reactContext,
|
|
75
|
+
paymentMethodTypeStr
|
|
76
|
+
)
|
|
77
|
+
promise.resolve(null)
|
|
88
78
|
}
|
|
89
79
|
|
|
90
80
|
@ReactMethod
|
|
@@ -101,17 +91,8 @@ class PrimerRNHeadlessUniversalCheckout(
|
|
|
101
91
|
successCallback: Callback
|
|
102
92
|
) {
|
|
103
93
|
|
|
104
|
-
val primerPaymentMethodType = PrimerPaymentMethodType.safeValueOf(paymentMethodType)
|
|
105
94
|
val type = ImageType.values().find { it.name.equals(assetType, ignoreCase = true) }
|
|
106
95
|
when {
|
|
107
|
-
primerPaymentMethodType == PaymentMethodType.UNKNOWN -> {
|
|
108
|
-
errorCallback.invoke(
|
|
109
|
-
json.encodeToString(
|
|
110
|
-
ErrorTypeRN.InvalidPaymentMethodType errorTo
|
|
111
|
-
"Asset for $paymentMethodType does not exist, make sure you don't have any typos."
|
|
112
|
-
)
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
96
|
type == null -> {
|
|
116
97
|
errorCallback.invoke(
|
|
117
98
|
json.encodeToString(
|
|
@@ -121,7 +102,7 @@ class PrimerRNHeadlessUniversalCheckout(
|
|
|
121
102
|
)
|
|
122
103
|
}
|
|
123
104
|
else -> {
|
|
124
|
-
PrimerHeadlessUniversalCheckout.getAsset(
|
|
105
|
+
PrimerHeadlessUniversalCheckout.getAsset(paymentMethodType, type)?.let { resourceId ->
|
|
125
106
|
val file = getFile(reactContext, paymentMethodType)
|
|
126
107
|
AssetsManager.saveBitmapToFile(
|
|
127
108
|
file,
|
package/android/src/main/java/com/primerioreactnative/PrimerRNHeadlessUniversalCheckoutListener.kt
CHANGED
|
@@ -15,7 +15,6 @@ import io.primer.android.completion.PrimerPaymentCreationDecisionHandler
|
|
|
15
15
|
import io.primer.android.completion.PrimerResumeDecisionHandler
|
|
16
16
|
import io.primer.android.components.PrimerHeadlessUniversalCheckoutListener
|
|
17
17
|
import io.primer.android.components.domain.core.models.PrimerHeadlessUniversalCheckoutPaymentMethod
|
|
18
|
-
import io.primer.android.data.configuration.models.PrimerPaymentMethodType
|
|
19
18
|
import io.primer.android.domain.PrimerCheckoutData
|
|
20
19
|
import io.primer.android.domain.action.models.PrimerClientSession
|
|
21
20
|
import io.primer.android.domain.error.models.PrimerError
|
|
@@ -47,29 +46,29 @@ class PrimerRNHeadlessUniversalCheckoutListener : PrimerHeadlessUniversalCheckou
|
|
|
47
46
|
sendEvent?.invoke(
|
|
48
47
|
PrimerHeadlessUniversalCheckoutEvent.ON_HUC_AVAILABLE_PAYMENT_METHODS_LOADED.eventName,
|
|
49
48
|
JSONObject().apply {
|
|
50
|
-
put("paymentMethodTypes", JSONArray(paymentMethods.map { it.paymentMethodType
|
|
49
|
+
put("paymentMethodTypes", JSONArray(paymentMethods.map { it.paymentMethodType }))
|
|
51
50
|
}
|
|
52
51
|
)
|
|
53
52
|
successCallback?.invoke(
|
|
54
|
-
Arguments.fromList(paymentMethods.map { it.paymentMethodType
|
|
53
|
+
Arguments.fromList(paymentMethods.map { it.paymentMethodType })
|
|
55
54
|
)
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
override fun onPreparationStarted(paymentMethodType:
|
|
57
|
+
override fun onPreparationStarted(paymentMethodType: String) {
|
|
59
58
|
sendEvent?.invoke(
|
|
60
59
|
PrimerHeadlessUniversalCheckoutEvent.ON_HUC_PREPARE_START.eventName,
|
|
61
60
|
JSONObject(Json.encodeToString(PrimerPaymentMethodDataRN(paymentMethodType)))
|
|
62
61
|
)
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
override fun onPaymentMethodShowed(paymentMethodType:
|
|
64
|
+
override fun onPaymentMethodShowed(paymentMethodType: String) {
|
|
66
65
|
sendEvent?.invoke(
|
|
67
66
|
PrimerHeadlessUniversalCheckoutEvent.ON_HUC_PAYMENT_METHOD_SHOW.eventName,
|
|
68
67
|
JSONObject(Json.encodeToString(PrimerPaymentMethodDataRN(paymentMethodType)))
|
|
69
68
|
)
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
override fun onTokenizationStarted(paymentMethodType:
|
|
71
|
+
override fun onTokenizationStarted(paymentMethodType: String) {
|
|
73
72
|
sendEvent?.invoke(
|
|
74
73
|
PrimerHeadlessUniversalCheckoutEvent.ON_HUC_TOKENIZE_START.eventName,
|
|
75
74
|
JSONObject(Json.encodeToString(PrimerPaymentMethodDataRN(paymentMethodType)))
|
package/android/src/main/java/com/primerioreactnative/datamodels/PrimerPaymentMethodDataRN.kt
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
package com.primerioreactnative.datamodels
|
|
2
2
|
|
|
3
|
-
import io.primer.android.data.configuration.models.PrimerPaymentMethodType
|
|
4
|
-
import io.primer.android.domain.tokenization.models.PrimerPaymentMethodData
|
|
5
3
|
import kotlinx.serialization.Serializable
|
|
6
4
|
|
|
7
5
|
@Serializable
|
|
8
|
-
data class PrimerPaymentMethodDataRN(val paymentMethodType:
|
|
6
|
+
data class PrimerPaymentMethodDataRN(val paymentMethodType: String)
|
|
@@ -95,7 +95,7 @@ class RNTPrimerHeadlessUniversalCheckout: RCTEventEmitter {
|
|
|
95
95
|
if let err = err {
|
|
96
96
|
errorCallback([err.rnError])
|
|
97
97
|
} else if let paymentMethodTypes = paymentMethodTypes {
|
|
98
|
-
successCallback([paymentMethodTypes
|
|
98
|
+
successCallback([paymentMethodTypes])
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -106,17 +106,13 @@ class RNTPrimerHeadlessUniversalCheckout: RCTEventEmitter {
|
|
|
106
106
|
errorCallback: @escaping RCTResponseSenderBlock,
|
|
107
107
|
successCallback: @escaping RCTResponseSenderBlock)
|
|
108
108
|
{
|
|
109
|
+
guard let unwrappedAssetType = PrimerAsset.ImageType(rawValue: assetTypeStr), let image = PrimerHeadlessUniversalCheckout.getAsset(for: paymentMethodTypeStr, assetType: unwrappedAssetType) else {
|
|
110
|
+
let err = NativeError(errorId: "missing-asset", errorDescription: "Failed to find \(assetTypeStr) for \(paymentMethodTypeStr)", recoverySuggestion: nil)
|
|
111
|
+
errorCallback([err.rnError])
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
109
115
|
do {
|
|
110
|
-
try validate(assetStr: paymentMethodTypeStr, assetTypeStr: assetTypeStr)
|
|
111
|
-
let paymentMethodType = PrimerPaymentMethodType(rawValue: paymentMethodTypeStr)
|
|
112
|
-
|
|
113
|
-
guard let image = PrimerHeadlessUniversalCheckout.getAsset(for: paymentMethodType, assetType: PrimerAsset.ImageType(rawValue: assetTypeStr)!) else {
|
|
114
|
-
let err = NativeError(errorId: "missing-asset", errorDescription: "Failed to find \(assetTypeStr) for \(paymentMethodTypeStr)", recoverySuggestion: nil)
|
|
115
|
-
errorCallback([err.rnError])
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
116
|
let imageURL = try self.tempStoreImage(image: image, name: paymentMethodTypeStr)
|
|
121
117
|
successCallback([imageURL.absoluteString])
|
|
122
118
|
} catch {
|
|
@@ -130,21 +126,19 @@ class RNTPrimerHeadlessUniversalCheckout: RCTEventEmitter {
|
|
|
130
126
|
errorCallback: @escaping RCTResponseSenderBlock,
|
|
131
127
|
successCallback: @escaping RCTResponseSenderBlock)
|
|
132
128
|
{
|
|
129
|
+
guard let cardNetwork = CardNetwork(rawValue: cardNetworkStr) else {
|
|
130
|
+
let err = NativeError(errorId: "invalid-card-network", errorDescription: "Card network for \(cardNetworkStr) does not exist, make sure you don't have any typos.", recoverySuggestion: nil)
|
|
131
|
+
errorCallback([err.rnError])
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
guard let unwrappedAssetType = PrimerAsset.ImageType(rawValue: assetTypeStr), let image = PrimerHeadlessUniversalCheckout.getAsset(for: cardNetwork, assetType: unwrappedAssetType) else {
|
|
136
|
+
let err = NativeError(errorId: "missing-asset", errorDescription: "Failed to find \(assetTypeStr) for \(cardNetworkStr)", recoverySuggestion: nil)
|
|
137
|
+
errorCallback([err.rnError])
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
133
141
|
do {
|
|
134
|
-
try validate(assetStr: cardNetworkStr, assetTypeStr: assetTypeStr)
|
|
135
|
-
guard let cardNetwork = CardNetwork(rawValue: cardNetworkStr) else {
|
|
136
|
-
let err = NativeError(errorId: "invalid-card-network", errorDescription: "Card network for \(cardNetworkStr) does not exist, make sure you don't have any typos.", recoverySuggestion: nil)
|
|
137
|
-
errorCallback([err.rnError])
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
guard let image = PrimerHeadlessUniversalCheckout.getAsset(for: cardNetwork, assetType: PrimerAsset.ImageType(rawValue: assetTypeStr)!) else {
|
|
142
|
-
let err = NativeError(errorId: "missing-asset", errorDescription: "Failed to find \(assetTypeStr) for \(cardNetworkStr)", recoverySuggestion: nil)
|
|
143
|
-
errorCallback([err.rnError])
|
|
144
|
-
return
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
142
|
let imageURL = try self.tempStoreImage(image: image, name: cardNetworkStr)
|
|
149
143
|
successCallback([imageURL.absoluteString])
|
|
150
144
|
} catch {
|
|
@@ -157,8 +151,7 @@ class RNTPrimerHeadlessUniversalCheckout: RCTEventEmitter {
|
|
|
157
151
|
resolver: RCTPromiseResolveBlock,
|
|
158
152
|
rejecter: RCTPromiseRejectBlock)
|
|
159
153
|
{
|
|
160
|
-
|
|
161
|
-
PrimerHeadlessUniversalCheckout.current.showPaymentMethod(paymentMethodType)
|
|
154
|
+
PrimerHeadlessUniversalCheckout.current.showPaymentMethod(paymentMethodTypeStr)
|
|
162
155
|
resolver(nil)
|
|
163
156
|
}
|
|
164
157
|
|
|
@@ -169,36 +162,6 @@ class RNTPrimerHeadlessUniversalCheckout: RCTEventEmitter {
|
|
|
169
162
|
|
|
170
163
|
// MARK: - HELPERS
|
|
171
164
|
|
|
172
|
-
private func validate(assetStr: String, assetTypeStr: String) throws {
|
|
173
|
-
var errors: [NativeError] = []
|
|
174
|
-
|
|
175
|
-
if PrimerPaymentMethodType(rawValue: assetStr) != .other(rawValue: assetStr) {
|
|
176
|
-
// ...
|
|
177
|
-
} else if CardNetwork(rawValue: assetStr) != nil {
|
|
178
|
-
// ...
|
|
179
|
-
} else {
|
|
180
|
-
let err = NativeError(errorId: "invalid-payment-method-type", errorDescription: "Asset for \(assetStr) does not exist, make sure you don't have any typos.", recoverySuggestion: nil)
|
|
181
|
-
errors.append(err)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if PrimerAsset.ImageType(rawValue: assetTypeStr) == nil {
|
|
186
|
-
let err = NativeError(errorId: "mismatch", errorDescription: "You have provided assetType=\(assetTypeStr), which is not valid", recoverySuggestion: "Use one of the following values: \(PrimerAsset.ImageType.allCases.compactMap({ $0.rawValue }))")
|
|
187
|
-
errors.append(err)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if errors.isEmpty {
|
|
191
|
-
return
|
|
192
|
-
} else if errors.count == 1 {
|
|
193
|
-
throw errors.first!
|
|
194
|
-
} else {
|
|
195
|
-
let errorDescription: String = errors.compactMap({ $0.errorDescription }).joined(separator: "/n")
|
|
196
|
-
let recoverySuggestion = errors.compactMap({ $0.recoverySuggestion }).joined(separator: "/n")
|
|
197
|
-
let err = NativeError(errorId: "underlying-errors", errorDescription: errorDescription, recoverySuggestion: recoverySuggestion)
|
|
198
|
-
throw err
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
165
|
private func tempStoreImage(image: UIImage, name: String) throws -> URL {
|
|
203
166
|
guard let imageURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("\(name).png") else {
|
|
204
167
|
let err = NativeError(errorId: "error", errorDescription: "Failed to create URL for asset", recoverySuggestion: nil)
|
package/ios/RNTPrimer.m
CHANGED
|
@@ -18,7 +18,7 @@ RCT_EXTERN_METHOD(showUniversalCheckoutWithClientToken:(NSString *)clientToken r
|
|
|
18
18
|
|
|
19
19
|
RCT_EXTERN_METHOD(showVaultManagerWithClientToken: (NSString *)clientToken resolver:(RCTPromiseResolveBlock)resolver rejecter:(RCTPromiseRejectBlock)rejecter)
|
|
20
20
|
|
|
21
|
-
RCT_EXTERN_METHOD(showPaymentMethod:(NSString *)
|
|
21
|
+
RCT_EXTERN_METHOD(showPaymentMethod:(NSString *)paymentMethodTypeStr intent:(NSString *)intentStr clientToken:(NSString *)clientToken resolver:(RCTPromiseResolveBlock)resolver rejecter:(RCTPromiseRejectBlock)rejecter)
|
|
22
22
|
|
|
23
23
|
RCT_EXTERN_METHOD(dismiss)
|
|
24
24
|
|
package/ios/RNTPrimer.swift
CHANGED
|
@@ -119,22 +119,15 @@ class RNTPrimer: RCTEventEmitter {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
@objc
|
|
122
|
-
public func showPaymentMethod(_
|
|
122
|
+
public func showPaymentMethod(_ paymentMethodTypeStr: String, intent: String, clientToken: String, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
|
|
123
123
|
DispatchQueue.main.async {
|
|
124
124
|
do {
|
|
125
|
-
let paymentMethodType = PrimerPaymentMethodType(rawValue: paymentMethodStr)
|
|
126
|
-
|
|
127
|
-
guard paymentMethodType != PrimerPaymentMethodType.other(rawValue: paymentMethodStr) else {
|
|
128
|
-
let err = NSError(domain: "native-bridge", code: 0, userInfo: [NSLocalizedDescriptionKey: "Payment method type \(paymentMethodStr) is not valid."])
|
|
129
|
-
throw err
|
|
130
|
-
}
|
|
131
|
-
|
|
132
125
|
guard let primerIntent = PrimerSessionIntent(rawValue: intent) else {
|
|
133
126
|
let err = NSError(domain: "native-bridge", code: 0, userInfo: [NSLocalizedDescriptionKey: "Intent \(intent) is not valid."])
|
|
134
127
|
throw err
|
|
135
128
|
}
|
|
136
129
|
|
|
137
|
-
PrimerSDK.Primer.shared.showPaymentMethod(
|
|
130
|
+
PrimerSDK.Primer.shared.showPaymentMethod(paymentMethodTypeStr, withIntent: primerIntent, andClientToken: clientToken) { err in
|
|
138
131
|
DispatchQueue.main.async {
|
|
139
132
|
if let err = err {
|
|
140
133
|
rejecter(err.rnError["errorId"]!, err.rnError["description"], err)
|
package/package.json
CHANGED