@stripe/stripe-react-native 0.39.0 → 0.40.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/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.40.0 - 2024-11-19
6
+
7
+ **Breaking changes**
8
+
9
+ - Removed support for FPX payments via the bank picker UI. If you'd like to accept FPX payments, we recommend using [Mobile Payment Element](https://docs.stripe.com/payments/accept-a-payment?platform=react-native). Also see the [FPX Payment guide](https://docs.stripe.com/payments/fpx/accept-a-payment?web-or-mobile=mobile) for more info on how to integrate FPX specifically.
10
+
11
+ **Features**
12
+
13
+ - `CustomerSheet` is now generally available!
14
+ - If you were using `CustomerSheetBeta`, change that to `CustomerSheet`.
15
+ - If you were using `CustomerSheetBeta.CustomerSheet`, change that to `CustomerSheet.Component`
16
+ - Enabled vertical mode
17
+
5
18
  ## 0.39.0 - 2024-10-15
6
19
 
7
20
  **Features**
@@ -55,6 +55,7 @@ class PaymentSheetFragment(
55
55
  }
56
56
  }
57
57
 
58
+ @OptIn(ExperimentalPaymentMethodLayoutApi::class)
58
59
  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
59
60
  super.onViewCreated(view, savedInstanceState)
60
61
  val merchantDisplayName = arguments?.getString("merchantDisplayName").orEmpty()
@@ -209,6 +210,10 @@ class PaymentSheetFragment(
209
210
  configurationBuilder.paymentMethodOrder(it)
210
211
  }
211
212
 
213
+ configurationBuilder.paymentMethodLayout(
214
+ mapToPaymentMethodLayout(arguments?.getString("paymentMethodLayout"))
215
+ )
216
+
212
217
  paymentSheetConfiguration = configurationBuilder.build()
213
218
 
214
219
  if (arguments?.getBoolean("customFlow") == true) {
@@ -490,6 +495,14 @@ fun mapToCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConf
490
495
  }
491
496
  }
492
497
 
498
+ fun mapToPaymentMethodLayout(str: String?): PaymentSheet.PaymentMethodLayout {
499
+ return when (str) {
500
+ "Horizontal" -> PaymentSheet.PaymentMethodLayout.Horizontal
501
+ "Vertical" -> PaymentSheet.PaymentMethodLayout.Vertical
502
+ else -> PaymentSheet.PaymentMethodLayout.Automatic
503
+ }
504
+ }
505
+
493
506
  fun mapToAddressCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode {
494
507
  return when (str) {
495
508
  "automatic" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
@@ -18,7 +18,6 @@ import com.stripe.android.googlepaylauncher.GooglePayLauncher
18
18
  import com.stripe.android.model.*
19
19
  import com.stripe.android.payments.bankaccount.CollectBankAccountConfiguration
20
20
  import com.stripe.android.paymentsheet.PaymentSheet
21
- import com.stripe.android.view.AddPaymentMethodActivityStarter
22
21
  import kotlinx.coroutines.CoroutineScope
23
22
  import kotlinx.coroutines.Dispatchers
24
23
  import kotlinx.coroutines.launch
@@ -77,14 +76,6 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
77
76
  }
78
77
  else -> {
79
78
  dispatchActivityResultsToFragments(requestCode, resultCode, data)
80
- try {
81
- val result = AddPaymentMethodActivityStarter.Result.fromIntent(data)
82
- if (data?.getParcelableExtra<Parcelable>("extra_activity_result") != null) {
83
- onFpxPaymentMethodResult(result)
84
- }
85
- } catch (e: java.lang.Exception) {
86
- Log.d("StripeReactNative", e.localizedMessage ?: e.toString())
87
- }
88
79
  }
89
80
  }
90
81
  }
@@ -219,48 +210,6 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
219
210
  paymentSheetFragment?.paymentSheetIntentCreationCallback?.complete(params)
220
211
  }
221
212
 
222
- private fun payWithFpx() {
223
- getCurrentActivityOrResolveWithError(confirmPromise)?.let {
224
- AddPaymentMethodActivityStarter(it)
225
- .startForResult(AddPaymentMethodActivityStarter.Args.Builder()
226
- .setPaymentMethodType(PaymentMethod.Type.Fpx)
227
- .build()
228
- )
229
- }
230
- }
231
-
232
- private fun onFpxPaymentMethodResult(result: AddPaymentMethodActivityStarter.Result) {
233
- when (result) {
234
- is AddPaymentMethodActivityStarter.Result.Success -> {
235
- if (confirmPaymentClientSecret != null && confirmPromise != null) {
236
- paymentLauncherFragment = PaymentLauncherFragment.forPayment(
237
- context = reactApplicationContext,
238
- stripe,
239
- publishableKey,
240
- stripeAccountId,
241
- confirmPromise!!,
242
- confirmPaymentClientSecret!!,
243
- ConfirmPaymentIntentParams.createWithPaymentMethodId(
244
- result.paymentMethod.id!!,
245
- confirmPaymentClientSecret!!
246
- )
247
- )
248
- } else {
249
- Log.e("StripeReactNative", "FPX payment failed. Promise and/or client secret is not set.")
250
- confirmPromise?.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), "FPX payment failed. Client secret is not set."))
251
- }
252
- }
253
- is AddPaymentMethodActivityStarter.Result.Failure -> {
254
- confirmPromise?.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), result.exception))
255
- }
256
- is AddPaymentMethodActivityStarter.Result.Canceled -> {
257
- confirmPromise?.resolve(createError(ConfirmPaymentErrorType.Canceled.toString(), "The payment has been canceled"))
258
- }
259
- }
260
- this.confirmPaymentClientSecret = null
261
- this.confirmPromise = null
262
- }
263
-
264
213
  @ReactMethod
265
214
  fun createPaymentMethod(data: ReadableMap, options: ReadableMap, promise: Promise) {
266
215
  val paymentMethodType = getValOr(data, "paymentMethodType")?.let { mapToPaymentMethodType(it) } ?: run {
@@ -460,15 +409,6 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
460
409
  else
461
410
  null // Expect that payment method was attached on the server
462
411
 
463
- val testOfflineBank = getBooleanOrFalse(params, "testOfflineBank")
464
-
465
- if (paymentMethodType == PaymentMethod.Type.Fpx && !testOfflineBank) {
466
- confirmPaymentClientSecret = paymentIntentClientSecret
467
- confirmPromise = promise
468
- payWithFpx()
469
- return
470
- }
471
-
472
412
  // if (paymentMethodType == PaymentMethod.Type.WeChatPay) {
473
413
  // val appId = getValOr(params, "appId") ?: run {
474
414
  // promise.resolve(createError("Failed", "You must provide appId"))
@@ -194,21 +194,4 @@ class CardFieldView: UIView, STPPaymentCardTextFieldDelegate {
194
194
  required init?(coder: NSCoder) {
195
195
  fatalError("init(coder:) has not been implemented")
196
196
  }
197
-
198
- func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
199
- //
200
- }
201
-
202
- func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
203
- //
204
- }
205
-
206
- func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPPaymentStatusBlock) {
207
- //
208
- }
209
-
210
- func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
211
- //
212
- }
213
-
214
197
  }
@@ -116,6 +116,15 @@ extension StripeSdk {
116
116
  if let paymentMethodOrder = params["paymentMethodOrder"] as? Array<String> {
117
117
  configuration.paymentMethodOrder = paymentMethodOrder
118
118
  }
119
+
120
+ switch params["paymentMethodLayout"] as? String? {
121
+ case "Horizontal":
122
+ configuration.paymentMethodLayout = .horizontal
123
+ case "Vertical":
124
+ configuration.paymentMethodLayout = .vertical
125
+ default:
126
+ configuration.paymentMethodLayout = .automatic
127
+ }
119
128
 
120
129
  return (nil, configuration)
121
130
  }
@@ -5,7 +5,7 @@ import StripeFinancialConnections
5
5
  import Foundation
6
6
 
7
7
  @objc(StripeSdk)
8
- class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdaptivePresentationControllerDelegate {
8
+ class StripeSdk: RCTEventEmitter, UIAdaptivePresentationControllerDelegate {
9
9
  public var cardFieldView: CardFieldView? = nil
10
10
  public var cardFormView: CardFormView? = nil
11
11
 
@@ -14,21 +14,21 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
14
14
  internal var paymentSheet: PaymentSheet?
15
15
  internal var paymentSheetFlowController: PaymentSheet.FlowController?
16
16
  var paymentSheetIntentCreationCallback: ((Result<String, Error>) -> Void)?
17
-
17
+
18
18
  var urlScheme: String? = nil
19
-
19
+
20
20
  var confirmPaymentResolver: RCTPromiseResolveBlock? = nil
21
-
21
+
22
22
  var confirmApplePayResolver: RCTPromiseResolveBlock? = nil
23
23
  var confirmApplePayPaymentClientSecret: String? = nil
24
24
  var confirmApplePaySetupClientSecret: String? = nil
25
25
  var confirmApplePayPaymentMethod: STPPaymentMethod? = nil
26
-
26
+
27
27
  var applePaymentAuthorizationController: PKPaymentAuthorizationViewController? = nil
28
28
  var createPlatformPayPaymentMethodResolver: RCTPromiseResolveBlock? = nil
29
29
  var platformPayUsesDeprecatedTokenFlow = false
30
30
  var applePaymentMethodFlowCanBeCanceled = false
31
-
31
+
32
32
  var confirmPaymentClientSecret: String? = nil
33
33
 
34
34
  var shippingMethodUpdateCompletion: ((PKPaymentRequestShippingMethodUpdate) -> Void)? = nil
@@ -48,7 +48,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
48
48
  var applePayShippingMethods: [PKShippingMethod] = []
49
49
  var applePayShippingAddressErrors: [Error]? = nil
50
50
  var applePayCouponCodeErrors: [Error]? = nil
51
-
51
+
52
52
  var customerSheetConfiguration = CustomerSheet.Configuration()
53
53
  var customerSheet: CustomerSheet? = nil
54
54
  var customerAdapter: StripeCustomerAdapter? = nil
@@ -59,7 +59,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
59
59
  var setSelectedPaymentOptionCallback: (() -> Void)? = nil
60
60
  var fetchSelectedPaymentOptionCallback: ((CustomerPaymentOption?) -> Void)? = nil
61
61
  var setupIntentClientSecretForCustomerAttachCallback: ((String) -> Void)? = nil
62
-
62
+
63
63
  var hasEventListeners = false
64
64
  override func startObserving() {
65
65
  hasEventListeners = true
@@ -67,7 +67,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
67
67
  override func stopObserving() {
68
68
  hasEventListeners = false
69
69
  }
70
-
70
+
71
71
  override func supportedEvents() -> [String]! {
72
72
  return ["onOrderTrackingCallback", "onConfirmHandlerCallback", "onCustomerAdapterFetchPaymentMethodsCallback", "onCustomerAdapterAttachPaymentMethodCallback",
73
73
  "onCustomerAdapterDetachPaymentMethodCallback", "onCustomerAdapterSetSelectedPaymentOptionCallback", "onCustomerAdapterFetchSelectedPaymentOptionCallback",
@@ -124,10 +124,10 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
124
124
  resolve(error)
125
125
  return
126
126
  }
127
-
127
+
128
128
  preparePaymentSheetInstance(params: params, configuration: configuration, resolve: resolve)
129
129
  }
130
-
130
+
131
131
  @objc(intentCreationCallback:resolver:rejecter:)
132
132
  func intentCreationCallback(result: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock,
133
133
  rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
@@ -174,7 +174,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
174
174
  }
175
175
  }
176
176
  }
177
-
177
+
178
178
  @objc(resetPaymentSheetCustomer:rejecter:)
179
179
  func resetPaymentSheetCustomer(resolver resolve: @escaping RCTPromiseResolveBlock,
180
180
  rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
@@ -187,7 +187,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
187
187
  resolver resolve: @escaping RCTPromiseResolveBlock,
188
188
  rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
189
189
  var paymentSheetViewController: UIViewController?
190
-
190
+
191
191
  if let timeout = options["timeout"] as? Double {
192
192
  DispatchQueue.main.asyncAfter(deadline: .now() + timeout/1000) {
193
193
  if let paymentSheetViewController = paymentSheetViewController {
@@ -278,7 +278,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
278
278
  err = Errors.createError(ErrorType.Failed, error as NSError?)
279
279
  }
280
280
  }
281
-
281
+
282
282
  parameters.mandateData = factory.createMandateData()
283
283
 
284
284
  return parameters
@@ -330,28 +330,28 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
330
330
  }
331
331
  return false
332
332
  }()
333
-
333
+
334
334
  if (shippingMethodUpdateCompletion == nil && shippingContactUpdateCompletion == nil && couponUpdateHandlerIsNil) {
335
335
  resolve(Errors.createError(ErrorType.Failed, "You can use this method only after either onShippingContactSelected, onShippingMethodSelected, or onCouponCodeEntered callbacks are triggered"))
336
336
  return
337
337
  }
338
-
338
+
339
339
  do {
340
340
  applePaySummaryItems = try ApplePayUtils.buildPaymentSummaryItems(items: summaryItems as? [[String : Any]])
341
341
  } catch {
342
342
  resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
343
343
  return
344
344
  }
345
-
345
+
346
346
  applePayShippingMethods = ApplePayUtils.buildShippingMethods(items: shippingMethods as? [[String : Any]])
347
-
347
+
348
348
  do {
349
349
  (applePayShippingAddressErrors, applePayCouponCodeErrors) = try ApplePayUtils.buildApplePayErrors(errorItems: errors)
350
350
  } catch {
351
351
  resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
352
352
  return
353
353
  }
354
-
354
+
355
355
 
356
356
  shippingMethodUpdateCompletion?(PKPaymentRequestShippingMethodUpdate.init(paymentSummaryItems: applePaySummaryItems))
357
357
  shippingContactUpdateCompletion?(PKPaymentRequestShippingContactUpdate.init(errors: applePayShippingAddressErrors, paymentSummaryItems: applePaySummaryItems, shippingMethods: applePayShippingMethods))
@@ -386,14 +386,14 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
386
386
  }
387
387
  }
388
388
  }
389
-
389
+
390
390
  @objc(isPlatformPaySupported:resolver:rejecter:)
391
391
  func isPlatformPaySupported(params: NSDictionary,
392
392
  resolver resolve: @escaping RCTPromiseResolveBlock,
393
393
  rejecter reject: @escaping RCTPromiseRejectBlock) {
394
394
  resolve(StripeAPI.deviceSupportsApplePay())
395
395
  }
396
-
396
+
397
397
  @objc(createPlatformPayPaymentMethod:usesDeprecatedTokenFlow:resolver:rejecter:)
398
398
  func createPlatformPayPaymentMethod(params: NSDictionary,
399
399
  usesDeprecatedTokenFlow: Bool,
@@ -408,7 +408,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
408
408
  resolve(error)
409
409
  return
410
410
  }
411
-
411
+
412
412
  self.applePaySummaryItems = paymentRequest.paymentSummaryItems
413
413
  self.applePayShippingMethods = paymentRequest.shippingMethods ?? []
414
414
  self.applePayShippingAddressErrors = nil
@@ -431,13 +431,13 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
431
431
  resolve(Errors.createError(ErrorType.Failed, "Invalid in-app payment request. Search the iOS logs for `NSUnderlyingError` to get more information."))
432
432
  }
433
433
  }
434
-
434
+
435
435
  @objc(dismissPlatformPay:rejecter:)
436
436
  func dismissPlatformPay(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
437
437
  let didDismiss = maybeDismissApplePay()
438
438
  resolve(didDismiss)
439
439
  }
440
-
440
+
441
441
  @objc(confirmPlatformPay:params:isPaymentIntent:resolver:rejecter:)
442
442
  func confirmPlatformPay(
443
443
  clientSecret: String?,
@@ -475,7 +475,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
475
475
  resolve(Errors.createError(ErrorType.Failed, "Payment not completed"))
476
476
  }
477
477
  }
478
-
478
+
479
479
  func configure3dSecure(_ params: NSDictionary) {
480
480
  let threeDSCustomizationSettings = STPPaymentHandler.shared().threeDSCustomizationSettings
481
481
  let uiCustomization = Mappers.mapUICustomization(params)
@@ -695,7 +695,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
695
695
  }
696
696
  }
697
697
  }
698
-
698
+
699
699
  @objc(collectBankAccount:clientSecret:params:resolver:rejecter:)
700
700
  func collectBankAccount(
701
701
  isPaymentIntent: Bool,
@@ -806,14 +806,6 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
806
806
  return
807
807
  }
808
808
 
809
- if (paymentMethodType == .FPX) {
810
- let testOfflineBank = paymentMethodData?["testOfflineBank"] as? Bool
811
- if (testOfflineBank == false || testOfflineBank == nil) {
812
- payWithFPX(paymentIntentClientSecret)
813
- return
814
- }
815
- }
816
-
817
809
  let (error, paymentIntentParams) = createPaymentIntentParams(paymentIntentClientSecret: paymentIntentClientSecret, paymentMethodType: paymentMethodType, paymentMethodData: paymentMethodData, options: options)
