Skip to content

Commit 4f0562b

Browse files
committed
feat(web): implement collectBankAccount and verifyMicrodeposits
Replace the UnimplementedError stubs in WebStripe with real implementations backed by the stripe_js bindings. Both collectBankAccount and verifyPaymentIntentWithMicrodeposits dispatch on isPaymentIntent and delegate to the corresponding Stripe.js call, returning a CollectBankAccountResult that wraps either the PaymentIntent or SetupIntent parsed from the JS response.
1 parent 57a75e7 commit 4f0562b

1 file changed

Lines changed: 86 additions & 10 deletions

File tree

packages/stripe_web/lib/src/web_stripe.dart

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -509,19 +509,95 @@ class WebStripe extends StripePlatform {
509509
}
510510

511511
@override
512-
Future<CollectBankAccountResult> collectBankAccount(
513-
{required bool isPaymentIntent,
514-
required String clientSecret,
515-
required CollectBankAccountParams params}) {
516-
throw UnimplementedError();
512+
Future<CollectBankAccountResult> collectBankAccount({
513+
required bool isPaymentIntent,
514+
required String clientSecret,
515+
required CollectBankAccountParams params,
516+
}) async {
517+
final billingDetails = params.paymentMethodData.billingDetails.toJs();
518+
519+
if (isPaymentIntent) {
520+
final response = await js.collectBankAccountForPayment(
521+
clientSecret,
522+
params: stripe_js.CollectBankAccountForPaymentParams(
523+
paymentMethodType: 'us_bank_account',
524+
paymentMethodData: stripe_js.CollectBankAccountForPaymentMethodData(
525+
billingDetails: billingDetails,
526+
),
527+
),
528+
);
529+
if (response.error != null) {
530+
throw StripeError(
531+
message: response.error?.message ?? '',
532+
code: response.error!.code,
533+
);
534+
}
535+
return CollectBankAccountResult.paymentIntent(
536+
response.paymentIntent!.parse(),
537+
);
538+
}
539+
540+
final response = await js.collectBankAccountForSetup(
541+
clientSecret,
542+
params: stripe_js.CollectBankAccountForSetupParams(
543+
paymentMethodType: 'us_bank_account',
544+
paymentMethodData: stripe_js.CollectBankAccountForSetupMethodData(
545+
billingDetails: billingDetails,
546+
),
547+
),
548+
);
549+
if (response.error != null) {
550+
throw StripeError(
551+
message: response.error?.message ?? '',
552+
code: response.error!.code,
553+
);
554+
}
555+
return CollectBankAccountResult.setupIntent(
556+
response.setupIntent!.parse(),
557+
);
517558
}
518559

519560
@override
520-
Future<CollectBankAccountResult> verifyPaymentIntentWithMicrodeposits(
521-
{required bool isPaymentIntent,
522-
required String clientSecret,
523-
required VerifyMicroDepositsParams params}) {
524-
throw UnimplementedError();
561+
Future<CollectBankAccountResult> verifyPaymentIntentWithMicrodeposits({
562+
required bool isPaymentIntent,
563+
required String clientSecret,
564+
required VerifyMicroDepositsParams params,
565+
}) async {
566+
if (isPaymentIntent) {
567+
final response = await js.verifyMicrodepositsForPayment(
568+
clientSecret,
569+
data: stripe_js.VerifyMicrodepositsForPaymentData(
570+
amounts: params.amounts,
571+
descriptorCode: params.descriptorCode,
572+
),
573+
);
574+
if (response.error != null) {
575+
throw StripeError(
576+
message: response.error?.message ?? '',
577+
code: response.error!.code,
578+
);
579+
}
580+
return CollectBankAccountResult.paymentIntent(
581+
response.paymentIntent!.parse(),
582+
);
583+
}
584+
585+
final response = await js.verifyMicrodepositsForSetup(
586+
clientSecret,
587+
data: stripe_js.VerifyMicrodepositsForSetupData(
588+
amounts: params.amounts,
589+
descriptorCode: params.descriptorCode,
590+
),
591+
);
592+
if (response.error != null) {
593+
throw StripeError(
594+
message: response.error?.message ?? '',
595+
code: response.error!.code,
596+
);
597+
}
598+
return CollectBankAccountResult.setupIntent(
599+
response.setupIntent!.parse(),
600+
);
525601
}
526602

527603
@override

0 commit comments

Comments
 (0)