Billing upgrade/downgrade, inviti in app e diretta YouTube da mobile.
Upgrade Stripe con addebito immediato; downgrade programmato a fine periodo. UX billing più sobria con box info; icone piani. API inviti e OAuth YouTube per staff trasmissione; deep link join; scelta partita programmata o nuova. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -11,48 +11,69 @@ RSpec.describe Billing::Stripe::ChangePlan do
|
||||
status: "active",
|
||||
stripe_attrs: {
|
||||
stripe_customer_id: "cus_test",
|
||||
stripe_subscription_id: "sub_test_123"
|
||||
stripe_subscription_id: "sub_test_123",
|
||||
billing_interval: "monthly",
|
||||
current_period_end: 1.month.from_now
|
||||
}
|
||||
)
|
||||
allow(MatchLiveTv).to receive(:stripe_enabled?).and_return(true)
|
||||
allow(MatchLiveTv).to receive(:stripe_premium_light_yearly_price_id).and_return("price_light_y")
|
||||
allow(MatchLiveTv).to receive(:stripe_premium_light_monthly_price_id).and_return("price_light_m")
|
||||
allow(MatchLiveTv).to receive(:stripe_premium_full_yearly_price_id).and_return("price_full_y")
|
||||
allow(MatchLiveTv).to receive(:stripe_premium_light_yearly_price_id).and_return("price_light_y")
|
||||
allow(MatchLiveTv).to receive(:stripe_premium_full_monthly_price_id).and_return("price_full_m")
|
||||
allow(MatchLiveTv).to receive(:stripe_premium_full_yearly_price_id).and_return("price_full_y")
|
||||
end
|
||||
|
||||
it "aggiorna Stripe e il piano locale verso premium_full" do
|
||||
stripe_item = double(id: "si_test")
|
||||
it "upgrade: always_invoice e addebito immediato" do
|
||||
stripe_item = double(id: "si_test", price: double(id: "price_light_m"))
|
||||
stripe_sub = double(
|
||||
id: "sub_test_123",
|
||||
customer: "cus_test",
|
||||
status: "active",
|
||||
current_period_start: Time.current.to_i,
|
||||
current_period_end: 1.year.from_now.to_i,
|
||||
cancel_at_period_end: false,
|
||||
items: double(data: [stripe_item])
|
||||
)
|
||||
updated_sub = stripe_sub
|
||||
allow(stripe_sub).to receive(:current_period_start).and_return(Time.current.to_i)
|
||||
allow(stripe_sub).to receive(:current_period_end).and_return(1.month.from_now.to_i)
|
||||
allow(stripe_item).to receive(:current_period_start).and_return(Time.current.to_i)
|
||||
allow(stripe_item).to receive(:current_period_end).and_return(1.month.from_now.to_i)
|
||||
|
||||
invoice = double(id: "in_up", status: "paid", amount_paid: 1500, currency: "eur")
|
||||
allow(Stripe::Subscription).to receive(:retrieve).with("sub_test_123").and_return(stripe_sub)
|
||||
allow(Stripe::Subscription).to receive(:update).and_return(updated_sub)
|
||||
allow(Stripe::Subscription).to receive(:update).and_return(stripe_sub)
|
||||
allow(Stripe::Invoice).to receive(:list).and_return(double(data: [invoice]))
|
||||
allow(Billing::Stripe::RecordPayment).to receive(:call)
|
||||
|
||||
described_class.call(club: club, plan_slug: "premium_full", interval: "yearly")
|
||||
result = described_class.call(club: club, plan_slug: "premium_full", interval: "monthly")
|
||||
|
||||
expect(Stripe::Subscription).to have_received(:update).with(
|
||||
"sub_test_123",
|
||||
hash_including(
|
||||
items: [{ id: "si_test", price: "price_full_y" }],
|
||||
metadata: { club_id: club.id, plan_slug: "premium_full", billing_interval: "yearly" }
|
||||
)
|
||||
hash_including(proration_behavior: "always_invoice", payment_behavior: "error_if_incomplete")
|
||||
)
|
||||
expect(result).to be_upgrade
|
||||
expect(club.reload.subscription.plan.slug).to eq("premium_full")
|
||||
end
|
||||
|
||||
it "rifiuta il cambio sullo stesso piano e intervallo" do
|
||||
club.subscription.update!(billing_interval: "yearly")
|
||||
expect {
|
||||
described_class.call(club: club, plan_slug: "premium_light", interval: "yearly")
|
||||
}.to raise_error(/già su questo piano/)
|
||||
it "downgrade: programma ScheduleDowngrade senza cambiare piano subito" do
|
||||
Billing::AssignPlan.call(
|
||||
club: club,
|
||||
plan_slug: "premium_full",
|
||||
status: "active",
|
||||
stripe_attrs: { stripe_subscription_id: "sub_test_123", billing_interval: "monthly" }
|
||||
)
|
||||
|
||||
allow(Billing::Stripe::ScheduleDowngrade).to receive(:call).and_return(
|
||||
Billing::Stripe::ChangePlanResult.new(
|
||||
kind: :downgrade,
|
||||
plan_slug: "premium_light",
|
||||
interval: "monthly",
|
||||
effective_at: 1.month.from_now
|
||||
)
|
||||
)
|
||||
|
||||
result = described_class.call(club: club, plan_slug: "premium_light", interval: "monthly")
|
||||
|
||||
expect(Billing::Stripe::ScheduleDowngrade).to have_received(:call)
|
||||
expect(result).to be_downgrade
|
||||
expect(club.reload.subscription.plan.slug).to eq("premium_full")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Billing::Stripe::PlanChangeKind do
|
||||
before { load Rails.root.join("db/seeds/plans.rb") }
|
||||
|
||||
it "classifica light → full come upgrade" do
|
||||
expect(described_class.classify(
|
||||
from_plan_slug: "premium_light",
|
||||
from_interval: "monthly",
|
||||
to_plan_slug: "premium_full",
|
||||
to_interval: "monthly"
|
||||
)).to eq(:upgrade)
|
||||
end
|
||||
|
||||
it "classifica full → light come downgrade" do
|
||||
expect(described_class.classify(
|
||||
from_plan_slug: "premium_full",
|
||||
from_interval: "monthly",
|
||||
to_plan_slug: "premium_light",
|
||||
to_interval: "monthly"
|
||||
)).to eq(:downgrade)
|
||||
end
|
||||
|
||||
it "classifica passaggio a annuale come upgrade sullo stesso piano" do
|
||||
expect(described_class.classify(
|
||||
from_plan_slug: "premium_light",
|
||||
from_interval: "monthly",
|
||||
to_plan_slug: "premium_light",
|
||||
to_interval: "yearly"
|
||||
)).to eq(:upgrade)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user