Skip to content

Fix LatestPeriodType case-insensitive deserialization for Stripe#379

Merged
ianrumac merged 2 commits intodevelopfrom
fix/latest-period-type-case-insensitive-serializer
Mar 10, 2026
Merged

Fix LatestPeriodType case-insensitive deserialization for Stripe#379
ianrumac merged 2 commits intodevelopfrom
fix/latest-period-type-case-insensitive-serializer

Conversation

@anglinb
Copy link
Contributor

@anglinb anglinb commented Mar 10, 2026

Summary

  • Replaces @SerialName-based serialization on LatestPeriodType with a custom case-insensitive serializer, matching the existing pattern used by LatestSubscriptionState
  • Fixes SerializationException when Stripe backend returns lowercase offerType values (e.g. "trial") in subscription/entitlement responses
  • Adds missing CODE and WINBACK variants to reach parity with the iOS OfferType enum
  • Updates ReceiptManager.determinePeriodType() to handle the two new variants

Test plan

  • Deserialize a Stripe subscription JSON with "offerType": "trial" and confirm no exception is thrown
  • Confirm existing Play Store responses with uppercase "TRIAL" still deserialize correctly
  • Verify determinePeriodType() returns the expected string for all LatestPeriodType values

🤖 Generated with Claude Code

Greptile Summary

This PR successfully fixes the SerializationException crashes caused by Stripe returning lowercase offerType values by implementing a custom case-insensitive KSerializer on LatestPeriodType. The implementation correctly mirrors the deserialization pattern used in the codebase.

Changes verified:

  • LatestPeriodType.kt: Custom deserializer with case-insensitive matching of enum values (handles "trial", "TRIAL", etc.)
  • LatestPeriodType.kt: Adds CODE and WINBACK enum variants for parity with iOS
  • ReceiptManager.kt: All six LatestPeriodType values are handled in determinePeriodType() with appropriate string mappings

The fix correctly resolves the stated problem: lowercase values from Stripe now deserialize without exceptions, while maintaining backward compatibility with existing uppercase formats.

Confidence Score: 4/5

  • Low risk — the case-insensitive deserialization fix is correct and correctly wired into ReceiptManager.
  • The PR implements a straightforward and correct fix for the stated problem: handling lowercase offerType values from Stripe. The custom serializer correctly implements case-insensitive deserialization, the new enum variants are properly added, and all six values are handled in the determinePeriodType() method. The implementation follows established patterns in the codebase. Minor consideration: the serializer throws on truly unknown values (rather than returning a fallback), but this is not a demonstrated issue with current Stripe data and the test plan focuses on known values.
  • No files require special attention.

Sequence Diagram

sequenceDiagram
    participant Stripe as Stripe Backend
    participant SDK as SDK (JSON Deserializer)
    participant Serializer as LatestPeriodTypeSerializer
    participant RM as ReceiptManager

    Stripe->>SDK: { "offerType": "trial" } (lowercase)
    SDK->>Serializer: decodeString("trial")
    Serializer->>Serializer: find entry where name.equals("trial", ignoreCase=true)
    alt Known value (TRIAL, CODE, SUBSCRIPTION, PROMOTIONAL, WINBACK, REVOKED)
        Serializer-->>SDK: LatestPeriodType.TRIAL
        SDK-->>RM: latestSubscriptionPeriodType = TRIAL
        RM->>RM: determinePeriodType() → "trial"
    else Unknown value (e.g. "new_type")
        Serializer-->>SDK: throws SerializationException
    end
Loading

Last reviewed commit: 0843c57

anglinb and others added 2 commits March 9, 2026 16:57
Replace @SerialName-based serialization with a custom case-insensitive
serializer so both lowercase Stripe values ("trial") and uppercase Play
Store values ("TRIAL") deserialize correctly. Add missing CODE and
WINBACK variants to match iOS OfferType parity.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ianrumac ianrumac merged commit f5aa48a into develop Mar 10, 2026
1 check failed
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