Skip to content

Commit

Permalink
feat: add retrieveSetupIntent
Browse files Browse the repository at this point in the history
  • Loading branch information
behnamsattar committed Jul 6, 2023
1 parent 26c2ef3 commit f9a1e24
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/stripe/lib/src/stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,19 @@ class Stripe {
}
}

/// Retrieves a [SetupIntent] using the provided [clientSecret].
///
/// Throws a [StripeException] in case retrieving the intent fails.
Future<SetupIntent> 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<void> openApplePaySetup() async {
await _platform.openApplePaySetup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ class MethodChannelStripe extends StripePlatform {
.parse(result: result!, successResultKey: 'paymentIntent');
}

@override
Future<SetupIntent> retrieveSetupIntent(String clientSecret) async {
final result = await _methodChannel
.invokeMapMethod<String, dynamic>('retrieveSetupIntent', {
'clientSecret': clientSecret,
});

return ResultParser<SetupIntent>(
parseJson: (json) => SetupIntent.fromJson(json))
.parse(result: result!, successResultKey: 'setupIntent');
}

@override
Future<PaymentSheetPaymentOption?> initPaymentSheet(
SetupPaymentSheetParameters params) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ abstract class StripePlatform extends PlatformInterface {
PaymentMethodOptions? options,
);
Future<PaymentIntent> retrievePaymentIntent(String clientSecret);
Future<SetupIntent> retrieveSetupIntent(String clientSecret);
Future<String> createTokenForCVCUpdate(String cvc);

/// Methods related to ACH payments
Expand Down
5 changes: 5 additions & 0 deletions packages/stripe_web/lib/src/web_stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ class WebStripe extends StripePlatform {
throw UnimplementedError();
}

@override
Future<SetupIntent> retrieveSetupIntent(String clientSecret) async {
throw UnimplementedError();
}

@override
Future<PaymentMethod> createGooglePayPaymentMethod(
CreateGooglePayPaymentParams params) {
Expand Down

0 comments on commit f9a1e24

Please sign in to comment.