11import 'dart:async' ;
22
33import 'package:flutter/foundation.dart' ;
4- import 'package:meta/meta.dart' ;
54import 'package:stripe_platform_interface/stripe_platform_interface.dart' ;
65
76/// [Stripe] is the facade of the library and exposes the operations that can be
@@ -102,13 +101,13 @@ class Stripe {
102101 /// [publishableKey] , [merchantIdentifier] , [stripeAccountId] ,
103102 /// [threeDSecureParams] , [urlScheme] , [setReturnUrlSchemeOnAndroid]
104103 Future <void > applySettings () => _initialise (
105- publishableKey: publishableKey,
106- merchantIdentifier: merchantIdentifier,
107- stripeAccountId: stripeAccountId,
108- threeDSecureParams: threeDSecureParams,
109- urlScheme: urlScheme,
110- setReturnUrlSchemeOnAndroid: setReturnUrlSchemeOnAndroid,
111- );
104+ publishableKey: publishableKey,
105+ merchantIdentifier: merchantIdentifier,
106+ stripeAccountId: stripeAccountId,
107+ threeDSecureParams: threeDSecureParams,
108+ urlScheme: urlScheme,
109+ setReturnUrlSchemeOnAndroid: setReturnUrlSchemeOnAndroid,
110+ );
112111
113112 /// Exposes a [ValueListenable] whether or not GooglePay (on Android) or Apple Pay (on iOS)
114113 /// is supported for this device.
@@ -133,8 +132,9 @@ class Stripe {
133132 }) async {
134133 await _awaitForSettings ();
135134 final isSupported = await _platform.isPlatformPaySupported (
136- params: googlePay,
137- paymentRequestOptions: webPaymentRequestCreateOptions);
135+ params: googlePay,
136+ paymentRequestOptions: webPaymentRequestCreateOptions,
137+ );
138138
139139 _isPlatformPaySupported ?? = ValueNotifier (false );
140140 _isPlatformPaySupported? .value = isSupported;
@@ -276,8 +276,10 @@ class Stripe {
276276 }) async {
277277 await _awaitForSettings ();
278278 try {
279- final paymentMethod =
280- await _platform.createPaymentMethod (params, options);
279+ final paymentMethod = await _platform.createPaymentMethod (
280+ params,
281+ options,
282+ );
281283 return paymentMethod;
282284 } on StripeError catch (error) {
283285 throw StripeError (message: error.message, code: error.message);
@@ -370,12 +372,16 @@ class Stripe {
370372 /// several seconds and it is important to not resubmit the form.
371373 ///
372374 /// Throws a [StripeException] when confirming the handle card action fails.
373- Future <PaymentIntent > handleNextAction (String paymentIntentClientSecret,
374- {String ? returnURL}) async {
375+ Future <PaymentIntent > handleNextAction (
376+ String paymentIntentClientSecret, {
377+ String ? returnURL,
378+ }) async {
375379 await _awaitForSettings ();
376380 try {
377- final paymentIntent = await _platform
378- .handleNextAction (paymentIntentClientSecret, returnURL: returnURL);
381+ final paymentIntent = await _platform.handleNextAction (
382+ paymentIntentClientSecret,
383+ returnURL: returnURL,
384+ );
379385 return paymentIntent;
380386 } on StripeError {
381387 //throw StripeError<CardActionError>(error.code, error.message);
@@ -389,13 +395,15 @@ class Stripe {
389395 ///
390396 /// Throws a [StripeException] when confirming the handle card action fails.
391397 Future <SetupIntent > handleNextActionForSetupIntent (
392- String setupIntentClientSecret,
393- {String ? returnURL}) async {
398+ String setupIntentClientSecret, {
399+ String ? returnURL,
400+ }) async {
394401 await _awaitForSettings ();
395402 try {
396403 final paymentIntent = await _platform.handleNextActionForSetupIntent (
397- setupIntentClientSecret,
398- returnURL: returnURL);
404+ setupIntentClientSecret,
405+ returnURL: returnURL,
406+ );
399407 return paymentIntent;
400408 } on StripeError {
401409 rethrow ;
@@ -416,7 +424,10 @@ class Stripe {
416424 await _awaitForSettings ();
417425 try {
418426 final setupIntent = await _platform.confirmSetupIntent (
419- paymentIntentClientSecret, params, options);
427+ paymentIntentClientSecret,
428+ params,
429+ options,
430+ );
420431 return setupIntent;
421432 } on StripeException {
422433 rethrow ;
@@ -428,14 +439,10 @@ class Stripe {
428439 /// Returns a single-use token.
429440 ///
430441 /// Throws [StripeError] in case creating the token fails.
431- Future <String ?> createTokenForCVCUpdate (
432- String cvc,
433- ) async {
442+ Future <String ?> createTokenForCVCUpdate (String cvc) async {
434443 await _awaitForSettings ();
435444 try {
436- final tokenId = await _platform.createTokenForCVCUpdate (
437- cvc,
438- );
445+ final tokenId = await _platform.createTokenForCVCUpdate (cvc);
439446 return tokenId;
440447 } on StripeError {
441448 //throw StripeError<CardActionError>(error.code, error.message);
@@ -451,9 +458,10 @@ class Stripe {
451458 required SetupPaymentSheetParameters paymentSheetParameters,
452459 }) async {
453460 assert (
454- ! (paymentSheetParameters.applePay != null &&
455- instance._merchantIdentifier == null ),
456- 'merchantIdentifier must be specified if you are using Apple Pay. Please refer to this article to get a merchant identifier: https://support.stripe.com/questions/enable-apple-pay-on-your-stripe-account' );
461+ ! (paymentSheetParameters.applePay != null &&
462+ instance._merchantIdentifier == null ),
463+ 'merchantIdentifier must be specified if you are using Apple Pay. Please refer to this article to get a merchant identifier: https://support.stripe.com/questions/enable-apple-pay-on-your-stripe-account' ,
464+ );
457465 await _awaitForSettings ();
458466 return _platform.initPaymentSheet (paymentSheetParameters);
459467 }
@@ -473,7 +481,8 @@ class Stripe {
473481 /// Method used to confirm to the user that the intent is created successfull
474482 /// or not successfull when using a defferred payment method.
475483 Future <void > intentCreationCallback (
476- IntentCreationCallbackParams params) async {
484+ IntentCreationCallbackParams params,
485+ ) async {
477486 await _awaitForSettings ();
478487 return await _platform.intentCreationCallback (params);
479488 }
@@ -506,7 +515,8 @@ class Stripe {
506515
507516 /// Inititialise google pay
508517 @Deprecated (
509- 'Use [confirmPlatformPaySetupIntent] or [confirmPlatformPayPaymentIntent] or [createPlatformPayPaymentMethod] instead.' )
518+ 'Use [confirmPlatformPaySetupIntent] or [confirmPlatformPayPaymentIntent] or [createPlatformPayPaymentMethod] instead.' ,
519+ )
510520 Future <void > initGooglePay (GooglePayInitParams params) async {
511521 return await _platform.initGooglePay (params);
512522 }
@@ -515,7 +525,8 @@ class Stripe {
515525 ///
516526 /// Throws a [StripeException] in case it is failing
517527 @Deprecated (
518- 'Use [confirmPlatformPaySetupIntent] or [confirmPlatformPayPaymentIntent].' )
528+ 'Use [confirmPlatformPaySetupIntent] or [confirmPlatformPayPaymentIntent].' ,
529+ )
519530 Future <void > presentGooglePay (PresentGooglePayParams params) async {
520531 return await _platform.presentGooglePay (params);
521532 }
@@ -525,7 +536,8 @@ class Stripe {
525536 /// Throws a [StripeException] in case it is failing
526537 @Deprecated ('Use [createPlatformPayPaymentMethod instead.' )
527538 Future <PaymentMethod > createGooglePayPaymentMethod (
528- CreateGooglePayPaymentParams params) async {
539+ CreateGooglePayPaymentParams params,
540+ ) async {
529541 return await _platform.createGooglePayPaymentMethod (params);
530542 }
531543
@@ -566,11 +578,9 @@ class Stripe {
566578 /// iOS at the moment.
567579 Future <PaymentIntent > verifyPaymentIntentWithMicrodeposits ({
568580 /// Whether the clientsecret is associated with setup or paymentintent
569-
570581 required bool isPaymentIntent,
571582
572583 /// The clientSecret of the payment and setup intent
573-
574584 required String clientSecret,
575585
576586 /// Parameters to verify the microdeposits.
@@ -596,7 +606,8 @@ class Stripe {
596606 /// on this particular device.
597607 /// Throws [StripeException] in case creating the token fails.
598608 Future <CanAddCardToWalletResult > canAddCardToWallet (
599- CanAddCardToWalletParams params) async {
609+ CanAddCardToWalletParams params,
610+ ) async {
600611 return await _platform.canAddCardToWallet (params);
601612 }
602613
@@ -616,7 +627,8 @@ class Stripe {
616627
617628 Future <FinancialConnectionTokenResult > collectBankAccountToken ({
618629 required String clientSecret,
619- CollectBankAccountTokenParams ? params,
630+ CollectBankAccountTokenParams params =
631+ const CollectBankAccountTokenParams (),
620632 }) async {
621633 try {
622634 return _platform.collectBankAccountToken (
@@ -637,7 +649,8 @@ class Stripe {
637649
638650 Future <FinancialConnectionSessionResult > collectFinancialConnectionsAccounts ({
639651 required String clientSecret,
640- CollectFinancialConnectionsAccountsParams ? params,
652+ CollectFinancialConnectionsAccountsParams params =
653+ const CollectFinancialConnectionsAccountsParams (),
641654 }) async {
642655 try {
643656 return _platform.collectFinancialConnectionsAccounts (
@@ -650,8 +663,9 @@ class Stripe {
650663 }
651664
652665 /// Initializes the customer sheet with the provided [parameters] .
653- Future <CustomerSheetResult ?> initCustomerSheet (
654- {required CustomerSheetInitParams customerSheetInitParams}) async {
666+ Future <CustomerSheetResult ?> initCustomerSheet ({
667+ required CustomerSheetInitParams customerSheetInitParams,
668+ }) async {
655669 await _awaitForSettings ();
656670 return _platform.initCustomerSheet (customerSheetInitParams);
657671 }
@@ -666,7 +680,7 @@ class Stripe {
666680
667681 /// Retrieve the customer sheet payment option selection.
668682 Future <CustomerSheetResult ?>
669- retrieveCustomerSheetPaymentOptionSelection () async {
683+ retrieveCustomerSheetPaymentOptionSelection () async {
670684 await _awaitForSettings ();
671685
672686 return _platform.retrieveCustomerSheetPaymentOptionSelection ();
@@ -711,13 +725,14 @@ class Stripe {
711725 }
712726 }
713727
714- Future <void > _initialise (
715- {required String publishableKey,
716- String ? stripeAccountId,
717- ThreeDSecureConfigurationParams ? threeDSecureParams,
718- String ? merchantIdentifier,
719- String ? urlScheme,
720- bool ? setReturnUrlSchemeOnAndroid}) async {
728+ Future <void > _initialise ({
729+ required String publishableKey,
730+ String ? stripeAccountId,
731+ ThreeDSecureConfigurationParams ? threeDSecureParams,
732+ String ? merchantIdentifier,
733+ String ? urlScheme,
734+ bool ? setReturnUrlSchemeOnAndroid,
735+ }) async {
721736 _needsSettings = false ;
722737 await _platform.initialise (
723738 publishableKey: publishableKey,
0 commit comments