Skip to content

fix: correct termsDisplay type to Map<String, TermsDisplay>#2385

Merged
remonh87 merged 2 commits into
flutter-stripe:mainfrom
realmeylisdev:fix/terms-display-type
Apr 9, 2026
Merged

fix: correct termsDisplay type to Map<String, TermsDisplay>#2385
remonh87 merged 2 commits into
flutter-stripe:mainfrom
realmeylisdev:fix/terms-display-type

Conversation

@realmeylisdev

@realmeylisdev realmeylisdev commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix termsDisplay field type from TermsDisplay? (single enum) to Map<String, TermsDisplay>?
  • Both native platforms expect a map like {"card": "automatic"} but the Dart model was sending a bare string, causing it to be silently ignored

Closes part of #2378

Test plan

  • Verify serialized JSON contains map structure
  • Run initPaymentSheet with termsDisplay map on both platforms

Summary by CodeRabbit

  • Improvements
    • Payment sheet setup now supports configurable terms-display settings per payment method, giving finer control over how terms are shown.
  • Bug Fixes
    • Unknown or unsupported terms-display values now safely default to automatic presentation to ensure consistent behavior.

…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.
@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6abcb536-c1ad-4650-9913-d2a2ea9a0322

📥 Commits

Reviewing files that changed from the base of the PR and between e52b06d and c29fda0.

📒 Files selected for processing (1)
  • packages/stripe_platform_interface/lib/src/models/payment_sheet.dart

📝 Walkthrough

Walkthrough

The termsDisplay field on SetupPaymentSheetParameters was changed from a single TermsDisplay? enum to a Map<String, TermsDisplay>?, with custom JSON (de)serialization helpers and updated generated Freezed/JSON code to handle the map and fallback unknown values to TermsDisplay.automatic.

Changes

Cohort / File(s) Summary
Model Definition & Serialization
packages/stripe_platform_interface/lib/src/models/payment_sheet.dart
Replaced TermsDisplay? termsDisplay with Map<String, TermsDisplay>? termsDisplay; added @JsonKey(toJson: _termsDisplayToJson, fromJson: _termsDisplayFromJson) and implemented helpers that serialize enum names and deserialize with unknown-value fallback to TermsDisplay.automatic.
Generated Freezed Model Code
packages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dart
Updated type references for termsDisplay across equality, hashCode, copyWith, private backing field, public getter (now returns EqualUnmodifiableMapView), and when/maybeWhen/whenOrNull callback signatures to Map<String, TermsDisplay>?.
Generated JSON Serialization
packages/stripe_platform_interface/lib/src/models/payment_sheet.g.dart
Replaced usage of generated enum map with calls to _termsDisplayFromJson/_termsDisplayToJson; removed _$TermsDisplayEnumMap constant and adjusted (de)serialization logic to use the custom helpers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Poem

🐰 I mapped each method's tiny voice,
From single enum to many-choice.
Helpers nibble, unknowns set right,
I hop in code through day and night.
Hooray—more fine-grained config delight! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: updating the termsDisplay field type from a single TermsDisplay enum to a Map<String, TermsDisplay>, which aligns with all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🔴 Critical

Fix version number and document the breaking API change in changelog.

The termsDisplay change (from TermsDisplay? to Map<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 for value.

The value from the JSON map is dynamic, and while the current implementation safely falls back to automatic when there's no match, explicitly handling the expected String type 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e221d6 and e52b06d.

📒 Files selected for processing (3)
  • packages/stripe_platform_interface/lib/src/models/payment_sheet.dart
  • packages/stripe_platform_interface/lib/src/models/payment_sheet.freezed.dart
  • packages/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 remonh87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you That was indeed wrong

@remonh87 remonh87 merged commit eaf6533 into flutter-stripe:main Apr 9, 2026
3 of 6 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants