Fix Stripe error on demo family deletion
This PR addresses an Stripe::InvalidRequestError that occurred when deleting demo families, specifically Stripe::InvalidRequestError: No such subscription: 'sub_demo_123'.
Problem:
Demo families are created with a synthetic stripe_id of 'sub_demo_123' by Demo::Generator. When a demo family was destroyed (e.g., by UserPurgeJob), the Family::Subscribeable#cancel_or_reject_active_subscription callback would attempt to cancel this non-existent subscription via the Stripe API, leading to an error.
Solution:
- Centralized Sentinel ID: The
'sub_demo_123'string has been extracted into a constantSubscription::DEMO_STRIPE_IDto serve as the single source of truth for the demo sentinel. synthetic?Predicate: Asynthetic?method has been added to theSubscriptionmodel. This predicate returnstrueif the subscription'sstripe_idmatchesSubscription::DEMO_STRIPE_ID, providing a clear way to identify demo subscriptions.- Guarded Stripe API Call: The
Family::Subscribeable#cancel_or_reject_active_subscriptioncallback now usessubscription.synthetic?as an early return guard. This prevents any attempt to call the Stripe API for demo subscriptions, resolving theInvalidRequestError. - Dependency Direction: This refactoring ensures that core billing logic (
Family::Subscribeable) does not have a direct dependency onDemo::Generator, improving architectural clarity. - Code Cleanup:
- Removed redundant
subscription.update!(status: :canceled)logic fromDemoFamilyRefreshJobas the primary guard is now inFamily::Subscribeable. - Updated comments and test files to consistently use
Subscription::DEMO_STRIPE_ID. - Fixed a
Layout/EmptyLinesAroundMethodBodyRuboCop violation inapp/jobs/demo_family_refresh_job.rb.
- Removed redundant
This change ensures that demo family deletion proceeds smoothly without unnecessary external API calls or errors.
Fixes SURE-APP-1BW
@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run
This PR was automatically generated by Sentry. You can adjust this setting at any time.