fix: correct termsDisplay type to Map<String, TermsDisplay>#2385
Conversation
…isplay> The native implementations expect termsDisplay as a map of payment method type strings to display settings, but the Dart model had it as a single enum value, causing it to be silently ignored by native code.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dart (1)
92-98:⚠️ Potential issue | 🔴 CriticalFix version number and document the breaking API change in changelog.
The termsDisplay change (from
TermsDisplay?toMap<String, TermsDisplay>?) is a breaking API change but 12.5.0 is a minor version bump. Semantic versioning requires a major version bump for breaking changes—this should be 13.0.0. Additionally, the changelog for 12.5.0 contains only a generic "Sync with Stripe React Native" entry with no mention of termsDisplay, the API change, or migration guidance.Either:
- Bump to version 13.0.0 and add a changelog entry documenting the breaking change with a migration example for callers updating from the single-enum shape to the map shape, or
- Revert the breaking change if the shape change was unintended.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dart` around lines 92 - 98, The change of the payment_sheet property termsDisplay from a single TermsDisplay? to Map<String, TermsDisplay>? is a breaking API change and requires a major version bump and changelog entry; update the package version to 13.0.0 (not 12.5.0) and add a detailed changelog note explaining the breaking change, include a migration example converting previous TermsDisplay usage to the new Map<String, TermsDisplay> shape, or alternatively revert the model change if the map shape was accidental; ensure references to the symbol termsDisplay and the enum TermsDisplay are mentioned in the changelog and migration snippet so callers can find and update usages.
🧹 Nitpick comments (1)
packages/stripe_platform_interface/lib/src/models/payment_sheet.dart (1)
668-677: Consider explicit type handling forvalue.The
valuefrom the JSON map isdynamic, and while the current implementation safely falls back toautomaticwhen there's no match, explicitly handling the expectedStringtype would make the intent clearer and provide better error resilience.♻️ Suggested improvement
Map<String, TermsDisplay>? _termsDisplayFromJson(Map<String, dynamic>? json) { if (json == null) return null; return json.map((key, value) => MapEntry( key, TermsDisplay.values.firstWhere( - (e) => e.name == value, + (e) => value is String && e.name == value, orElse: () => TermsDisplay.automatic, ), )); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/stripe_platform_interface/lib/src/models/payment_sheet.dart` around lines 668 - 677, The _termsDisplayFromJson function currently treats map values as dynamic; make the expected String handling explicit by converting or casting value to String (e.g., value as String? or value?.toString()) before comparing against TermsDisplay.name, and handle null/non-string cases by falling back to TermsDisplay.automatic; update the map conversion in _termsDisplayFromJson to coerce/validate the value to a String and then use TermsDisplay.values.firstWhere(..., orElse: () => TermsDisplay.automatic) so non-string or missing values are safely handled.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@packages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dart`:
- Around line 92-98: The change of the payment_sheet property termsDisplay from
a single TermsDisplay? to Map<String, TermsDisplay>? is a breaking API change
and requires a major version bump and changelog entry; update the package
version to 13.0.0 (not 12.5.0) and add a detailed changelog note explaining the
breaking change, include a migration example converting previous TermsDisplay
usage to the new Map<String, TermsDisplay> shape, or alternatively revert the
model change if the map shape was accidental; ensure references to the symbol
termsDisplay and the enum TermsDisplay are mentioned in the changelog and
migration snippet so callers can find and update usages.
---
Nitpick comments:
In `@packages/stripe_platform_interface/lib/src/models/payment_sheet.dart`:
- Around line 668-677: The _termsDisplayFromJson function currently treats map
values as dynamic; make the expected String handling explicit by converting or
casting value to String (e.g., value as String? or value?.toString()) before
comparing against TermsDisplay.name, and handle null/non-string cases by falling
back to TermsDisplay.automatic; update the map conversion in
_termsDisplayFromJson to coerce/validate the value to a String and then use
TermsDisplay.values.firstWhere(..., orElse: () => TermsDisplay.automatic) so
non-string or missing values are safely handled.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d1f9ffcb-e0cb-4ad8-b390-1bac02520f4d
📒 Files selected for processing (3)
packages/stripe_platform_interface/lib/src/models/payment_sheet.dartpackages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dartpackages/stripe_platform_interface/lib/src/models/payment_sheet.g.dart
Guard against non-string values from the JSON map by checking value is String before comparing against enum names.
remonh87
left a comment
There was a problem hiding this comment.
thank you That was indeed wrong
Summary
termsDisplayfield type fromTermsDisplay?(single enum) toMap<String, TermsDisplay>?{"card": "automatic"}but the Dart model was sending a bare string, causing it to be silently ignoredCloses part of #2378
Test plan
initPaymentSheetwith termsDisplay map on both platformsSummary by CodeRabbit