@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
@@ -20,21 +20,21 @@ import com.facebook.react.bridge.UiThreadUtil
20
20
  import com.facebook.react.bridge.WritableMap
21
21
  import com.facebook.react.bridge.WritableNativeMap
22
22
  import com.facebook.react.module.annotations.ReactModule
23
- import com.reactnativestripesdk.addresssheet.AddressLauncherFragment
24
- import com.reactnativestripesdk.customersheet.CustomerSheetFragment
23
+ import com.reactnativestripesdk.addresssheet.AddressLauncherManager
24
+ import com.reactnativestripesdk.customersheet.CustomerSheetManager
25
25
  import com.reactnativestripesdk.pushprovisioning.PushProvisioningProxy
26
26
  import com.reactnativestripesdk.utils.ConfirmPaymentErrorType
27
27
  import com.reactnativestripesdk.utils.CreateTokenErrorType
28
28
  import com.reactnativestripesdk.utils.ErrorType
29
29
  import com.reactnativestripesdk.utils.GooglePayErrorType
30
+ import com.reactnativestripesdk.utils.StripeUIManager
30
31
  import com.reactnativestripesdk.utils.createCanAddCardResult
31
32
  import com.reactnativestripesdk.utils.createError
32
33
  import com.reactnativestripesdk.utils.createMissingActivityError
33
34
  import com.reactnativestripesdk.utils.createMissingInitError
34
35
  import com.reactnativestripesdk.utils.createResult
35
36
  import com.reactnativestripesdk.utils.getBooleanOr
36
- import com.reactnativestripesdk.utils.getBooleanOrFalse
37
- import com.reactnativestripesdk.utils.getMapOrNull
37
+ import com.reactnativestripesdk.utils.getIntOrNull
38
38
  import com.reactnativestripesdk.utils.getValOr
39
39
  import com.reactnativestripesdk.utils.mapFromPaymentIntentResult
40
40
  import com.reactnativestripesdk.utils.mapFromPaymentMethod
@@ -46,8 +46,6 @@ import com.reactnativestripesdk.utils.mapToPaymentMethodType
46
46
  import com.reactnativestripesdk.utils.mapToReturnURL
47
47
  import com.reactnativestripesdk.utils.mapToShippingDetails
48
48
  import com.reactnativestripesdk.utils.mapToUICustomization
49
- import com.reactnativestripesdk.utils.removeFragment
50
- import com.reactnativestripesdk.utils.toBundleObject
51
49
  import com.stripe.android.ApiResultCallback
52
50
  import com.stripe.android.GooglePayJsonFactory
53
51
  import com.stripe.android.PaymentAuthConfig
@@ -55,6 +53,8 @@ import com.stripe.android.PaymentConfiguration
55
53
  import com.stripe.android.Stripe
56
54
  import com.stripe.android.core.ApiVersion
57
55
  import com.stripe.android.core.AppInfo
56
+ import com.stripe.android.core.reactnative.ReactNativeSdkInternal
57
+ import com.stripe.android.customersheet.CustomerSheet
58
58
  import com.stripe.android.googlepaylauncher.GooglePayLauncher
59
59
  import com.stripe.android.model.BankAccountTokenParams
60
60
  import com.stripe.android.model.CardParams
@@ -73,6 +73,7 @@ import kotlinx.coroutines.launch
73
73
  import org.json.JSONObject
74
74
 
75
75
  @ReactModule(name = StripeSdkModule.NAME)
76
+ @OptIn(ReactNativeSdkInternal::class)
76
77
  class StripeSdkModule(
77
78
  reactContext: ReactApplicationContext,
78
79
  ) : NativeStripeSdkModuleSpec(reactContext) {
@@ -87,11 +88,15 @@ class StripeSdkModule(
87
88
  private var createPlatformPayPaymentMethodPromise: Promise? = null
88
89
  private var platformPayUsesDeprecatedTokenFlow = false
89
90
 
90
- private var paymentSheetFragment: PaymentSheetFragment? = null
91
- private var paymentLauncherFragment: PaymentLauncherFragment? = null
92
- private var collectBankAccountLauncherFragment: CollectBankAccountLauncherFragment? = null
91
+ private val stripeUIManagers = mutableListOf<StripeUIManager>()
92
+ private var paymentSheetManager: PaymentSheetManager? = null
93
+ private var paymentLauncherManager: PaymentLauncherManager? = null
94
+ private var collectBankAccountLauncherManager: CollectBankAccountLauncherManager? = null
95
+ private var financialConnectionsSheetManager: FinancialConnectionsSheetManager? = null
96
+ private var googlePayLauncherManager: GooglePayLauncherManager? = null
97
+ private var googlePayPaymentMethodLauncherManager: GooglePayPaymentMethodLauncherManager? = null
93
98
 
94
- private var customerSheetFragment: CustomerSheetFragment? = null
99
+ private var customerSheetManager: CustomerSheetManager? = null
95
100
 
96
101
  internal var embeddedIntentCreationCallback = CompletableDeferred<ReadableMap>()
97
102
  internal var embeddedConfirmationTokenCreationCallback = CompletableDeferred<ReadableMap>()
@@ -102,20 +107,6 @@ class StripeSdkModule(
102
107
 
103
108
  val eventEmitter: EventEmitterCompat by lazy { EventEmitterCompat(reactApplicationContext) }
104
109
 
105
- // If you create a new Fragment, you must put the tag here, otherwise result callbacks for that
106
- // Fragment will not work on RN < 0.65
107
- private val allStripeFragmentTags: List<String>
108
- get() =
109
- listOf(
110
- PaymentSheetFragment.TAG,
111
- PaymentLauncherFragment.TAG,
112
- CollectBankAccountLauncherFragment.TAG,
113
- FinancialConnectionsSheetFragment.TAG,
114
- AddressLauncherFragment.TAG,
115
- GooglePayLauncherFragment.TAG,
116
- CustomerSheetFragment.TAG,
117
- )
118
-
119
110
  private val mActivityEventListener =
120
111
  object : BaseActivityEventListener() {
121
112
  override fun onActivityResult(
@@ -143,10 +134,6 @@ class StripeSdkModule(
143
134
  )
144
135
  }
145
136
  }
146
-
147
- else -> {
148
- dispatchActivityResultsToFragments(requestCode, resultCode, data)
149
- }
150
137
  }
151
138
  }
152
139
  }
@@ -156,19 +143,22 @@ class StripeSdkModule(
156
143
  reactContext.addActivityEventListener(mActivityEventListener)
157
144
  }
158
145
 
