@stripe/stripe-react-native 0.55.1 → 0.57.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/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +4 -3
- package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +7 -6
- package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +11 -11
- package/android/src/main/java/com/reactnativestripesdk/{CollectBankAccountLauncherFragment.kt → CollectBankAccountLauncherManager.kt} +21 -44
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +17 -24
- package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +8 -0
- package/android/src/main/java/com/reactnativestripesdk/{FinancialConnectionsSheetFragment.kt → FinancialConnectionsSheetManager.kt} +30 -77
- package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +107 -0
- package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherManager.kt +37 -0
- package/android/src/main/java/com/reactnativestripesdk/{PaymentLauncherFragment.kt → PaymentLauncherManager.kt} +39 -77
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +8 -20
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +366 -483
- package/android/src/main/java/com/reactnativestripesdk/{PaymentSheetFragment.kt → PaymentSheetManager.kt} +79 -88
- package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +3 -2
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +213 -210
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherManager.kt +78 -0
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +48 -35
- package/android/src/main/java/com/reactnativestripesdk/customersheet/{CustomerSheetFragment.kt → CustomerSheetManager.kt} +127 -104
- package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +35 -0
- package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +47 -12
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +87 -142
- package/android/src/main/java/com/reactnativestripesdk/utils/StripeUIManager.kt +62 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerDelegate.java +12 -0
- package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java +4 -0
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +8 -64
- package/ios/AddressSheet/AddressSheetView.swift +1 -1
- package/ios/ApplePayButtonManager.m +1 -1
- package/ios/ApplePayButtonView.swift +2 -2
- package/ios/FinancialConnections.swift +2 -2
- package/ios/Mappers.swift +2 -4
- package/ios/NewArch/ApplePayButtonComponentView.mm +1 -1
- package/ios/OldArch/StripeSdkEventEmitterCompat.h +2 -0
- package/ios/OldArch/StripeSdkEventEmitterCompat.m +12 -0
- package/ios/PaymentMethodFactory.swift +0 -17
- package/ios/PushProvisioning/AddToWalletButtonView.swift +1 -1
- package/ios/StripeSdk.mm +14 -0
- package/ios/StripeSdkEmitter.swift +2 -0
- package/ios/StripeSdkImpl+CustomerSheet.swift +71 -20
- package/ios/StripeSdkImpl+PaymentSheet.swift +29 -13
- package/ios/StripeSdkImpl.swift +9 -7
- package/lib/commonjs/components/AddToWalletButton.js +1 -1
- package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
- package/lib/commonjs/components/AddressSheet.js +1 -1
- package/lib/commonjs/components/AddressSheet.js.map +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
- package/lib/commonjs/components/CardField.js +1 -1
- package/lib/commonjs/components/CardField.js.map +1 -1
- package/lib/commonjs/components/CardForm.js +1 -1
- package/lib/commonjs/components/CardForm.js.map +1 -1
- package/lib/commonjs/components/CustomerSheet.js +1 -1
- package/lib/commonjs/components/CustomerSheet.js.map +1 -1
- package/lib/commonjs/components/PlatformPayButton.js +1 -1
- package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
- package/lib/commonjs/components/StripeContainer.js +1 -1
- package/lib/commonjs/components/StripeContainer.js.map +1 -1
- package/lib/commonjs/events.js.map +1 -1
- package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
- package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -1
- package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/types/PaymentIntent.js.map +1 -1
- package/lib/commonjs/types/PaymentSheet.js.map +1 -1
- package/lib/module/components/AddToWalletButton.js +1 -1
- package/lib/module/components/AddToWalletButton.js.map +1 -1
- package/lib/module/components/AddressSheet.js +1 -1
- package/lib/module/components/AddressSheet.js.map +1 -1
- package/lib/module/components/AuBECSDebitForm.js +1 -1
- package/lib/module/components/AuBECSDebitForm.js.map +1 -1
- package/lib/module/components/CardField.js +1 -1
- package/lib/module/components/CardField.js.map +1 -1
- package/lib/module/components/CardForm.js +1 -1
- package/lib/module/components/CardForm.js.map +1 -1
- package/lib/module/components/CustomerSheet.js +1 -1
- package/lib/module/components/CustomerSheet.js.map +1 -1
- package/lib/module/components/PlatformPayButton.js +1 -1
- package/lib/module/components/PlatformPayButton.js.map +1 -1
- package/lib/module/components/StripeContainer.js +1 -1
- package/lib/module/components/StripeContainer.js.map +1 -1
- package/lib/module/events.js.map +1 -1
- package/lib/module/specs/NativeApplePayButton.js +1 -1
- package/lib/module/specs/NativeApplePayButton.js.map +1 -1
- package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/module/types/EmbeddedPaymentElement.js +1 -1
- package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/module/types/PaymentIntent.js.map +1 -1
- package/lib/module/types/PaymentSheet.js.map +1 -1
- package/lib/typescript/src/components/CustomerSheet.d.ts +1 -1
- package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -1
- package/lib/typescript/src/events.d.ts +2 -0
- package/lib/typescript/src/events.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeApplePayButton.d.ts +1 -1
- package/lib/typescript/src/specs/NativeApplePayButton.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +3 -1
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
- package/lib/typescript/src/types/ConfirmationToken.d.ts +0 -3
- package/lib/typescript/src/types/ConfirmationToken.d.ts.map +1 -1
- package/lib/typescript/src/types/CustomerSheet.d.ts +70 -12
- package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -1
- package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts +2 -4
- package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentIntent.d.ts +1 -9
- package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentMethod.d.ts +2 -8
- package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentSheet.d.ts +1 -6
- package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/CustomerSheet.tsx +65 -9
- package/src/components/PlatformPayButton.tsx +1 -1
- package/src/events.ts +2 -0
- package/src/specs/NativeApplePayButton.ts +1 -1
- package/src/specs/NativeStripeSdkModule.ts +7 -0
- package/src/types/ConfirmationToken.ts +0 -3
- package/src/types/CustomerSheet.ts +80 -12
- package/src/types/EmbeddedPaymentElement.tsx +2 -4
- package/src/types/PaymentIntent.ts +0 -10
- package/src/types/PaymentMethod.ts +0 -9
- package/src/types/PaymentSheet.ts +1 -6
- package/stripe-react-native.podspec +1 -1
- package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +0 -146
- package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +0 -68
- package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +0 -102
- package/android/src/main/java/com/reactnativestripesdk/utils/StripeFragment.kt +0 -52
|
@@ -28,16 +28,20 @@ import com.reactnativestripesdk.utils.KeepJsAwakeTask
|
|
|
28
28
|
import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
|
|
29
29
|
import com.reactnativestripesdk.utils.PaymentSheetErrorType
|
|
30
30
|
import com.reactnativestripesdk.utils.PaymentSheetException
|
|
31
|
-
import com.reactnativestripesdk.utils.
|
|
31
|
+
import com.reactnativestripesdk.utils.StripeUIManager
|
|
32
32
|
import com.reactnativestripesdk.utils.createError
|
|
33
33
|
import com.reactnativestripesdk.utils.createResult
|
|
34
|
+
import com.reactnativestripesdk.utils.forEachKey
|
|
35
|
+
import com.reactnativestripesdk.utils.getBooleanOr
|
|
36
|
+
import com.reactnativestripesdk.utils.getIntOr
|
|
37
|
+
import com.reactnativestripesdk.utils.isEmpty
|
|
34
38
|
import com.reactnativestripesdk.utils.mapFromConfirmationToken
|
|
35
39
|
import com.reactnativestripesdk.utils.mapFromCustomPaymentMethod
|
|
36
40
|
import com.reactnativestripesdk.utils.mapFromPaymentMethod
|
|
37
41
|
import com.reactnativestripesdk.utils.mapToPreferredNetworks
|
|
38
42
|
import com.reactnativestripesdk.utils.parseCustomPaymentMethods
|
|
39
|
-
import com.reactnativestripesdk.utils.removeFragment
|
|
40
43
|
import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
|
|
44
|
+
import com.stripe.android.core.reactnative.ReactNativeSdkInternal
|
|
41
45
|
import com.stripe.android.model.PaymentMethod
|
|
42
46
|
import com.stripe.android.paymentelement.ConfirmCustomPaymentMethodCallback
|
|
43
47
|
import com.stripe.android.paymentelement.CreateIntentWithConfirmationTokenCallback
|
|
@@ -47,7 +51,6 @@ import com.stripe.android.paymentelement.ExperimentalCustomPaymentMethodsApi
|
|
|
47
51
|
import com.stripe.android.paymentelement.PaymentMethodOptionsSetupFutureUsagePreview
|
|
48
52
|
import com.stripe.android.paymentsheet.CreateIntentCallback
|
|
49
53
|
import com.stripe.android.paymentsheet.CreateIntentResult
|
|
50
|
-
import com.stripe.android.paymentsheet.ExperimentalCustomerSessionApi
|
|
51
54
|
import com.stripe.android.paymentsheet.PaymentOptionResultCallback
|
|
52
55
|
import com.stripe.android.paymentsheet.PaymentSheet
|
|
53
56
|
import com.stripe.android.paymentsheet.PaymentSheetResult
|
|
@@ -60,12 +63,17 @@ import kotlinx.coroutines.launch
|
|
|
60
63
|
import java.io.ByteArrayOutputStream
|
|
61
64
|
import kotlin.Exception
|
|
62
65
|
|
|
63
|
-
@OptIn(
|
|
64
|
-
class
|
|
65
|
-
|
|
66
|
+
@OptIn(
|
|
67
|
+
ReactNativeSdkInternal::class,
|
|
68
|
+
ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class,
|
|
69
|
+
ExperimentalCustomPaymentMethodsApi::class,
|
|
70
|
+
)
|
|
71
|
+
class PaymentSheetManager(
|
|
72
|
+
context: ReactApplicationContext,
|
|
73
|
+
private val arguments: ReadableMap,
|
|
74
|
+
private val initPromise: Promise,
|
|
75
|
+
) : StripeUIManager(context),
|
|
66
76
|
ConfirmCustomPaymentMethodCallback {
|
|
67
|
-
private lateinit var context: ReactApplicationContext
|
|
68
|
-
private lateinit var initPromise: Promise
|
|
69
77
|
private var paymentSheet: PaymentSheet? = null
|
|
70
78
|
private var flowController: PaymentSheet.FlowController? = null
|
|
71
79
|
private var paymentIntentClientSecret: String? = null
|
|
@@ -73,7 +81,6 @@ class PaymentSheetFragment :
|
|
|
73
81
|
private var intentConfiguration: PaymentSheet.IntentConfiguration? = null
|
|
74
82
|
private lateinit var paymentSheetConfiguration: PaymentSheet.Configuration
|
|
75
83
|
private var confirmPromise: Promise? = null
|
|
76
|
-
private var presentPromise: Promise? = null
|
|
77
84
|
private var paymentSheetTimedOut = false
|
|
78
85
|
internal var paymentSheetIntentCreationCallback = CompletableDeferred<ReadableMap>()
|
|
79
86
|
internal var paymentSheetConfirmationTokenCreationCallback = CompletableDeferred<ReadableMap>()
|
|
@@ -81,39 +88,40 @@ class PaymentSheetFragment :
|
|
|
81
88
|
|
|
82
89
|
@SuppressLint("RestrictedApi")
|
|
83
90
|
@OptIn(ExperimentalCustomPaymentMethodsApi::class)
|
|
84
|
-
override fun
|
|
85
|
-
val
|
|
91
|
+
override fun onCreate() {
|
|
92
|
+
val activity = getCurrentActivityOrResolveWithError(initPromise) ?: return
|
|
93
|
+
val merchantDisplayName = arguments.getString("merchantDisplayName").orEmpty()
|
|
86
94
|
if (merchantDisplayName.isEmpty()) {
|
|
87
95
|
initPromise.resolve(
|
|
88
96
|
createError(ErrorType.Failed.toString(), "merchantDisplayName cannot be empty or null."),
|
|
89
97
|
)
|
|
90
98
|
return
|
|
91
99
|
}
|
|
92
|
-
val primaryButtonLabel = arguments
|
|
93
|
-
val googlePayConfig = buildGooglePayConfig(arguments
|
|
94
|
-
val linkConfig = buildLinkConfig(arguments
|
|
95
|
-
val allowsDelayedPaymentMethods = arguments
|
|
96
|
-
val
|
|
97
|
-
val billingConfigParams = arguments
|
|
98
|
-
val paymentMethodOrder = arguments
|
|
100
|
+
val primaryButtonLabel = arguments.getString("primaryButtonLabel")
|
|
101
|
+
val googlePayConfig = buildGooglePayConfig(arguments.getMap("googlePay"))
|
|
102
|
+
val linkConfig = buildLinkConfig(arguments.getMap("link"))
|
|
103
|
+
val allowsDelayedPaymentMethods = arguments.getBooleanOr("allowsDelayedPaymentMethods", false)
|
|
104
|
+
val billingDetailsMap = arguments.getMap("defaultBillingDetails")
|
|
105
|
+
val billingConfigParams = arguments.getMap("billingDetailsCollectionConfiguration")
|
|
106
|
+
val paymentMethodOrder = arguments.getStringArrayList("paymentMethodOrder")
|
|
99
107
|
val allowsRemovalOfLastSavedPaymentMethod =
|
|
100
|
-
arguments
|
|
101
|
-
paymentIntentClientSecret = arguments
|
|
102
|
-
setupIntentClientSecret = arguments
|
|
108
|
+
arguments.getBooleanOr("allowsRemovalOfLastSavedPaymentMethod", true)
|
|
109
|
+
paymentIntentClientSecret = arguments.getString("paymentIntentClientSecret").orEmpty()
|
|
110
|
+
setupIntentClientSecret = arguments.getString("setupIntentClientSecret").orEmpty()
|
|
103
111
|
intentConfiguration =
|
|
104
112
|
try {
|
|
105
|
-
buildIntentConfiguration(arguments
|
|
113
|
+
buildIntentConfiguration(arguments.getMap("intentConfiguration"))
|
|
106
114
|
} catch (error: PaymentSheetException) {
|
|
107
115
|
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
|
|
108
116
|
return
|
|
109
117
|
}
|
|
110
118
|
|
|
111
119
|
// Determine which callback type to use based on what's provided
|
|
112
|
-
val
|
|
113
|
-
val useConfirmationTokenCallback =
|
|
120
|
+
val intentConfigMap = arguments.getMap("intentConfiguration")
|
|
121
|
+
val useConfirmationTokenCallback = intentConfigMap?.hasKey("confirmationTokenConfirmHandler") == true
|
|
114
122
|
val appearance =
|
|
115
123
|
try {
|
|
116
|
-
buildPaymentSheetAppearance(arguments
|
|
124
|
+
buildPaymentSheetAppearance(arguments.getMap("appearance"), context)
|
|
117
125
|
} catch (error: PaymentSheetAppearanceException) {
|
|
118
126
|
initPromise.resolve(createError(ErrorType.Failed.toString(), error))
|
|
119
127
|
return
|
|
@@ -128,7 +136,7 @@ class PaymentSheetFragment :
|
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
val shippingDetails =
|
|
131
|
-
arguments
|
|
139
|
+
arguments.getMap("defaultShippingDetails")?.let {
|
|
132
140
|
AddressSheetView.buildAddressDetails(it)
|
|
133
141
|
}
|
|
134
142
|
|
|
@@ -184,9 +192,6 @@ class PaymentSheetFragment :
|
|
|
184
192
|
|
|
185
193
|
is PaymentSheetResult.Completed -> {
|
|
186
194
|
resolvePaymentResult(WritableNativeMap())
|
|
187
|
-
// Remove the fragment now, we can be sure it won't be needed again if an intent is
|
|
188
|
-
// successful
|
|
189
|
-
removeFragment(context)
|
|
190
195
|
paymentSheet = null
|
|
191
196
|
flowController = null
|
|
192
197
|
}
|
|
@@ -254,33 +259,33 @@ class PaymentSheetFragment :
|
|
|
254
259
|
email = mapToCollectionMode(billingConfigParams?.getString("email")),
|
|
255
260
|
address = mapToAddressCollectionMode(billingConfigParams?.getString("address")),
|
|
256
261
|
attachDefaultsToPaymentMethod =
|
|
257
|
-
billingConfigParams?.
|
|
262
|
+
billingConfigParams?.getBooleanOr("attachDefaultsToPaymentMethod", false) ?: false,
|
|
258
263
|
)
|
|
259
264
|
|
|
260
265
|
var defaultBillingDetails: PaymentSheet.BillingDetails? = null
|
|
261
|
-
if (
|
|
262
|
-
val
|
|
266
|
+
if (billingDetailsMap != null) {
|
|
267
|
+
val addressMap = billingDetailsMap.getMap("address")
|
|
263
268
|
val address =
|
|
264
269
|
PaymentSheet.Address(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
270
|
+
addressMap?.getString("city"),
|
|
271
|
+
addressMap?.getString("country"),
|
|
272
|
+
addressMap?.getString("line1"),
|
|
273
|
+
addressMap?.getString("line2"),
|
|
274
|
+
addressMap?.getString("postalCode"),
|
|
275
|
+
addressMap?.getString("state"),
|
|
271
276
|
)
|
|
272
277
|
defaultBillingDetails =
|
|
273
278
|
PaymentSheet.BillingDetails(
|
|
274
279
|
address,
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
280
|
+
billingDetailsMap.getString("email"),
|
|
281
|
+
billingDetailsMap.getString("name"),
|
|
282
|
+
billingDetailsMap.getString("phone"),
|
|
278
283
|
)
|
|
279
284
|
}
|
|
280
285
|
val configurationBuilder =
|
|
281
286
|
PaymentSheet.Configuration
|
|
282
287
|
.Builder(merchantDisplayName)
|
|
283
|
-
.allowsDelayedPaymentMethods(allowsDelayedPaymentMethods
|
|
288
|
+
.allowsDelayedPaymentMethods(allowsDelayedPaymentMethods)
|
|
284
289
|
.defaultBillingDetails(defaultBillingDetails)
|
|
285
290
|
.customer(customerConfiguration)
|
|
286
291
|
.googlePay(googlePayConfig)
|
|
@@ -289,21 +294,21 @@ class PaymentSheetFragment :
|
|
|
289
294
|
.link(linkConfig)
|
|
290
295
|
.billingDetailsCollectionConfiguration(billingDetailsConfig)
|
|
291
296
|
.preferredNetworks(
|
|
292
|
-
mapToPreferredNetworks(arguments
|
|
297
|
+
mapToPreferredNetworks(arguments.getIntegerArrayList("preferredNetworks")),
|
|
293
298
|
).allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod)
|
|
294
299
|
.cardBrandAcceptance(mapToCardBrandAcceptance(arguments))
|
|
295
|
-
.customPaymentMethods(parseCustomPaymentMethods(arguments))
|
|
300
|
+
.customPaymentMethods(parseCustomPaymentMethods(arguments.getMap("customPaymentMethodConfiguration")))
|
|
296
301
|
|
|
297
302
|
primaryButtonLabel?.let { configurationBuilder.primaryButtonLabel(it) }
|
|
298
303
|
paymentMethodOrder?.let { configurationBuilder.paymentMethodOrder(it) }
|
|
299
304
|
|
|
300
305
|
configurationBuilder.paymentMethodLayout(
|
|
301
|
-
mapToPaymentMethodLayout(arguments
|
|
306
|
+
mapToPaymentMethodLayout(arguments.getString("paymentMethodLayout")),
|
|
302
307
|
)
|
|
303
308
|
|
|
304
309
|
paymentSheetConfiguration = configurationBuilder.build()
|
|
305
310
|
|
|
306
|
-
if (arguments
|
|
311
|
+
if (arguments.getBoolean("customFlow") == true) {
|
|
307
312
|
flowController =
|
|
308
313
|
if (intentConfiguration != null) {
|
|
309
314
|
val builder =
|
|
@@ -319,14 +324,14 @@ class PaymentSheetFragment :
|
|
|
319
324
|
}
|
|
320
325
|
builder
|
|
321
326
|
.confirmCustomPaymentMethodCallback(this)
|
|
322
|
-
.build(
|
|
327
|
+
.build(activity)
|
|
323
328
|
} else {
|
|
324
329
|
PaymentSheet.FlowController
|
|
325
330
|
.Builder(
|
|
326
331
|
resultCallback = paymentResultCallback,
|
|
327
332
|
paymentOptionResultCallback = paymentOptionCallback,
|
|
328
333
|
).confirmCustomPaymentMethodCallback(this)
|
|
329
|
-
.build(
|
|
334
|
+
.build(activity)
|
|
330
335
|
}
|
|
331
336
|
configureFlowController()
|
|
332
337
|
} else {
|
|
@@ -338,22 +343,23 @@ class PaymentSheetFragment :
|
|
|
338
343
|
} else {
|
|
339
344
|
builder.createIntentCallback(createIntentCallback)
|
|
340
345
|
}
|
|
346
|
+
@SuppressLint("RestrictedApi")
|
|
341
347
|
builder
|
|
342
348
|
.confirmCustomPaymentMethodCallback(this)
|
|
343
|
-
.build(
|
|
349
|
+
.build(activity, signal)
|
|
344
350
|
} else {
|
|
351
|
+
@SuppressLint("RestrictedApi")
|
|
345
352
|
PaymentSheet
|
|
346
353
|
.Builder(paymentResultCallback)
|
|
347
354
|
.confirmCustomPaymentMethodCallback(this)
|
|
348
|
-
.build(
|
|
355
|
+
.build(activity, signal)
|
|
349
356
|
}
|
|
350
357
|
initPromise.resolve(WritableNativeMap())
|
|
351
358
|
}
|
|
352
359
|
}
|
|
353
360
|
|
|
354
|
-
fun
|
|
361
|
+
override fun onPresent() {
|
|
355
362
|
keepJsAwake = KeepJsAwakeTask(context).apply { start() }
|
|
356
|
-
presentPromise = promise
|
|
357
363
|
if (paymentSheet != null) {
|
|
358
364
|
if (!paymentIntentClientSecret.isNullOrEmpty()) {
|
|
359
365
|
paymentSheet?.presentWithPaymentIntent(
|
|
@@ -371,7 +377,7 @@ class PaymentSheetFragment :
|
|
|
371
377
|
} else if (flowController != null) {
|
|
372
378
|
flowController?.presentPaymentOptions()
|
|
373
379
|
} else {
|
|
374
|
-
promise
|
|
380
|
+
promise?.resolve(createMissingInitError())
|
|
375
381
|
}
|
|
376
382
|
}
|
|
377
383
|
|
|
@@ -479,7 +485,7 @@ class PaymentSheetFragment :
|
|
|
479
485
|
|
|
480
486
|
private fun resolvePresentPromise(value: Any?) {
|
|
481
487
|
keepJsAwake?.stop()
|
|
482
|
-
|
|
488
|
+
promise?.resolve(value)
|
|
483
489
|
}
|
|
484
490
|
|
|
485
491
|
private fun resolvePaymentResult(map: WritableMap) {
|
|
@@ -565,20 +571,6 @@ class PaymentSheetFragment :
|
|
|
565
571
|
}
|
|
566
572
|
|
|
567
573
|
companion object {
|
|
568
|
-
internal const val TAG = "payment_sheet_launch_fragment"
|
|
569
|
-
|
|
570
|
-
internal fun create(
|
|
571
|
-
context: ReactApplicationContext,
|
|
572
|
-
arguments: Bundle,
|
|
573
|
-
initPromise: Promise,
|
|
574
|
-
): PaymentSheetFragment {
|
|
575
|
-
val instance = PaymentSheetFragment()
|
|
576
|
-
instance.context = context
|
|
577
|
-
instance.initPromise = initPromise
|
|
578
|
-
instance.arguments = arguments
|
|
579
|
-
return instance
|
|
580
|
-
}
|
|
581
|
-
|
|
582
574
|
private val mapIntToButtonType =
|
|
583
575
|
mapOf(
|
|
584
576
|
1 to PaymentSheet.GooglePayConfiguration.ButtonType.Buy,
|
|
@@ -597,8 +589,8 @@ class PaymentSheetFragment :
|
|
|
597
589
|
"No payment sheet has been initialized yet. You must call `initPaymentSheet` before `presentPaymentSheet`.",
|
|
598
590
|
)
|
|
599
591
|
|
|
600
|
-
internal fun buildGooglePayConfig(params:
|
|
601
|
-
if (params == null || params.isEmpty) {
|
|
592
|
+
internal fun buildGooglePayConfig(params: ReadableMap?): PaymentSheet.GooglePayConfiguration? {
|
|
593
|
+
if (params == null || params.isEmpty()) {
|
|
602
594
|
return null
|
|
603
595
|
}
|
|
604
596
|
|
|
@@ -608,7 +600,7 @@ class PaymentSheetFragment :
|
|
|
608
600
|
val amount = params.getString("amount")?.toLongOrNull()
|
|
609
601
|
val label = params.getString("label")
|
|
610
602
|
val buttonType =
|
|
611
|
-
mapIntToButtonType.get(params.
|
|
603
|
+
mapIntToButtonType.get(params.getIntOr("buttonType", 0))
|
|
612
604
|
?: PaymentSheet.GooglePayConfiguration.ButtonType.Pay
|
|
613
605
|
|
|
614
606
|
return PaymentSheet.GooglePayConfiguration(
|
|
@@ -626,7 +618,7 @@ class PaymentSheetFragment :
|
|
|
626
618
|
)
|
|
627
619
|
}
|
|
628
620
|
|
|
629
|
-
internal fun buildLinkConfig(params:
|
|
621
|
+
internal fun buildLinkConfig(params: ReadableMap?): PaymentSheet.LinkConfiguration {
|
|
630
622
|
if (params == null) {
|
|
631
623
|
return PaymentSheet.LinkConfiguration()
|
|
632
624
|
}
|
|
@@ -646,12 +638,12 @@ class PaymentSheetFragment :
|
|
|
646
638
|
}
|
|
647
639
|
|
|
648
640
|
@Throws(PaymentSheetException::class)
|
|
649
|
-
internal fun buildIntentConfiguration(intentConfigurationParams:
|
|
641
|
+
internal fun buildIntentConfiguration(intentConfigurationParams: ReadableMap?): PaymentSheet.IntentConfiguration? {
|
|
650
642
|
if (intentConfigurationParams == null) {
|
|
651
643
|
return null
|
|
652
644
|
}
|
|
653
645
|
val modeParams =
|
|
654
|
-
intentConfigurationParams.
|
|
646
|
+
intentConfigurationParams.getMap("mode")
|
|
655
647
|
?: throw PaymentSheetException(
|
|
656
648
|
"If `intentConfiguration` is provided, `intentConfiguration.mode` is required",
|
|
657
649
|
)
|
|
@@ -665,8 +657,8 @@ class PaymentSheetFragment :
|
|
|
665
657
|
}
|
|
666
658
|
|
|
667
659
|
@OptIn(PaymentMethodOptionsSetupFutureUsagePreview::class)
|
|
668
|
-
private fun buildIntentConfigurationMode(modeParams:
|
|
669
|
-
if (modeParams.
|
|
660
|
+
private fun buildIntentConfigurationMode(modeParams: ReadableMap): PaymentSheet.IntentConfiguration.Mode =
|
|
661
|
+
if (modeParams.hasKey("amount")) {
|
|
670
662
|
val currencyCode =
|
|
671
663
|
modeParams.getString("currencyCode")
|
|
672
664
|
?: throw PaymentSheetException(
|
|
@@ -677,7 +669,7 @@ class PaymentSheetFragment :
|
|
|
677
669
|
currency = currencyCode,
|
|
678
670
|
setupFutureUse = mapToSetupFutureUse(modeParams.getString("setupFutureUsage")),
|
|
679
671
|
captureMethod = mapToCaptureMethod(modeParams.getString("captureMethod")),
|
|
680
|
-
paymentMethodOptions = mapToPaymentMethodOptions(modeParams.
|
|
672
|
+
paymentMethodOptions = mapToPaymentMethodOptions(modeParams.getMap("paymentMethodOptions")),
|
|
681
673
|
)
|
|
682
674
|
} else {
|
|
683
675
|
val setupFutureUsage =
|
|
@@ -691,12 +683,11 @@ class PaymentSheetFragment :
|
|
|
691
683
|
)
|
|
692
684
|
}
|
|
693
685
|
|
|
694
|
-
@OptIn(ExperimentalCustomerSessionApi::class)
|
|
695
686
|
@Throws(PaymentSheetException::class)
|
|
696
|
-
internal fun buildCustomerConfiguration(
|
|
697
|
-
val customerId =
|
|
698
|
-
val customerEphemeralKeySecret =
|
|
699
|
-
val customerSessionClientSecret =
|
|
687
|
+
internal fun buildCustomerConfiguration(map: ReadableMap?): PaymentSheet.CustomerConfiguration? {
|
|
688
|
+
val customerId = map?.getString("customerId").orEmpty()
|
|
689
|
+
val customerEphemeralKeySecret = map?.getString("customerEphemeralKeySecret").orEmpty()
|
|
690
|
+
val customerSessionClientSecret = map?.getString("customerSessionClientSecret").orEmpty()
|
|
700
691
|
return if (customerSessionClientSecret.isNotEmpty() &&
|
|
701
692
|
customerEphemeralKeySecret.isNotEmpty()
|
|
702
693
|
) {
|
|
@@ -798,11 +789,11 @@ fun mapToCaptureMethod(type: String?): PaymentSheet.IntentConfiguration.CaptureM
|
|
|
798
789
|
}
|
|
799
790
|
|
|
800
791
|
@OptIn(PaymentMethodOptionsSetupFutureUsagePreview::class)
|
|
801
|
-
fun mapToPaymentMethodOptions(options:
|
|
802
|
-
val
|
|
792
|
+
fun mapToPaymentMethodOptions(options: ReadableMap?): PaymentSheet.IntentConfiguration.Mode.Payment.PaymentMethodOptions? {
|
|
793
|
+
val sfuMap = options?.getMap("setupFutureUsageValues")
|
|
803
794
|
val paymentMethodToSfuMap = mutableMapOf<PaymentMethod.Type, PaymentSheet.IntentConfiguration.SetupFutureUse>()
|
|
804
|
-
|
|
805
|
-
val sfuValue = mapToSetupFutureUse(
|
|
795
|
+
sfuMap?.forEachKey { code ->
|
|
796
|
+
val sfuValue = mapToSetupFutureUse(sfuMap.getString(code))
|
|
806
797
|
val paymentMethodType = PaymentMethod.Type.fromCode(code)
|
|
807
798
|
if (paymentMethodType != null && sfuValue != null) {
|
|
808
799
|
paymentMethodToSfuMap[paymentMethodType] = sfuValue
|
|
@@ -817,8 +808,8 @@ fun mapToPaymentMethodOptions(options: Bundle?): PaymentSheet.IntentConfiguratio
|
|
|
817
808
|
}
|
|
818
809
|
}
|
|
819
810
|
|
|
820
|
-
fun mapToCardBrandAcceptance(params:
|
|
821
|
-
val cardBrandAcceptanceParams = params?.
|
|
811
|
+
fun mapToCardBrandAcceptance(params: ReadableMap?): PaymentSheet.CardBrandAcceptance {
|
|
812
|
+
val cardBrandAcceptanceParams = params?.getMap("cardBrandAcceptance") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
822
813
|
val filter = cardBrandAcceptanceParams.getString("filter") ?: return PaymentSheet.CardBrandAcceptance.all()
|
|
823
814
|
|
|
824
815
|
return when (filter) {
|
|
@@ -107,7 +107,8 @@ abstract class StripeAbstractComposeView(
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
fun handleOnDropViewInstance() {
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
if (lifecycleRegistry.currentState.isAtLeast(Lifecycle.State.CREATED)) {
|
|
111
|
+
lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
112
|
+
}
|
|
112
113
|
}
|
|
113
114
|
}
|