diff --git a/app/models/organization.rb b/app/models/organization.rb index a87bc998a4d..bbcd60a321a 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -63,7 +63,7 @@ class Organization < ApplicationRecord ].freeze INTEGRATIONS = %w[ - netsuite okta anrok xero progressive_billing hubspot auto_dunning revenue_analytics salesforce api_permissions revenue_share + netsuite okta anrok xero progressive_billing hubspot auto_dunning revenue_analytics salesforce api_permissions revenue_share zero_amount_fees ].freeze PREMIUM_INTEGRATIONS = INTEGRATIONS - %w[anrok] diff --git a/app/services/fees/charge_service.rb b/app/services/fees/charge_service.rb index 813ec47713e..2d4e3d4b656 100644 --- a/app/services/fees/charge_service.rb +++ b/app/services/fees/charge_service.rb @@ -178,6 +178,7 @@ def init_fee(amount_result, properties:, charge_filter:) def should_persit_fee?(fee, fees) return true if context == :recurring + return true if fee.organization.premium_integrations.include?("zero_amount_fees") return true if fee.units != 0 || fee.amount_cents != 0 || fee.events_count != 0 return true if adjusted_fee(charge_filter: fee.charge_filter, grouped_by: fee.grouped_by).present? return true if fee.true_up_parent_fee.present? diff --git a/spec/services/fees/charge_service_spec.rb b/spec/services/fees/charge_service_spec.rb index 92e0c5b01f7..f8e3ef39e14 100644 --- a/spec/services/fees/charge_service_spec.rb +++ b/spec/services/fees/charge_service_spec.rb @@ -114,6 +114,18 @@ expect(result).to be_success expect(result.fees.count).to eq(0) end + + context 'when organization as zero_amount_fees premium integration' do + before do + organization.update!(premium_integrations: ["zero_amount_fees"]) + end + + it "creates a fee" do + result = charge_subscription_service.call + expect(result).to be_success + expect(result.fees.count).to eq(1) + end + end end context "with events" do @@ -2089,7 +2101,17 @@ context "when apply taxes" do let(:apply_taxes) { true } - before { create(:tax, organization:, rate: 20) } + before do + create(:tax, organization:, rate: 20) + + create( + :event, + organization: invoice.organization, + subscription:, + code: billable_metric.code, + timestamp: boundaries[:charges_to_datetime] - 2.days + ) + end it "creates a fee with applied taxes" do result = charge_subscription_service.call @@ -2098,18 +2120,18 @@ id: String, invoice_id: invoice.id, charge_id: charge.id, - amount_cents: 0, - precise_amount_cents: 0.0, + amount_cents: 2000, + precise_amount_cents: 2000.0, amount_currency: "EUR", - units: 0, - unit_amount_cents: 0, - precise_unit_amount: 0.0, - events_count: 0, + units: 1, + unit_amount_cents: 2000, + precise_unit_amount: 20.0, + events_count: 1, payment_status: "pending", taxes_rate: 20.0, - taxes_amount_cents: 0, - taxes_precise_amount_cents: 0.0 + taxes_amount_cents: 400, + taxes_precise_amount_cents: 400.0 ) expect(result.fees.first.applied_taxes.count).to eq(1) end