diff --git a/config/initializers/stripe.rb b/config/initializers/stripe.rb index e0c3e70e7..66af4fc28 100644 --- a/config/initializers/stripe.rb +++ b/config/initializers/stripe.rb @@ -8,37 +8,6 @@ Stripe.api_version = ENV['STRIPE_API_VERSION'] || '2025-08-27.preview' # V2 Billing Configuration Rails.application.config.stripe_v2 = { enabled: ENV['STRIPE_V2_ENABLED'] == 'true', - usage_reporting_enabled: ENV['STRIPE_V2_USAGE_REPORTING_ENABLED'] != 'false', meter_id: ENV.fetch('STRIPE_V2_METER_ID', nil), - meter_event_name: ENV.fetch('STRIPE_V2_METER_EVENT_NAME', nil), - - # Plan-specific configurations - plans: { - free: { - pricing_plan_id: ENV.fetch('STRIPE_V2_FREE_PLAN_ID', nil), - monthly_credits: ENV.fetch('STRIPE_V2_FREE_CREDITS', '100').to_i, - price_per_agent_per_month: ENV.fetch('STRIPE_V2_FREE_PRICE', '0').to_f - }, - startup: { - pricing_plan_id: ENV.fetch('STRIPE_V2_STARTUP_PLAN_ID', nil), - monthly_credits: ENV.fetch('STRIPE_V2_STARTUP_CREDITS', '500').to_i, - price_per_agent_per_month: ENV.fetch('STRIPE_V2_STARTUP_PRICE', '19').to_f - }, - business: { - pricing_plan_id: ENV.fetch('STRIPE_V2_BUSINESS_PLAN_ID', nil), - monthly_credits: ENV.fetch('STRIPE_V2_BUSINESS_CREDITS', '2000').to_i, - price_per_agent_per_month: ENV.fetch('STRIPE_V2_BUSINESS_PRICE', '39').to_f - }, - enterprise: { - pricing_plan_id: ENV.fetch('STRIPE_V2_ENTERPRISE_PLAN_ID', nil), - monthly_credits: ENV.fetch('STRIPE_V2_ENTERPRISE_CREDITS', '5000').to_i, - price_per_agent_per_month: ENV.fetch('STRIPE_V2_ENTERPRISE_PRICE', '99').to_f - } - }, - - # Topup configuration (same for all plans) - topup: { - price_per_credit: ENV.fetch('STRIPE_V2_TOPUP_PRICE_PER_CREDIT', '0.01').to_f, - available_packs: [100, 500, 1000, 2500, 5000] - } + meter_event_name: ENV.fetch('STRIPE_V2_METER_EVENT_NAME', nil) } diff --git a/enterprise/app/services/enterprise/ai/captain_credit_service.rb b/enterprise/app/services/enterprise/ai/captain_credit_service.rb index 97097be53..d3bd96520 100644 --- a/enterprise/app/services/enterprise/ai/captain_credit_service.rb +++ b/enterprise/app/services/enterprise/ai/captain_credit_service.rb @@ -15,12 +15,10 @@ class Enterprise::Ai::CaptainCreditService service.use_credit(feature: feature, amount: amount, metadata: metadata) end - # rubocop:disable Naming/PredicateName - def has_credits? + def credits_available? return true if account.custom_attributes['stripe_billing_version'].to_i != 2 service = Enterprise::Billing::V2::CreditManagementService.new(account: account) service.total_credits.positive? end - # rubocop:enable Naming/PredicateName end diff --git a/enterprise/app/services/enterprise/billing/v2/usage_reporter_service.rb b/enterprise/app/services/enterprise/billing/v2/usage_reporter_service.rb index 2b7efed71..dc4ff5e4d 100644 --- a/enterprise/app/services/enterprise/billing/v2/usage_reporter_service.rb +++ b/enterprise/app/services/enterprise/billing/v2/usage_reporter_service.rb @@ -23,8 +23,7 @@ class Enterprise::Billing::V2::UsageReporterService < Enterprise::Billing::V2::B def should_report_usage? v2_enabled? && stripe_customer_id.present? && - meter_event_name.present? && - v2_config[:usage_reporting_enabled] != false + meter_event_name.present? end def meter_event_name diff --git a/spec/enterprise/services/enterprise/ai/captain_credit_service_spec.rb b/spec/enterprise/services/enterprise/ai/captain_credit_service_spec.rb index 036b6aaf2..fbab6c42d 100644 --- a/spec/enterprise/services/enterprise/ai/captain_credit_service_spec.rb +++ b/spec/enterprise/services/enterprise/ai/captain_credit_service_spec.rb @@ -37,10 +37,10 @@ describe Enterprise::Ai::CaptainCreditService do end end - describe '#has_credits?' do + describe '#credits_available?' do context 'when account is not on v2 billing' do it 'returns true without checking credit service' do - expect(service.has_credits?).to be(true) + expect(service.credits_available?).to be(true) expect(Enterprise::Billing::V2::CreditManagementService).not_to have_received(:new) end end @@ -52,7 +52,7 @@ describe Enterprise::Ai::CaptainCreditService do end it 'returns credit availability from credit service' do - expect(service.has_credits?).to be(true) + expect(service.credits_available?).to be(true) expect(credit_service).to have_received(:total_credits) end end diff --git a/spec/enterprise/services/enterprise/billing/v2/usage_reporter_service_spec.rb b/spec/enterprise/services/enterprise/billing/v2/usage_reporter_service_spec.rb index 48d274e43..b96b26440 100644 --- a/spec/enterprise/services/enterprise/billing/v2/usage_reporter_service_spec.rb +++ b/spec/enterprise/services/enterprise/billing/v2/usage_reporter_service_spec.rb @@ -16,7 +16,6 @@ describe Enterprise::Billing::V2::UsageReporterService do config[:meter_id] = 'mtr_test_123' config[:meter_event_name] = 'chat_prompts' - config[:usage_reporting_enabled] = true end after { config.replace(original_config) } @@ -39,12 +38,4 @@ describe Enterprise::Billing::V2::UsageReporterService do expect(kw[:params][:payload][:stripe_customer_id]).to eq('cus_test_123') end end - - it 'returns failure when usage reporting disabled' do - Rails.application.config.stripe_v2[:usage_reporting_enabled] = false - - result = service.report(5, 'ai_test') - - expect(result).to include(success: false) - end end