@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.
Files changed (126) hide show
  1. package/android/gradle.properties +1 -1
  2. package/android/src/main/java/com/reactnativestripesdk/AuBECSDebitFormView.kt +4 -3
  3. package/android/src/main/java/com/reactnativestripesdk/CardFieldView.kt +7 -6
  4. package/android/src/main/java/com/reactnativestripesdk/CardFormView.kt +11 -11
  5. package/android/src/main/java/com/reactnativestripesdk/{CollectBankAccountLauncherFragment.kt → CollectBankAccountLauncherManager.kt} +21 -44
  6. package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +17 -24
  7. package/android/src/main/java/com/reactnativestripesdk/EventEmitterCompat.kt +8 -0
  8. package/android/src/main/java/com/reactnativestripesdk/{FinancialConnectionsSheetFragment.kt → FinancialConnectionsSheetManager.kt} +30 -77
  9. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherManager.kt +107 -0
  10. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherManager.kt +37 -0
  11. package/android/src/main/java/com/reactnativestripesdk/{PaymentLauncherFragment.kt → PaymentLauncherManager.kt} +39 -77
  12. package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +8 -20
  13. package/android/src/main/java/com/reactnativestripesdk/PaymentSheetAppearance.kt +366 -483
  14. package/android/src/main/java/com/reactnativestripesdk/{PaymentSheetFragment.kt → PaymentSheetManager.kt} +79 -88
  15. package/android/src/main/java/com/reactnativestripesdk/StripeAbstractComposeView.kt +3 -2
  16. package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +213 -210
  17. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherManager.kt +78 -0
  18. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressSheetView.kt +48 -35
  19. package/android/src/main/java/com/reactnativestripesdk/customersheet/{CustomerSheetFragment.kt → CustomerSheetManager.kt} +127 -104
  20. package/android/src/main/java/com/reactnativestripesdk/customersheet/ReactNativeCustomerSessionProvider.kt +35 -0
  21. package/android/src/main/java/com/reactnativestripesdk/utils/Extensions.kt +47 -12
  22. package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +87 -142
  23. package/android/src/main/java/com/reactnativestripesdk/utils/StripeUIManager.kt +62 -0
  24. package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerDelegate.java +12 -0
  25. package/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java +4 -0
  26. package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +8 -64
  27. package/ios/AddressSheet/AddressSheetView.swift +1 -1
  28. package/ios/ApplePayButtonManager.m +1 -1
  29. package/ios/ApplePayButtonView.swift +2 -2
  30. package/ios/FinancialConnections.swift +2 -2
  31. package/ios/Mappers.swift +2 -4
  32. package/ios/NewArch/ApplePayButtonComponentView.mm +1 -1
  33. package/ios/OldArch/StripeSdkEventEmitterCompat.h +2 -0
  34. package/ios/OldArch/StripeSdkEventEmitterCompat.m +12 -0
  35. package/ios/PaymentMethodFactory.swift +0 -17
  36. package/ios/PushProvisioning/AddToWalletButtonView.swift +1 -1
  37. package/ios/StripeSdk.mm +14 -0
  38. package/ios/StripeSdkEmitter.swift +2 -0
  39. package/ios/StripeSdkImpl+CustomerSheet.swift +71 -20
  40. package/ios/StripeSdkImpl+PaymentSheet.swift +29 -13
  41. package/ios/StripeSdkImpl.swift +9 -7
  42. package/lib/commonjs/components/AddToWalletButton.js +1 -1
  43. package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
  44. package/lib/commonjs/components/AddressSheet.js +1 -1
  45. package/lib/commonjs/components/AddressSheet.js.map +1 -1
  46. package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
  47. package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
  48. package/lib/commonjs/components/CardField.js +1 -1
  49. package/lib/commonjs/components/CardField.js.map +1 -1
  50. package/lib/commonjs/components/CardForm.js +1 -1
  51. package/lib/commonjs/components/CardForm.js.map +1 -1
  52. package/lib/commonjs/components/CustomerSheet.js +1 -1
  53. package/lib/commonjs/components/CustomerSheet.js.map +1 -1
  54. package/lib/commonjs/components/PlatformPayButton.js +1 -1
  55. package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
  56. package/lib/commonjs/components/StripeContainer.js +1 -1
  57. package/lib/commonjs/components/StripeContainer.js.map +1 -1
  58. package/lib/commonjs/events.js.map +1 -1
  59. package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
  60. package/lib/commonjs/specs/NativeApplePayButton.js.map +1 -1
  61. package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
  62. package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
  63. package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
  64. package/lib/commonjs/types/PaymentIntent.js.map +1 -1
  65. package/lib/commonjs/types/PaymentSheet.js.map +1 -1
  66. package/lib/module/components/AddToWalletButton.js +1 -1
  67. package/lib/module/components/AddToWalletButton.js.map +1 -1
  68. package/lib/module/components/AddressSheet.js +1 -1
  69. package/lib/module/components/AddressSheet.js.map +1 -1
  70. package/lib/module/components/AuBECSDebitForm.js +1 -1
  71. package/lib/module/components/AuBECSDebitForm.js.map +1 -1
  72. package/lib/module/components/CardField.js +1 -1
  73. package/lib/module/components/CardField.js.map +1 -1
  74. package/lib/module/components/CardForm.js +1 -1
  75. package/lib/module/components/CardForm.js.map +1 -1
  76. package/lib/module/components/CustomerSheet.js +1 -1
  77. package/lib/module/components/CustomerSheet.js.map +1 -1
  78. package/lib/module/components/PlatformPayButton.js +1 -1
  79. package/lib/module/components/PlatformPayButton.js.map +1 -1
  80. package/lib/module/components/StripeContainer.js +1 -1
  81. package/lib/module/components/StripeContainer.js.map +1 -1
  82. package/lib/module/events.js.map +1 -1
  83. package/lib/module/specs/NativeApplePayButton.js +1 -1
  84. package/lib/module/specs/NativeApplePayButton.js.map +1 -1
  85. package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
  86. package/lib/module/types/EmbeddedPaymentElement.js +1 -1
  87. package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
  88. package/lib/module/types/PaymentIntent.js.map +1 -1
  89. package/lib/module/types/PaymentSheet.js.map +1 -1
  90. package/lib/typescript/src/components/CustomerSheet.d.ts +1 -1
  91. package/lib/typescript/src/components/CustomerSheet.d.ts.map +1 -1
  92. package/lib/typescript/src/events.d.ts +2 -0
  93. package/lib/typescript/src/events.d.ts.map +1 -1
  94. package/lib/typescript/src/specs/NativeApplePayButton.d.ts +1 -1
  95. package/lib/typescript/src/specs/NativeApplePayButton.d.ts.map +1 -1
  96. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +3 -1
  97. package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
  98. package/lib/typescript/src/types/ConfirmationToken.d.ts +0 -3
  99. package/lib/typescript/src/types/ConfirmationToken.d.ts.map +1 -1
  100. package/lib/typescript/src/types/CustomerSheet.d.ts +70 -12
  101. package/lib/typescript/src/types/CustomerSheet.d.ts.map +1 -1
  102. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts +2 -4
  103. package/lib/typescript/src/types/EmbeddedPaymentElement.d.ts.map +1 -1
  104. package/lib/typescript/src/types/PaymentIntent.d.ts +1 -9
  105. package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -1
  106. package/lib/typescript/src/types/PaymentMethod.d.ts +2 -8
  107. package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -1
  108. package/lib/typescript/src/types/PaymentSheet.d.ts +1 -6
  109. package/lib/typescript/src/types/PaymentSheet.d.ts.map +1 -1
  110. package/package.json +1 -1
  111. package/src/components/CustomerSheet.tsx +65 -9
  112. package/src/components/PlatformPayButton.tsx +1 -1
  113. package/src/events.ts +2 -0
  114. package/src/specs/NativeApplePayButton.ts +1 -1
  115. package/src/specs/NativeStripeSdkModule.ts +7 -0
  116. package/src/types/ConfirmationToken.ts +0 -3
  117. package/src/types/CustomerSheet.ts +80 -12
  118. package/src/types/EmbeddedPaymentElement.tsx +2 -4
  119. package/src/types/PaymentIntent.ts +0 -10
  120. package/src/types/PaymentMethod.ts +0 -9
  121. package/src/types/PaymentSheet.ts +1 -6
  122. package/stripe-react-native.podspec +1 -1
  123. package/android/src/main/java/com/reactnativestripesdk/GooglePayLauncherFragment.kt +0 -146
  124. package/android/src/main/java/com/reactnativestripesdk/GooglePayPaymentMethodLauncherFragment.kt +0 -68
  125. package/android/src/main/java/com/reactnativestripesdk/addresssheet/AddressLauncherFragment.kt +0 -102
  126. 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.StripeFragment
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(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class, ExperimentalCustomPaymentMethodsApi::class)
64
- class PaymentSheetFragment :
65
- StripeFragment(),
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 prepare() {
85
- val merchantDisplayName = arguments?.getString("merchantDisplayName").orEmpty()
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?.getString("primaryButtonLabel")
93
- val googlePayConfig = buildGooglePayConfig(arguments?.getBundle("googlePay"))
94
- val linkConfig = buildLinkConfig(arguments?.getBundle("link"))
95
- val allowsDelayedPaymentMethods = arguments?.getBoolean("allowsDelayedPaymentMethods")
96
- val billingDetailsBundle = arguments?.getBundle("defaultBillingDetails")
97
- val billingConfigParams = arguments?.getBundle("billingDetailsCollectionConfiguration")
98
- val paymentMethodOrder = arguments?.getStringArrayList("paymentMethodOrder")
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?.getBoolean("allowsRemovalOfLastSavedPaymentMethod", true) ?: true
101
- paymentIntentClientSecret = arguments?.getString("paymentIntentClientSecret").orEmpty()
102
- setupIntentClientSecret = arguments?.getString("setupIntentClientSecret").orEmpty()
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?.getBundle("intentConfiguration"))
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 intentConfigBundle = arguments?.getBundle("intentConfiguration")
113
- val useConfirmationTokenCallback = intentConfigBundle?.containsKey("confirmationTokenConfirmHandler") == true
120
+ val intentConfigMap = arguments.getMap("intentConfiguration")
121
+ val useConfirmationTokenCallback = intentConfigMap?.hasKey("confirmationTokenConfirmHandler") == true
114
122
  val appearance =
