mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Subscription tests and domain (#2209)
* Save work * Subscriptions and trials domain * Store family ID on customer * Remove indirection of stripe calls * Test simplifications * Update brakeman * Fix stripe tests in CI * Update billing page to show subscription details * Remove legacy columns * Complete billing settings page * Fix hardcoded plan name * Handle subscriptions for self hosting mode * Lint fixes
This commit is contained in:
parent
8c10e87387
commit
5da4bb6dc3
40 changed files with 1041 additions and 233 deletions
46
db/migrate/20250502164951_create_subscriptions.rb
Normal file
46
db/migrate/20250502164951_create_subscriptions.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
class CreateSubscriptions < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
create_table :subscriptions, id: :uuid do |t|
|
||||
t.references :family, null: false, foreign_key: true, type: :uuid
|
||||
|
||||
t.string :status, null: false
|
||||
|
||||
t.string :stripe_id
|
||||
t.decimal :amount, precision: 19, scale: 4
|
||||
t.string :currency
|
||||
t.string :interval
|
||||
|
||||
t.datetime :current_period_ends_at
|
||||
t.datetime :trial_ends_at
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
if Rails.application.config.app_mode.managed?
|
||||
execute <<~SQL
|
||||
INSERT INTO subscriptions (family_id, status, trial_ends_at, created_at, updated_at)
|
||||
SELECT
|
||||
f.id,
|
||||
CASE
|
||||
WHEN f.trial_started_at IS NOT NULL THEN 'trialing'
|
||||
ELSE COALESCE(f.stripe_subscription_status, 'incomplete')
|
||||
END,
|
||||
CASE
|
||||
WHEN f.trial_started_at IS NOT NULL THEN f.trial_started_at + INTERVAL '14 days'
|
||||
ELSE NULL
|
||||
END,
|
||||
now(),
|
||||
now()
|
||||
FROM families f
|
||||
SQL
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
remove_column :families, :stripe_subscription_status, :string
|
||||
remove_column :families, :trial_started_at, :datetime
|
||||
remove_column :families, :stripe_plan_id, :string
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue