mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 22:34:47 +00:00
* fix: Show cancellation message when subscription is pending cancellation When a subscription is cancelled via Stripe, the UI incorrectly showed "Your contribution continues on..." instead of reflecting the cancellation status. This fix adds tracking of `cancel_at_period_end` from Stripe webhooks and displays "Your contribution ends on..." when a subscription has been cancelled but is still active until the billing period ends. https://claude.ai/code/session_01Y8ELTdK1k9o315iSq43TRN * chore: Update schema.rb with cancel_at_period_end column https://claude.ai/code/session_01Y8ELTdK1k9o315iSq43TRN * Schema version --------- Co-authored-by: Claude <noreply@anthropic.com>
43 lines
914 B
Ruby
43 lines
914 B
Ruby
class Subscription < ApplicationRecord
|
|
TRIAL_DAYS = 45
|
|
|
|
belongs_to :family
|
|
|
|
# https://docs.stripe.com/api/subscriptions/object
|
|
enum :status, {
|
|
incomplete: "incomplete",
|
|
incomplete_expired: "incomplete_expired",
|
|
trialing: "trialing", # We use this, but "offline" (no through Stripe's interface)
|
|
active: "active",
|
|
past_due: "past_due",
|
|
canceled: "canceled",
|
|
unpaid: "unpaid",
|
|
paused: "paused"
|
|
}
|
|
|
|
validates :stripe_id, presence: true, if: :active?
|
|
validates :trial_ends_at, presence: true, if: :trialing?
|
|
validates :family_id, uniqueness: true
|
|
|
|
class << self
|
|
def new_trial_ends_at
|
|
TRIAL_DAYS.days.from_now
|
|
end
|
|
end
|
|
|
|
def name
|
|
case interval
|
|
when "month"
|
|
"Monthly Contribution"
|
|
when "year"
|
|
"Annual Contribution"
|
|
else
|
|
"Open demo"
|
|
end
|
|
end
|
|
|
|
def pending_cancellation?
|
|
active? && cancel_at_period_end?
|
|
end
|
|
end
|