Skip to content

Commit

Permalink
feat(fee): Add zero_amount_fees premium integration
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet committed Jan 23, 2025
1 parent 89fbadf commit 672f572
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
1 change: 1 addition & 0 deletions app/services/fees/charge_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
40 changes: 31 additions & 9 deletions spec/services/fees/charge_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 672f572

Please sign in to comment.