159
- // Necessary on older versions of React Native (~0.65 and below)
160
- private fun dispatchActivityResultsToFragments(
161
- requestCode: Int,
162
- resultCode: Int,
163
- data: Intent?,
164
- ) {
165
- getCurrentActivityOrResolveWithError(null)?.supportFragmentManager?.let { fragmentManager ->
166
- for (tag in allStripeFragmentTags) {
167
- fragmentManager.findFragmentByTag(tag)?.let {
168
- it.activity?.activityResultRegistry?.dispatchResult(requestCode, resultCode, data)
169
- }
170
- }
171
- }
146
+ override fun invalidate() {
147
+ super.invalidate()
148
+
149
+ stripeUIManagers.forEach { it.destroy() }
150
+ stripeUIManagers.clear()
151
+ }
152
+
153
+ private fun registerStripeUIManager(uiManager: StripeUIManager) {
154
+ uiManager.create()
155
+ stripeUIManagers.add(uiManager)
156
+ }
157
+
158
+ private fun unregisterStripeUIManager(uiManager: StripeUIManager?) {
159
+ val uiManager = uiManager ?: return
160
+ uiManager.destroy()
161
+ stripeUIManagers.remove(uiManager)
172
162
  }
173
163
 
174
164
  private fun configure3dSecure(params: ReadableMap) {
@@ -203,18 +193,18 @@ class StripeSdkModule(
203
193
  promise: Promise,
204
194
  ) {
205
195
  val publishableKey = getValOr(params, "publishableKey", null) as String
206
- val appInfo = getMapOrNull(params, "appInfo") as ReadableMap
196
+ val appInfo = params.getMap("appInfo") as ReadableMap
207
197
  this.stripeAccountId = getValOr(params, "stripeAccountId", null)
208
198
  val urlScheme = getValOr(params, "urlScheme", null)
209
- val setReturnUrlSchemeOnAndroid = getBooleanOrFalse(params, "setReturnUrlSchemeOnAndroid")
199
+ val setReturnUrlSchemeOnAndroid = params.getBooleanOr("setReturnUrlSchemeOnAndroid", false)
210
200
  this.urlScheme = if (setReturnUrlSchemeOnAndroid) urlScheme else null
211
201
 
212
- getMapOrNull(params, "threeDSecureParams")?.let {
202
+ params.getMap("threeDSecureParams")?.let {
213
203
  configure3dSecure(it)
214
204
  }
215
205
 
216
206
  this.publishableKey = publishableKey
217
- AddressLauncherFragment.publishableKey = publishableKey
207
+ AddressLauncherManager.publishableKey = publishableKey
218
208
 
219
209
  val name = getValOr(appInfo, "name", "") as String
220
210
  val partnerId = getValOr(appInfo, "partnerId", "")
@@ -237,28 +227,11 @@ class StripeSdkModule(
237
227
  params: ReadableMap,
238
228
  promise: Promise,
239
229
  ) {
240
- getCurrentActivityOrResolveWithError(promise)?.let { activity ->
241
- paymentSheetFragment?.removeFragment(reactApplicationContext)
242
- val bundle = toBundleObject(params)
243
-
244
- // Handle custom payment methods separately since toBundleObject cannot handle arrays of objects
245
- val customPaymentMethodConfig = params.getMap("customPaymentMethodConfiguration")
246
- if (customPaymentMethodConfig != null) {
247
- // Store the original ReadableMap for custom payment methods
248
- bundle.putSerializable("customPaymentMethodConfigurationReadableMap", customPaymentMethodConfig.toHashMap())
230
+ unregisterStripeUIManager(paymentSheetManager)
231
+ paymentSheetManager =
232
+ PaymentSheetManager(reactApplicationContext, params, promise).also {
233
+ registerStripeUIManager(it)
249
234
  }
250
-
251
- paymentSheetFragment =
252
- PaymentSheetFragment.create(reactApplicationContext, bundle, promise)
253
- try {
254
- activity.supportFragmentManager
255
- .beginTransaction()
256
- .add(paymentSheetFragment!!, PaymentSheetFragment.TAG)
257
- .commit()
258
- } catch (error: IllegalStateException) {
259
- promise.resolve(createError(ErrorType.Failed.toString(), error.message))
260
- }
261
- }
262
235
  }
263
236
 
264
237
  @ReactMethod
@@ -266,30 +239,30 @@ class StripeSdkModule(
266
239
  options: ReadableMap,
267
240
  promise: Promise,
268
241
  ) {
269
- if (paymentSheetFragment == null) {
270
- promise.resolve(PaymentSheetFragment.createMissingInitError())
242
+ if (paymentSheetManager == null) {
243
+ promise.resolve(PaymentSheetManager.createMissingInitError())
271
244
  return
272
245
  }
273
246
 
274
247
  val timeoutKey = "timeout"
275
248
  if (options.hasKey(timeoutKey)) {
276
- paymentSheetFragment?.presentWithTimeout(
249
+ paymentSheetManager?.presentWithTimeout(
277
250
  options.getInt(timeoutKey).toLong(),
278
251
  promise,
279
252
  )
280
253
  } else {
281
- paymentSheetFragment?.present(promise)
254
+ paymentSheetManager?.present(promise)
282
255
  }
283
256
  }
284
257
 
285
258
  @ReactMethod
286
259
  override fun confirmPaymentSheetPayment(promise: Promise) {
287
- if (paymentSheetFragment == null) {
288
- promise.resolve(PaymentSheetFragment.createMissingInitError())
260
+ if (paymentSheetManager == null) {
261
+ promise.resolve(PaymentSheetManager.createMissingInitError())
289
262
  return
290
263
  }
291
264
 
292
- paymentSheetFragment?.confirmPayment(promise)
265
+ paymentSheetManager?.confirmPayment(promise)
293
266
  }
294
267
 
295
268
  @ReactMethod
@@ -305,12 +278,12 @@ class StripeSdkModule(
305
278
  ) {
306
279
  embeddedIntentCreationCallback.complete(params)
307
280
 
308
- if (paymentSheetFragment == null) {
309
- promise.resolve(PaymentSheetFragment.createMissingInitError())
281
+ if (paymentSheetManager == null) {
282
+ promise.resolve(PaymentSheetManager.createMissingInitError())
310
283
  return
311
284
  }
312
285
 
313
- paymentSheetFragment?.paymentSheetIntentCreationCallback?.complete(params)
286
+ paymentSheetManager?.paymentSheetIntentCreationCallback?.complete(params)
314
287
  }
315
288
 
316
289
  @ReactMethod
@@ -333,12 +306,12 @@ class StripeSdkModule(
333
306
  embeddedConfirmationTokenCreationCallback.complete(params)
334
307
  paymentSheetConfirmationTokenCreationCallback.complete(params)
335
308
 
336
- if (paymentSheetFragment == null) {
337
- promise.resolve(PaymentSheetFragment.createMissingInitError())
309
+ if (paymentSheetManager == null) {
310
+ promise.resolve(PaymentSheetManager.createMissingInitError())
338
311
  return
339
312
  }
340
313
 
341
- paymentSheetFragment?.paymentSheetConfirmationTokenCreationCallback?.complete(params)
314
+ paymentSheetManager?.paymentSheetConfirmationTokenCreationCallback?.complete(params)
342
315
  }
343
316
 
344
317
  @ReactMethod
@@ -357,7 +330,7 @@ class StripeSdkModule(
357
330
  )
358
331
  return
359
332
  }
360
- val paymentMethodData = getMapOrNull(data, "paymentMethodData")
333
+ val paymentMethodData = data.getMap("paymentMethodData")
361
334
  val factory =
362
335
  PaymentMethodCreateParamsFactory(paymentMethodData, options, cardFieldView, cardFormView)
363
336
  try {
@@ -492,7 +465,7 @@ class StripeSdkModule(
492
465
  }
493
466
 
494
467
  val cardAddress = cardFieldView?.cardAddress ?: cardFormView?.cardAddress
495
- val address = getMapOrNull(params, "address")
468
+ val address = params.getMap("address")
496
469
  val cardParams =
497
470
  CardParams(
498
471
  number = cardParamsMap["number"] as String,
@@ -547,15 +520,19 @@ class StripeSdkModule(
547
520
  returnUrl: String?,
548
521
  promise: Promise,
549
522
  ) {
550
- paymentLauncherFragment =
551
- PaymentLauncherFragment.forNextActionPayment(
552
- context = reactApplicationContext,
553
- stripe,
554
- publishableKey,
555
- stripeAccountId,
556
- promise,
557
- paymentIntentClientSecret,
558
- )
523
+ unregisterStripeUIManager(paymentSheetManager)
524
+ paymentLauncherManager =
525
+ PaymentLauncherManager
526
+ .forNextActionPayment(
527
+ context = reactApplicationContext,
528
+ stripe,
529
+ publishableKey,
530
+ stripeAccountId,
531
+ paymentIntentClientSecret,
532
+ ).also {
533
+ registerStripeUIManager(it)
534
+ it.present(promise)
535
+ }
559
536
  }
560
537
 
561
538
  @ReactMethod
@@ -564,15 +541,19 @@ class StripeSdkModule(
564
541
  returnUrl: String?,
565
542
  promise: Promise,
566
543
  ) {
567
- paymentLauncherFragment =
568
- PaymentLauncherFragment.forNextActionSetup(
569
- context = reactApplicationContext,
570
- stripe,
571
- publishableKey,
572
- stripeAccountId,
573
- promise,
574
- setupIntentClientSecret,
575
- )
544
+ unregisterStripeUIManager(paymentLauncherManager)
545
+ paymentLauncherManager =
546
+ PaymentLauncherManager
547
+ .forNextActionSetup(
548
+ context = reactApplicationContext,
549
+ stripe,
550
+ publishableKey,
551
+ stripeAccountId,
552
+ setupIntentClientSecret,
553
+ ).also {
554
+ registerStripeUIManager(it)
555
+ it.present(promise)
556
+ }
576
557
  }
577
558
 
578
559
  // TODO: Uncomment when WeChat is re-enabled in stripe-ios
@@ -601,7 +582,7 @@ class StripeSdkModule(
601
582
  options: ReadableMap?,
602
583
  promise: Promise,
603
584
  ) {
604
- val paymentMethodData = getMapOrNull(params, "paymentMethodData")
585
+ val paymentMethodData = params?.getMap("paymentMethodData")
605
586
  val paymentMethodType =
606
587
  if (params != null) {
607
588
  mapToPaymentMethodType(params.getString("paymentMethodType")) ?: run {
@@ -641,17 +622,21 @@ class StripeSdkModule(
641
622
  confirmParams.returnUrl = mapToReturnURL(urlScheme)
642
623
  }
643
624
  confirmParams.shipping =
644
- mapToShippingDetails(getMapOrNull(paymentMethodData, "shippingDetails"))
645
- paymentLauncherFragment =
646
- PaymentLauncherFragment.forPayment(
647
- context = reactApplicationContext,
648
- stripe,
649
- publishableKey,
650
- stripeAccountId,
651
- promise,
652
- paymentIntentClientSecret,
653
- confirmParams,
654
- )
625
+ mapToShippingDetails(paymentMethodData?.getMap("shippingDetails"))
626
+ unregisterStripeUIManager(paymentLauncherManager)
627
+ paymentLauncherManager =
628
+ PaymentLauncherManager
629
+ .forPayment(
630
+ context = reactApplicationContext,
631
+ stripe,
632
+ publishableKey,
633
+ stripeAccountId,
634
+ paymentIntentClientSecret,
635
+ confirmParams,
636
+ ).also {
637
+ registerStripeUIManager(it)
638
+ it.present(promise)
639
+ }
655
640
  } catch (error: PaymentMethodCreateParamsException) {
656
641
  promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
657
642
  }
@@ -699,7 +684,7 @@ class StripeSdkModule(
699
684
 
700
685
  val factory =
701
686
  PaymentMethodCreateParamsFactory(
702
- getMapOrNull(params, "paymentMethodData"),
687
+ params.getMap("paymentMethodData"),
703
688
  options,
704
689
  cardFieldView,
705
690
  cardFormView,
@@ -715,16 +700,20 @@ class StripeSdkModule(
715
700
  urlScheme?.let {
716
701
  confirmParams.returnUrl = mapToReturnURL(urlScheme)
717
702
  }
718
- paymentLauncherFragment =
719
- PaymentLauncherFragment.forSetup(
720
- context = reactApplicationContext,
721
- stripe,
722
- publishableKey,
723
- stripeAccountId,
724
- promise,
725
- setupIntentClientSecret,
726
- confirmParams,
727
- )
703
+ unregisterStripeUIManager(paymentLauncherManager)
704
+ paymentLauncherManager =
705
+ PaymentLauncherManager
706
+ .forSetup(
707
+ context = reactApplicationContext,
708
+ stripe,
709
+ publishableKey,
710
+ stripeAccountId,
711
+ setupIntentClientSecret,
712
+ confirmParams,
713
+ ).also {
714
+ registerStripeUIManager(it)
715
+ it.present(promise)
716
+ }
728
717
  } catch (error: PaymentMethodCreateParamsException) {
729
718
  promise.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), error))
730
719
  }
@@ -736,24 +725,16 @@ class StripeSdkModule(
736
725
  promise: Promise,
737
726
  ) {
738
727
  val googlePayParams = params?.getMap("googlePay")
739
- val fragment =
740
- GooglePayPaymentMethodLauncherFragment.create(
728
+ unregisterStripeUIManager(googlePayPaymentMethodLauncherManager)
729
+ googlePayPaymentMethodLauncherManager =
730
+ GooglePayPaymentMethodLauncherManager(
741
731
  reactApplicationContext,
742
- getBooleanOrFalse(googlePayParams, "testEnv"),
743
- getBooleanOrFalse(googlePayParams, "existingPaymentMethodRequired"),
744
- promise,
745
- )
746
-
747
- getCurrentActivityOrResolveWithError(promise)?.let {
748
- try {
749
- it.supportFragmentManager
750
- .beginTransaction()
751
- .add(fragment, GooglePayPaymentMethodLauncherFragment.TAG)
752
- .commit()
753
- } catch (error: IllegalStateException) {
754
- promise.resolve(createError(ErrorType.Failed.toString(), error.message))
732
+ googlePayParams?.getBooleanOr("testEnv", false) ?: false,
733
+ googlePayParams?.getBooleanOr("existingPaymentMethodRequired", false) ?: false,
734
+ ).also {
735
+ registerStripeUIManager(it)
736
+ it.present(promise)
755
737
  }
756
- }
757
738
  }
758
739
 
759
740
  @ReactMethod
@@ -779,12 +760,12 @@ class StripeSdkModule(
779
760
  return
780
761
  }
781
762
 
782
- GooglePayLauncherFragment().also {
783
- it.presentGooglePaySheet(
763
+ googlePayLauncherManager =
764
+ GooglePayLauncherManager(
765
+ reactApplicationContext,
784
766
  clientSecret,
785
- if (isPaymentIntent) GooglePayLauncherFragment.Mode.ForPayment else GooglePayLauncherFragment.Mode.ForSetup,
767
+ if (isPaymentIntent) GooglePayLauncherManager.Mode.ForPayment else GooglePayLauncherManager.Mode.ForSetup,
786
768
  googlePayParams,
787
- reactApplicationContext,
788
769
  ) { launcherResult, errorMap ->
789
770
  if (errorMap != null) {
790
771
  promise.resolve(errorMap)
@@ -849,7 +830,6 @@ class StripeSdkModule(
849
830
  }
850
831
  }
851
832
  }
852
- }
853
833
  }
854
834
 
855
835
  @ReactMethod
@@ -946,7 +926,7 @@ class StripeSdkModule(
946
926
  params: ReadableMap,
947
927
  promise: Promise,
948
928
  ) {
949
- val paymentMethodData = getMapOrNull(params, "paymentMethodData")
929
+ val paymentMethodData = params.getMap("paymentMethodData")
950
930
  val paymentMethodType = mapToPaymentMethodType(getValOr(params, "paymentMethodType", null))
951
931
  if (paymentMethodType != PaymentMethod.Type.USBankAccount) {
952
932
  promise.resolve(
@@ -958,7 +938,7 @@ class StripeSdkModule(
958
938
  return
959
939
  }
960
940
 
961
- val billingDetails = getMapOrNull(paymentMethodData, "billingDetails")
941
+ val billingDetails = paymentMethodData?.getMap("billingDetails")
962
942
 
963
943
  val name = billingDetails?.getString("name")
964
944
  if (name.isNullOrEmpty()) {
@@ -977,26 +957,19 @@ class StripeSdkModule(
977
957
  billingDetails.getString("email"),
978
958
  )
979
959
 
980
- collectBankAccountLauncherFragment =
981
- CollectBankAccountLauncherFragment.create(
960
+ unregisterStripeUIManager(collectBankAccountLauncherManager)
961
+ collectBankAccountLauncherManager =
962
+ CollectBankAccountLauncherManager(
982
963
  reactApplicationContext,
983
964
  publishableKey,
984
965
  stripeAccountId,
985
966
  clientSecret,
986
967
  isPaymentIntent,
987
968
  collectParams,
988
- promise,
989
- )
990
- getCurrentActivityOrResolveWithError(promise)?.let {
991
- try {
992
- it.supportFragmentManager
993
- .beginTransaction()
994
- .add(collectBankAccountLauncherFragment!!, "collect_bank_account_launcher_fragment")
995
- .commit()
996
- } catch (error: IllegalStateException) {
997
- promise.resolve(createError(ErrorType.Failed.toString(), error.message))
969
+ ).also {
970
+ registerStripeUIManager(it)
971
+ it.present(promise)
998
972
  }
999
- }
1000
973
  }
1001
974
 
1002
975
  @ReactMethod
@@ -1094,16 +1067,18 @@ class StripeSdkModule(
1094
1067
  promise.resolve(createMissingInitError())
1095
1068
  return
1096
1069
  }
1097
- FinancialConnectionsSheetFragment().also {
1098
- it.presentFinancialConnectionsSheet(
1070
+ unregisterStripeUIManager(financialConnectionsSheetManager)
1071
+ financialConnectionsSheetManager =
1072
+ FinancialConnectionsSheetManager(
1073
+ reactApplicationContext,
1099
1074
  clientSecret,
1100
- FinancialConnectionsSheetFragment.Mode.ForToken,
1075
+ FinancialConnectionsSheetManager.Mode.ForToken,
1101
1076
  publishableKey,
1102
1077
  stripeAccountId,
1103
- promise,
1104
- reactApplicationContext,
1105
- )
1106
- }
1078
+ ).also {
1079
+ registerStripeUIManager(it)
1080
+ it.present(promise)
1081
+ }
1107
1082
  }
1108
1083
 
1109
1084
  @ReactMethod
@@ -1116,16 +1091,19 @@ class StripeSdkModule(
1116
1091
  promise.resolve(createMissingInitError())
1117
1092
  return
1118
1093
  }
1119
- FinancialConnectionsSheetFragment().also {
1120
- it.presentFinancialConnectionsSheet(
1094
+
1095
+ unregisterStripeUIManager(financialConnectionsSheetManager)
1096
+ financialConnectionsSheetManager =
1097
+ FinancialConnectionsSheetManager(
1098
+ reactApplicationContext,
1121
1099
  clientSecret,
1122
- FinancialConnectionsSheetFragment.Mode.ForSession,
1100
+ FinancialConnectionsSheetManager.Mode.ForSession,
1123
1101
  publishableKey,
1124
1102
  stripeAccountId,
1125
- promise,
1126
- reactApplicationContext,
1127
- )
1128
- }
1103
+ ).also {
1104
+ registerStripeUIManager(it)
1105
+ it.present(promise)
1106
+ }
1129
1107
  }
1130
1108
 
1131
1109
  @ReactMethod
@@ -1139,25 +1117,11 @@ class StripeSdkModule(
1139
1117
  return
1140
1118
  }
1141
1119
 
1142
- getCurrentActivityOrResolveWithError(promise)?.let { activity ->
1143
- customerSheetFragment?.removeFragment(reactApplicationContext)
1144
- customerSheetFragment =
1145
- CustomerSheetFragment().also {
1146
- it.context = reactApplicationContext
1147
- it.initPromise = promise
1148
- val bundle = toBundleObject(params)
1149
- bundle.putBundle("customerAdapter", toBundleObject(customerAdapterOverrides))
1150
- it.arguments = bundle
1151
- }
1152
- try {
1153
- activity.supportFragmentManager
1154
- .beginTransaction()
1155
- .add(customerSheetFragment!!, CustomerSheetFragment.TAG)
1156
- .commit()
1157
- } catch (error: IllegalStateException) {
1158
- promise.resolve(createError(ErrorType.Failed.toString(), error.message))
1120
+ unregisterStripeUIManager(customerSheetManager)
1121
+ customerSheetManager =
1122
+ CustomerSheetManager(reactApplicationContext, params, customerAdapterOverrides, promise).also {
1123
+ registerStripeUIManager(it)
1159
1124
  }
1160
- }
1161
1125
  }
1162
1126
 
1163
1127
  @ReactMethod
@@ -1165,19 +1129,16 @@ class StripeSdkModule(
1165
1129
  params: ReadableMap,
1166
1130
  promise: Promise,
1167
1131
  ) {
1168
- var timeout: Long? = null
1169
- if (params.hasKey("timeout")) {
1170
- timeout = params.getInt("timeout").toLong()
1171
- }
1172
- customerSheetFragment?.present(timeout, promise) ?: run {
1173
- promise.resolve(CustomerSheetFragment.createMissingInitError())
1132
+ val timeout = params.getIntOrNull("timeout")?.toLong()
1133
+ customerSheetManager?.present(promise, timeout) ?: run {
1134
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1174
1135
  }
1175
1136
  }
1176
1137
 
1177
1138
  @ReactMethod
1178
1139
  override fun retrieveCustomerSheetPaymentOptionSelection(promise: Promise) {
1179
- customerSheetFragment?.retrievePaymentOptionSelection(promise) ?: run {
1180
- promise.resolve(CustomerSheetFragment.createMissingInitError())
1140
+ customerSheetManager?.retrievePaymentOptionSelection(promise) ?: run {
1141
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1181
1142
  }
1182
1143
  }
1183
1144
 
@@ -1186,7 +1147,7 @@ class StripeSdkModule(
1186
1147
  paymentMethodJsonObjects: ReadableArray,
1187
1148
  promise: Promise,
1188
1149
  ) {
1189
- customerSheetFragment?.let { fragment ->
1150
+ customerSheetManager?.let { fragment ->
1190
1151
  val paymentMethods = mutableListOf<PaymentMethod>()
1191
1152
  for (paymentMethodJson in paymentMethodJsonObjects.toArrayList()) {
1192
1153
  PaymentMethod.fromJson(JSONObject((paymentMethodJson as HashMap<*, *>)))?.let {
@@ -1200,7 +1161,7 @@ class StripeSdkModule(
1200
1161
  }
1201
1162
  fragment.customerAdapter?.fetchPaymentMethodsCallback?.complete(paymentMethods)
1202
1163
  } ?: run {
1203
- promise.resolve(CustomerSheetFragment.createMissingInitError())
1164
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1204
1165
  return
1205
1166
  }
1206
1167
  }
@@ -1210,7 +1171,7 @@ class StripeSdkModule(
1210
1171
  paymentMethodJson: ReadableMap,
1211
1172
  promise: Promise,
1212
1173
  ) {
1213
- customerSheetFragment?.let {
1174
+ customerSheetManager?.let {
1214
1175
  val paymentMethod =
1215
1176
  PaymentMethod.fromJson(JSONObject(paymentMethodJson.toHashMap() as HashMap<*, *>))
1216
1177
  if (paymentMethod == null) {
@@ -1222,7 +1183,7 @@ class StripeSdkModule(
1222
1183
  }
1223
1184
  it.customerAdapter?.attachPaymentMethodCallback?.complete(paymentMethod)
1224
1185
  } ?: run {
1225
- promise.resolve(CustomerSheetFragment.createMissingInitError())
1186
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1226
1187
  return
1227
1188
  }
1228
1189
  }
@@ -1232,7 +1193,7 @@ class StripeSdkModule(
1232
1193
  paymentMethodJson: ReadableMap,
1233
1194
  promise: Promise,
1234
1195
  ) {
1235
- customerSheetFragment?.let {
1196
+ customerSheetManager?.let {
1236
1197
  val paymentMethod =
1237
1198
  PaymentMethod.fromJson(JSONObject(paymentMethodJson.toHashMap() as HashMap<*, *>))
1238
1199
  if (paymentMethod == null) {
@@ -1244,17 +1205,17 @@ class StripeSdkModule(
1244
1205
  }
1245
1206
  it.customerAdapter?.detachPaymentMethodCallback?.complete(paymentMethod)
1246
1207
  } ?: run {
1247
- promise.resolve(CustomerSheetFragment.createMissingInitError())
1208
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1248
1209
  return
1249
1210
  }
1250
1211
  }
1251
1212
 
1252
1213
  @ReactMethod
1253
1214
  override fun customerAdapterSetSelectedPaymentOptionCallback(promise: Promise) {
1254
- customerSheetFragment?.let {
1215
+ customerSheetManager?.let {
1255
1216
  it.customerAdapter?.setSelectedPaymentOptionCallback?.complete(Unit)
1256
1217
  } ?: run {
1257
- promise.resolve(CustomerSheetFragment.createMissingInitError())
1218
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1258
1219
  return
1259
1220
  }
1260
1221
  }
@@ -1264,10 +1225,10 @@ class StripeSdkModule(
1264
1225
  paymentOption: String?,
1265
1226
  promise: Promise,
1266
1227
  ) {
1267
- customerSheetFragment?.let {
1228
+ customerSheetManager?.let {
1268
1229
  it.customerAdapter?.fetchSelectedPaymentOptionCallback?.complete(paymentOption)
1269
1230
  } ?: run {
1270
- promise.resolve(CustomerSheetFragment.createMissingInitError())
1231
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1271
1232
  return
1272
1233
  }
1273
1234
  }
@@ -1277,10 +1238,52 @@ class StripeSdkModule(
1277
1238
  clientSecret: String,
1278
1239
  promise: Promise,
1279
1240
  ) {
1280
- customerSheetFragment?.let {
1241
+ customerSheetManager?.let {
1281
1242
  it.customerAdapter?.setupIntentClientSecretForCustomerAttachCallback?.complete(clientSecret)
1282
1243
  } ?: run {
1283
- promise.resolve(CustomerSheetFragment.createMissingInitError())
1244
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1245
+ return
1246
+ }
1247
+ }
1248
+
1249
+ @ReactMethod
1250
+ override fun clientSecretProviderSetupIntentClientSecretCallback(
1251
+ setupIntentClientSecret: String,
1252
+ promise: Promise,
1253
+ ) {
1254
+ customerSheetManager?.let {
1255
+ it.customerSessionProvider?.provideSetupIntentClientSecretCallback?.complete(setupIntentClientSecret)
1256
+ } ?: run {
1257
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1258
+ return
1259
+ }
1260
+ }
1261
+
1262
+ @ReactMethod
1263
+ override fun clientSecretProviderCustomerSessionClientSecretCallback(
1264
+ customerSessionClientSecretJson: ReadableMap,
1265
+ promise: Promise,
1266
+ ) {
1267
+ val clientSecret = customerSessionClientSecretJson.getString("clientSecret")
1268
+ val customerId = customerSessionClientSecretJson.getString("customerId")
1269
+
1270
+ if (clientSecret.isNullOrEmpty() || customerId.isNullOrEmpty()) {
1271
+ Log.e(
1272
+ "StripeReactNative",
1273
+ "Invalid CustomerSessionClientSecret format",
1274
+ )
1275
+ return
1276
+ }
1277
+
1278
+ customerSheetManager?.let {
1279
+ it.customerSessionProvider?.providesCustomerSessionClientSecretCallback?.complete(
1280
+ CustomerSheet.CustomerSessionClientSecret.create(
1281
+ customerId = customerId,
1282
+ clientSecret = clientSecret,
1283
+ ),
1284
+ )
1285
+ } ?: run {
1286
+ promise.resolve(CustomerSheetManager.createMissingInitError())
1284
1287
  return
1285
1288
  }
1286
1289
  }