Billing Stripe, link regia mobile e staff solo trasmissione.
Aggiunge fatturazione club, pagina regia condivisibile senza account, roster squadre e rimuove la modalità controller dall'app (v1.1.0). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
57
backend/spec/services/billing/stripe/change_plan_spec.rb
Normal file
57
backend/spec/services/billing/stripe/change_plan_spec.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Billing::Stripe::ChangePlan do
|
||||
let(:club) { Club.create!(name: "Billing Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
|
||||
|
||||
before do
|
||||
load Rails.root.join("db/seeds/plans.rb")
|
||||
Billing::AssignPlan.call(
|
||||
club: club,
|
||||
plan_slug: "premium_light",
|
||||
status: "active",
|
||||
stripe_attrs: {
|
||||
stripe_customer_id: "cus_test",
|
||||
stripe_subscription_id: "sub_test_123"
|
||||
}
|
||||
)
|
||||
allow(MatchLiveTv).to receive(:stripe_enabled?).and_return(true)
|
||||
allow(MatchLiveTv).to receive(:stripe_premium_light_price_id).and_return("price_light")
|
||||
allow(MatchLiveTv).to receive(:stripe_premium_full_price_id).and_return("price_full")
|
||||
Plan.find_by!(slug: "premium_light").update!(stripe_price_id: "price_light")
|
||||
Plan.find_by!(slug: "premium_full").update!(stripe_price_id: "price_full")
|
||||
end
|
||||
|
||||
it "aggiorna Stripe e il piano locale verso premium_full" do
|
||||
stripe_item = double(id: "si_test")
|
||||
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::Subscription).to receive(:retrieve).with("sub_test_123").and_return(stripe_sub)
|
||||
allow(Stripe::Subscription).to receive(:update).and_return(updated_sub)
|
||||
|
||||
described_class.call(club: club, plan_slug: "premium_full")
|
||||
|
||||
expect(Stripe::Subscription).to have_received(:update).with(
|
||||
"sub_test_123",
|
||||
hash_including(
|
||||
items: [{ id: "si_test", price: "price_full" }],
|
||||
metadata: { club_id: club.id, plan_slug: "premium_full" }
|
||||
)
|
||||
)
|
||||
expect(club.reload.subscription.plan.slug).to eq("premium_full")
|
||||
end
|
||||
|
||||
it "rifiuta il cambio sullo stesso piano" do
|
||||
expect {
|
||||
described_class.call(club: club, plan_slug: "premium_light")
|
||||
}.to raise_error(/già su questo piano/)
|
||||
end
|
||||
end
|
||||
37
backend/spec/services/billing/stripe/record_payment_spec.rb
Normal file
37
backend/spec/services/billing/stripe/record_payment_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Billing::Stripe::RecordPayment do
|
||||
let(:club) { Club.create!(name: "Pay Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
|
||||
|
||||
before do
|
||||
load Rails.root.join("db/seeds/plans.rb")
|
||||
Billing::AssignPlan.call(club: club, plan_slug: "premium_light", stripe_attrs: { stripe_subscription_id: "sub_x" })
|
||||
end
|
||||
|
||||
it "crea un pagamento da fattura Stripe" do
|
||||
invoice = double(
|
||||
id: "in_test_1",
|
||||
subscription: "sub_x",
|
||||
metadata: { "club_id" => club.id },
|
||||
amount_paid: 4000,
|
||||
currency: "eur",
|
||||
status: "paid",
|
||||
description: "Premium Light",
|
||||
payment_intent: "pi_x",
|
||||
charge: "ch_x",
|
||||
invoice_pdf: "https://stripe.com/invoice.pdf",
|
||||
hosted_invoice_url: "https://stripe.com/hosted",
|
||||
status_transitions: double(paid_at: Time.current.to_i),
|
||||
lines: double(data: [double(description: "Premium Light annuale")]),
|
||||
subscription_details: nil
|
||||
)
|
||||
allow(invoice).to receive(:metadata).and_return({ "club_id" => club.id })
|
||||
|
||||
payment = described_class.call(stripe_invoice: invoice)
|
||||
|
||||
expect(payment).to be_persisted
|
||||
expect(payment.club).to eq(club)
|
||||
expect(payment.amount_cents).to eq(4000)
|
||||
expect(payment.stripe_invoice_id).to eq("in_test_1")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user