Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,15 @@ class _UsBankAccountDirectDebitScreenState
),
);

if (result.status == PaymentIntentsStatus.RequiresConfirmation) {
final paymentIntent = switch (result) {
CollectBankAccountPaymentIntentResult(:final paymentIntent) =>
paymentIntent,
CollectBankAccountSetupIntentResult() => null,
};
if (paymentIntent?.status == PaymentIntentsStatus.RequiresConfirmation) {
setState(() {
canConfirm = true;
clientSecretForConfirm = result.clientSecret;
clientSecretForConfirm = paymentIntent!.clientSecret;
});
if (context.mounted) {
scaffoldMessenger.showSnackBar(
Expand Down
12 changes: 8 additions & 4 deletions packages/stripe/lib/src/stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,10 @@ class Stripe {

/// Collect the bankaccount details for the payment intent.
///
/// Only US bank accounts are supported.
Future<PaymentIntent> collectBankAccount({
/// Only US bank accounts are supported. The returned
/// [CollectBankAccountResult] is a sealed union containing either a
/// [PaymentIntent] or a [SetupIntent] depending on [isPaymentIntent].
Future<CollectBankAccountResult> collectBankAccount({
/// Whether the clientsecret is associated with setup or paymentintent
required bool isPaymentIntent,

Expand All @@ -655,8 +657,10 @@ class Stripe {
/// Verify the bank account with microtransactions
///
/// Only US bank accounts are supported.This method is only implemented for
/// iOS at the moment.
Future<PaymentIntent> verifyPaymentIntentWithMicrodeposits({
/// iOS at the moment. The returned [CollectBankAccountResult] is a sealed
/// union containing either a [PaymentIntent] or a [SetupIntent] depending on
/// [isPaymentIntent].
Future<CollectBankAccountResult> verifyPaymentIntentWithMicrodeposits({
/// Whether the clientsecret is associated with setup or paymentintent
required bool isPaymentIntent,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:stripe_platform_interface/src/result_parser.dart';

import 'models/app_info.dart';
import 'models/card_details.dart';
import 'models/collect_bank_account_result.dart';
import 'models/errors.dart';
import 'models/payment_intents.dart';
import 'models/payment_methods.dart';
Expand Down Expand Up @@ -569,7 +570,7 @@ class MethodChannelStripe extends StripePlatform {
}

@override
Future<PaymentIntent> collectBankAccount({
Future<CollectBankAccountResult> collectBankAccount({
required bool isPaymentIntent,
required String clientSecret,
required CollectBankAccountParams params,
Expand All @@ -583,13 +584,11 @@ class MethodChannelStripe extends StripePlatform {

_financialConnectionsEventHandler = params.onEvent;

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

@override
Future<PaymentIntent> verifyPaymentIntentWithMicrodeposits({
Future<CollectBankAccountResult> verifyPaymentIntentWithMicrodeposits({
required bool isPaymentIntent,
required String clientSecret,
required VerifyMicroDepositsParams params,
Expand All @@ -601,9 +600,7 @@ class MethodChannelStripe extends StripePlatform {
'clientSecret': clientSecret,
});

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

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:freezed_annotation/freezed_annotation.dart';

import 'errors.dart';
import 'payment_intents.dart';
import 'setup_intent.dart';

part 'collect_bank_account_result.freezed.dart';

/// Result of `collectBankAccount` / `verifyPaymentIntentWithMicrodeposits`.
///
/// Native SDKs return either a payment intent or a setup intent depending on
/// the client secret that was supplied, so the result is modelled as a sealed
/// union to keep both flows strongly typed.
@freezed
sealed class CollectBankAccountResult with _$CollectBankAccountResult {
Comment thread
remonh87 marked this conversation as resolved.
const factory CollectBankAccountResult.paymentIntent(
PaymentIntent paymentIntent,
) = CollectBankAccountPaymentIntentResult;

const factory CollectBankAccountResult.setupIntent(SetupIntent setupIntent) =
CollectBankAccountSetupIntentResult;

/// Parses a native method-channel response into the matching variant, or
/// throws [StripeException] when neither key is present.
factory CollectBankAccountResult.fromJson(Map<String, dynamic> json) {
final payment = json['paymentIntent'];
if (payment is Map<String, dynamic>) {
return CollectBankAccountResult.paymentIntent(
PaymentIntent.fromJson(payment),
);
}
final setup = json['setupIntent'];
if (setup is Map<String, dynamic>) {
return CollectBankAccountResult.setupIntent(SetupIntent.fromJson(setup));
}
throw StripeException.fromJson(json);
}
}
Loading
Loading