diff --git a/config/routes.rb b/config/routes.rb index 171f7b7c9..4eae70fdc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -432,8 +432,6 @@ Rails.application.routes.draw do post :toggle_deletion # V2 Billing endpoints get :credits_balance - get :usage_metrics - post :enable_v2_billing end end end diff --git a/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb b/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb index 9bcfa58ad..0f66efc89 100644 --- a/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb +++ b/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb @@ -57,8 +57,6 @@ class Enterprise::Api::V1::AccountsController < Api::BaseController # V2 Billing Endpoints def credits_balance - return render_v2_not_enabled unless v2_enabled? - service = Enterprise::Billing::V2::CreditManagementService.new(account: @account) balance = service.credit_balance @@ -70,41 +68,6 @@ class Enterprise::Api::V1::AccountsController < Api::BaseController } end - def usage_metrics - return render_v2_not_enabled unless v2_enabled? - - service = Enterprise::Billing::V2::UsageAnalyticsService.new(account: @account) - result = service.fetch_usage_summary - - if result[:success] - render json: result - else - render json: { error: result[:message] }, status: :unprocessable_entity - end - end - - def enable_v2_billing - unless Rails.application.config.stripe_v2[:enabled] - return render json: { error: 'V2 billing not enabled system-wide' }, - status: :unprocessable_entity - end - return render json: { error: 'Account already on V2 billing' }, status: :ok if @account.custom_attributes['stripe_billing_version'].to_i == 2 - - plan_type = params[:plan_type] || 'startup' - service = Enterprise::Billing::V2::SubscriptionService.new(account: @account) - result = service.migrate_to_v2(plan_type: plan_type) - - if result[:success] - render json: { - success: true, - message: result[:message], - billing_version: @account.custom_attributes['stripe_billing_version'] - } - else - render json: { error: result[:message] }, status: :unprocessable_entity - end - end - private def check_cloud_env diff --git a/enterprise/app/services/enterprise/ai/captain_credit_service.rb b/enterprise/app/services/enterprise/ai/captain_credit_service.rb index d3bd96520..3da523b53 100644 --- a/enterprise/app/services/enterprise/ai/captain_credit_service.rb +++ b/enterprise/app/services/enterprise/ai/captain_credit_service.rb @@ -14,11 +14,4 @@ class Enterprise::Ai::CaptainCreditService service = Enterprise::Billing::V2::CreditManagementService.new(account: account) service.use_credit(feature: feature, amount: amount, metadata: metadata) end - - 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 end diff --git a/enterprise/app/services/enterprise/billing/v2/concerns/payment_intent_handler.rb b/enterprise/app/services/enterprise/billing/v2/concerns/payment_intent_handler.rb index 2f45b1b0c..75dcb02f6 100644 --- a/enterprise/app/services/enterprise/billing/v2/concerns/payment_intent_handler.rb +++ b/enterprise/app/services/enterprise/billing/v2/concerns/payment_intent_handler.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - module Enterprise::Billing::V2::Concerns::PaymentIntentHandler extend ActiveSupport::Concern 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 fbab6c42d..14ae0506f 100644 --- a/spec/enterprise/services/enterprise/ai/captain_credit_service_spec.rb +++ b/spec/enterprise/services/enterprise/ai/captain_credit_service_spec.rb @@ -36,25 +36,4 @@ describe Enterprise::Ai::CaptainCreditService do end end end - - describe '#credits_available?' do - context 'when account is not on v2 billing' do - it 'returns true without checking credit service' do - expect(service.credits_available?).to be(true) - expect(Enterprise::Billing::V2::CreditManagementService).not_to have_received(:new) - end - end - - context 'when account is on v2 billing' do - before do - account.update!(custom_attributes: (account.custom_attributes || {}).merge('stripe_billing_version' => 2)) - allow(credit_service).to receive(:total_credits).and_return(5) - end - - it 'returns credit availability from credit service' do - expect(service.credits_available?).to be(true) - expect(credit_service).to have_received(:total_credits) - end - end - end end