From df8e22afe9e56341365e7d7e0b2b58141949ad33 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Tue, 13 May 2025 08:56:32 -0400 Subject: [PATCH] Stripe tasks --- lib/tasks/stripe.rake | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/tasks/stripe.rake diff --git a/lib/tasks/stripe.rake b/lib/tasks/stripe.rake new file mode 100644 index 00000000..7e2124de --- /dev/null +++ b/lib/tasks/stripe.rake @@ -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