From 01e1e81cc8c3c7964f8bb5d2de61b238276a231d Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Tue, 9 Jul 2024 09:38:00 +0200 Subject: [PATCH 1/3] misc: Remove deprecated fields --- lib/lago-ruby-client.rb | 1 - lib/lago/api/client.rb | 4 -- lib/lago/api/resources/billable_metric.rb | 1 - lib/lago/api/resources/group.rb | 24 ---------- lib/lago/api/resources/plan.rb | 1 - lib/lago/api/resources/subscription.rb | 3 +- spec/factories/group.rb | 9 ---- spec/factories/subscription.rb | 2 +- spec/fixtures/api/billable_metric.json | 8 ---- spec/fixtures/api/billable_metric_index.json | 2 - spec/fixtures/api/customer_past_usage.json | 1 - spec/fixtures/api/customer_usage.json | 20 -------- spec/fixtures/api/fee.json | 1 - spec/fixtures/api/invoice.json | 6 +-- spec/fixtures/api/organization.json | 5 +- spec/fixtures/api/plans.json | 9 ---- .../lago/api/resources/applied_coupon_spec.rb | 26 +++++----- .../api/resources/billable_metric_spec.rb | 6 +-- spec/lago/api/resources/fee_spec.rb | 4 +- spec/lago/api/resources/group_spec.rb | 47 ------------------- spec/lago/api/resources/subscription_spec.rb | 25 +++++----- spec/spec_helper.rb | 1 - 22 files changed, 39 insertions(+), 167 deletions(-) delete mode 100644 lib/lago/api/resources/group.rb delete mode 100644 spec/factories/group.rb delete mode 100644 spec/lago/api/resources/group_spec.rb diff --git a/lib/lago-ruby-client.rb b/lib/lago-ruby-client.rb index b2785e5..f3963e0 100644 --- a/lib/lago-ruby-client.rb +++ b/lib/lago-ruby-client.rb @@ -21,7 +21,6 @@ require 'lago/api/resources/event' require 'lago/api/resources/fee' require 'lago/api/resources/gross_revenue' -require 'lago/api/resources/group' require 'lago/api/resources/invoice' require 'lago/api/resources/invoice_collection' require 'lago/api/resources/invoiced_usage' diff --git a/lib/lago/api/client.rb b/lib/lago/api/client.rb index 6fdead0..09d7f86 100644 --- a/lib/lago/api/client.rb +++ b/lib/lago/api/client.rb @@ -39,10 +39,6 @@ def fees Lago::Api::Resources::Fee.new(self) end - def groups - Lago::Api::Resources::Group.new(self) - end - def applied_coupons Lago::Api::Resources::AppliedCoupon.new(self) end diff --git a/lib/lago/api/resources/billable_metric.rb b/lib/lago/api/resources/billable_metric.rb index c7ee56b..d17dd50 100644 --- a/lib/lago/api/resources/billable_metric.rb +++ b/lib/lago/api/resources/billable_metric.rb @@ -22,7 +22,6 @@ def whitelist_params(params) aggregation_type: params[:aggregation_type], weighted_interval: params[:weighted_interval], field_name: params[:field_name], - group: params[:group], filters: params[:filters], }.compact, } diff --git a/lib/lago/api/resources/group.rb b/lib/lago/api/resources/group.rb deleted file mode 100644 index 329e4ea..0000000 --- a/lib/lago/api/resources/group.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -module Lago - module Api - module Resources - class Group < Base - def api_resource - 'groups' - end - - def root_name - 'group' - end - - def get_all(code, options = {}) - path = "/api/v1/billable_metrics/#{code}/groups" - response = connection.get_all(options, path) - - JSON.parse(response.to_json, object_class: OpenStruct) - end - end - end - end -end diff --git a/lib/lago/api/resources/plan.rb b/lib/lago/api/resources/plan.rb index 63c9051..75fb4d4 100644 --- a/lib/lago/api/resources/plan.rb +++ b/lib/lago/api/resources/plan.rb @@ -59,7 +59,6 @@ def whitelist_charges(charges) :invoice_display_name, :min_amount_cents, :properties, - :group_properties, :filters, :tax_codes, ) diff --git a/lib/lago/api/resources/subscription.rb b/lib/lago/api/resources/subscription.rb index d8df7d0..6fbc451 100644 --- a/lib/lago/api/resources/subscription.rb +++ b/lib/lago/api/resources/subscription.rb @@ -22,9 +22,8 @@ def whitelist_params(params) billing_time: params[:billing_time], subscription_at: params[:subscription_at], ending_at: params[:ending_at], - subscription_date: params[:subscription_date], # Deprecated plan_overrides: params[:plan_overrides], - }.compact + }.compact, } end end diff --git a/spec/factories/group.rb b/spec/factories/group.rb deleted file mode 100644 index d878720..0000000 --- a/spec/factories/group.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :group, class: OpenStruct do - lago_id { 'lago_internal_id' } - key { 'aws' } - value { 'europe' } - end -end diff --git a/spec/factories/subscription.rb b/spec/factories/subscription.rb index 81d34cd..b8194b2 100644 --- a/spec/factories/subscription.rb +++ b/spec/factories/subscription.rb @@ -9,7 +9,7 @@ billing_time { 'calendar' } started_at { '2022-05-05T12:27:30Z' } ending_at { '2022-08-05T00:00:00Z' } - subscription_date { '2022-05-05' } + subscription_at { '2022-05-05T12:27:30Z' } terminated_at { nil } canceled_at { nil } created_at { '2022-05-05T12:27:30Z' } diff --git a/spec/fixtures/api/billable_metric.json b/spec/fixtures/api/billable_metric.json index 249438e..f951bd4 100644 --- a/spec/fixtures/api/billable_metric.json +++ b/spec/fixtures/api/billable_metric.json @@ -9,14 +9,6 @@ "recurring": false, "field_name": "amount_sum", "created_at": "2022-04-29T08:59:51Z", - "group": { - "key": "country", - "values": [ - "france", - "italy", - "spain" - ] - }, "filters": [ { "key": "country", diff --git a/spec/fixtures/api/billable_metric_index.json b/spec/fixtures/api/billable_metric_index.json index b775f73..4fc85f9 100644 --- a/spec/fixtures/api/billable_metric_index.json +++ b/spec/fixtures/api/billable_metric_index.json @@ -10,7 +10,6 @@ "recurring": false, "field_name": "amount_sum", "created_at": "2022-04-29T08:59:51Z", - "group": {}, "filters": [], "active_subscriptions_count": 0, "draft_invoices_count": 0, @@ -26,7 +25,6 @@ "recurring": false, "field_name": "amount_sum", "created_at": "2022-04-30T08:59:51Z", - "group": {}, "filters": [], "active_subscriptions_count": 0, "draft_invoices_count": 0, diff --git a/spec/fixtures/api/customer_past_usage.json b/spec/fixtures/api/customer_past_usage.json index 7fa783f..5ce24f2 100644 --- a/spec/fixtures/api/customer_past_usage.json +++ b/spec/fixtures/api/customer_past_usage.json @@ -25,7 +25,6 @@ "code": "usage_metric", "aggregation_type": "sum" }, - "groups": [], "filters": [ { "units": "3.0", diff --git a/spec/fixtures/api/customer_usage.json b/spec/fixtures/api/customer_usage.json index 8c70456..420533e 100644 --- a/spec/fixtures/api/customer_usage.json +++ b/spec/fixtures/api/customer_usage.json @@ -25,16 +25,6 @@ "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", @@ -55,16 +45,6 @@ "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", diff --git a/spec/fixtures/api/fee.json b/spec/fixtures/api/fee.json index f123517..1ca4a7c 100644 --- a/spec/fixtures/api/fee.json +++ b/spec/fixtures/api/fee.json @@ -1,7 +1,6 @@ { "fee": { "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", diff --git a/spec/fixtures/api/invoice.json b/spec/fixtures/api/invoice.json index 67bfe62..3869623 100644 --- a/spec/fixtures/api/invoice.json +++ b/spec/fixtures/api/invoice.json @@ -96,7 +96,7 @@ "status": "active", "billing_time": "anniversary", "terminated_at": null, - "subscription_date": "2022-04-29", + "subscription_at": "2022-04-29T12:27:30Z", "previous_plan_code": null, "next_plan_code": null, "downgrade_plan_date": null @@ -140,9 +140,9 @@ "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90", "amount_cents": 10, "amount_currency": "EUR", - "before_vat": true, + "before_taxes": true, "item": { - "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90", + "lago_item_id": "1a901a90-1a90-1a90-1a90-1a901a901a90", "type": "coupon", "code": "free_beer", "name": "Free Beer" diff --git a/spec/fixtures/api/organization.json b/spec/fixtures/api/organization.json index a31661f..277ff64 100644 --- a/spec/fixtures/api/organization.json +++ b/spec/fixtures/api/organization.json @@ -3,7 +3,9 @@ "name": "Hooli", "created_at": "2022-05-02T13:04:09Z", "webhook_url": "https://test-example.example", - "webhook_urls": ["https://test-example.example"], + "webhook_urls": [ + "https://test-example.example" + ], "country": null, "default_currency": "USD", "address_line1": null, @@ -22,7 +24,6 @@ "billing_configuration": { "invoice_footer": null, "invoice_grace_period": 3, - "vat_rate": 15.0, "document_locale": "fr" }, "taxes": [ diff --git a/spec/fixtures/api/plans.json b/spec/fixtures/api/plans.json index 20d8199..2cd3ca7 100644 --- a/spec/fixtures/api/plans.json +++ b/spec/fixtures/api/plans.json @@ -33,15 +33,6 @@ "agent_name" ] }, - "group_properties": [ - { - "group_id": "gfc1e851-5be6-4343-a0ee-39a81d8b4ee1", - "values": { - "amount": "0.22" - }, - "invoice_display_name": "Europe" - } - ], "filters": [ { "invoice_display_name": "From France", diff --git a/spec/lago/api/resources/applied_coupon_spec.rb b/spec/lago/api/resources/applied_coupon_spec.rb index c21ae15..8b60887 100644 --- a/spec/lago/api/resources/applied_coupon_spec.rb +++ b/spec/lago/api/resources/applied_coupon_spec.rb @@ -11,7 +11,7 @@ { 'status' => 422, 'error' => 'Unprocessable Entity', - 'message' => 'Validation error on the record' + 'message' => 'Validation error on the record', }.to_json end @@ -19,7 +19,7 @@ let(:params) { factory_applied_coupon.to_h } let(:body) do { - 'applied_coupon' => factory_applied_coupon.to_h + 'applied_coupon' => factory_applied_coupon.to_h, } end @@ -34,10 +34,10 @@ 'frequency' => factory_applied_coupon.frequency, 'amount_cents' => 123, 'amount_currency' => 'EUR', - 'expiration_date' => '2022-04-29', + 'expiration_at' => '2022-04-29T08:59:51Z', 'created_at' => '2022-04-29T08:59:51Z', - 'terminated_at' => '2022-04-29T08:59:51Z' - } + 'terminated_at' => '2022-04-29T08:59:51Z', + }, }.to_json end @@ -83,18 +83,18 @@ 'amount_currency' => 'EUR', 'frequency_duration' => 3, 'frequency_duration_remaining' => 1, - 'expiration_date' => '2022-04-29', + 'expiration_at' => '2022-04-29T08:59:51Z', 'created_at' => '2022-04-29T08:59:51Z', - 'terminated_at' => '2022-04-29T08:59:51Z' - } + 'terminated_at' => '2022-04-29T08:59:51Z', + }, ], 'meta': { 'current_page' => 1, 'next_page' => 2, 'prev_page' => nil, 'total_pages' => 7, - 'total_count' => 63 - } + 'total_count' => 63, + }, }.to_json end @@ -152,10 +152,10 @@ 'frequency' => factory_applied_coupon.frequency, 'amount_cents' => 123, 'amount_currency' => 'EUR', - 'expiration_date' => '2022-04-29', + 'expiration_at' => '2022-04-29T08:59:51Z', 'created_at' => '2022-04-29T08:59:51Z', - 'terminated_at' => '2022-04-29T08:59:51Z' - } + 'terminated_at' => '2022-04-29T08:59:51Z', + }, }.to_json end diff --git a/spec/lago/api/resources/billable_metric_spec.rb b/spec/lago/api/resources/billable_metric_spec.rb index f1d4d01..b54f9af 100644 --- a/spec/lago/api/resources/billable_metric_spec.rb +++ b/spec/lago/api/resources/billable_metric_spec.rb @@ -19,14 +19,14 @@ end describe '#create' do - let(:group) do + let(:filters) do { key: 'country', values: %w[france italy spain], } end - let(:params) { create(:create_billable_metric).to_h.merge(group: group) } + let(:params) { create(:create_billable_metric).to_h.merge(filters: [filters.to_h]) } context 'when billable metric is successfully created' do before do @@ -40,7 +40,7 @@ expect(billable_metric.lago_id).to eq('b7ab2926-1de8-4428-9bcd-779314ac129b') expect(billable_metric.name).to eq('bm_name') - expect(billable_metric.group.to_h).to eq(group) + expect(billable_metric.filters.map(&:to_h)).to eq([filters.to_h]) expect(billable_metric.weighted_interval).to be_nil end end diff --git a/spec/lago/api/resources/fee_spec.rb b/spec/lago/api/resources/fee_spec.rb index 148aed6..3f0b734 100644 --- a/spec/lago/api/resources/fee_spec.rb +++ b/spec/lago/api/resources/fee_spec.rb @@ -12,7 +12,7 @@ let(:fee_id) { fee_json['lago_id'] } let(:fee_invoice_display_name) { fee_json['invoice_display_name'] } let(:fee_item_invoice_display_name) { fee_json['item']['invoice_display_name'] } - let(:fee_item_group_invoice_display_name) { fee_json['item']['group_invoice_display_name'] } + let(:fee_item_filter_invoice_display_name) { fee_json['item']['filter_invoice_display_name'] } let(:error_response) do { @@ -35,7 +35,7 @@ expect(fee.lago_id).to eq(fee_id) expect(fee.invoice_display_name).to eq(fee_invoice_display_name) expect(fee.item.invoice_display_name).to eq(fee_item_invoice_display_name) - expect(fee.item.group_invoice_display_name).to eq(fee_item_group_invoice_display_name) + expect(fee.item.filter_invoice_display_name).to eq(fee_item_filter_invoice_display_name) end end diff --git a/spec/lago/api/resources/group_spec.rb b/spec/lago/api/resources/group_spec.rb deleted file mode 100644 index adbbfcc..0000000 --- a/spec/lago/api/resources/group_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Lago::Api::Resources::Group do - subject(:resource) { described_class.new(client) } - - let(:client) { Lago::Api::Client.new } - let(:group) { build(:group) } - let(:lago_id) { 'lago_internal_id' } - let(:metric) { build(:create_billable_metric) } - - let(:not_found_response) do - { - 'status' => 404, - 'error' => 'Not Found', - 'code' => 'billable_metric_not_found', - } - end - - describe '#get_all' do - let(:response_body) do - { - 'groups' => [group.to_h], - 'meta' => { - 'current_page' => 1, - 'next_page' => nil, - 'prev_page' => nil, - 'total_pages' => 1, - 'total_count' => 1, - }, - } - end - - before do - stub_request(:get, "https://api.getlago.com/api/v1/billable_metrics/#{metric.code}/groups?per_page=2&page=1") - .to_return(body: response_body.to_json, status: 200) - end - - it 'returns a list of groups' do - response = resource.get_all(metric.code, { per_page: 2, page: 1 }) - - expect(response['groups'].first['lago_id']).to eq(group.lago_id) - expect(response['meta']['current_page']).to eq(1) - end - end -end diff --git a/spec/lago/api/resources/subscription_spec.rb b/spec/lago/api/resources/subscription_spec.rb index d2b8514..501a37e 100644 --- a/spec/lago/api/resources/subscription_spec.rb +++ b/spec/lago/api/resources/subscription_spec.rb @@ -4,24 +4,25 @@ RSpec.describe Lago::Api::Resources::Subscription do subject(:resource) { described_class.new(client) } + let(:client) { Lago::Api::Client.new } let(:factory_subscription) { build(:subscription) } let(:error_response) do { 'status' => 422, 'error' => 'Unprocessable Entity', - 'message' => 'Validation error on the record' + 'message' => 'Validation error on the record', }.to_json end let(:response) do { - 'subscription' => factory_subscription.to_h + 'subscription' => factory_subscription.to_h, }.to_json end let(:pending_subscription) { create(:subscription, id: '456', status: 'pending') } let(:response_with_pending) do { - 'subscription' => pending_subscription.to_h + 'subscription' => pending_subscription.to_h, }.to_json end @@ -31,7 +32,7 @@ external_customer_id: factory_subscription.external_customer_id, plan_code: factory_subscription.plan_code, external_id: factory_subscription.external_id, - subscription_date: factory_subscription.subscription_date, + subscription_at: factory_subscription.subscription_at, billing_time: factory_subscription.billing_time, ending_at: factory_subscription.ending_at, plan_overrides: { @@ -40,12 +41,12 @@ amount_cents: 2000, invoice_display_name: 'Minimum commitment (C1)', }, - } + }, } end let(:body) do { - 'subscription' => params + 'subscription' => params, } end @@ -63,7 +64,7 @@ expect(subscription.plan_code).to eq(factory_subscription.plan_code) expect(subscription.status).to eq(factory_subscription.status) expect(subscription.external_id).to eq(factory_subscription.external_id) - expect(subscription.subscription_date).to eq(factory_subscription.subscription_date) + expect(subscription.subscription_at).to eq(factory_subscription.subscription_at) expect(subscription.billing_time).to eq(factory_subscription.billing_time) expect(subscription.ending_at).to eq(factory_subscription.ending_at) end @@ -101,7 +102,7 @@ context 'when subscription is pending' do before do stub_request(:delete, 'https://api.getlago.com/api/v1/subscriptions/456?status=pending') - .to_return(body: response_with_pending, status: 200) + .to_return(body: response_with_pending, status: 200) end it 'returns subscription' do @@ -129,7 +130,7 @@ let(:params) { { name: 'new name' } } let(:body) do { - 'subscription' => params + 'subscription' => params, } end @@ -193,15 +194,15 @@ let(:response) do { 'subscriptions' => [ - factory_subscription.to_h + factory_subscription.to_h, ], 'meta': { 'current_page' => 1, 'next_page' => 2, 'prev_page' => nil, 'total_pages' => 7, - 'total_count' => 63 - } + 'total_count' => 63, + }, }.to_json end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f397ec8..d84533e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,7 +17,6 @@ require 'lago/api/resources/event' require 'lago/api/resources/fee' require 'lago/api/resources/gross_revenue' -require 'lago/api/resources/group' require 'lago/api/resources/invoice' require 'lago/api/resources/invoice_collection' require 'lago/api/resources/invoiced_usage' From 24d31cd6b9fb3d4a35a803d27b60ef8b69074f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Semp=C3=A9?= Date: Wed, 10 Jul 2024 14:26:07 +0200 Subject: [PATCH 2/3] misc: Force external_subscription_id when creating an event --- lib/lago/api/resources/event.rb | 1 - spec/factories/event.rb | 2 +- spec/fixtures/api/event.json | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/lago/api/resources/event.rb b/lib/lago/api/resources/event.rb index b53dc8e..330d77a 100644 --- a/lib/lago/api/resources/event.rb +++ b/lib/lago/api/resources/event.rb @@ -30,7 +30,6 @@ def whitelist_params(params) { root_name => { transaction_id: params[:transaction_id], - external_customer_id: params[:external_customer_id], code: params[:code], timestamp: params[:timestamp], external_subscription_id: params[:external_subscription_id], diff --git a/spec/factories/event.rb b/spec/factories/event.rb index d367c90..7f453c0 100644 --- a/spec/factories/event.rb +++ b/spec/factories/event.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :event, class: OpenStruct do transaction_id { 'UNIQUE_ID' } - external_customer_id { '5eb02857-a71e-4ea2-bcf9-57d8885990ba' } + external_subscription_id { '5eb02857-a71e-4ea2-bcf9-57d8885990ba' } code { '123' } timestamp { '2022-05-05T12:27:30Z' } properties do diff --git a/spec/fixtures/api/event.json b/spec/fixtures/api/event.json index 565fcde..8d9ede0 100644 --- a/spec/fixtures/api/event.json +++ b/spec/fixtures/api/event.json @@ -3,7 +3,6 @@ "lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90", "transaction_id": "1a901a90-1a90-1a90-1a90-1a901a901a90", "lago_customer_id": "1a901a90-1a90-1a90-1a90-1a901a901a90", - "external_customer_id": "1a901a90-1a90-1a90-1a90-1a901a901a90", "code": "bm_code", "timestamp": "2022-04-29T08:59:51.998Z", "properties": { From 342b02c670410ad813b2be4aa5326170588c5587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Semp=C3=A9?= Date: Thu, 11 Jul 2024 15:23:37 +0200 Subject: [PATCH 3/3] misc: Force external_subscription_id when estimating fees --- lib/lago/api/resources/event.rb | 1 - spec/factories/event.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/lago/api/resources/event.rb b/lib/lago/api/resources/event.rb index 330d77a..ef4b118 100644 --- a/lib/lago/api/resources/event.rb +++ b/lib/lago/api/resources/event.rb @@ -48,7 +48,6 @@ def whitelist_estimate_params(params) { root_name => { code: params[:code], - external_customer_id: params[:external_customer_id], external_subscription_id: params[:external_subscription_id], properties: params[:properties], }.compact, diff --git a/spec/factories/event.rb b/spec/factories/event.rb index 7f453c0..eadf726 100644 --- a/spec/factories/event.rb +++ b/spec/factories/event.rb @@ -28,7 +28,6 @@ end factory :estimate_fees_event, class: OpenStruct do - external_customer_id { '5eb02857-a71e-4ea2-bcf9-57d8885990ba' } external_subscription_id { '5eb02857-a71e-4ea2-bcf9-57d8885990ba' } code { '123' } properties do