115
123
  try {
116
- buildPaymentSheetAppearance(arguments?.getBundle("appearance"), context)
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?.getBundle("defaultShippingDetails")?.let {
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?.getBoolean("attachDefaultsToPaymentMethod", false) ?: false,
262
+ billingConfigParams?.getBooleanOr("attachDefaultsToPaymentMethod", false) ?: false,
258
263
  )
259
264
 
260
265
  var defaultBillingDetails: PaymentSheet.BillingDetails? = null
261
- if (billingDetailsBundle != null) {
262
- val addressBundle = billingDetailsBundle.getBundle("address")
266
+ if (billingDetailsMap != null) {
267
+ val addressMap = billingDetailsMap.getMap("address")
263
268
  val address =
264
269
  PaymentSheet.Address(
265
- addressBundle?.getString("city"),
266
- addressBundle?.getString("country"),
267
- addressBundle?.getString("line1"),
268
- addressBundle?.getString("line2"),
269
- addressBundle?.getString("postalCode"),
270
- addressBundle?.getString("state"),
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
- billingDetailsBundle.getString("email"),
276
- billingDetailsBundle.getString("name"),
277
- billingDetailsBundle.getString("phone"),
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 ?: false)
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?.getIntegerArrayList("preferredNetworks")),
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?.getString("paymentMethodLayout")),
306
+ mapToPaymentMethodLayout(arguments.getString("paymentMethodLayout")),
302
307
  )
303
308
 
304
309
  paymentSheetConfiguration = configurationBuilder.build()
305
310
 
306
- if (arguments?.getBoolean("customFlow") == true) {
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(this)
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(this)
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(this)
349
+ .build(activity, signal)
344
350
  } else {
351
+ @SuppressLint("RestrictedApi")
345
352
  PaymentSheet
346
353
  .Builder(paymentResultCallback)
347
354
  .confirmCustomPaymentMethodCallback(this)
348
- .build(this)
355
+ .build(activity, signal)
349
356
  }
350
357
  initPromise.resolve(WritableNativeMap())
351
358
  }
352
359
  }
353
360
 
354
- fun present(promise: Promise) {
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.resolve(createMissingInitError())
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
- presentPromise?.resolve(value)
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: Bundle?): PaymentSheet.GooglePayConfiguration? {
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.getInt("buttonType"))
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: Bundle?): PaymentSheet.LinkConfiguration {
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: Bundle?): PaymentSheet.IntentConfiguration? {
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.getBundle("mode")
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: Bundle): PaymentSheet.IntentConfiguration.Mode =
669
- if (modeParams.containsKey("amount")) {
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.getBundle("paymentMethodOptions")),
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(bundle: Bundle?): PaymentSheet.CustomerConfiguration? {
697
- val customerId = bundle?.getString("customerId").orEmpty()
698
- val customerEphemeralKeySecret = bundle?.getString("customerEphemeralKeySecret").orEmpty()
699
- val customerSessionClientSecret = bundle?.getString("customerSessionClientSecret").orEmpty()
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: Bundle?): PaymentSheet.IntentConfiguration.Mode.Payment.PaymentMethodOptions? {
802
- val sfuBundle = options?.getBundle("setupFutureUsageValues")
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
- sfuBundle?.keySet()?.forEach { code ->
805
- val sfuValue = mapToSetupFutureUse(sfuBundle?.getString(code))
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: Bundle?): PaymentSheet.CardBrandAcceptance {
821
- val cardBrandAcceptanceParams = params?.getBundle("cardBrandAcceptance") ?: return PaymentSheet.CardBrandAcceptance.all()
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
- // Update the lifecycle state to DESTROYED to cause the composition to be destroyed.
111
- lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
110
+ if (lifecycleRegistry.currentState.isAtLeast(Lifecycle.State.CREATED)) {
111
+ lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
112
+ }
112
113
  }
113
114
  }