mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 15:35:22 +02:00
Merge branch 'main' of github.com:maybe-finance/maybe into zachgoll/plaid-domain-improvements
This commit is contained in:
commit
3cab7164d3
5 changed files with 36 additions and 3 deletions
|
@ -10,7 +10,6 @@
|
|||
variant: "outline",
|
||||
disabled: Current.family.syncing?,
|
||||
icon: "refresh-cw",
|
||||
class: ""
|
||||
) %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% elsif Rails.env.development? %>
|
||||
<%= icon(
|
||||
"refresh-cw",
|
||||
as_button: true,
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class AddUniquenessToSubscriptions < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
remove_index :subscriptions, :family_id
|
||||
add_index :subscriptions, :family_id, unique: true
|
||||
end
|
||||
end
|
2
db/schema.rb
generated
2
db/schema.rb
generated
|
@ -580,7 +580,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_05_12_171654) do
|
|||
t.datetime "trial_ends_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["family_id"], name: "index_subscriptions_on_family_id"
|
||||
t.index ["family_id"], name: "index_subscriptions_on_family_id", unique: true
|
||||
end
|
||||
|
||||
create_table "syncs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
|
|
28
lib/tasks/stripe.rake
Normal file
28
lib/tasks/stripe.rake
Normal file
|
@ -0,0 +1,28 @@
|
|||
namespace :stripe do
|
||||
desc "Sync legacy Stripe subscriptions"
|
||||
task sync_legacy_subscriptions: :environment do
|
||||
cli = Stripe::StripeClient.new(ENV["STRIPE_SECRET_KEY"])
|
||||
|
||||
subs = cli.v1.subscriptions.list
|
||||
|
||||
subs.auto_paging_each do |sub|
|
||||
details = sub.items.data.first
|
||||
|
||||
family = Family.find_by(stripe_customer_id: sub.customer)
|
||||
|
||||
if family.nil?
|
||||
puts "Family not found for Stripe customer ID: #{sub.customer}, skipping"
|
||||
next
|
||||
end
|
||||
|
||||
family.subscription.update!(
|
||||
stripe_id: sub.id,
|
||||
status: sub.status,
|
||||
interval: details.plan.interval,
|
||||
amount: details.plan.amount / 100.0,
|
||||
currency: details.plan.currency.upcase,
|
||||
current_period_ends_at: Time.at(details.current_period_end)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue