@@ -14,6 +14,7 @@ import 'package:stripe_platform_interface/src/models/wallet.dart';
1414import 'package:stripe_platform_interface/src/result_parser.dart' ;
1515
1616import 'models/app_info.dart' ;
17+ import 'models/capture_method.dart' ;
1718import 'models/card_details.dart' ;
1819import 'models/errors.dart' ;
1920import 'models/payment_intents.dart' ;
@@ -583,9 +584,7 @@ class MethodChannelStripe extends StripePlatform {
583584
584585 _financialConnectionsEventHandler = params.onEvent;
585586
586- return ResultParser <PaymentIntent >(
587- parseJson: (json) => PaymentIntent .fromJson (json),
588- ).parse (result: result! , successResultKey: 'paymentIntent' );
587+ return _parseIntentResult (result! , isPaymentIntent: isPaymentIntent);
589588 }
590589
591590 @override
@@ -601,9 +600,73 @@ class MethodChannelStripe extends StripePlatform {
601600 'clientSecret' : clientSecret,
602601 });
603602
603+ return _parseIntentResult (result! , isPaymentIntent: isPaymentIntent);
604+ }
605+
606+ /// Parses a method channel result that may contain either a `paymentIntent`
607+ /// or `setupIntent` key depending on [isPaymentIntent] .
608+ ///
609+ /// When [isPaymentIntent] is false, the native SDK returns the result under
610+ /// the `setupIntent` key. This helper converts the setup intent data into a
611+ /// [PaymentIntent] to satisfy the platform interface contract.
612+ PaymentIntent _parseIntentResult (
613+ Map <String , dynamic > result, {
614+ required bool isPaymentIntent,
615+ }) {
616+ if (isPaymentIntent) {
617+ return ResultParser <PaymentIntent >(
618+ parseJson: (json) => PaymentIntent .fromJson (json),
619+ ).parse (result: result, successResultKey: 'paymentIntent' );
620+ }
621+
622+ final setupIntentJson = result['setupIntent' ] as Map <String , dynamic >? ;
623+ if (setupIntentJson != null ) {
624+ return PaymentIntent (
625+ id: setupIntentJson['id' ] as String ? ?? '' ,
626+ amount: 0 ,
627+ created: setupIntentJson['created' ]? .toString () ?? '' ,
628+ currency: '' ,
629+ status: _parseStatus (setupIntentJson['status' ] as String ? ?? '' ),
630+ clientSecret: setupIntentJson['clientSecret' ] as String ? ?? '' ,
631+ livemode: setupIntentJson['livemode' ] as bool ? ?? false ,
632+ paymentMethodId: setupIntentJson['paymentMethodId' ] as String ? ,
633+ captureMethod: CaptureMethod .Automatic ,
634+ confirmationMethod: ConfirmationMethod .Automatic ,
635+ );
636+ }
637+
638+ // Fallback: try paymentIntent key in case the native SDK format changes.
604639 return ResultParser <PaymentIntent >(
605640 parseJson: (json) => PaymentIntent .fromJson (json),
606- ).parse (result: result! , successResultKey: 'paymentIntent' );
641+ ).parse (result: result, successResultKey: 'paymentIntent' );
642+ }
643+
644+ static PaymentIntentsStatus _parseStatus (String value) {
645+ switch (value) {
646+ case 'Succeeded' :
647+ case 'succeeded' :
648+ return PaymentIntentsStatus .Succeeded ;
649+ case 'RequiresPaymentMethod' :
650+ case 'requires_payment_method' :
651+ return PaymentIntentsStatus .RequiresPaymentMethod ;
652+ case 'RequiresConfirmation' :
653+ case 'requires_confirmation' :
654+ return PaymentIntentsStatus .RequiresConfirmation ;
655+ case 'Canceled' :
656+ case 'canceled' :
657+ return PaymentIntentsStatus .Canceled ;
658+ case 'Processing' :
659+ case 'processing' :
660+ return PaymentIntentsStatus .Processing ;
661+ case 'RequiresAction' :
662+ case 'requires_action' :
663+ return PaymentIntentsStatus .RequiresAction ;
664+ case 'RequiresCapture' :
665+ case 'requires_capture' :
666+ return PaymentIntentsStatus .RequiresCapture ;
667+ default :
668+ return PaymentIntentsStatus .Unknown ;
669+ }
607670 }
608671
609672 @override
0 commit comments