diff --git a/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb b/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb index 742bac00a..5fc6bc082 100644 --- a/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb +++ b/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb @@ -12,7 +12,7 @@ class Enterprise::Billing::CreateStripeCustomerService customer_id = prepare_customer_id update_account_for_v2_billing(customer_id) - enable_plan_specific_features(default_plan['name']) + enable_plan_specific_features('Hacker') end private @@ -26,26 +26,16 @@ class Enterprise::Billing::CreateStripeCustomerService customer_id end - def default_quantity - default_plan['default_quantity'] || DEFAULT_QUANTITY - end - def billing_email account.administrators.first.email end - def default_plan - installation_config = InstallationConfig.find_by(name: 'CHATWOOT_CLOUD_PLANS') - @default_plan ||= installation_config&.value&.first - end - def v2_configs_present? - InstallationConfig.find_by(name: 'STRIPE_HACKER_PLAN_ID').present? && - default_plan.present? + InstallationConfig.find_by(name: 'STRIPE_HACKER_PLAN_ID').present? end def raise_config_error - raise StandardError, 'V2 billing configuration is required. Please configure STRIPE_HACKER_PLAN_ID and CHATWOOT_CLOUD_PLANS.' + raise StandardError, 'V2 billing configuration is required. Please configure STRIPE_HACKER_PLAN_ID.' end def existing_subscription? diff --git a/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb b/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb index efcaf4a02..5343e9ef0 100644 --- a/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb +++ b/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb @@ -78,12 +78,6 @@ class Enterprise::Billing::HandleStripeEventService cloud_plans.find { |config| config['product_id'].include?(plan_id) } end - def default_plan? - cloud_plans = InstallationConfig.find_by(name: CLOUD_PLANS_CONFIG)&.value || [] - default_plan = cloud_plans.first || {} - account.custom_attributes['plan_name'] == default_plan['name'] - end - def process_credit_grant_created grant_id = extract_credit_grant_id(@event.data.object) return if grant_id.blank? diff --git a/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb b/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb index 33941cee8..f56428d0a 100644 --- a/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb +++ b/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb @@ -205,8 +205,10 @@ RSpec.describe 'Enterprise Billing APIs', type: :request do }, 'conversation' => {}, 'captain' => { - 'documents' => { 'consumed' => 0, 'current_available' => ChatwootApp.max_limit, 'total_count' => ChatwootApp.max_limit }, - 'responses' => { 'consumed' => 0, 'current_available' => ChatwootApp.max_limit, 'total_count' => ChatwootApp.max_limit } + 'documents' => { 'consumed' => 0, 'current_available' => ChatwootApp.max_limit, 'total_count' => ChatwootApp.max_limit, + 'monthly' => nil, 'topup' => nil }, + 'responses' => { 'consumed' => 0, 'current_available' => ChatwootApp.max_limit, 'total_count' => ChatwootApp.max_limit, + 'monthly' => 0, 'topup' => 0 } }, 'non_web_inboxes' => {} } diff --git a/spec/enterprise/controllers/enterprise/webooks/stripe_controller_spec.rb b/spec/enterprise/controllers/enterprise/webooks/stripe_controller_spec.rb index 3b5b68e46..647add070 100644 --- a/spec/enterprise/controllers/enterprise/webooks/stripe_controller_spec.rb +++ b/spec/enterprise/controllers/enterprise/webooks/stripe_controller_spec.rb @@ -1,31 +1,32 @@ require 'rails_helper' -# rubocop:disable RSpec/VerifiedDoubles RSpec.describe 'Enterprise::Webhooks::StripeController', type: :request do describe 'POST /enterprise/webhooks/stripe' do let(:params) { { content: 'hello' } } + let(:v1_event_params) { { type: 'invoice.created', data: { object: {} } }.to_json } it 'delegates to the v1 handler for legacy events' do - handle_stripe = double - event = double('Stripe::Event', type: 'invoice.created') + handle_stripe = instance_double(Enterprise::Billing::HandleStripeEventService) + event = instance_double(Stripe::Event, type: 'invoice.created') allow(Stripe::Webhook).to receive(:construct_event).and_return(event) allow(Enterprise::Billing::HandleStripeEventService).to receive(:new).and_return(handle_stripe) allow(handle_stripe).to receive(:perform) - post '/enterprise/webhooks/stripe', headers: { 'Stripe-Signature': 'test' }, params: params + post '/enterprise/webhooks/stripe', headers: { 'Stripe-Signature': 'test' }, params: v1_event_params, as: :json expect(handle_stripe).to have_received(:perform).with(event: event) end it 'delegates v2 billing events to the v2 webhook handler' do - event = double('Stripe::Event', type: 'v2.billing.pricing_plan_subscription.servicing_activated') + v2_event_params = { type: 'v2.billing.pricing_plan_subscription.servicing_activated', data: { object: {} } }.to_json + event = instance_double(Stripe::Event, type: 'v2.billing.pricing_plan_subscription.servicing_activated') handler_double = instance_double(Enterprise::Billing::V2::WebhookHandlerService, perform: { success: true }) allow(Stripe::Webhook).to receive(:construct_event).and_return(event) allow(Enterprise::Billing::V2::WebhookHandlerService).to receive(:new).and_return(handler_double) - post '/enterprise/webhooks/stripe', headers: { 'Stripe-Signature': 'test' }, params: params + post '/enterprise/webhooks/stripe', headers: { 'Stripe-Signature': 'test' }, params: v2_event_params, as: :json expect(Enterprise::Billing::V2::WebhookHandlerService).to have_received(:new) expect(handler_double).to have_received(:perform).with(event: event) @@ -43,4 +44,3 @@ RSpec.describe 'Enterprise::Webhooks::StripeController', type: :request do end end end -# rubocop:enable RSpec/VerifiedDoubles