Skip to content

Commit

Permalink
fix current usage taxes
Browse files Browse the repository at this point in the history
  • Loading branch information
lovrocolic committed Jan 28, 2025
1 parent dff1706 commit c7eed43
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def fee_item(fee)
mapped_item ||= empty_struct

{
'item_id' => fee.id,
'item_id' => fee.id || fee.item_id,
'item_code' => mapped_item.external_id,
'amount_cents' => fee.sub_total_excluding_taxes_amount_cents&.to_i
}
Expand Down
4 changes: 3 additions & 1 deletion app/services/invoices/customer_usage_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def compute_amounts_with_provider_taxes
result.fees_taxes = taxes_result.fees

invoice.fees.each do |fee|
fee_taxes = result.fees_taxes.find { |item| item.item_id == fee.id }
fee_taxes = result.fees_taxes.find do |item|
(item.item_id == fee.item_id) && (item.amount_cents.to_i == fee.sub_total_excluding_taxes_amount_cents&.to_i)
end

res = Fees::ApplyProviderTaxesService.call(fee:, fee_taxes:)
res.raise_if_error!
Expand Down
10 changes: 8 additions & 2 deletions spec/services/invoices/customer_usage_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@
let(:endpoint) { 'https://api.nango.dev/v1/anrok/draft_invoices' }
let(:body) do
p = Rails.root.join('spec/fixtures/integration_aggregator/taxes/invoices/success_response.json')
File.read(p)
json = File.read(p)

# setting item_id based on the test example
response = JSON.parse(json)
response['succeededInvoices'].first['fees'].last['item_id'] = charge.billable_metric.id
response['succeededInvoices'].first['fees'].last['amount_cents'] = 2532

response.to_json
end
let(:integration_collection_mapping) do
create(
Expand All @@ -151,7 +158,6 @@
allow(LagoHttpClient::Client).to receive(:new).with(endpoint).and_return(lago_client)
allow(lago_client).to receive(:post_with_response).and_return(response)
allow(response).to receive(:body).and_return(body)
allow_any_instance_of(Fee).to receive(:id).and_return('lago_fee_id') # rubocop:disable RSpec/AnyInstance
end

it 'initializes an invoice' do
Expand Down

0 comments on commit c7eed43

Please sign in to comment.