cleanup code, remove unnecessary

This commit is contained in:
Tanmay Sharma
2025-10-12 17:02:16 +05:30
parent 19a851c01d
commit cef23891af
5 changed files with 0 additions and 69 deletions
-2
View File
@@ -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
@@ -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
@@ -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
@@ -1,5 +1,3 @@
# frozen_string_literal: true
module Enterprise::Billing::V2::Concerns::PaymentIntentHandler
extend ActiveSupport::Concern
@@ -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