Skip to content

Commit

Permalink
Merge pull request #238 from getlago/feat-apply-taxes-current-usage
Browse files Browse the repository at this point in the history
feat: add apply taxes params to current usage
  • Loading branch information
brunomiguelpinto authored Feb 6, 2025
2 parents 7495e95 + 2551790 commit 3e01cb1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/lago/api/resources/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ def root_name
'customer'
end

def current_usage(external_customer_id, external_subscription_id)
uri = URI(
"#{client.base_api_url}#{api_resource}/#{external_customer_id}" \
"/current_usage?external_subscription_id=#{external_subscription_id}",
)
def current_usage(external_customer_id, external_subscription_id, apply_taxes: nil)
query_params = { external_subscription_id: external_subscription_id }
query_params[:apply_taxes] = apply_taxes unless apply_taxes.nil?
query_string = URI.encode_www_form(query_params)

uri = URI("#{client.base_api_url}#{api_resource}/#{external_customer_id}/current_usage?#{query_string}")
connection.get(uri, identifier: nil)
end

Expand Down
14 changes: 14 additions & 0 deletions spec/lago/api/resources/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
end
end

context 'when the optional apply_taxes parameter is provided' do
let(:apply_taxes) { 'true' }
before do
stub_request(:get, "https://api.getlago.com/api/v1/customers/#{customer_external_id}/current_usage")
.with(query: { external_subscription_id: subscription_external_id, apply_taxes: apply_taxes })
.to_return(body: customer_usage_response, status: 200)
end

it 'returns the usage of the customer with apply_taxes applied' do
response = resource.current_usage(customer_external_id, subscription_external_id, apply_taxes: apply_taxes)
expect(response['customer_usage']['from_datetime']).to eq('2022-07-01T00:00:00Z')
end
end

context 'when the customer does not exists' do
let(:customer_external_id) { 'DOESNOTEXIST' }

Expand Down

0 comments on commit 3e01cb1

Please sign in to comment.