From f9a1e24cf48e0465113d63eae5d7c08c5d8c0624 Mon Sep 17 00:00:00 2001 From: Behnam Sattar Date: Thu, 6 Jul 2023 17:36:20 -0400 Subject: [PATCH] feat: add retrieveSetupIntent --- packages/stripe/lib/src/stripe.dart | 13 +++++++++++++ .../com/flutter/stripe/StripeAndroidPlugin.kt | 4 ++++ .../lib/src/method_channel_stripe.dart | 12 ++++++++++++ .../lib/src/stripe_platform_interface.dart | 1 + packages/stripe_web/lib/src/web_stripe.dart | 5 +++++ 5 files changed, 35 insertions(+) diff --git a/packages/stripe/lib/src/stripe.dart b/packages/stripe/lib/src/stripe.dart index 65ade184f..642d2632e 100644 --- a/packages/stripe/lib/src/stripe.dart +++ b/packages/stripe/lib/src/stripe.dart @@ -331,6 +331,19 @@ class Stripe { } } + /// Retrieves a [SetupIntent] using the provided [clientSecret]. + /// + /// Throws a [StripeException] in case retrieving the intent fails. + Future retrieveSetupIntent(String clientSecret) async { + await _awaitForSettings(); + try { + final setupIntent = await _platform.retrieveSetupIntent(clientSecret); + return setupIntent; + } on StripeError catch (error) { + throw StripeError(message: error.message, code: error.message); + } + } + /// Opens the UI to set up credit cards for Apple Pay. Future openApplePaySetup() async { await _platform.openApplePaySetup(); diff --git a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeAndroidPlugin.kt b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeAndroidPlugin.kt index 67412317a..8127bbd03 100644 --- a/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeAndroidPlugin.kt +++ b/packages/stripe_android/android/src/main/kotlin/com/flutter/stripe/StripeAndroidPlugin.kt @@ -119,6 +119,10 @@ If you continue to have trouble, follow this discussion to get some support http clientSecret = call.requiredArgument("clientSecret"), promise = Promise(result) ) + "retrieveSetupIntent" -> stripeSdk.retrieveSetupIntent( + clientSecret = call.requiredArgument("clientSecret"), + promise = Promise(result) + ) "initPaymentSheet" -> stripeSdk.initPaymentSheet( params = call.requiredArgument("params"), promise = Promise(result) diff --git a/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart b/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart index c93592b9a..f8db5f149 100644 --- a/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart +++ b/packages/stripe_platform_interface/lib/src/method_channel_stripe.dart @@ -225,6 +225,18 @@ class MethodChannelStripe extends StripePlatform { .parse(result: result!, successResultKey: 'paymentIntent'); } + @override + Future retrieveSetupIntent(String clientSecret) async { + final result = await _methodChannel + .invokeMapMethod('retrieveSetupIntent', { + 'clientSecret': clientSecret, + }); + + return ResultParser( + parseJson: (json) => SetupIntent.fromJson(json)) + .parse(result: result!, successResultKey: 'setupIntent'); + } + @override Future initPaymentSheet( SetupPaymentSheetParameters params) async { diff --git a/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart b/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart index 326bf30f7..3261f2c27 100644 --- a/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart +++ b/packages/stripe_platform_interface/lib/src/stripe_platform_interface.dart @@ -130,6 +130,7 @@ abstract class StripePlatform extends PlatformInterface { PaymentMethodOptions? options, ); Future retrievePaymentIntent(String clientSecret); + Future retrieveSetupIntent(String clientSecret); Future createTokenForCVCUpdate(String cvc); /// Methods related to ACH payments diff --git a/packages/stripe_web/lib/src/web_stripe.dart b/packages/stripe_web/lib/src/web_stripe.dart index 2b6c8eeed..01daabab8 100644 --- a/packages/stripe_web/lib/src/web_stripe.dart +++ b/packages/stripe_web/lib/src/web_stripe.dart @@ -359,6 +359,11 @@ class WebStripe extends StripePlatform { throw UnimplementedError(); } + @override + Future retrieveSetupIntent(String clientSecret) async { + throw UnimplementedError(); + } + @override Future createGooglePayPaymentMethod( CreateGooglePayPaymentParams params) {