Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/lago/api/resources/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def wallets
def current_usage( # rubocop:disable Metrics/ParameterLists
external_customer_id, external_subscription_id, apply_taxes: nil,
charge_id: nil, charge_code: nil, billable_metric_code: nil, group: nil,
filter_by_charge_id: nil, filter_by_charge_code: nil, filter_by_group: nil, full_usage: nil
filter_by_charge_id: nil, filter_by_charge_code: nil, filter_by_group: nil, full_usage: nil,
filter_by_presentation: nil
)
query_params = { external_subscription_id: external_subscription_id }
query_params[:apply_taxes] = apply_taxes unless apply_taxes.nil?
Expand All @@ -33,6 +34,10 @@ def current_usage( # rubocop:disable Metrics/ParameterLists
query_params[:filter_by_charge_code] = filter_by_charge_code unless filter_by_charge_code.nil?
filter_by_group&.each { |k, v| query_params[:"filter_by_group[#{k}]"] = v }
query_params[:full_usage] = full_usage unless full_usage.nil?
unless filter_by_presentation.nil?
query_params[:filter_by_presentation] =
filter_by_presentation_param(filter_by_presentation)
end
query_string = URI.encode_www_form(query_params)

uri = URI("#{client.base_api_url}#{api_resource}/#{external_customer_id}/current_usage?#{query_string}")
Expand Down Expand Up @@ -126,6 +131,10 @@ def whitelist_params(params)
{ root_name => result_hash }
end

def filter_by_presentation_param(filter_by_presentation)
filter_by_presentation.is_a?(String) ? filter_by_presentation : JSON.generate(filter_by_presentation)
end

def whitelist_billing_configuration(billing_params)
(billing_params || {}).slice(
:invoice_grace_period,
Expand Down
7 changes: 6 additions & 1 deletion spec/factories/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
invoice_display_name: 'Charge 1',
min_amount_cents: 0,
accepts_target_wallet: false,
properties: { amount: '0.22' },
properties: {
amount: '0.22',
presentation_group_keys: [
{ value: 'region', options: { display_in_invoice: true } },
],
},
},
]
end
Expand Down
135 changes: 135 additions & 0 deletions spec/fixtures/api/customer_projected_usage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"customer_usage": {
"from_datetime": "2022-07-01T00:00:00Z",
"to_datetime": "2022-07-31T23:59:59Z",
"issuing_date": "2022-08-01",
"currency": "EUR",
"amount_cents": 123,
"projected_amount_cents": 246,
"total_amount_cents": 123,
"projected_total_amount_cents": 246,
"taxes_amount_cents": 0,
"projected_taxes_amount_cents": 0,
"charges_usage": [
{
"units": "1.0",
"projected_units": "2.0",
"events_count": 1,
"amount_cents": 123,
"projected_amount_cents": 246,
"amount_currency": "EUR",
"charge": {
"lago_id": "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba",
"charge_model": "graduated",
"invoice_display_name": "add_on_invoice_display_name"
},
"billable_metric": {
"lago_id": "99a6094e-199b-4101-896a-54e927ce7bd7",
"name": "Usage metric",
"code": "usage_metric",
"aggregation_type": "sum"
},
"filters": [
{
"units": "3.0",
"projected_units": "6.0",
"events_count": 1,
"amount_cents": 123,
"projected_amount_cents": 246,
"values": {
"country": ["france"]
},
"presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "2.0"
}
],
"projected_presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "4.0"
}
]
}
],
"presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "2.0"
}
],
"projected_presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "4.0"
}
],
"grouped_usage": [
{
"amount_cents": 123,
"projected_amount_cents": 246,
"events_count": 1,
"units": "3.0",
"projected_units": "6.0",
"grouped_by": {
"agent_name": "aragorn"
},
"filters": [
{
"units": "3.0",
"projected_units": "6.0",
"events_count": 1,
"amount_cents": 123,
"projected_amount_cents": 246,
"values": {
"country": ["france"]
},
"presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "2.0"
}
],
"projected_presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "4.0"
}
]
}
],
"presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "2.0"
}
],
"projected_presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "4.0"
}
]
}
]
}
]
}
}
36 changes: 34 additions & 2 deletions spec/fixtures/api/customer_usage.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,23 @@
"country": [
"france"
]
}
},
"presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "2.0"
}
]
}
],
"presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "2.0"
}
],
"grouped_usage": [
Expand All @@ -54,7 +70,23 @@
"country": [
"france"
]
}
},
"presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "2.0"
}
]
}
],
"presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "2.0"
}
]
}
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/api/fee.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
"total_amount_currency": "EUR",
"units": "10.0",
"events_count": 10,
"presentation_breakdowns": [
{
"presentation_by": {
"team": "engineering"
},
"units": "2.0"
}
],
"applied_taxes": [
{
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
Expand Down
10 changes: 9 additions & 1 deletion spec/fixtures/api/plan.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@
"min_amount_cents": 0,
"properties": {
"amount": "0.22",
"pricing_group_keys": ["agent_name"]
"pricing_group_keys": ["agent_name"],
"presentation_group_keys": [
{
"value": "region",
"options": {
"display_in_invoice": true
}
}
]
},
"filters": [
{
Expand Down
10 changes: 9 additions & 1 deletion spec/fixtures/api/plan_charge.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
"min_amount_cents": 0,
"prorated": false,
"properties": {
"amount": "0.22"
"amount": "0.22",
"presentation_group_keys": [
{
"value": "region",
"options": {
"display_in_invoice": true
}
}
]
},
"filters": [],
"taxes": [],
Expand Down
10 changes: 9 additions & 1 deletion spec/fixtures/api/plan_charges.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
"min_amount_cents": 0,
"prorated": false,
"properties": {
"amount": "0.22"
"amount": "0.22",
"presentation_group_keys": [
{
"value": "region",
"options": {
"display_in_invoice": true
}
}
]
},
"filters": [],
"taxes": [],
Expand Down
10 changes: 9 additions & 1 deletion spec/fixtures/api/plans.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
"accepts_target_wallet": false,
"properties": {
"amount": "0.22",
"pricing_group_keys": ["agent_name"]
"pricing_group_keys": ["agent_name"],
"presentation_group_keys": [
{
"value": "region",
"options": {
"display_in_invoice": true
}
}
]
},
"filters": [
{
Expand Down
10 changes: 9 additions & 1 deletion spec/fixtures/api/subscription_charge.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@
"min_amount_cents": 0,
"prorated": false,
"properties": {
"amount": "0.22"
"amount": "0.22",
"presentation_group_keys": [
{
"value": "region",
"options": {
"display_in_invoice": true
}
}
]
},
"filters": [],
"taxes": [],
Expand Down
10 changes: 9 additions & 1 deletion spec/fixtures/api/subscription_charges.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
"min_amount_cents": 0,
"prorated": false,
"properties": {
"amount": "0.22"
"amount": "0.22",
"presentation_group_keys": [
{
"value": "region",
"options": {
"display_in_invoice": true
}
}
]
},
"filters": [],
"taxes": [],
Expand Down
Loading
Loading