1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00
Maybe/lib/tasks/stripe.rake
Zach Gollwitzer df8e22afe9 Stripe tasks
2025-05-13 08:56:32 -04:00

28 lines
796 B
Ruby

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