818
810
 
819
811
  if (error != nil) {
@@ -864,14 +856,14 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
864
856
  err = Errors.createError(ErrorType.Failed, error as NSError?)
865
857
  }
866
858
  }
867
-
859
+
868
860
  do {
869
861
  parameters.paymentMethodOptions = try factory.createOptions(paymentMethodType: paymentMethodType)
870
862
  parameters.mandateData = factory.createMandateData()
871
863
  } catch {
872
864
  err = Errors.createError(ErrorType.Failed, error as NSError?)
873
865
  }
874
-
866
+
875
867
  return parameters
876
868
  }
877
869
  }()
@@ -1071,7 +1063,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
1071
1063
  }
1072
1064
  FinancialConnections.present(withClientSecret: clientSecret, returnURL: returnURL, resolve: resolve)
1073
1065
  }
1074
-
1066
+
1075
1067
  @objc(configureOrderTracking:orderIdentifier:webServiceUrl:authenticationToken:resolver:rejecter:)
1076
1068
  func configureOrderTracking(
1077
1069
  orderTypeIdentifier: String,
@@ -1102,35 +1094,6 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
1102
1094
  confirmPaymentResolver?(Errors.createError(ErrorType.Canceled, "FPX Payment has been canceled"))
1103
1095
  }
1104
1096
 
1105
- func payWithFPX(_ paymentIntentClientSecret: String) {
1106
- let vc = STPBankSelectionViewController.init(bankMethod: .FPX)
1107
-
1108
- vc.delegate = self
1109
-
1110
- DispatchQueue.main.async {
1111
- vc.presentationController?.delegate = self
1112
-
1113
- let share = UIApplication.shared.delegate
1114
- share?.window??.rootViewController?.present(vc, animated: true)
1115
- }
1116
- }
1117
-
1118
- func bankSelectionViewController(_ bankViewController: STPBankSelectionViewController, didCreatePaymentMethodParams paymentMethodParams: STPPaymentMethodParams) {
1119
- guard let clientSecret = confirmPaymentClientSecret else {
1120
- confirmPaymentResolver?(Errors.createError(ErrorType.Failed, "Missing paymentIntentClientSecret"))
1121
- return
1122
- }
1123
- let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
1124
- paymentIntentParams.paymentMethodParams = paymentMethodParams
1125
-
1126
- if let urlScheme = urlScheme {
1127
- paymentIntentParams.returnURL = Mappers.mapToReturnURL(urlScheme: urlScheme)
1128
- }
1129
- let paymentHandler = STPPaymentHandler.shared()
1130
- bankViewController.dismiss(animated: true)
1131
- paymentHandler.confirmPayment(paymentIntentParams, with: self, completion: onCompleteConfirmPayment)
1132
- }
1133
-
1134
1097
  func onCompleteConfirmPayment(status: STPPaymentHandlerActionStatus, paymentIntent: STPPaymentIntent?, error: NSError?) {
1135
1098
  self.confirmPaymentClientSecret = nil
1136
1099
  switch (status) {
@@ -1,2 +1,2 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.CustomerSheetBeta=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _NativeStripeSdk=_interopRequireDefault(require("../NativeStripeSdk"));var eventEmitter=new _reactNative.NativeEventEmitter(_reactNative.NativeModules.StripeSdk);var fetchPaymentMethodsCallback=null;var attachPaymentMethodCallback=null;var detachPaymentMethodCallback=null;var setSelectedPaymentOptionCallback=null;var fetchSelectedPaymentOptionCallback=null;var setupIntentClientSecretForCustomerAttachCallback=null;var initialize=function(){var _ref=(0,_asyncToGenerator2.default)(function*(params){var customerAdapterOverrides={};if(params.customerAdapter){customerAdapterOverrides=configureCustomerAdapterEventListeners(params.customerAdapter);}try{var _yield$NativeStripeSd=yield _NativeStripeSdk.default.initCustomerSheet(params,customerAdapterOverrides),error=_yield$NativeStripeSd.error;if(error){return{error:error};}return{};}catch(error){return{error:error};}});return function initialize(_x){return _ref.apply(this,arguments);};}();var configureCustomerAdapterEventListeners=function configureCustomerAdapterEventListeners(customerAdapter){if(customerAdapter.fetchPaymentMethods){var _fetchPaymentMethodsC;(_fetchPaymentMethodsC=fetchPaymentMethodsCallback)==null?void 0:_fetchPaymentMethodsC.remove();fetchPaymentMethodsCallback=eventEmitter.addListener('onCustomerAdapterFetchPaymentMethodsCallback',(0,_asyncToGenerator2.default)(function*(){if(customerAdapter.fetchPaymentMethods){var paymentMethods=yield customerAdapter.fetchPaymentMethods();yield _NativeStripeSdk.default.customerAdapterFetchPaymentMethodsCallback(paymentMethods);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `fetchPaymentMethods` on your CustomerAdapter, but no matching method was found.');}}));}if(customerAdapter.attachPaymentMethod){var _attachPaymentMethodC;(_attachPaymentMethodC=attachPaymentMethodCallback)==null?void 0:_attachPaymentMethodC.remove();attachPaymentMethodCallback=eventEmitter.addListener('onCustomerAdapterAttachPaymentMethodCallback',function(){var _ref4=(0,_asyncToGenerator2.default)(function*(_ref3){var paymentMethodId=_ref3.paymentMethodId;if(customerAdapter.attachPaymentMethod){var paymentMethod=yield customerAdapter.attachPaymentMethod(paymentMethodId);yield _NativeStripeSdk.default.customerAdapterAttachPaymentMethodCallback(paymentMethod);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `attachPaymentMethod` on your CustomerAdapter, but no matching method was found.');}});return function(_x2){return _ref4.apply(this,arguments);};}());}if(customerAdapter.detachPaymentMethod){var _detachPaymentMethodC;(_detachPaymentMethodC=detachPaymentMethodCallback)==null?void 0:_detachPaymentMethodC.remove();detachPaymentMethodCallback=eventEmitter.addListener('onCustomerAdapterDetachPaymentMethodCallback',function(){var _ref6=(0,_asyncToGenerator2.default)(function*(_ref5){var paymentMethodId=_ref5.paymentMethodId;if(customerAdapter.detachPaymentMethod){var paymentMethod=yield customerAdapter.detachPaymentMethod(paymentMethodId);yield _NativeStripeSdk.default.customerAdapterDetachPaymentMethodCallback(paymentMethod);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `detachPaymentMethod` on your CustomerAdapter, but no matching method was found.');}});return function(_x3){return _ref6.apply(this,arguments);};}());}if(customerAdapter.setSelectedPaymentOption){var _setSelectedPaymentOp;(_setSelectedPaymentOp=setSelectedPaymentOptionCallback)==null?void 0:_setSelectedPaymentOp.remove();setSelectedPaymentOptionCallback=eventEmitter.addListener('onCustomerAdapterSetSelectedPaymentOptionCallback',function(){var _ref8=(0,_asyncToGenerator2.default)(function*(_ref7){var paymentOption=_ref7.paymentOption;if(customerAdapter.setSelectedPaymentOption){yield customerAdapter.setSelectedPaymentOption(paymentOption);yield _NativeStripeSdk.default.customerAdapterSetSelectedPaymentOptionCallback();}else{throw new Error('[@stripe/stripe-react-native] Tried to call `setSelectedPaymentOption` on your CustomerAdapter, but no matching method was found.');}});return function(_x4){return _ref8.apply(this,arguments);};}());}if(customerAdapter.fetchSelectedPaymentOption){var _fetchSelectedPayment;(_fetchSelectedPayment=fetchSelectedPaymentOptionCallback)==null?void 0:_fetchSelectedPayment.remove();fetchSelectedPaymentOptionCallback=eventEmitter.addListener('onCustomerAdapterFetchSelectedPaymentOptionCallback',(0,_asyncToGenerator2.default)(function*(){if(customerAdapter.fetchSelectedPaymentOption){var paymentOption=yield customerAdapter.fetchSelectedPaymentOption();yield _NativeStripeSdk.default.customerAdapterFetchSelectedPaymentOptionCallback(paymentOption);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `fetchSelectedPaymentOption` on your CustomerAdapter, but no matching method was found.');}}));}if(customerAdapter.setupIntentClientSecretForCustomerAttach){var _setupIntentClientSec;(_setupIntentClientSec=setupIntentClientSecretForCustomerAttachCallback)==null?void 0:_setupIntentClientSec.remove();setupIntentClientSecretForCustomerAttachCallback=eventEmitter.addListener('onCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback',(0,_asyncToGenerator2.default)(function*(){if(customerAdapter.setupIntentClientSecretForCustomerAttach){var clientSecret=yield customerAdapter.setupIntentClientSecretForCustomerAttach();yield _NativeStripeSdk.default.customerAdapterSetupIntentClientSecretForCustomerAttachCallback(clientSecret);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `setupIntentClientSecretForCustomerAttach` on your CustomerAdapter, but no matching method was found.');}}));}return{fetchPaymentMethods:!!customerAdapter.fetchPaymentMethods,attachPaymentMethod:!!customerAdapter.attachPaymentMethod,detachPaymentMethod:!!customerAdapter.detachPaymentMethod,setSelectedPaymentOption:!!customerAdapter.setSelectedPaymentOption,fetchSelectedPaymentOption:!!customerAdapter.fetchSelectedPaymentOption,setupIntentClientSecretForCustomerAttach:!!customerAdapter.setupIntentClientSecretForCustomerAttach};};var present=function(){var _ref11=(0,_asyncToGenerator2.default)(function*(){var params=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};try{return yield _NativeStripeSdk.default.presentCustomerSheet(params);}catch(error){return{error:error};}});return function present(){return _ref11.apply(this,arguments);};}();var retrievePaymentOptionSelection=function(){var _ref12=(0,_asyncToGenerator2.default)(function*(){try{return yield _NativeStripeSdk.default.retrieveCustomerSheetPaymentOptionSelection();}catch(error){return{error:error};}});return function retrievePaymentOptionSelection(){return _ref12.apply(this,arguments);};}();function CustomerSheet(_ref13){var visible=_ref13.visible,presentationStyle=_ref13.presentationStyle,animationStyle=_ref13.animationStyle,style=_ref13.style,appearance=_ref13.appearance,setupIntentClientSecret=_ref13.setupIntentClientSecret,customerId=_ref13.customerId,customerEphemeralKeySecret=_ref13.customerEphemeralKeySecret,merchantDisplayName=_ref13.merchantDisplayName,headerTextForSelectionScreen=_ref13.headerTextForSelectionScreen,defaultBillingDetails=_ref13.defaultBillingDetails,billingDetailsCollectionConfiguration=_ref13.billingDetailsCollectionConfiguration,returnURL=_ref13.returnURL,removeSavedPaymentMethodMessage=_ref13.removeSavedPaymentMethodMessage,applePayEnabled=_ref13.applePayEnabled,googlePayEnabled=_ref13.googlePayEnabled,timeout=_ref13.timeout,onResult=_ref13.onResult,customerAdapter=_ref13.customerAdapter;_react.default.useEffect(function(){if(visible){initialize({style:style,appearance:appearance,setupIntentClientSecret:setupIntentClientSecret,customerId:customerId,customerEphemeralKeySecret:customerEphemeralKeySecret,merchantDisplayName:merchantDisplayName,headerTextForSelectionScreen:headerTextForSelectionScreen,defaultBillingDetails:defaultBillingDetails,billingDetailsCollectionConfiguration:billingDetailsCollectionConfiguration,returnURL:returnURL,removeSavedPaymentMethodMessage:removeSavedPaymentMethodMessage,applePayEnabled:applePayEnabled,googlePayEnabled:googlePayEnabled,customerAdapter:customerAdapter}).then(function(initResult){if(initResult.error){onResult(initResult);}else{present({timeout:timeout,presentationStyle:presentationStyle,animationStyle:animationStyle}).then(function(presentResult){onResult(presentResult);});}});}},[visible]);return null;}var CustomerSheetBeta={CustomerSheet:CustomerSheet,initialize:initialize,present:present,retrievePaymentOptionSelection:retrievePaymentOptionSelection};exports.CustomerSheetBeta=CustomerSheetBeta;
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.CustomerSheet=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _NativeStripeSdk=_interopRequireDefault(require("../NativeStripeSdk"));var eventEmitter=new _reactNative.NativeEventEmitter(_reactNative.NativeModules.StripeSdk);var fetchPaymentMethodsCallback=null;var attachPaymentMethodCallback=null;var detachPaymentMethodCallback=null;var setSelectedPaymentOptionCallback=null;var fetchSelectedPaymentOptionCallback=null;var setupIntentClientSecretForCustomerAttachCallback=null;var initialize=function(){var _ref=(0,_asyncToGenerator2.default)(function*(params){var customerAdapterOverrides={};if(params.customerAdapter){customerAdapterOverrides=configureCustomerAdapterEventListeners(params.customerAdapter);}try{var _yield$NativeStripeSd=yield _NativeStripeSdk.default.initCustomerSheet(params,customerAdapterOverrides),error=_yield$NativeStripeSd.error;if(error){return{error:error};}return{};}catch(error){return{error:error};}});return function initialize(_x){return _ref.apply(this,arguments);};}();var configureCustomerAdapterEventListeners=function configureCustomerAdapterEventListeners(customerAdapter){if(customerAdapter.fetchPaymentMethods){var _fetchPaymentMethodsC;(_fetchPaymentMethodsC=fetchPaymentMethodsCallback)==null?void 0:_fetchPaymentMethodsC.remove();fetchPaymentMethodsCallback=eventEmitter.addListener('onCustomerAdapterFetchPaymentMethodsCallback',(0,_asyncToGenerator2.default)(function*(){if(customerAdapter.fetchPaymentMethods){var paymentMethods=yield customerAdapter.fetchPaymentMethods();yield _NativeStripeSdk.default.customerAdapterFetchPaymentMethodsCallback(paymentMethods);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `fetchPaymentMethods` on your CustomerAdapter, but no matching method was found.');}}));}if(customerAdapter.attachPaymentMethod){var _attachPaymentMethodC;(_attachPaymentMethodC=attachPaymentMethodCallback)==null?void 0:_attachPaymentMethodC.remove();attachPaymentMethodCallback=eventEmitter.addListener('onCustomerAdapterAttachPaymentMethodCallback',function(){var _ref4=(0,_asyncToGenerator2.default)(function*(_ref3){var paymentMethodId=_ref3.paymentMethodId;if(customerAdapter.attachPaymentMethod){var paymentMethod=yield customerAdapter.attachPaymentMethod(paymentMethodId);yield _NativeStripeSdk.default.customerAdapterAttachPaymentMethodCallback(paymentMethod);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `attachPaymentMethod` on your CustomerAdapter, but no matching method was found.');}});return function(_x2){return _ref4.apply(this,arguments);};}());}if(customerAdapter.detachPaymentMethod){var _detachPaymentMethodC;(_detachPaymentMethodC=detachPaymentMethodCallback)==null?void 0:_detachPaymentMethodC.remove();detachPaymentMethodCallback=eventEmitter.addListener('onCustomerAdapterDetachPaymentMethodCallback',function(){var _ref6=(0,_asyncToGenerator2.default)(function*(_ref5){var paymentMethodId=_ref5.paymentMethodId;if(customerAdapter.detachPaymentMethod){var paymentMethod=yield customerAdapter.detachPaymentMethod(paymentMethodId);yield _NativeStripeSdk.default.customerAdapterDetachPaymentMethodCallback(paymentMethod);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `detachPaymentMethod` on your CustomerAdapter, but no matching method was found.');}});return function(_x3){return _ref6.apply(this,arguments);};}());}if(customerAdapter.setSelectedPaymentOption){var _setSelectedPaymentOp;(_setSelectedPaymentOp=setSelectedPaymentOptionCallback)==null?void 0:_setSelectedPaymentOp.remove();setSelectedPaymentOptionCallback=eventEmitter.addListener('onCustomerAdapterSetSelectedPaymentOptionCallback',function(){var _ref8=(0,_asyncToGenerator2.default)(function*(_ref7){var paymentOption=_ref7.paymentOption;if(customerAdapter.setSelectedPaymentOption){yield customerAdapter.setSelectedPaymentOption(paymentOption);yield _NativeStripeSdk.default.customerAdapterSetSelectedPaymentOptionCallback();}else{throw new Error('[@stripe/stripe-react-native] Tried to call `setSelectedPaymentOption` on your CustomerAdapter, but no matching method was found.');}});return function(_x4){return _ref8.apply(this,arguments);};}());}if(customerAdapter.fetchSelectedPaymentOption){var _fetchSelectedPayment;(_fetchSelectedPayment=fetchSelectedPaymentOptionCallback)==null?void 0:_fetchSelectedPayment.remove();fetchSelectedPaymentOptionCallback=eventEmitter.addListener('onCustomerAdapterFetchSelectedPaymentOptionCallback',(0,_asyncToGenerator2.default)(function*(){if(customerAdapter.fetchSelectedPaymentOption){var paymentOption=yield customerAdapter.fetchSelectedPaymentOption();yield _NativeStripeSdk.default.customerAdapterFetchSelectedPaymentOptionCallback(paymentOption);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `fetchSelectedPaymentOption` on your CustomerAdapter, but no matching method was found.');}}));}if(customerAdapter.setupIntentClientSecretForCustomerAttach){var _setupIntentClientSec;(_setupIntentClientSec=setupIntentClientSecretForCustomerAttachCallback)==null?void 0:_setupIntentClientSec.remove();setupIntentClientSecretForCustomerAttachCallback=eventEmitter.addListener('onCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback',(0,_asyncToGenerator2.default)(function*(){if(customerAdapter.setupIntentClientSecretForCustomerAttach){var clientSecret=yield customerAdapter.setupIntentClientSecretForCustomerAttach();yield _NativeStripeSdk.default.customerAdapterSetupIntentClientSecretForCustomerAttachCallback(clientSecret);}else{throw new Error('[@stripe/stripe-react-native] Tried to call `setupIntentClientSecretForCustomerAttach` on your CustomerAdapter, but no matching method was found.');}}));}return{fetchPaymentMethods:!!customerAdapter.fetchPaymentMethods,attachPaymentMethod:!!customerAdapter.attachPaymentMethod,detachPaymentMethod:!!customerAdapter.detachPaymentMethod,setSelectedPaymentOption:!!customerAdapter.setSelectedPaymentOption,fetchSelectedPaymentOption:!!customerAdapter.fetchSelectedPaymentOption,setupIntentClientSecretForCustomerAttach:!!customerAdapter.setupIntentClientSecretForCustomerAttach};};var present=function(){var _ref11=(0,_asyncToGenerator2.default)(function*(){var params=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};try{return yield _NativeStripeSdk.default.presentCustomerSheet(params);}catch(error){return{error:error};}});return function present(){return _ref11.apply(this,arguments);};}();var retrievePaymentOptionSelection=function(){var _ref12=(0,_asyncToGenerator2.default)(function*(){try{return yield _NativeStripeSdk.default.retrieveCustomerSheetPaymentOptionSelection();}catch(error){return{error:error};}});return function retrievePaymentOptionSelection(){return _ref12.apply(this,arguments);};}();function Component(_ref13){var visible=_ref13.visible,presentationStyle=_ref13.presentationStyle,animationStyle=_ref13.animationStyle,style=_ref13.style,appearance=_ref13.appearance,setupIntentClientSecret=_ref13.setupIntentClientSecret,customerId=_ref13.customerId,customerEphemeralKeySecret=_ref13.customerEphemeralKeySecret,merchantDisplayName=_ref13.merchantDisplayName,headerTextForSelectionScreen=_ref13.headerTextForSelectionScreen,defaultBillingDetails=_ref13.defaultBillingDetails,billingDetailsCollectionConfiguration=_ref13.billingDetailsCollectionConfiguration,returnURL=_ref13.returnURL,removeSavedPaymentMethodMessage=_ref13.removeSavedPaymentMethodMessage,applePayEnabled=_ref13.applePayEnabled,googlePayEnabled=_ref13.googlePayEnabled,timeout=_ref13.timeout,onResult=_ref13.onResult,customerAdapter=_ref13.customerAdapter;_react.default.useEffect(function(){if(visible){initialize({style:style,appearance:appearance,setupIntentClientSecret:setupIntentClientSecret,customerId:customerId,customerEphemeralKeySecret:customerEphemeralKeySecret,merchantDisplayName:merchantDisplayName,headerTextForSelectionScreen:headerTextForSelectionScreen,defaultBillingDetails:defaultBillingDetails,billingDetailsCollectionConfiguration:billingDetailsCollectionConfiguration,returnURL:returnURL,removeSavedPaymentMethodMessage:removeSavedPaymentMethodMessage,applePayEnabled:applePayEnabled,googlePayEnabled:googlePayEnabled,customerAdapter:customerAdapter}).then(function(initResult){if(initResult.error){onResult(initResult);}else{present({timeout:timeout,presentationStyle:presentationStyle,animationStyle:animationStyle}).then(function(presentResult){onResult(presentResult);});}});}},[visible]);return null;}var CustomerSheet={Component:Component,initialize:initialize,present:present,retrievePaymentOptionSelection:retrievePaymentOptionSelection};exports.CustomerSheet=CustomerSheet;
2
2
  //# sourceMappingURL=CustomerSheet.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["eventEmitter","NativeEventEmitter","NativeModules","StripeSdk","fetchPaymentMethodsCallback","attachPaymentMethodCallback","detachPaymentMethodCallback","setSelectedPaymentOptionCallback","fetchSelectedPaymentOptionCallback","setupIntentClientSecretForCustomerAttachCallback","initialize","params","customerAdapterOverrides","customerAdapter","configureCustomerAdapterEventListeners","NativeStripeSdk","initCustomerSheet","error","fetchPaymentMethods","remove","addListener","paymentMethods","customerAdapterFetchPaymentMethodsCallback","Error","attachPaymentMethod","paymentMethodId","paymentMethod","customerAdapterAttachPaymentMethodCallback","detachPaymentMethod","customerAdapterDetachPaymentMethodCallback","setSelectedPaymentOption","paymentOption","customerAdapterSetSelectedPaymentOptionCallback","fetchSelectedPaymentOption","customerAdapterFetchSelectedPaymentOptionCallback","setupIntentClientSecretForCustomerAttach","clientSecret","customerAdapterSetupIntentClientSecretForCustomerAttachCallback","present","presentCustomerSheet","retrievePaymentOptionSelection","retrieveCustomerSheetPaymentOptionSelection","CustomerSheet","visible","presentationStyle","animationStyle","style","appearance","setupIntentClientSecret","customerId","customerEphemeralKeySecret","merchantDisplayName","headerTextForSelectionScreen","defaultBillingDetails","billingDetailsCollectionConfiguration","returnURL","removeSavedPaymentMethodMessage","applePayEnabled","googlePayEnabled","timeout","onResult","React","useEffect","then","initResult","presentResult","CustomerSheetBeta"],"sources":["CustomerSheet.tsx"],"sourcesContent":["import React from 'react';\nimport {\n NativeEventEmitter,\n NativeModules,\n EmitterSubscription,\n} from 'react-native';\nimport NativeStripeSdk from '../NativeStripeSdk';\nimport type {\n CustomerSheetInitParams,\n CustomerSheetPresentParams,\n CustomerSheetResult,\n CustomerSheetError,\n StripeError,\n CustomerAdapter,\n} from '../types';\n\nconst eventEmitter = new NativeEventEmitter(NativeModules.StripeSdk);\nlet fetchPaymentMethodsCallback: EmitterSubscription | null = null;\nlet attachPaymentMethodCallback: EmitterSubscription | null = null;\nlet detachPaymentMethodCallback: EmitterSubscription | null = null;\nlet setSelectedPaymentOptionCallback: EmitterSubscription | null = null;\nlet fetchSelectedPaymentOptionCallback: EmitterSubscription | null = null;\nlet setupIntentClientSecretForCustomerAttachCallback: EmitterSubscription | null =\n null;\n\n/** Initialize an instance of Customer Sheet with your desired configuration. */\nconst initialize = async (\n params: CustomerSheetInitParams\n): Promise<{ error?: StripeError<CustomerSheetError> }> => {\n let customerAdapterOverrides = {};\n if (params.customerAdapter) {\n customerAdapterOverrides = configureCustomerAdapterEventListeners(\n params.customerAdapter\n );\n }\n\n try {\n const { error } = await NativeStripeSdk.initCustomerSheet(\n params,\n customerAdapterOverrides\n );\n if (error) {\n return { error };\n }\n return {};\n } catch (error: any) {\n return {\n error,\n };\n }\n};\n\nconst configureCustomerAdapterEventListeners = (\n customerAdapter: CustomerAdapter\n): { [Property in keyof CustomerAdapter]: boolean } => {\n if (customerAdapter.fetchPaymentMethods) {\n fetchPaymentMethodsCallback?.remove();\n fetchPaymentMethodsCallback = eventEmitter.addListener(\n 'onCustomerAdapterFetchPaymentMethodsCallback',\n async () => {\n if (customerAdapter.fetchPaymentMethods) {\n const paymentMethods = await customerAdapter.fetchPaymentMethods();\n await NativeStripeSdk.customerAdapterFetchPaymentMethodsCallback(\n paymentMethods\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `fetchPaymentMethods` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.attachPaymentMethod) {\n attachPaymentMethodCallback?.remove();\n attachPaymentMethodCallback = eventEmitter.addListener(\n 'onCustomerAdapterAttachPaymentMethodCallback',\n async ({ paymentMethodId }: { paymentMethodId: string }) => {\n if (customerAdapter.attachPaymentMethod) {\n const paymentMethod = await customerAdapter.attachPaymentMethod(\n paymentMethodId\n );\n await NativeStripeSdk.customerAdapterAttachPaymentMethodCallback(\n paymentMethod\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `attachPaymentMethod` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.detachPaymentMethod) {\n detachPaymentMethodCallback?.remove();\n detachPaymentMethodCallback = eventEmitter.addListener(\n 'onCustomerAdapterDetachPaymentMethodCallback',\n async ({ paymentMethodId }: { paymentMethodId: string }) => {\n if (customerAdapter.detachPaymentMethod) {\n const paymentMethod = await customerAdapter.detachPaymentMethod(\n paymentMethodId\n );\n await NativeStripeSdk.customerAdapterDetachPaymentMethodCallback(\n paymentMethod\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `detachPaymentMethod` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.setSelectedPaymentOption) {\n setSelectedPaymentOptionCallback?.remove();\n setSelectedPaymentOptionCallback = eventEmitter.addListener(\n 'onCustomerAdapterSetSelectedPaymentOptionCallback',\n async ({ paymentOption }: { paymentOption: string }) => {\n if (customerAdapter.setSelectedPaymentOption) {\n await customerAdapter.setSelectedPaymentOption(paymentOption);\n await NativeStripeSdk.customerAdapterSetSelectedPaymentOptionCallback();\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `setSelectedPaymentOption` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.fetchSelectedPaymentOption) {\n fetchSelectedPaymentOptionCallback?.remove();\n fetchSelectedPaymentOptionCallback = eventEmitter.addListener(\n 'onCustomerAdapterFetchSelectedPaymentOptionCallback',\n async () => {\n if (customerAdapter.fetchSelectedPaymentOption) {\n const paymentOption =\n await customerAdapter.fetchSelectedPaymentOption();\n await NativeStripeSdk.customerAdapterFetchSelectedPaymentOptionCallback(\n paymentOption\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `fetchSelectedPaymentOption` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.setupIntentClientSecretForCustomerAttach) {\n setupIntentClientSecretForCustomerAttachCallback?.remove();\n setupIntentClientSecretForCustomerAttachCallback = eventEmitter.addListener(\n 'onCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback',\n async () => {\n if (customerAdapter.setupIntentClientSecretForCustomerAttach) {\n const clientSecret =\n await customerAdapter.setupIntentClientSecretForCustomerAttach();\n await NativeStripeSdk.customerAdapterSetupIntentClientSecretForCustomerAttachCallback(\n clientSecret\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `setupIntentClientSecretForCustomerAttach` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n return {\n fetchPaymentMethods: !!customerAdapter.fetchPaymentMethods,\n attachPaymentMethod: !!customerAdapter.attachPaymentMethod,\n detachPaymentMethod: !!customerAdapter.detachPaymentMethod,\n setSelectedPaymentOption: !!customerAdapter.setSelectedPaymentOption,\n fetchSelectedPaymentOption: !!customerAdapter.fetchSelectedPaymentOption,\n setupIntentClientSecretForCustomerAttach:\n !!customerAdapter.setupIntentClientSecretForCustomerAttach,\n };\n};\n\n/** Launches the Customer Sheet UI. */\nconst present = async (\n params: CustomerSheetPresentParams = {}\n): Promise<CustomerSheetResult> => {\n try {\n return await NativeStripeSdk.presentCustomerSheet(params);\n } catch (error: any) {\n return {\n error,\n };\n }\n};\n\n/**\n * You can use this to obtain the selected payment method without presenting the CustomerSheet.\n * This will return an error if you have not called `.initialize`\n */\nconst retrievePaymentOptionSelection =\n async (): Promise<CustomerSheetResult> => {\n try {\n return await NativeStripeSdk.retrieveCustomerSheetPaymentOptionSelection();\n } catch (error: any) {\n return {\n error,\n };\n }\n };\n\n/**\n * Props\n */\nexport type Props = {\n /** Whether the sheet is visible. Defaults to false. */\n visible: boolean;\n /** Called when the user submits, dismisses, or cancels the sheet, or when an error occurs. */\n onResult: (result: CustomerSheetResult) => void;\n} & CustomerSheetInitParams &\n CustomerSheetPresentParams;\n\n/**\n * A component wrapper around the Customer Sheet functions. Upon passing `true` to the `visible` prop,\n * Customer Sheet will call `initialize` and `present`, and the result(s) will be passed through to the\n * onResult callback.\n *\n * @example\n * ```ts\n * const [selectedPaymentOption, setSelectedPaymentOption] = React.useState(null);\n * const [customerSheetVisible, setCustomerSheetVisible] = React.useState(false);\n *\n * return (\n * <CustomerSheet\n * visible={customerSheetVisible}\n * customerEphemeralKeySecret={ephemeralKeySecret}\n * customerId={customer}\n * returnURL={'stripe-example://stripe-redirect'}\n * onResult={({ error, paymentOption, paymentMethod }) => {\n * setCustomerSheetVisible(false);\n * if (error) {\n * Alert.alert(error.code, error.localizedMessage);\n * }\n * if (paymentOption) {\n * setSelectedPaymentOption(paymentOption);\n * console.log(JSON.stringify(paymentOption, null, 2));\n * }\n * if (paymentMethod) {\n * console.log(JSON.stringify(paymentMethod, null, 2));\n * }\n * }}\n * />\n * );\n * ```\n * @param __namedParameters Props\n * @returns JSX.Element\n * @category ReactComponents\n */\nfunction CustomerSheet({\n visible,\n presentationStyle,\n animationStyle,\n style,\n appearance,\n setupIntentClientSecret,\n customerId,\n customerEphemeralKeySecret,\n merchantDisplayName,\n headerTextForSelectionScreen,\n defaultBillingDetails,\n billingDetailsCollectionConfiguration,\n returnURL,\n removeSavedPaymentMethodMessage,\n applePayEnabled,\n googlePayEnabled,\n timeout,\n onResult,\n customerAdapter,\n}: Props) {\n React.useEffect(() => {\n if (visible) {\n initialize({\n style,\n appearance,\n setupIntentClientSecret,\n customerId,\n customerEphemeralKeySecret,\n merchantDisplayName,\n headerTextForSelectionScreen,\n defaultBillingDetails,\n billingDetailsCollectionConfiguration,\n returnURL,\n removeSavedPaymentMethodMessage,\n applePayEnabled,\n googlePayEnabled,\n customerAdapter,\n }).then((initResult) => {\n if (initResult.error) {\n onResult(initResult);\n } else {\n present({\n timeout,\n presentationStyle,\n animationStyle,\n }).then((presentResult) => {\n onResult(presentResult);\n });\n }\n });\n }\n // Only run this hook when visible prop changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [visible]);\n\n return null;\n}\n\n/**\n * The Customer Sheet is a prebuilt UI component that lets your customers manage their saved payment methods.\n */\nexport const CustomerSheetBeta = {\n CustomerSheet,\n initialize,\n present,\n retrievePaymentOptionSelection,\n};\n"],"mappings":"+QAAA,oDACA,yCAKA,2EAUA,GAAMA,aAAY,CAAG,GAAIC,gCAAkB,CAACC,0BAAa,CAACC,SAAS,CAAC,CACpE,GAAIC,4BAAuD,CAAG,IAAI,CAClE,GAAIC,4BAAuD,CAAG,IAAI,CAClE,GAAIC,4BAAuD,CAAG,IAAI,CAClE,GAAIC,iCAA4D,CAAG,IAAI,CACvE,GAAIC,mCAA8D,CAAG,IAAI,CACzE,GAAIC,iDAA4E,CAC9E,IAAI,CAGN,GAAMC,WAAU,oDAAG,UACjBC,MAA+B,CAC0B,CACzD,GAAIC,yBAAwB,CAAG,CAAC,CAAC,CAC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C,SAACC,UAAU,CAAK,CACtB,GAAIA,UAAU,CAAC/C,KAAK,CAAE,CACpB2C,QAAQ,CAACI,UAAU,CAAC,CACtB,CAAC,IAAM,CACL1B,OAAO,CAAC,CACNqB,OAAO,CAAPA,OAAO,CACPf,iBAAiB,CAAjBA,iBAAiB,CACjBC,cAAc,CAAdA,cACF,CAAC,CAAC,CAACkB,IAAI,CAAC,SAACE,aAAa,CAAK,CACzBL,QAAQ,CAACK,aAAa,CAAC,CACzB,CAAC,CAAC,CACJ,CACF,CAAC,CAAC,CACJ,CAGF,CAAC,CAAE,CAACtB,OAAO,CAAC,CAAC,CAEb,MAAO,KAAI,CACb,CAKO,GAAMuB,kBAAiB,CAAG,CAC/BxB,aAAa,CAAbA,aAAa,CACbhC,UAAU,CAAVA,UAAU,CACV4B,OAAO,CAAPA,OAAO,CACPE,8BAA8B,CAA9BA,8BACF,CAAC,CAAC"}
1
+ {"version":3,"names":["eventEmitter","NativeEventEmitter","NativeModules","StripeSdk","fetchPaymentMethodsCallback","attachPaymentMethodCallback","detachPaymentMethodCallback","setSelectedPaymentOptionCallback","fetchSelectedPaymentOptionCallback","setupIntentClientSecretForCustomerAttachCallback","initialize","params","customerAdapterOverrides","customerAdapter","configureCustomerAdapterEventListeners","NativeStripeSdk","initCustomerSheet","error","fetchPaymentMethods","remove","addListener","paymentMethods","customerAdapterFetchPaymentMethodsCallback","Error","attachPaymentMethod","paymentMethodId","paymentMethod","customerAdapterAttachPaymentMethodCallback","detachPaymentMethod","customerAdapterDetachPaymentMethodCallback","setSelectedPaymentOption","paymentOption","customerAdapterSetSelectedPaymentOptionCallback","fetchSelectedPaymentOption","customerAdapterFetchSelectedPaymentOptionCallback","setupIntentClientSecretForCustomerAttach","clientSecret","customerAdapterSetupIntentClientSecretForCustomerAttachCallback","present","presentCustomerSheet","retrievePaymentOptionSelection","retrieveCustomerSheetPaymentOptionSelection","Component","visible","presentationStyle","animationStyle","style","appearance","setupIntentClientSecret","customerId","customerEphemeralKeySecret","merchantDisplayName","headerTextForSelectionScreen","defaultBillingDetails","billingDetailsCollectionConfiguration","returnURL","removeSavedPaymentMethodMessage","applePayEnabled","googlePayEnabled","timeout","onResult","React","useEffect","then","initResult","presentResult","CustomerSheet"],"sources":["CustomerSheet.tsx"],"sourcesContent":["import React from 'react';\nimport {\n NativeEventEmitter,\n NativeModules,\n EmitterSubscription,\n} from 'react-native';\nimport NativeStripeSdk from '../NativeStripeSdk';\nimport type {\n CustomerSheetInitParams,\n CustomerSheetPresentParams,\n CustomerSheetResult,\n CustomerSheetError,\n StripeError,\n CustomerAdapter,\n} from '../types';\n\nconst eventEmitter = new NativeEventEmitter(NativeModules.StripeSdk);\nlet fetchPaymentMethodsCallback: EmitterSubscription | null = null;\nlet attachPaymentMethodCallback: EmitterSubscription | null = null;\nlet detachPaymentMethodCallback: EmitterSubscription | null = null;\nlet setSelectedPaymentOptionCallback: EmitterSubscription | null = null;\nlet fetchSelectedPaymentOptionCallback: EmitterSubscription | null = null;\nlet setupIntentClientSecretForCustomerAttachCallback: EmitterSubscription | null =\n null;\n\n/** Initialize an instance of Customer Sheet with your desired configuration. */\nconst initialize = async (\n params: CustomerSheetInitParams\n): Promise<{ error?: StripeError<CustomerSheetError> }> => {\n let customerAdapterOverrides = {};\n if (params.customerAdapter) {\n customerAdapterOverrides = configureCustomerAdapterEventListeners(\n params.customerAdapter\n );\n }\n\n try {\n const { error } = await NativeStripeSdk.initCustomerSheet(\n params,\n customerAdapterOverrides\n );\n if (error) {\n return { error };\n }\n return {};\n } catch (error: any) {\n return {\n error,\n };\n }\n};\n\nconst configureCustomerAdapterEventListeners = (\n customerAdapter: CustomerAdapter\n): { [Property in keyof CustomerAdapter]: boolean } => {\n if (customerAdapter.fetchPaymentMethods) {\n fetchPaymentMethodsCallback?.remove();\n fetchPaymentMethodsCallback = eventEmitter.addListener(\n 'onCustomerAdapterFetchPaymentMethodsCallback',\n async () => {\n if (customerAdapter.fetchPaymentMethods) {\n const paymentMethods = await customerAdapter.fetchPaymentMethods();\n await NativeStripeSdk.customerAdapterFetchPaymentMethodsCallback(\n paymentMethods\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `fetchPaymentMethods` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.attachPaymentMethod) {\n attachPaymentMethodCallback?.remove();\n attachPaymentMethodCallback = eventEmitter.addListener(\n 'onCustomerAdapterAttachPaymentMethodCallback',\n async ({ paymentMethodId }: { paymentMethodId: string }) => {\n if (customerAdapter.attachPaymentMethod) {\n const paymentMethod = await customerAdapter.attachPaymentMethod(\n paymentMethodId\n );\n await NativeStripeSdk.customerAdapterAttachPaymentMethodCallback(\n paymentMethod\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `attachPaymentMethod` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.detachPaymentMethod) {\n detachPaymentMethodCallback?.remove();\n detachPaymentMethodCallback = eventEmitter.addListener(\n 'onCustomerAdapterDetachPaymentMethodCallback',\n async ({ paymentMethodId }: { paymentMethodId: string }) => {\n if (customerAdapter.detachPaymentMethod) {\n const paymentMethod = await customerAdapter.detachPaymentMethod(\n paymentMethodId\n );\n await NativeStripeSdk.customerAdapterDetachPaymentMethodCallback(\n paymentMethod\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `detachPaymentMethod` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.setSelectedPaymentOption) {\n setSelectedPaymentOptionCallback?.remove();\n setSelectedPaymentOptionCallback = eventEmitter.addListener(\n 'onCustomerAdapterSetSelectedPaymentOptionCallback',\n async ({ paymentOption }: { paymentOption: string }) => {\n if (customerAdapter.setSelectedPaymentOption) {\n await customerAdapter.setSelectedPaymentOption(paymentOption);\n await NativeStripeSdk.customerAdapterSetSelectedPaymentOptionCallback();\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `setSelectedPaymentOption` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.fetchSelectedPaymentOption) {\n fetchSelectedPaymentOptionCallback?.remove();\n fetchSelectedPaymentOptionCallback = eventEmitter.addListener(\n 'onCustomerAdapterFetchSelectedPaymentOptionCallback',\n async () => {\n if (customerAdapter.fetchSelectedPaymentOption) {\n const paymentOption =\n await customerAdapter.fetchSelectedPaymentOption();\n await NativeStripeSdk.customerAdapterFetchSelectedPaymentOptionCallback(\n paymentOption\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `fetchSelectedPaymentOption` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n if (customerAdapter.setupIntentClientSecretForCustomerAttach) {\n setupIntentClientSecretForCustomerAttachCallback?.remove();\n setupIntentClientSecretForCustomerAttachCallback = eventEmitter.addListener(\n 'onCustomerAdapterSetupIntentClientSecretForCustomerAttachCallback',\n async () => {\n if (customerAdapter.setupIntentClientSecretForCustomerAttach) {\n const clientSecret =\n await customerAdapter.setupIntentClientSecretForCustomerAttach();\n await NativeStripeSdk.customerAdapterSetupIntentClientSecretForCustomerAttachCallback(\n clientSecret\n );\n } else {\n throw new Error(\n '[@stripe/stripe-react-native] Tried to call `setupIntentClientSecretForCustomerAttach` on your CustomerAdapter, but no matching method was found.'\n );\n }\n }\n );\n }\n\n return {\n fetchPaymentMethods: !!customerAdapter.fetchPaymentMethods,\n attachPaymentMethod: !!customerAdapter.attachPaymentMethod,\n detachPaymentMethod: !!customerAdapter.detachPaymentMethod,\n setSelectedPaymentOption: !!customerAdapter.setSelectedPaymentOption,\n fetchSelectedPaymentOption: !!customerAdapter.fetchSelectedPaymentOption,\n setupIntentClientSecretForCustomerAttach:\n !!customerAdapter.setupIntentClientSecretForCustomerAttach,\n };\n};\n\n/** Launches the Customer Sheet UI. */\nconst present = async (\n params: CustomerSheetPresentParams = {}\n): Promise<CustomerSheetResult> => {\n try {\n return await NativeStripeSdk.presentCustomerSheet(params);\n } catch (error: any) {\n return {\n error,\n };\n }\n};\n\n/**\n * You can use this to obtain the selected payment method without presenting the CustomerSheet.\n * This will return an error if you have not called `.initialize`\n */\nconst retrievePaymentOptionSelection =\n async (): Promise<CustomerSheetResult> => {\n try {\n return await NativeStripeSdk.retrieveCustomerSheetPaymentOptionSelection();\n } catch (error: any) {\n return {\n error,\n };\n }\n };\n\n/**\n * Props\n */\nexport type Props = {\n /** Whether the sheet is visible. Defaults to false. */\n visible: boolean;\n /** Called when the user submits, dismisses, or cancels the sheet, or when an error occurs. */\n onResult: (result: CustomerSheetResult) => void;\n} & CustomerSheetInitParams &\n CustomerSheetPresentParams;\n\n/**\n * A component wrapper around the Customer Sheet functions. Upon passing `true` to the `visible` prop,\n * Customer Sheet will call `initialize` and `present`, and the result(s) will be passed through to the\n * onResult callback.\n *\n * @example\n * ```ts\n * const [selectedPaymentOption, setSelectedPaymentOption] = React.useState(null);\n * const [customerSheetVisible, setCustomerSheetVisible] = React.useState(false);\n *\n * return (\n * <CustomerSheet\n * visible={customerSheetVisible}\n * customerEphemeralKeySecret={ephemeralKeySecret}\n * customerId={customer}\n * returnURL={'stripe-example://stripe-redirect'}\n * onResult={({ error, paymentOption, paymentMethod }) => {\n * setCustomerSheetVisible(false);\n * if (error) {\n * Alert.alert(error.code, error.localizedMessage);\n * }\n * if (paymentOption) {\n * setSelectedPaymentOption(paymentOption);\n * console.log(JSON.stringify(paymentOption, null, 2));\n * }\n * if (paymentMethod) {\n * console.log(JSON.stringify(paymentMethod, null, 2));\n * }\n * }}\n * />\n * );\n * ```\n * @param __namedParameters Props\n * @returns JSX.Element\n * @category ReactComponents\n */\nfunction Component({\n visible,\n presentationStyle,\n animationStyle,\n style,\n appearance,\n setupIntentClientSecret,\n customerId,\n customerEphemeralKeySecret,\n merchantDisplayName,\n headerTextForSelectionScreen,\n defaultBillingDetails,\n billingDetailsCollectionConfiguration,\n returnURL,\n removeSavedPaymentMethodMessage,\n applePayEnabled,\n googlePayEnabled,\n timeout,\n onResult,\n customerAdapter,\n}: Props) {\n React.useEffect(() => {\n if (visible) {\n initialize({\n style,\n appearance,\n setupIntentClientSecret,\n customerId,\n customerEphemeralKeySecret,\n merchantDisplayName,\n headerTextForSelectionScreen,\n defaultBillingDetails,\n billingDetailsCollectionConfiguration,\n returnURL,\n removeSavedPaymentMethodMessage,\n applePayEnabled,\n googlePayEnabled,\n customerAdapter,\n }).then((initResult) => {\n if (initResult.error) {\n onResult(initResult);\n } else {\n present({\n timeout,\n presentationStyle,\n animationStyle,\n }).then((presentResult) => {\n onResult(presentResult);\n });\n }\n });\n }\n // Only run this hook when visible prop changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [visible]);\n\n return null;\n}\n\n/**\n * The Customer Sheet is a prebuilt UI component that lets your customers manage their saved payment methods.\n */\nexport const CustomerSheet = {\n Component,\n initialize,\n present,\n retrievePaymentOptionSelection,\n};\n"],"mappings":"2QAAA,oDACA,yCAKA,2EAUA,GAAMA,aAAY,CAAG,GAAIC,gCAAkB,CAACC,0BAAa,CAACC,SAAS,CAAC,CACpE,GAAIC,4BAAuD,CAAG,IAAI,CAClE,GAAIC,4BAAuD,CAAG,IAAI,CAClE,GAAIC,4BAAuD,CAAG,IAAI,CAClE,GAAIC,iCAA4D,CAAG,IAAI,CACvE,GAAIC,mCAA8D,CAAG,IAAI,CACzE,GAAIC,iDAA4E,CAC9E,IAAI,CAGN,GAAMC,WAAU,oDAAG,UACjBC,MAA+B,CAC0B,CACzD,GAAIC,yBAAwB,CAAG,CAAC,CAAC,CACjC,GAAID,MAAM,CAACE,eAAe,CAAE,CAC1BD,wBAAwB,CAAGE,sCAAsC,CAC/DH,MAAM,CAACE,eAAe,CACvB,CACH,CAEA,GAAI,CACF,+BAAwBE,yBAAe,CAACC,iBAAiB,CACvDL,MAAM,CACNC,wBAAwB,CACzB,CAHOK,KAAK,uBAALA,KAAK,CAIb,GAAIA,KAAK,CAAE,CACT,MAAO,CAAEA,KAAK,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,CACzBL,QAAQ,CAACK,aAAa,CAAC,CACzB,CAAC,CAAC,CACJ,CACF,CAAC,CAAC,CACJ,CAGF,CAAC,CAAE,CAACtB,OAAO,CAAC,CAAC,CAEb,MAAO,KAAI,CACb,CAKO,GAAMuB,cAAa,CAAG,CAC3BxB,SAAS,CAATA,SAAS,CACThC,UAAU,CAAVA,UAAU,CACV4B,OAAO,CAAPA,OAAO,CACPE,8BAA8B,CAA9BA,8BACF,CAAC,CAAC"}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,"__esModule",{value:true});exports.CollectionMode=exports.CaptureMethod=exports.AddressCollectionMode=void 0;var CollectionMode;exports.CollectionMode=CollectionMode;(function(CollectionMode){CollectionMode["AUTOMATIC"]="automatic";CollectionMode["NEVER"]="never";CollectionMode["ALWAYS"]="always";})(CollectionMode||(exports.CollectionMode=CollectionMode={}));var AddressCollectionMode;exports.AddressCollectionMode=AddressCollectionMode;(function(AddressCollectionMode){AddressCollectionMode["AUTOMATIC"]="automatic";AddressCollectionMode["NEVER"]="never";AddressCollectionMode["FULL"]="full";})(AddressCollectionMode||(exports.AddressCollectionMode=AddressCollectionMode={}));var CaptureMethod;exports.CaptureMethod=CaptureMethod;(function(CaptureMethod){CaptureMethod["Automatic"]="Automatic";CaptureMethod["Manual"]="Manual";CaptureMethod["AutomaticAsync"]="AutomaticAsync";})(CaptureMethod||(exports.CaptureMethod=CaptureMethod={}));
1
+ Object.defineProperty(exports,"__esModule",{value:true});exports.PaymentMethodLayout=exports.CollectionMode=exports.CaptureMethod=exports.AddressCollectionMode=void 0;var CollectionMode;exports.CollectionMode=CollectionMode;(function(CollectionMode){CollectionMode["AUTOMATIC"]="automatic";CollectionMode["NEVER"]="never";CollectionMode["ALWAYS"]="always";})(CollectionMode||(exports.CollectionMode=CollectionMode={}));var AddressCollectionMode;exports.AddressCollectionMode=AddressCollectionMode;(function(AddressCollectionMode){AddressCollectionMode["AUTOMATIC"]="automatic";AddressCollectionMode["NEVER"]="never";AddressCollectionMode["FULL"]="full";})(AddressCollectionMode||(exports.AddressCollectionMode=AddressCollectionMode={}));var CaptureMethod;exports.CaptureMethod=CaptureMethod;(function(CaptureMethod){CaptureMethod["Automatic"]="Automatic";CaptureMethod["Manual"]="Manual";CaptureMethod["AutomaticAsync"]="AutomaticAsync";})(CaptureMethod||(exports.CaptureMethod=CaptureMethod={}));var PaymentMethodLayout;exports.PaymentMethodLayout=PaymentMethodLayout;(function(PaymentMethodLayout){PaymentMethodLayout["Horizontal"]="Horizontal";PaymentMethodLayout["Vertical"]="Vertical";PaymentMethodLayout["Automatic"]="Automatic";})(PaymentMethodLayout||(exports.PaymentMethodLayout=PaymentMethodLayout={}));
2
2
  //# sourceMappingURL=PaymentSheet.js.map