Skip to content

Commit

Permalink
feat(filter): Add filter fields
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet committed Apr 9, 2024
1 parent 1561dd2 commit 0ad3e65
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 52 deletions.
1 change: 1 addition & 0 deletions lib/lago/api/resources/billable_metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def whitelist_params(params)
weighted_interval: params[:weighted_interval],
field_name: params[:field_name],
group: params[:group],
filters: params[:filters],
}.compact,
}
end
Expand Down
1 change: 1 addition & 0 deletions lib/lago/api/resources/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def whitelist_charges(charges)
:min_amount_cents,
:properties,
:group_properties,
:filters,
:tax_codes,
)

Expand Down
16 changes: 15 additions & 1 deletion spec/fixtures/api/billable_metric.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@
"created_at": "2022-04-29T08:59:51Z",
"group": {
"key": "country",
"values": ["france", "italy", "spain"]
"values": [
"france",
"italy",
"spain"
]
},
"filters": [
{
"key": "country",
"values": [
"france",
"italy",
"spain"
]
}
],
"active_subscriptions_count": 0,
"draft_invoices_count": 0,
"plans_count": 0
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/api/billable_metric_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"field_name": "amount_sum",
"created_at": "2022-04-29T08:59:51Z",
"group": {},
"filters": [],
"active_subscriptions_count": 0,
"draft_invoices_count": 0,
"plans_count": 0
Expand All @@ -26,6 +27,7 @@
"field_name": "amount_sum",
"created_at": "2022-04-30T08:59:51Z",
"group": {},
"filters": [],
"active_subscriptions_count": 0,
"draft_invoices_count": 0,
"plans_count": 0
Expand Down
15 changes: 14 additions & 1 deletion spec/fixtures/api/customer_past_usage.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,20 @@
"name": "Usage metric",
"code": "usage_metric",
"aggregation_type": "sum"
}
},
"groups": [],
"filters": [
{
"units": "3.0",
"events_count": 1,
"amount_cents": 123,
"values": {
"country": [
"france"
]
}
}
]
}
]
}
Expand Down
64 changes: 59 additions & 5 deletions spec/fixtures/api/customer_usage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"from_datetime": "2022-07-01T00:00:00Z",
"to_datetime": "2022-07-31T23:59:59Z",
"issuing_date": "2022-08-01",
"lago_invoice_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"invoice_id": null,
"currency": "EUR",
"amount_cents": 123,
"total_amount_cents": 123,
Expand All @@ -15,16 +15,70 @@
"amount_cents": 123,
"amount_currency": "EUR",
"charge": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_id": "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba",
"charge_model": "graduated",
"invoice_display_name": "Setup"
"invoice_display_name": "add_on_invoice_display_name"
},
"billable_metric": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_id": "99a6094e-199b-4101-896a-54e927ce7bd7",
"name": "Usage metric",
"code": "usage_metric",
"aggregation_type": "sum"
}
},
"groups": [
{
"lago_id": "12435687-1de8-4428-9bcd-779314ac1111",
"key": "google",
"value": "europe",
"units": "3.0",
"events_count": 1,
"amount_cents": 123
}
],
"filters": [
{
"units": "3.0",
"events_count": 1,
"amount_cents": 123,
"values": {
"country": [
"france"
]
}
}
],
"grouped_usage": [
{
"amount_cents": 123,
"events_count": 1,
"units": "3.0",
"grouped_by": {
"agent_name": "aragorn"
},
"groups": [
{
"lago_id": "12435687-1de8-4428-9bcd-779314ac1111",
"key": "google",
"value": "europe",
"units": "3.0",
"events_count": 1,
"amount_cents": 123
}
],
"filters": [
{
"units": "3.0",
"events_count": 1,
"amount_cents": 123,
"values": {
"country": [
"france"
]
}
}
]
}
]
}
]
}
Expand Down
17 changes: 8 additions & 9 deletions spec/fixtures/api/fee.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"fee": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_group_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_invoice_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_true_up_fee_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_id": "5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba",
"lago_group_id": "1a2d9c8d-5875-4688-9854-5ccfd414bc5e",
"lago_charge_filter_id": "1a2d9c8d-5875-4688-9854-5ccfd414bc5e",
"lago_invoice_id": "1a2d9c8d-5875-4688-9854-5ccfd414bc5e",
"lago_true_up_fee_id": "1a2d9c8d-5875-4688-9854-5ccfd414bc5e",
"lago_true_up_parent_fee_id": null,
"invoice_display_name": "Fee name",
"invoice_display_name": "fee_invoice_display_name",
"item": {
"type": "charge",
"code": "fee_code",
"name": "Fee Code",
"invoice_display_name": "Fee C1",
"group_invoice_display_name": "Transactions - ACH",
"invoice_display_name": "charge_invoice_display_name",
"charge_filter_invoice_display_name": "charge_filter_invoice_display_name",
"grouped_by": {
"agent_name": "aragorn"
}
Expand All @@ -23,9 +24,7 @@
"total_amount_cents": 140,
"total_amount_currency": "EUR",
"units": "10.0",
"precise_unit_amount": "14.0",
"events_count": 10,
"amount_details": {},
"applied_taxes": [
{
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
Expand Down
73 changes: 57 additions & 16 deletions spec/fixtures/api/plan.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,66 @@
{
"plan": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"name": "plan1",
"invoice_display_name": "PLN1",
"created_at": "2022-04-29T08:59:51Z",
"lago_id": "b7ab2926-1de8-4428-9bcd-779314ac1111",
"name": "test1",
"invoice_display_name": "test plan 1",
"created_at": "2022-07-01T14:47:14Z",
"code": "plan_code",
"interval": "monthly",
"description": "desc",
"amount_cents": 100,
"interval": "weekly",
"description": "hello_this_is_desc333",
"amount_cents": 900,
"amount_currency": "EUR",
"trial_period": 2,
"pay_in_advance": false,
"bill_charges_monthly": false,
"trial_period": 3.0,
"pay_in_advance": true,
"bill_charges_monthly": null,
"active_subscriptions_count": 0,
"draft_invoices_count": 0,
"charges": [
{
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_billable_metric_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_id": "51c1e851-5be6-4343-a0ee-39a81d8b4ee1",
"lago_billable_metric_id": "a6947936-628f-4945-8857-db6858ee7941",
"billable_metric_code": "bm_code",
"created_at": "2022-04-29T08:59:51Z",
"created_at": "2022-07-01T14:47:14Z",
"amount_currency": "EUR",
"prorated": false,
"charge_model": "standard",
"pay_in_advance": false,
"pay_in_advance": true,
"invoiceable": true,
"invoice_display_name": "Setup",
"min_amount_cents": 0,
"properties": {
"amount": "0.22",
"grouped_by": [
"agent_name"
]
}
},
"filters": [
{
"invoice_display_name": "From France",
"properties": {
"amount": "0.33"
},
"values": {
"country": [
"France"
]
}
}
],
"taxes": [
{
"lago_id": "b7ab2926-1de8-4428-9bcd-779314ac129b",
"name": "tax_name",
"code": "tax_code",
"rate": 15.0,
"description": "tax_desc",
"add_ons_count": 0,
"customers_count": 0,
"plans_count": 0,
"charges_count": 0,
"applied_to_organization": false,
"created_at": "2022-04-29T08:59:51Z"
}
]
}
],
"minimum_commitment": {
Expand All @@ -48,7 +79,17 @@
},
"taxes": [
{
"code": "tax_code"
"lago_id": "b7ab2926-1de8-4428-9bcd-779314ac129b",
"name": "tax_name",
"code": "tax_code",
"rate": 15.0,
"description": "tax_desc",
"add_ons_count": 0,
"customers_count": 0,
"plans_count": 0,
"charges_count": 0,
"applied_to_organization": false,
"created_at": "2022-04-29T08:59:51Z"
}
]
}
Expand Down
Loading

0 comments on commit 0ad3e65

Please sign in to comment.