From feb86e5e078b6ba802726f5898911bbfb29045f9 Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Mon, 15 Jul 2024 10:37:52 +0200 Subject: [PATCH] misc: Remove deprecated API fields (#2261) ## Context Related to https://docs.getlago.com/guide/migration/migration-to-v1.2.0#3-deprecated-fields ## Description This PR removes all deprecated fields from the REST API --- app/controllers/api/v1/coupons_controller.rb | 12 +- .../api/v1/customers_controller.rb | 3 - .../api/v1/organizations_controller.rb | 5 +- .../api/v1/subscriptions_controller.rb | 10 +- app/controllers/api/v1/wallets_controller.rb | 16 +-- .../organizations/base_organization_type.rb | 1 - .../organizations/billing_configuration.rb | 1 - app/legacy_inputs/coupon_legacy_input.rb | 12 -- .../subscription_legacy_input.rb | 12 -- app/legacy_inputs/wallet_legacy_input.rb | 12 -- app/models/customer.rb | 1 - app/models/organization.rb | 1 - .../v1/applied_coupon_serializer.rb | 7 -- app/serializers/v1/coupon_serializer.rb | 10 +- app/serializers/v1/credit_note_serializer.rb | 6 +- app/serializers/v1/credit_serializer.rb | 8 +- app/serializers/v1/customer_serializer.rb | 9 +- .../v1/customers/usage_serializer.rb | 6 +- app/serializers/v1/event_error_serializer.rb | 7 -- app/serializers/v1/fee_serializer.rb | 6 +- app/serializers/v1/invoice_serializer.rb | 6 +- .../v1/legacy/applied_coupon_serializer.rb | 13 --- .../v1/legacy/coupon_serializer.rb | 13 --- .../v1/legacy/credit_note_serializer.rb | 20 ---- .../v1/legacy/credit_serializer.rb | 16 --- .../v1/legacy/customer_serializer.rb | 13 --- .../v1/legacy/customers/usage_serializer.rb | 20 ---- .../v1/legacy/event_error_serializer.rb | 20 ---- app/serializers/v1/legacy/fee_serializer.rb | 19 ---- .../v1/legacy/invoice_serializer.rb | 28 ----- .../v1/legacy/organization_serializer.rb | 13 --- .../v1/legacy/subscription_serializer.rb | 13 --- .../v1/legacy/wallet_serializer.rb | 14 --- app/serializers/v1/organization_serializer.rb | 8 +- app/serializers/v1/subscription_serializer.rb | 6 +- app/serializers/v1/wallet_serializer.rb | 8 +- app/services/customers/create_service.rb | 25 ----- app/services/customers/update_service.rb | 3 - app/services/organizations/update_service.rb | 25 ----- schema.graphql | 1 - schema.json | 18 --- spec/factories/organizations.rb | 1 - .../resolvers/organization_resolver_spec.rb | 3 +- .../api/v1/applied_coupons_controller_spec.rb | 2 +- .../api/v1/coupons_controller_spec.rb | 37 ------- .../api/v1/credit_notes_controller_spec.rb | 9 +- .../api/v1/customers/usage_controller_spec.rb | 9 +- .../api/v1/customers_controller_spec.rb | 5 - .../requests/api/v1/events_controller_spec.rb | 2 - spec/requests/api/v1/fees_controller_spec.rb | 4 - .../api/v1/invoices_controller_spec.rb | 2 +- .../api/v1/organizations_controller_spec.rb | 3 - .../api/v1/subscriptions_controller_spec.rb | 5 +- .../api/v1/wallets_controller_spec.rb | 43 -------- .../v1/applied_coupon_serializer_spec.rb | 1 - spec/serializers/v1/coupon_serializer_spec.rb | 6 - .../v1/credit_note_serializer_spec.rb | 12 +- spec/serializers/v1/credit_serializer_spec.rb | 4 - .../v1/customer_serializer_spec.rb | 1 - .../v1/customers/usage_serializer_spec.rb | 11 -- .../v1/event_error_serializer_spec.rb | 10 -- spec/serializers/v1/fee_serializer_spec.rb | 5 +- .../serializers/v1/invoice_serializer_spec.rb | 14 +-- .../v1/organization_serializer_spec.rb | 1 - spec/serializers/v1/wallet_serializer_spec.rb | 5 - spec/services/coupons/create_service_spec.rb | 2 +- .../create_from_termination_spec.rb | 2 - .../services/customers/create_service_spec.rb | 103 ------------------ .../services/customers/update_service_spec.rb | 24 ---- .../organizations/update_service_spec.rb | 90 --------------- .../invoices/generated_service_spec.rb | 2 +- 71 files changed, 36 insertions(+), 829 deletions(-) delete mode 100644 app/legacy_inputs/coupon_legacy_input.rb delete mode 100644 app/legacy_inputs/subscription_legacy_input.rb delete mode 100644 app/legacy_inputs/wallet_legacy_input.rb delete mode 100644 app/serializers/v1/legacy/applied_coupon_serializer.rb delete mode 100644 app/serializers/v1/legacy/coupon_serializer.rb delete mode 100644 app/serializers/v1/legacy/credit_note_serializer.rb delete mode 100644 app/serializers/v1/legacy/credit_serializer.rb delete mode 100644 app/serializers/v1/legacy/customer_serializer.rb delete mode 100644 app/serializers/v1/legacy/customers/usage_serializer.rb delete mode 100644 app/serializers/v1/legacy/event_error_serializer.rb delete mode 100644 app/serializers/v1/legacy/fee_serializer.rb delete mode 100644 app/serializers/v1/legacy/invoice_serializer.rb delete mode 100644 app/serializers/v1/legacy/organization_serializer.rb delete mode 100644 app/serializers/v1/legacy/subscription_serializer.rb delete mode 100644 app/serializers/v1/legacy/wallet_serializer.rb diff --git a/app/controllers/api/v1/coupons_controller.rb b/app/controllers/api/v1/coupons_controller.rb index b157b82052c..0776002ec57 100644 --- a/app/controllers/api/v1/coupons_controller.rb +++ b/app/controllers/api/v1/coupons_controller.rb @@ -6,10 +6,7 @@ class CouponsController < Api::BaseController def create service = Coupons::CreateService.new result = service.create( - CouponLegacyInput.new( - current_organization, - input_params.merge(organization_id: current_organization.id) - ).create_input + input_params.merge(organization_id: current_organization.id).to_h ) if result.success? @@ -24,10 +21,7 @@ def update result = Coupons::UpdateService.call( coupon:, - params: CouponLegacyInput.new( - current_organization, - input_params - ).update_input + params: input_params.to_h ) if result.success? @@ -89,8 +83,6 @@ def input_params :frequency_duration, :expiration, :expiration_at, - # NOTE: Legacy field - :expiration_date, :reusable, applies_to: [ plan_codes: [], diff --git a/app/controllers/api/v1/customers_controller.rb b/app/controllers/api/v1/customers_controller.rb index cfee3d39b5f..766476d7e68 100644 --- a/app/controllers/api/v1/customers_controller.rb +++ b/app/controllers/api/v1/customers_controller.rb @@ -127,9 +127,6 @@ def create_params :sync, :sync_with_provider, :document_locale, - - # NOTE(legacy): vat has been moved to tax model - :vat_rate, provider_payment_methods: [] ], metadata: [ diff --git a/app/controllers/api/v1/organizations_controller.rb b/app/controllers/api/v1/organizations_controller.rb index b5f00e08bab..ba957c62b30 100644 --- a/app/controllers/api/v1/organizations_controller.rb +++ b/app/controllers/api/v1/organizations_controller.rb @@ -69,10 +69,7 @@ def input_params billing_configuration: [ :invoice_footer, :invoice_grace_period, - :document_locale, - - # NOTE(legacy): vat has been moved to tax model - :vat_rate + :document_locale ] ) end diff --git a/app/controllers/api/v1/subscriptions_controller.rb b/app/controllers/api/v1/subscriptions_controller.rb index e4d44469a96..da97a5072b7 100644 --- a/app/controllers/api/v1/subscriptions_controller.rb +++ b/app/controllers/api/v1/subscriptions_controller.rb @@ -17,10 +17,7 @@ def create result = Subscriptions::CreateService.call( customer:, plan:, - params: SubscriptionLegacyInput.new( - current_organization, - create_params - ).create_input + params: create_params.to_h ) if result.success? @@ -64,10 +61,7 @@ def update result = Subscriptions::UpdateService.call( subscription:, - params: SubscriptionLegacyInput.new( - current_organization, - update_params - ).update_input + params: update_params.to_h ) if result.success? diff --git a/app/controllers/api/v1/wallets_controller.rb b/app/controllers/api/v1/wallets_controller.rb index 1beafd8887a..f93511a4dbb 100644 --- a/app/controllers/api/v1/wallets_controller.rb +++ b/app/controllers/api/v1/wallets_controller.rb @@ -5,12 +5,9 @@ module V1 class WalletsController < Api::BaseController def create result = Wallets::CreateService.call( - params: WalletLegacyInput.new( - current_organization, - input_params - .merge(organization_id: current_organization.id) - .merge(customer:).to_h.deep_symbolize_keys - ).create_input + params: input_params + .merge(organization_id: current_organization.id) + .merge(customer:).to_h.deep_symbolize_keys ) if result.success? @@ -23,10 +20,7 @@ def create def update result = Wallets::UpdateService.call( wallet: current_organization.wallets.find_by(id: params[:id]), - params: WalletLegacyInput.new( - current_organization, - update_params.merge(id: params[:id]).to_h.deep_symbolize_keys - ).update_input + params: update_params.merge(id: params[:id]).to_h.deep_symbolize_keys ) if result.success? @@ -86,7 +80,6 @@ def input_params :paid_credits, :granted_credits, :expiration_at, - :expiration_date, # NOTE: Legacy field recurring_transaction_rules: [ :granted_credits, :interval, @@ -108,7 +101,6 @@ def update_params params.require(:wallet).permit( :name, :expiration_at, - :expiration_date, # NOTE: Legacy field recurring_transaction_rules: [ :lago_id, :interval, diff --git a/app/graphql/types/organizations/base_organization_type.rb b/app/graphql/types/organizations/base_organization_type.rb index 1fc9aca4f6b..ba7b42d31a3 100644 --- a/app/graphql/types/organizations/base_organization_type.rb +++ b/app/graphql/types/organizations/base_organization_type.rb @@ -6,7 +6,6 @@ class BaseOrganizationType < BaseObject def billing_configuration { id: "#{object&.id}-c0nf", # Each nested object needs ID so that appollo cache system can work properly - vat_rate: object&.vat_rate, invoice_footer: object&.invoice_footer, invoice_grace_period: object&.invoice_grace_period, document_locale: object&.document_locale, diff --git a/app/graphql/types/organizations/billing_configuration.rb b/app/graphql/types/organizations/billing_configuration.rb index 59fbadbb947..287c4292fbf 100644 --- a/app/graphql/types/organizations/billing_configuration.rb +++ b/app/graphql/types/organizations/billing_configuration.rb @@ -9,7 +9,6 @@ class BillingConfiguration < Types::BaseObject field :id, ID, null: false field :invoice_footer, String field :invoice_grace_period, Integer, null: false - field :vat_rate, Float, null: false end end end diff --git a/app/legacy_inputs/coupon_legacy_input.rb b/app/legacy_inputs/coupon_legacy_input.rb deleted file mode 100644 index 85b1454bac3..00000000000 --- a/app/legacy_inputs/coupon_legacy_input.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class CouponLegacyInput < BaseLegacyInput - def create_input - if args[:expiration_date].present? - args[:expiration_at] ||= date_in_organization_timezone(args[:expiration_date], end_of_day: true) - end - - args - end - alias_method :update_input, :create_input -end diff --git a/app/legacy_inputs/subscription_legacy_input.rb b/app/legacy_inputs/subscription_legacy_input.rb deleted file mode 100644 index 3944ed05ea5..00000000000 --- a/app/legacy_inputs/subscription_legacy_input.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class SubscriptionLegacyInput < BaseLegacyInput - def create_input - if args[:subscription_date].present? - args[:subscription_at] ||= date_in_organization_timezone(args[:subscription_date], end_of_day: false) - end - - args - end - alias_method :update_input, :create_input -end diff --git a/app/legacy_inputs/wallet_legacy_input.rb b/app/legacy_inputs/wallet_legacy_input.rb deleted file mode 100644 index f3f0381fbb7..00000000000 --- a/app/legacy_inputs/wallet_legacy_input.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -class WalletLegacyInput < BaseLegacyInput - def create_input - if args[:expiration_date].present? - args[:expiration_at] ||= date_in_organization_timezone(args[:expiration_date], end_of_day: true) - end - - args - end - alias_method :update_input, :create_input -end diff --git a/app/models/customer.rb b/app/models/customer.rb index b2f055e1791..d2a56898332 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -59,7 +59,6 @@ class Customer < ApplicationRecord validates :net_payment_term, numericality: {greater_than_or_equal_to: 0}, allow_nil: true validates :payment_provider, inclusion: {in: PAYMENT_PROVIDERS}, allow_nil: true validates :timezone, timezone: true, allow_nil: true - validates :vat_rate, numericality: {less_than_or_equal_to: 100, greater_than_or_equal_to: 0}, allow_nil: true def self.ransackable_attributes(_auth_object = nil) %w[id name external_id email] diff --git a/app/models/organization.rb b/app/models/organization.rb index 16d4c239521..7788cf9e0ca 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -67,7 +67,6 @@ class Organization < ApplicationRecord if: :logo? validates :name, presence: true validates :timezone, timezone: true - validates :vat_rate, numericality: {less_than_or_equal_to: 100, greater_than_or_equal_to: 0} validates :webhook_url, url: true, allow_nil: true validate :validate_email_settings diff --git a/app/serializers/v1/applied_coupon_serializer.rb b/app/serializers/v1/applied_coupon_serializer.rb index 7d9e68950a3..21a4bcf217c 100644 --- a/app/serializers/v1/applied_coupon_serializer.rb +++ b/app/serializers/v1/applied_coupon_serializer.rb @@ -23,7 +23,6 @@ def serialize terminated_at: model.terminated_at&.iso8601 } - payload = payload.merge(legacy_values) payload = payload.merge(credits) if include?(:credits) payload @@ -41,11 +40,5 @@ def amount_cents_remaining def credits ::CollectionSerializer.new(model.credits, ::V1::CreditSerializer, collection_name: 'credits').serialize end - - def legacy_values - ::V1::Legacy::AppliedCouponSerializer.new( - model - ).serialize - end end end diff --git a/app/serializers/v1/coupon_serializer.rb b/app/serializers/v1/coupon_serializer.rb index 932a59502d4..6aea4f4a003 100644 --- a/app/serializers/v1/coupon_serializer.rb +++ b/app/serializers/v1/coupon_serializer.rb @@ -23,15 +23,7 @@ def serialize expiration: model.expiration, expiration_at: model.expiration_at&.iso8601, terminated_at: model.terminated_at&.iso8601 - }.merge(legacy_values) - end - - private - - def legacy_values - ::V1::Legacy::CouponSerializer.new( - model - ).serialize + } end end end diff --git a/app/serializers/v1/credit_note_serializer.rb b/app/serializers/v1/credit_note_serializer.rb index f76750c0cf0..851d687fe7e 100644 --- a/app/serializers/v1/credit_note_serializer.rb +++ b/app/serializers/v1/credit_note_serializer.rb @@ -26,7 +26,7 @@ def serialize created_at: model.created_at.iso8601, updated_at: model.updated_at.iso8601, file_url: model.file_url - }.merge(legacy_values) + } payload.merge!(customer) if include?(:customer) payload.merge!(items) if include?(:items) @@ -58,9 +58,5 @@ def applied_taxes collection_name: 'applied_taxes' ).serialize end - - def legacy_values - ::V1::Legacy::CreditNoteSerializer.new(model).serialize - end end end diff --git a/app/serializers/v1/credit_serializer.rb b/app/serializers/v1/credit_serializer.rb index a492ef0e8f0..3f1cf85668e 100644 --- a/app/serializers/v1/credit_serializer.rb +++ b/app/serializers/v1/credit_serializer.rb @@ -18,13 +18,7 @@ def serialize lago_id: model.invoice_id, payment_status: model.invoice.payment_status } - }.deep_merge(legacy_values) - end - - private - - def legacy_values - ::V1::Legacy::CreditSerializer.new(model).serialize + } end end end diff --git a/app/serializers/v1/customer_serializer.rb b/app/serializers/v1/customer_serializer.rb index 9e34664fd55..c823fd0f5d6 100644 --- a/app/serializers/v1/customer_serializer.rb +++ b/app/serializers/v1/customer_serializer.rb @@ -31,7 +31,7 @@ def serialize external_salesforce_id: model.external_salesforce_id, billing_configuration:, shipping_address: model.shipping_address - }.merge(legacy_values.except(:billing_configuration)) + } payload = payload.merge(metadata) payload = payload.merge(taxes) if include?(:taxes) @@ -56,9 +56,8 @@ def billing_configuration invoice_grace_period: model.invoice_grace_period, payment_provider: model.payment_provider, payment_provider_code: model.payment_provider_code, - vat_rate: model.vat_rate, document_locale: model.document_locale - }.merge(legacy_values[:billing_configuration]) + } case model.payment_provider&.to_sym when :stripe @@ -76,10 +75,6 @@ def billing_configuration configuration end - def legacy_values - @legacy_values ||= ::V1::Legacy::CustomerSerializer.new(model).serialize - end - def taxes ::CollectionSerializer.new(model.taxes, ::V1::TaxSerializer, collection_name: 'taxes').serialize end diff --git a/app/serializers/v1/customers/usage_serializer.rb b/app/serializers/v1/customers/usage_serializer.rb index f0f96641314..e74432f8b63 100644 --- a/app/serializers/v1/customers/usage_serializer.rb +++ b/app/serializers/v1/customers/usage_serializer.rb @@ -13,7 +13,7 @@ def serialize total_amount_cents: model.total_amount_cents, taxes_amount_cents: model.taxes_amount_cents, lago_invoice_id: nil - }.merge(legacy_values) + } payload.merge!(charges_usage) if include?(:charges_usage) payload @@ -26,10 +26,6 @@ def charges_usage charges_usage: ::V1::Customers::ChargeUsageSerializer.new(model.fees).serialize } end - - def legacy_values - ::V1::Legacy::Customers::UsageSerializer.new(model).serialize - end end end end diff --git a/app/serializers/v1/event_error_serializer.rb b/app/serializers/v1/event_error_serializer.rb index 61646696278..3d74dd44089 100644 --- a/app/serializers/v1/event_error_serializer.rb +++ b/app/serializers/v1/event_error_serializer.rb @@ -10,17 +10,10 @@ def serialize } payload.merge!(event) - payload.merge(legacy_values) end private - def legacy_values - ::V1::Legacy::EventErrorSerializer.new( - model.event - ).serialize - end - def event {event: ::V1::EventSerializer.new(model.event).serialize} end diff --git a/app/serializers/v1/fee_serializer.rb b/app/serializers/v1/fee_serializer.rb index 8f358070f68..57b1c1be75f 100644 --- a/app/serializers/v1/fee_serializer.rb +++ b/app/serializers/v1/fee_serializer.rb @@ -42,7 +42,7 @@ def serialize failed_at: model.failed_at&.iso8601, refunded_at: model.refunded_at&.iso8601, amount_details: model.amount_details - }.deep_merge(legacy_values) + } payload.merge!(date_boundaries) if model.charge? || model.subscription? payload.merge!(pay_in_advance_charge_attributes) if model.pay_in_advance? @@ -110,10 +110,6 @@ def applied_taxes ).serialize end - def legacy_values - ::V1::Legacy::FeeSerializer.new(model).serialize - end - def pay_in_advance if model.charge? model.pay_in_advance diff --git a/app/serializers/v1/invoice_serializer.rb b/app/serializers/v1/invoice_serializer.rb index beb50bdab53..ecc1a2f1abf 100644 --- a/app/serializers/v1/invoice_serializer.rb +++ b/app/serializers/v1/invoice_serializer.rb @@ -26,7 +26,7 @@ def serialize prepaid_credit_amount_cents: model.prepaid_credit_amount_cents, file_url: model.file_url, version_number: model.version_number - }.merge(legacy_values) + } payload.merge!(customer) if include?(:customer) payload.merge!(subscriptions) if include?(:subscriptions) @@ -89,9 +89,5 @@ def applied_taxes collection_name: 'applied_taxes' ).serialize end - - def legacy_values - ::V1::Legacy::InvoiceSerializer.new(model).serialize - end end end diff --git a/app/serializers/v1/legacy/applied_coupon_serializer.rb b/app/serializers/v1/legacy/applied_coupon_serializer.rb deleted file mode 100644 index aa5cb5e358f..00000000000 --- a/app/serializers/v1/legacy/applied_coupon_serializer.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class AppliedCouponSerializer < ModelSerializer - def serialize - { - expiration_date: model.coupon.expiration_at&.to_date&.iso8601 - } - end - end - end -end diff --git a/app/serializers/v1/legacy/coupon_serializer.rb b/app/serializers/v1/legacy/coupon_serializer.rb deleted file mode 100644 index 3f9b7bdf4c8..00000000000 --- a/app/serializers/v1/legacy/coupon_serializer.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class CouponSerializer < ModelSerializer - def serialize - { - expiration_date: model.expiration_at&.to_date&.iso8601 - } - end - end - end -end diff --git a/app/serializers/v1/legacy/credit_note_serializer.rb b/app/serializers/v1/legacy/credit_note_serializer.rb deleted file mode 100644 index d5d363cf41c..00000000000 --- a/app/serializers/v1/legacy/credit_note_serializer.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class CreditNoteSerializer < ModelSerializer - def serialize - { - total_amount_currency: model.total_amount_currency, - vat_amount_cents: model.taxes_amount_cents, - vat_amount_currency: model.currency, - sub_total_vat_excluded_amount_cents: model.sub_total_excluding_taxes_amount_cents, - sub_total_vat_excluded_amount_currency: model.currency, - balance_amount_currency: model.balance_amount_currency, - credit_amount_currency: model.credit_amount_currency, - refund_amount_currency: model.refund_amount_currency - } - end - end - end -end diff --git a/app/serializers/v1/legacy/credit_serializer.rb b/app/serializers/v1/legacy/credit_serializer.rb deleted file mode 100644 index c1cd01d5b31..00000000000 --- a/app/serializers/v1/legacy/credit_serializer.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class CreditSerializer < ModelSerializer - def serialize - { - before_vat: model.before_taxes, - item: { - lago_id: model.item_id - } - } - end - end - end -end diff --git a/app/serializers/v1/legacy/customer_serializer.rb b/app/serializers/v1/legacy/customer_serializer.rb deleted file mode 100644 index bfd902aa390..00000000000 --- a/app/serializers/v1/legacy/customer_serializer.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class CustomerSerializer < ModelSerializer - def serialize - { - billing_configuration: {vat_rate: model.vat_rate} - } - end - end - end -end diff --git a/app/serializers/v1/legacy/customers/usage_serializer.rb b/app/serializers/v1/legacy/customers/usage_serializer.rb deleted file mode 100644 index 023ca793da5..00000000000 --- a/app/serializers/v1/legacy/customers/usage_serializer.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - module Customers - class UsageSerializer < ModelSerializer - def serialize - { - from_date: model.from_datetime&.to_date, - to_date: model.to_datetime&.to_date, - amount_currency: model.currency, - total_amount_currency: model.currency, - vat_amount_currency: model.currency, - vat_amount_cents: model.taxes_amount_cents - } - end - end - end - end -end diff --git a/app/serializers/v1/legacy/event_error_serializer.rb b/app/serializers/v1/legacy/event_error_serializer.rb deleted file mode 100644 index c0b9a11279d..00000000000 --- a/app/serializers/v1/legacy/event_error_serializer.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class EventErrorSerializer < ModelSerializer - def serialize - { - input_params: { - transaction_id: model.transaction_id, - external_subscription_id: model.external_subscription_id, - external_customer_id: model.external_customer_id, - timestamp: model.timestamp.to_f, - code: model.code, - properties: model.properties - } - } - end - end - end -end diff --git a/app/serializers/v1/legacy/fee_serializer.rb b/app/serializers/v1/legacy/fee_serializer.rb deleted file mode 100644 index 42d6a63491d..00000000000 --- a/app/serializers/v1/legacy/fee_serializer.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class FeeSerializer < ModelSerializer - def serialize - { - vat_amount_cents: model.taxes_amount_cents, - vat_amount_currency: model.currency, - unit_amount_cents: model.unit_amount_cents, - lago_group_id: model.group_id, - item: { - group_invoice_display_name: model.charge_filter&.display_name - } - } - end - end - end -end diff --git a/app/serializers/v1/legacy/invoice_serializer.rb b/app/serializers/v1/legacy/invoice_serializer.rb deleted file mode 100644 index 70eb19fa283..00000000000 --- a/app/serializers/v1/legacy/invoice_serializer.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class InvoiceSerializer < ModelSerializer - def serialize - { - legacy:, - amount_currency: model.currency, - vat_amount_currency: model.currency, - credit_amount_currency: model.currency, - total_amount_currency: model.currency, - amount_cents: model.fees_amount_cents, - credit_amount_cents: model.credits.sum(:amount_cents), - vat_amount_cents: model.taxes_amount_cents, - sub_total_vat_excluded_amount_cents: model.sub_total_excluding_taxes_amount_cents, - sub_total_vat_included_amount_cents: model.sub_total_including_taxes_amount_cents - } - end - - private - - def legacy - model.version_number < Invoice::CREDIT_NOTES_MIN_VERSION - end - end - end -end diff --git a/app/serializers/v1/legacy/organization_serializer.rb b/app/serializers/v1/legacy/organization_serializer.rb deleted file mode 100644 index c8aec4a20ef..00000000000 --- a/app/serializers/v1/legacy/organization_serializer.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class OrganizationSerializer < ModelSerializer - def serialize - { - billing_configuration: {vat_rate: model.vat_rate} - } - end - end - end -end diff --git a/app/serializers/v1/legacy/subscription_serializer.rb b/app/serializers/v1/legacy/subscription_serializer.rb deleted file mode 100644 index 311733deae2..00000000000 --- a/app/serializers/v1/legacy/subscription_serializer.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class SubscriptionSerializer < ModelSerializer - def serialize - { - subscription_date: model.subscription_at&.to_date - } - end - end - end -end diff --git a/app/serializers/v1/legacy/wallet_serializer.rb b/app/serializers/v1/legacy/wallet_serializer.rb deleted file mode 100644 index ee0eb89c6ec..00000000000 --- a/app/serializers/v1/legacy/wallet_serializer.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module V1 - module Legacy - class WalletSerializer < ModelSerializer - def serialize - { - expiration_date: model.expiration_at&.to_date&.iso8601, - balance: model.balance.to_s - } - end - end - end -end diff --git a/app/serializers/v1/organization_serializer.rb b/app/serializers/v1/organization_serializer.rb index 9a5cecb8235..40cd993db69 100644 --- a/app/serializers/v1/organization_serializer.rb +++ b/app/serializers/v1/organization_serializer.rb @@ -26,7 +26,7 @@ def serialize document_number_prefix: model.document_number_prefix, tax_identification_number: model.tax_identification_number, billing_configuration: - }.merge(legacy_values.except(:billing_configuration)) + } payload = payload.merge(taxes) if include?(:taxes) @@ -40,11 +40,7 @@ def billing_configuration invoice_footer: model.invoice_footer, invoice_grace_period: model.invoice_grace_period, document_locale: model.document_locale - }.merge(legacy_values[:billing_configuration]) - end - - def legacy_values - @legacy_values ||= ::V1::Legacy::OrganizationSerializer.new(model).serialize + } end def taxes diff --git a/app/serializers/v1/subscription_serializer.rb b/app/serializers/v1/subscription_serializer.rb index be111367261..73400f97134 100644 --- a/app/serializers/v1/subscription_serializer.rb +++ b/app/serializers/v1/subscription_serializer.rb @@ -22,7 +22,7 @@ def serialize previous_plan_code: model.previous_subscription&.plan&.code, next_plan_code: model.next_subscription&.plan&.code, downgrade_plan_date: model.downgrade_plan_date&.iso8601 - }.merge(legacy_values) + } payload = payload.merge(customer:) if include?(:customer) payload = payload.merge(plan:) if include?(:plan) @@ -32,10 +32,6 @@ def serialize private - def legacy_values - ::V1::Legacy::SubscriptionSerializer.new(model).serialize - end - def customer ::V1::CustomerSerializer.new(model.customer).serialize end diff --git a/app/serializers/v1/wallet_serializer.rb b/app/serializers/v1/wallet_serializer.rb index 109518a22c7..24592097d09 100644 --- a/app/serializers/v1/wallet_serializer.rb +++ b/app/serializers/v1/wallet_serializer.rb @@ -23,7 +23,7 @@ def serialize last_balance_sync_at: model.last_balance_sync_at&.iso8601, last_consumed_credit_at: model.last_consumed_credit_at&.iso8601, terminated_at: model.terminated_at - }.merge(legacy_values) + } payload.merge!(recurring_transaction_rules) if include?(:recurring_transaction_rules) @@ -32,12 +32,6 @@ def serialize private - def legacy_values - ::V1::Legacy::WalletSerializer.new( - model - ).serialize - end - def recurring_transaction_rules ::CollectionSerializer.new( model.recurring_transaction_rules, diff --git a/app/services/customers/create_service.rb b/app/services/customers/create_service.rb index 3e119a1d3b0..2c0a981a0a3 100644 --- a/app/services/customers/create_service.rb +++ b/app/services/customers/create_service.rb @@ -137,7 +137,6 @@ def create(**args) legal_number: args[:legal_number], net_payment_term: args[:net_payment_term], external_salesforce_id: args[:external_salesforce_id], - vat_rate: args[:vat_rate], payment_provider: args[:payment_provider], payment_provider_code: args[:payment_provider_code], currency: args[:currency], @@ -251,9 +250,6 @@ def handle_api_billing_configuration(customer, params, new_customer) Customers::UpdateInvoiceGracePeriodService.call(customer:, grace_period: billing[:invoice_grace_period]) end - # NOTE(legacy): keep accepting vat_rate field temporary by converting it into tax - handle_legacy_vat_rate(customer:, vat_rate: billing[:vat_rate]) if billing.key?(:vat_rate) - customer.document_locale = billing[:document_locale] if billing.key?(:document_locale) if new_customer || should_create_billing_configuration?(billing, customer) @@ -318,27 +314,6 @@ def track_customer_created(customer) ) end - def handle_legacy_vat_rate(customer:, vat_rate:) - if customer.taxes.count > 1 - result.single_validation_failure!( - field: :vat_rate, - error_code: 'multiple_taxes' - ).raise_if_error! - end - - # NOTE(legacy): Keep updating vat_rate until we remove the field - customer.vat_rate = vat_rate - - current_tax = customer.taxes.first - return if current_tax&.rate == vat_rate - - tax = customer.organization.taxes - .create_with(rate: vat_rate, name: "Tax (#{vat_rate}%)") - .find_or_create_by!(code: "tax_#{vat_rate}") - - Customers::ApplyTaxesService.call(customer:, tax_codes: [tax.code]) - end - def should_create_billing_configuration?(billing, customer) billing[:sync_with_provider] && customer.provider_customer&.provider_customer_id.nil? end diff --git a/app/services/customers/update_service.rb b/app/services/customers/update_service.rb index 881e947bb90..a65087305ea 100644 --- a/app/services/customers/update_service.rb +++ b/app/services/customers/update_service.rb @@ -51,8 +51,6 @@ def update(**args) assign_premium_attributes(customer, args) - # TODO: delete this when GraphQL will use billing_configuration. - customer.vat_rate = args[:vat_rate] if args.key?(:vat_rate) customer.payment_provider = args[:payment_provider] if args.key?(:payment_provider) customer.payment_provider_code = args[:payment_provider_code] if args.key?(:payment_provider_code) customer.invoice_footer = args[:invoice_footer] if args.key?(:invoice_footer) @@ -69,7 +67,6 @@ def update(**args) if args.key?(:billing_configuration) billing = args[:billing_configuration] customer.invoice_footer = billing[:invoice_footer] if billing.key?(:invoice_footer) - customer.vat_rate = billing[:vat_rate] if billing.key?(:vat_rate) if License.premium? && billing.key?(:invoice_grace_period) Customers::UpdateInvoiceGracePeriodService.call(customer:, grace_period: billing[:invoice_grace_period]) diff --git a/app/services/organizations/update_service.rb b/app/services/organizations/update_service.rb index eb445810d04..17699ba77de 100644 --- a/app/services/organizations/update_service.rb +++ b/app/services/organizations/update_service.rb @@ -31,9 +31,6 @@ def call organization.invoice_footer = billing[:invoice_footer] if billing.key?(:invoice_footer) organization.document_locale = billing[:document_locale] if billing.key?(:document_locale) - # NOTE(legacy): keep accepting vat_rate field temporary by converting it into tax rate - handle_legacy_vat_rate(billing[:vat_rate]) if billing.key?(:vat_rate) - # NOTE: handle eu tax management for organization handle_eu_tax_management(params[:eu_tax_management]) if params.key?(:eu_tax_management) @@ -97,28 +94,6 @@ def handle_base64_logo ) end - def handle_legacy_vat_rate(vat_rate) - if organization.taxes.applied_to_organization.count > 1 - result.single_validation_failure!(field: :vat_rate, error_code: 'multiple_taxes') - .raise_if_error! - end - - # NOTE(legacy): Keep updating vat_rate until we remove the field - organization.vat_rate = vat_rate - - current_tax = organization.taxes.applied_to_organization.first - return if current_tax&.rate == vat_rate - - current_tax&.update!(applied_to_organization: false) - return if vat_rate.zero? - - organization.taxes.create_with( - rate: vat_rate, - name: "Tax (#{vat_rate}%)", - applied_to_organization: true - ).find_or_create_by!(code: "tax_#{vat_rate}") - end - def handle_eu_tax_management(eu_tax_management) trying_to_enable_eu_tax_management = params[:eu_tax_management] && !organization.eu_tax_management if !organization.eu_vat_eligible? && trying_to_enable_eu_tax_management diff --git a/schema.graphql b/schema.graphql index 58fc6df98de..f876e00ace9 100644 --- a/schema.graphql +++ b/schema.graphql @@ -5147,7 +5147,6 @@ type OrganizationBillingConfiguration { id: ID! invoiceFooter: String invoiceGracePeriod: Int! - vatRate: Float! } input OrganizationBillingConfigurationInput { diff --git a/schema.json b/schema.json index 3c8c7f63642..0d2661faff5 100644 --- a/schema.json +++ b/schema.json @@ -24672,24 +24672,6 @@ "deprecationReason": null, "args": [ - ] - }, - { - "name": "vatRate", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Float", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - ] } ], diff --git a/spec/factories/organizations.rb b/spec/factories/organizations.rb index ead1d77b1da..4f01e0bfb00 100644 --- a/spec/factories/organizations.rb +++ b/spec/factories/organizations.rb @@ -4,7 +4,6 @@ factory :organization do name { Faker::Company.name } default_currency { 'USD' } - vat_rate { 20 } email { Faker::Internet.email } email_settings { ['invoice.finalized', 'credit_note.created'] } diff --git a/spec/graphql/resolvers/organization_resolver_spec.rb b/spec/graphql/resolvers/organization_resolver_spec.rb index 5390d1b6ca0..dc409999f64 100644 --- a/spec/graphql/resolvers/organization_resolver_spec.rb +++ b/spec/graphql/resolvers/organization_resolver_spec.rb @@ -45,7 +45,7 @@ taxIdentificationNumber apiKey webhookUrl - billingConfiguration { invoiceFooter vatRate } + billingConfiguration { invoiceFooter } emailSettings taxes { id code } } @@ -68,7 +68,6 @@ expect(data['taxIdentificationNumber']).to eq(organization.tax_identification_number) expect(data['apiKey']).to eq(organization.api_key) expect(data['webhookUrl']).to eq(organization.webhook_endpoints.first.webhook_url) - expect(data['billingConfiguration']['vatRate']).to eq(organization.vat_rate) expect(data['billingConfiguration']['invoiceFooter']).to eq(organization.invoice_footer) expect(data['emailSettings']).to eq(organization.email_settings.map { _1.tr('.', '_') }) expect(data['taxes']).to eq [] diff --git a/spec/requests/api/v1/applied_coupons_controller_spec.rb b/spec/requests/api/v1/applied_coupons_controller_spec.rb index 0c205a59935..b42d9967509 100644 --- a/spec/requests/api/v1/applied_coupons_controller_spec.rb +++ b/spec/requests/api/v1/applied_coupons_controller_spec.rb @@ -35,7 +35,7 @@ expect(json[:applied_coupon][:external_customer_id]).to eq(customer.external_id) expect(json[:applied_coupon][:amount_cents]).to eq(coupon.amount_cents) expect(json[:applied_coupon][:amount_currency]).to eq(coupon.amount_currency) - expect(json[:applied_coupon][:expiration_date]).to be_nil + expect(json[:applied_coupon][:expiration_at]).to be_nil expect(json[:applied_coupon][:created_at]).to be_present expect(json[:applied_coupon][:terminated_at]).to be_nil end diff --git a/spec/requests/api/v1/coupons_controller_spec.rb b/spec/requests/api/v1/coupons_controller_spec.rb index 57d9df3cbc7..40b8f04e845 100644 --- a/spec/requests/api/v1/coupons_controller_spec.rb +++ b/spec/requests/api/v1/coupons_controller_spec.rb @@ -39,23 +39,6 @@ expect(json[:coupon][:limited_billable_metrics]).to eq(true) expect(json[:coupon][:billable_metric_codes].first).to eq(billable_metric.code) end - - context 'with expiration date input' do - before do - create_params.except!(:expiration_at) - create_params[:expiration_date] = expiration_at.to_date - end - - it 'creates a coupon' do - post_with_token(organization, '/api/v1/coupons', {coupon: create_params}) - - expect(response).to have_http_status(:success) - expect(json[:coupon][:lago_id]).to be_present - expect(json[:coupon][:code]).to eq(create_params[:code]) - expect(json[:coupon][:name]).to eq(create_params[:name]) - expect(json[:coupon][:expiration_at]).to eq(expiration_at.end_of_day.iso8601) - end - end end describe 'update' do @@ -88,26 +71,6 @@ expect(json[:coupon][:expiration_at]).to eq(expiration_at.iso8601) end - context 'with expiration date input' do - before do - update_params.except!(:expiration_at) - update_params[:expiration_date] = expiration_at.to_date - end - - it 'creates a coupon' do - put_with_token( - organization, - "/api/v1/coupons/#{coupon.code}", - {coupon: update_params} - ) - - expect(response).to have_http_status(:success) - expect(json[:coupon][:lago_id]).to eq(coupon.id) - expect(json[:coupon][:code]).to eq(update_params[:code]) - expect(json[:coupon][:expiration_at]).to eq(expiration_at.end_of_day.iso8601) - end - end - context 'when coupon does not exist' do it 'returns not_found error' do put_with_token(organization, '/api/v1/coupons/invalid', {coupon: update_params}) diff --git a/spec/requests/api/v1/credit_notes_controller_spec.rb b/spec/requests/api/v1/credit_notes_controller_spec.rb index fdbb562bcbe..06c467026f2 100644 --- a/spec/requests/api/v1/credit_notes_controller_spec.rb +++ b/spec/requests/api/v1/credit_notes_controller_spec.rb @@ -38,12 +38,10 @@ invoice_number: invoice.number, credit_status: credit_note.credit_status, reason: credit_note.reason, + currency: credit_note.currency, total_amount_cents: credit_note.total_amount_cents, - total_amount_currency: credit_note.total_amount_currency, credit_amount_cents: credit_note.credit_amount_cents, - credit_amount_currency: credit_note.credit_amount_currency, balance_amount_cents: credit_note.balance_amount_cents, - balance_amount_currency: credit_note.balance_amount_currency, created_at: credit_note.created_at.iso8601, updated_at: credit_note.updated_at.iso8601, applied_taxes: [] @@ -276,14 +274,11 @@ refund_status: 'pending', reason: 'duplicated_charge', description: 'Duplicated charge', + currency: 'EUR', total_amount_cents: 15, - total_amount_currency: 'EUR', credit_amount_cents: 10, - credit_amount_currency: 'EUR', balance_amount_cents: 10, - balance_amount_currency: 'EUR', refund_amount_cents: 5, - refund_amount_currency: 'EUR', applied_taxes: [] ) diff --git a/spec/requests/api/v1/customers/usage_controller_spec.rb b/spec/requests/api/v1/customers/usage_controller_spec.rb index 82903ced04c..be8544e954d 100644 --- a/spec/requests/api/v1/customers/usage_controller_spec.rb +++ b/spec/requests/api/v1/customers/usage_controller_spec.rb @@ -70,15 +70,12 @@ aggregate_failures do expect(response).to have_http_status(:success) - expect(json[:customer_usage][:from_date]).to eq(Time.zone.today.beginning_of_month.iso8601) - expect(json[:customer_usage][:to_date]).to eq(Time.zone.today.end_of_month.iso8601) + expect(json[:customer_usage][:from_datetime]).to eq(Time.zone.today.beginning_of_month.beginning_of_day.iso8601) + expect(json[:customer_usage][:to_datetime]).to eq(Time.zone.today.end_of_month.end_of_day.iso8601) expect(json[:customer_usage][:issuing_date]).to eq(Time.zone.today.end_of_month.iso8601) expect(json[:customer_usage][:amount_cents]).to eq(5) - expect(json[:customer_usage][:amount_currency]).to eq('EUR') + expect(json[:customer_usage][:currency]).to eq('EUR') expect(json[:customer_usage][:total_amount_cents]).to eq(6) - expect(json[:customer_usage][:total_amount_currency]).to eq('EUR') - expect(json[:customer_usage][:vat_amount_cents]).to eq(1) - expect(json[:customer_usage][:vat_amount_currency]).to eq('EUR') charge_usage = json[:customer_usage][:charges_usage].first expect(charge_usage[:billable_metric][:name]).to eq(metric.name) diff --git a/spec/requests/api/v1/customers_controller_spec.rb b/spec/requests/api/v1/customers_controller_spec.rb index 3600796df83..bb2c7fe521d 100644 --- a/spec/requests/api/v1/customers_controller_spec.rb +++ b/spec/requests/api/v1/customers_controller_spec.rb @@ -65,7 +65,6 @@ payment_provider: 'stripe', payment_provider_code: stripe_provider.code, provider_customer_id: 'stripe_id', - vat_rate: 20, document_locale: 'fr', provider_payment_methods: } @@ -98,7 +97,6 @@ expect(billing[:payment_provider_code]).to eq(stripe_provider.code) expect(billing[:provider_customer_id]).to eq('stripe_id') expect(billing[:invoice_grace_period]).to eq(3) - expect(billing[:vat_rate]).to eq(20) expect(billing[:document_locale]).to eq('fr') expect(billing[:provider_payment_methods]).to eq(%w[card]) end @@ -121,7 +119,6 @@ expect(billing[:payment_provider_code]).to eq(stripe_provider.code) expect(billing[:provider_customer_id]).to eq('stripe_id') expect(billing[:invoice_grace_period]).to eq(3) - expect(billing[:vat_rate]).to eq(20) expect(billing[:document_locale]).to eq('fr') expect(billing[:provider_payment_methods]).to eq(%w[card sepa_debit]) end @@ -144,7 +141,6 @@ expect(billing[:payment_provider_code]).to eq(stripe_provider.code) expect(billing[:provider_customer_id]).to eq('stripe_id') expect(billing[:invoice_grace_period]).to eq(3) - expect(billing[:vat_rate]).to eq(20) expect(billing[:document_locale]).to eq('fr') expect(billing[:provider_payment_methods]).to eq(%w[card]) end @@ -167,7 +163,6 @@ expect(billing[:payment_provider_code]).to eq(stripe_provider.code) expect(billing[:provider_customer_id]).to eq('stripe_id') expect(billing[:invoice_grace_period]).to eq(3) - expect(billing[:vat_rate]).to eq(20) expect(billing[:document_locale]).to eq('fr') expect(billing[:provider_payment_methods]).to eq(%w[sepa_debit]) end diff --git a/spec/requests/api/v1/events_controller_spec.rb b/spec/requests/api/v1/events_controller_spec.rb index 86302fb64ab..ff47108e22b 100644 --- a/spec/requests/api/v1/events_controller_spec.rb +++ b/spec/requests/api/v1/events_controller_spec.rb @@ -160,8 +160,6 @@ expect(fee[:pay_in_advance]).to eq(true) expect(fee[:amount_cents]).to be_an(Integer) expect(fee[:amount_currency]).to eq('EUR') - expect(fee[:vat_amount_cents]).to be_an(Integer) - expect(fee[:vat_amount_currency]).to eq('EUR') expect(fee[:units]).to eq('1.0') expect(fee[:events_count]).to eq(1) end diff --git a/spec/requests/api/v1/fees_controller_spec.rb b/spec/requests/api/v1/fees_controller_spec.rb index 7dc6d585694..02ef6d6fcfd 100644 --- a/spec/requests/api/v1/fees_controller_spec.rb +++ b/spec/requests/api/v1/fees_controller_spec.rb @@ -18,7 +18,6 @@ expect(json[:fee]).to include( lago_id: fee.id, - lago_group_id: fee.group_id, amount_cents: fee.amount_cents, amount_currency: fee.amount_currency, taxes_amount_cents: fee.taxes_amount_cents, @@ -46,7 +45,6 @@ expect(json[:fee]).to include( lago_id: fee.id, - lago_group_id: fee.group_id, amount_cents: fee.amount_cents, amount_currency: fee.amount_currency, taxes_amount_cents: fee.taxes_amount_cents, @@ -100,11 +98,9 @@ expect(json[:fee]).to include( lago_id: fee.reload.id, - lago_group_id: fee.group_id, amount_cents: fee.amount_cents, amount_currency: fee.amount_currency, taxes_amount_cents: fee.taxes_amount_cents, - vat_amount_cents: fee.taxes_amount_cents, units: fee.units.to_s, events_count: fee.events_count, payment_status: fee.payment_status, diff --git a/spec/requests/api/v1/invoices_controller_spec.rb b/spec/requests/api/v1/invoices_controller_spec.rb index ec9fac3c474..3c65db2faa2 100644 --- a/spec/requests/api/v1/invoices_controller_spec.rb +++ b/spec/requests/api/v1/invoices_controller_spec.rb @@ -43,7 +43,7 @@ lago_id: String, issuing_date: Time.current.to_date.to_s, invoice_type: 'one_off', - amount_cents: 2800, + fees_amount_cents: 2800, taxes_amount_cents: 560, total_amount_cents: 3360, currency: 'EUR' diff --git a/spec/requests/api/v1/organizations_controller_spec.rb b/spec/requests/api/v1/organizations_controller_spec.rb index 6878cd34613..34468d23335 100644 --- a/spec/requests/api/v1/organizations_controller_spec.rb +++ b/spec/requests/api/v1/organizations_controller_spec.rb @@ -26,7 +26,6 @@ billing_configuration: { invoice_footer: 'footer', invoice_grace_period: 3, - vat_rate: 20, document_locale: 'fr' } } @@ -46,7 +45,6 @@ expect(json[:organization][:default_currency]).to eq('EUR') expect(json[:organization][:webhook_url]).to eq(webhook_url) expect(json[:organization][:webhook_urls]).to eq([webhook_url]) - expect(json[:organization][:vat_rate]).to eq(update_params[:vat_rate]) expect(json[:organization][:document_numbering]).to eq('per_customer') expect(json[:organization][:document_number_prefix]).to eq('ORG-2') # TODO(:timezone): Timezone update is turned off for now @@ -55,7 +53,6 @@ billing = json[:organization][:billing_configuration] expect(billing[:invoice_footer]).to eq('footer') expect(billing[:document_locale]).to eq('fr') - expect(billing[:vat_rate]).to eq(20) expect(json[:organization][:taxes]).not_to be_nil end diff --git a/spec/requests/api/v1/subscriptions_controller_spec.rb b/spec/requests/api/v1/subscriptions_controller_spec.rb index 74b4063a2b7..c88f910b228 100644 --- a/spec/requests/api/v1/subscriptions_controller_spec.rb +++ b/spec/requests/api/v1/subscriptions_controller_spec.rb @@ -138,7 +138,7 @@ name: 'subscription name', external_id: SecureRandom.uuid, billing_time: 'anniversary', - subscription_date: subscription_at.to_date + subscription_at: subscription_at } end @@ -156,8 +156,7 @@ expect(json[:subscription][:name]).to eq('subscription name') expect(json[:subscription][:started_at]).to be_present expect(json[:subscription][:billing_time]).to eq('anniversary') - expect(json[:subscription][:subscription_at]).to eq(Time.current.beginning_of_day.iso8601) - expect(json[:subscription][:subscription_date].to_s).to eq(Time.current.to_date.to_s) + expect(json[:subscription][:subscription_at]).to eq(Time.zone.parse(subscription_at).iso8601) expect(json[:subscription][:previous_plan_code]).to be_nil expect(json[:subscription][:next_plan_code]).to be_nil expect(json[:subscription][:downgrade_plan_date]).to be_nil diff --git a/spec/requests/api/v1/wallets_controller_spec.rb b/spec/requests/api/v1/wallets_controller_spec.rb index e433f1ff1a0..57f73f08305 100644 --- a/spec/requests/api/v1/wallets_controller_spec.rb +++ b/spec/requests/api/v1/wallets_controller_spec.rb @@ -36,26 +36,6 @@ end end - context 'with expiration date' do - before do - create_params.except!(:expiration_at) - create_params[:expiration_date] = expiration_at.to_date - end - - it 'creates a wallet' do - post_with_token(organization, '/api/v1/wallets', {wallet: create_params}) - - aggregate_failures do - expect(response).to have_http_status(:success) - - expect(json[:wallet][:lago_id]).to be_present - expect(json[:wallet][:name]).to eq(create_params[:name]) - expect(json[:wallet][:external_customer_id]).to eq(customer.external_id) - expect(json[:wallet][:expiration_at]).to eq((Time.current + 1.year).end_of_day.iso8601) - end - end - end - context 'with recurring transaction rules' do around { |test| lago_premium!(&test) } @@ -124,29 +104,6 @@ end end - context 'with expiration date' do - before do - update_params.except!(:expiration_at) - update_params[:expiration_date] = expiration_at.to_date - end - - it 'updates a wallet' do - put_with_token( - organization, - "/api/v1/wallets/#{wallet.id}", - {wallet: update_params} - ) - - aggregate_failures do - expect(response).to have_http_status(:success) - - expect(json[:wallet][:lago_id]).to eq(wallet.id) - expect(json[:wallet][:name]).to eq(update_params[:name]) - expect(json[:wallet][:expiration_at]).to eq((Time.current + 1.year).end_of_day.iso8601) - end - end - end - context 'when wallet does not exist' do it 'returns not_found error' do put_with_token(organization, '/api/v1/wallets/invalid', {wallet: update_params}) diff --git a/spec/serializers/v1/applied_coupon_serializer_spec.rb b/spec/serializers/v1/applied_coupon_serializer_spec.rb index a3eafe6a8d4..229e9ffd341 100644 --- a/spec/serializers/v1/applied_coupon_serializer_spec.rb +++ b/spec/serializers/v1/applied_coupon_serializer_spec.rb @@ -38,7 +38,6 @@ expect(result['applied_coupon']['credits'].first['lago_id']).to eq(credit.id) expect(result['applied_coupon']['credits'].first['amount_cents']).to eq(credit.amount_cents) expect(result['applied_coupon']['credits'].first['amount_currency']).to eq(credit.amount_currency) - expect(result['applied_coupon']['credits'].first['item']['lago_id']).to eq(credit.item_id) expect(result['applied_coupon']['credits'].first['item']['type']).to eq(credit.item_type) expect(result['applied_coupon']['credits'].first['item']['code']).to eq(credit.item_code) expect(result['applied_coupon']['credits'].first['item']['name']).to eq(credit.item_name) diff --git a/spec/serializers/v1/coupon_serializer_spec.rb b/spec/serializers/v1/coupon_serializer_spec.rb index a1a37b0f62d..6fe39c5f204 100644 --- a/spec/serializers/v1/coupon_serializer_spec.rb +++ b/spec/serializers/v1/coupon_serializer_spec.rb @@ -30,10 +30,4 @@ expect(result['coupon']['billable_metric_codes']).to eq([]) end end - - it 'serializes the legacy fields' do - result = JSON.parse(serializer.to_json) - - expect(result['coupon']['expiration_date']).to eq(coupon.expiration_at&.to_date&.iso8601) - end end diff --git a/spec/serializers/v1/credit_note_serializer_spec.rb b/spec/serializers/v1/credit_note_serializer_spec.rb index 3616a19f9bd..3b91d688aa6 100644 --- a/spec/serializers/v1/credit_note_serializer_spec.rb +++ b/spec/serializers/v1/credit_note_serializer_spec.rb @@ -35,17 +35,7 @@ 'coupons_adjustment_amount_cents' => credit_note.coupons_adjustment_amount_cents, 'created_at' => credit_note.created_at.iso8601, 'updated_at' => credit_note.updated_at.iso8601, - 'file_url' => credit_note.file_url, - - # NOTE: deprecated fields - 'total_amount_currency' => credit_note.total_amount_currency, - 'vat_amount_currency' => credit_note.currency, - 'sub_total_vat_excluded_amount_currency' => credit_note.currency, - 'balance_amount_currency' => credit_note.balance_amount_currency, - 'credit_amount_currency' => credit_note.credit_amount_currency, - 'refund_amount_currency' => credit_note.refund_amount_currency, - 'vat_amount_cents' => credit_note.taxes_amount_cents, - 'sub_total_vat_excluded_amount_cents' => credit_note.sub_total_excluding_taxes_amount_cents + 'file_url' => credit_note.file_url ) expect(result['credit_note'].keys).to include('customer', 'items') diff --git a/spec/serializers/v1/credit_serializer_spec.rb b/spec/serializers/v1/credit_serializer_spec.rb index 70f4a9c27a0..0727304f320 100644 --- a/spec/serializers/v1/credit_serializer_spec.rb +++ b/spec/serializers/v1/credit_serializer_spec.rb @@ -21,10 +21,6 @@ expect(result['credit']['item']['name']).to eq(credit.item_name) expect(result['credit']['invoice']['payment_status']).to eq(credit.invoice.payment_status) expect(result['credit']['invoice']['lago_id']).to eq(credit.invoice.id) - - # NOTE: legacy fields - expect(result['credit']['before_vat']).to eq(false) - expect(result['credit']['item']['lago_id']).to eq(credit.item_id) end end end diff --git a/spec/serializers/v1/customer_serializer_spec.rb b/spec/serializers/v1/customer_serializer_spec.rb index 862cac8e7d0..a81882a1321 100644 --- a/spec/serializers/v1/customer_serializer_spec.rb +++ b/spec/serializers/v1/customer_serializer_spec.rb @@ -48,7 +48,6 @@ expect(result['customer']['billing_configuration']['payment_provider']).to eq(customer.payment_provider) expect(result['customer']['billing_configuration']['payment_provider_code']).to eq(customer.payment_provider_code) expect(result['customer']['billing_configuration']['invoice_grace_period']).to eq(customer.invoice_grace_period) - expect(result['customer']['billing_configuration']['vat_rate']).to eq(customer.vat_rate) expect(result['customer']['billing_configuration']['document_locale']).to eq(customer.document_locale) expect(result['customer']['shipping_address']['address_line1']).to eq('test1') expect(result['customer']['shipping_address']['city']).to eq('Paris') diff --git a/spec/serializers/v1/customers/usage_serializer_spec.rb b/spec/serializers/v1/customers/usage_serializer_spec.rb index 1d4d4339c7a..4054b541ebf 100644 --- a/spec/serializers/v1/customers/usage_serializer_spec.rb +++ b/spec/serializers/v1/customers/usage_serializer_spec.rb @@ -45,11 +45,7 @@ expect(result['customer_usage']['currency']).to eq('EUR') expect(result['customer_usage']['taxes_amount_cents']).to eq(1) expect(result['customer_usage']['amount_cents']).to eq(5) - expect(result['customer_usage']['amount_currency']).to eq('EUR') expect(result['customer_usage']['total_amount_cents']).to eq(6) - expect(result['customer_usage']['total_amount_currency']).to eq('EUR') - expect(result['customer_usage']['vat_amount_cents']).to eq(1) - expect(result['customer_usage']['vat_amount_currency']).to eq('EUR') charge_usage = result['customer_usage']['charges_usage'].first expect(charge_usage['billable_metric']['name']).to eq('Charge') @@ -62,11 +58,4 @@ expect(charge_usage['groups']).to eq([]) end end - - it 'serializes the legacy value' do - aggregate_failures do - expect(result['customer_usage']['from_date']).to eq(Time.current.beginning_of_month.to_date.iso8601) - expect(result['customer_usage']['to_date']).to eq(Time.current.end_of_month.to_date.iso8601) - end - end end diff --git a/spec/serializers/v1/event_error_serializer_spec.rb b/spec/serializers/v1/event_error_serializer_spec.rb index 020c0531e4a..d2711dcdfb3 100644 --- a/spec/serializers/v1/event_error_serializer_spec.rb +++ b/spec/serializers/v1/event_error_serializer_spec.rb @@ -34,16 +34,6 @@ 'external_subscription_id' => event_error.event.external_subscription_id, 'created_at' => event_error.event.created_at.iso8601 ) - - # NOTE: legacy values - expect(result['event_error']['input_params']).to include( - 'transaction_id' => event_error.event.transaction_id, - 'external_subscription_id' => event_error.event.external_subscription_id, - 'external_customer_id' => event_error.event.external_customer_id, - 'timestamp' => event_error.event.timestamp.to_f, - 'code' => event_error.event.code, - 'properties' => event_error.event.properties - ) end end end diff --git a/spec/serializers/v1/fee_serializer_spec.rb b/spec/serializers/v1/fee_serializer_spec.rb index 98768a905ab..d71e48ed50f 100644 --- a/spec/serializers/v1/fee_serializer_spec.rb +++ b/spec/serializers/v1/fee_serializer_spec.rb @@ -22,7 +22,6 @@ aggregate_failures do expect(result['fee']).to include( 'lago_id' => fee.id, - 'lago_group_id' => fee.group_id, 'lago_charge_filter_id' => fee.charge_filter_id, 'lago_invoice_id' => fee.invoice_id, 'lago_true_up_fee_id' => fee.true_up_fee&.id, @@ -35,11 +34,9 @@ 'amount_currency' => fee.amount_currency, 'taxes_amount_cents' => fee.taxes_amount_cents, 'taxes_rate' => fee.taxes_rate, - 'vat_amount_cents' => fee.taxes_amount_cents, 'total_amount_cents' => fee.total_amount_cents, 'total_amount_currency' => fee.amount_currency, 'units' => fee.units.to_s, - 'unit_amount_cents' => fee.unit_amount_cents, 'precise_unit_amount' => fee.precise_unit_amount.to_s, 'pay_in_advance' => fee.subscription.plan.pay_in_advance, 'invoiceable' => true, @@ -137,7 +134,7 @@ 'code' => fee.item_code, 'name' => fee.item_name, 'invoice_display_name' => fee.invoice_name, - 'group_invoice_display_name' => fee.filter_display_name, + 'filter_invoice_display_name' => fee.filter_display_name, 'lago_item_id' => fee.item_id, 'item_type' => fee.item_type ) diff --git a/spec/serializers/v1/invoice_serializer_spec.rb b/spec/serializers/v1/invoice_serializer_spec.rb index 563779fc637..d3ec5fc3609 100644 --- a/spec/serializers/v1/invoice_serializer_spec.rb +++ b/spec/serializers/v1/invoice_serializer_spec.rb @@ -36,19 +36,7 @@ 'sub_total_including_taxes_amount_cents' => invoice.sub_total_including_taxes_amount_cents, 'total_amount_cents' => invoice.total_amount_cents, 'file_url' => invoice.file_url, - 'version_number' => 4, - - # NOTE: deprecated fields - 'legacy' => false, - 'amount_currency' => invoice.currency, - 'vat_amount_currency' => invoice.currency, - 'credit_amount_currency' => invoice.currency, - 'total_amount_currency' => invoice.currency, - 'amount_cents' => invoice.fees.sum(:amount_cents), - 'credit_amount_cents' => invoice.credits.sum(:amount_cents), - 'vat_amount_cents' => invoice.taxes_amount_cents, - 'sub_total_vat_excluded_amount_cents' => invoice.sub_total_excluding_taxes_amount_cents, - 'sub_total_vat_included_amount_cents' => invoice.sub_total_including_taxes_amount_cents + 'version_number' => 4 ) expect(result['invoice']['metadata'].first).to include( diff --git a/spec/serializers/v1/organization_serializer_spec.rb b/spec/serializers/v1/organization_serializer_spec.rb index 013a3701576..588a891e8a1 100644 --- a/spec/serializers/v1/organization_serializer_spec.rb +++ b/spec/serializers/v1/organization_serializer_spec.rb @@ -33,7 +33,6 @@ expect(result['organization']['legal_number']).to eq(org.legal_number) expect(result['organization']['billing_configuration']['invoice_footer']).to eq(org.invoice_footer) expect(result['organization']['billing_configuration']['invoice_grace_period']).to eq(org.invoice_grace_period) - expect(result['organization']['billing_configuration']['vat_rate']).to eq(org.vat_rate) expect(result['organization']['billing_configuration']['document_locale']).to eq(org.document_locale) expect(result['organization']['tax_identification_number']).to eq(org.tax_identification_number) expect(result['organization']['timezone']).to eq(org.timezone) diff --git a/spec/serializers/v1/wallet_serializer_spec.rb b/spec/serializers/v1/wallet_serializer_spec.rb index 8daf28a384e..1a6e8f6cf5a 100644 --- a/spec/serializers/v1/wallet_serializer_spec.rb +++ b/spec/serializers/v1/wallet_serializer_spec.rb @@ -32,11 +32,6 @@ 'ongoing_usage_balance_cents' => wallet.ongoing_usage_balance_cents, 'consumed_credits' => wallet.consumed_credits.to_s ) - - # NOTE: legacy values - expect(result['wallet']).to include( - 'balance' => wallet.balance.to_s - ) end end end diff --git a/spec/services/coupons/create_service_spec.rb b/spec/services/coupons/create_service_spec.rb index a764446e918..314a1706804 100644 --- a/spec/services/coupons/create_service_spec.rb +++ b/spec/services/coupons/create_service_spec.rb @@ -72,7 +72,7 @@ frequency: 'once', percentage_rate: 20.00, expiration: 'time_limit', - expiration_date: (Time.current + 3.days).to_date + expiration_at: (Time.current + 3.days).iso8601 } end diff --git a/spec/services/credit_notes/create_from_termination_spec.rb b/spec/services/credit_notes/create_from_termination_spec.rb index 089524fd011..4681c7ac8cf 100644 --- a/spec/services/credit_notes/create_from_termination_spec.rb +++ b/spec/services/credit_notes/create_from_termination_spec.rb @@ -374,8 +374,6 @@ ) end - before { organization.vat_rate = 0 } - it 'creates a credit note' do travel_to(terminated_at) do result = create_service.call diff --git a/spec/services/customers/create_service_spec.rb b/spec/services/customers/create_service_spec.rb index 953c61bcfbd..7b4ad8480aa 100644 --- a/spec/services/customers/create_service_spec.rb +++ b/spec/services/customers/create_service_spec.rb @@ -18,7 +18,6 @@ currency: 'EUR', tax_identification_number: '123456789', billing_configuration: { - vat_rate: 20, document_locale: 'fr' }, shipping_address: { @@ -52,7 +51,6 @@ expect(customer.timezone).to be_nil billing = create_args[:billing_configuration] - expect(customer.vat_rate).to eq(billing[:vat_rate]) expect(customer.document_locale).to eq(billing[:document_locale]) expect(customer.invoice_grace_period).to be_nil @@ -83,7 +81,6 @@ name: create_args[:name], currency: create_args[:currency], timezone: nil, - vat_rate: billing[:vat_rate], document_locale: billing[:document_locale], invoice_grace_period: nil ) @@ -129,7 +126,6 @@ name: 'Foo Bar', currency: 'EUR', billing_configuration: { - vat_rate: 20, document_locale: 'fr' }, metadata: [ @@ -256,7 +252,6 @@ expect(result.customer).to eq(customer) expect(result.customer.name).to eq(create_args[:name]) expect(result.customer.external_id).to eq(create_args[:external_id]) - expect(result.customer.vat_rate).to eq(create_args[:billing_configuration][:vat_rate]) expect(result.customer.document_locale).to eq(create_args[:billing_configuration][:document_locale]) end end @@ -271,7 +266,6 @@ name: 'Foo Bar', currency: 'EUR', billing_configuration: { - vat_rate: 20, document_locale: 'fr' }, metadata: [ @@ -317,7 +311,6 @@ name: 'Foo Bar', currency: 'EUR', billing_configuration: { - vat_rate: 20, document_locale: 'fr' }, metadata: [ @@ -378,7 +371,6 @@ name: 'Foo Bar', currency: 'EUR', billing_configuration: { - vat_rate: 20, document_locale: 'fr' }, integration_customers: @@ -582,7 +574,6 @@ external_id: SecureRandom.uuid, name: 'Foo Bar', billing_configuration: { - vat_rate: 28, payment_provider:, payment_provider_code:, provider_customer_id: 'stripe_id' @@ -613,7 +604,6 @@ expect(result.customer).to eq(customer) # NOTE: It should not erase exsting properties - expect(result.customer.vat_rate).to eq(28) expect(result.customer.payment_provider).to eq('stripe') expect(result.customer.stripe_customer).to be_present @@ -637,7 +627,6 @@ expect(result.customer).to eq(customer) # NOTE: It should not erase existing properties - expect(result.customer.vat_rate).to eq(28) expect(result.customer.payment_provider).to eq(nil) expect(result.customer.stripe_customer).not_to be_present expect(result.customer.gocardless_customer).not_to be_present @@ -651,7 +640,6 @@ external_id: SecureRandom.uuid, name: 'Foo Bar', billing_configuration: { - vat_rate: 28, sync_with_provider: true } } @@ -668,7 +656,6 @@ expect(result.customer).to eq(customer) # NOTE: It should not erase existing properties - expect(result.customer.vat_rate).to eq(28) expect(result.customer.payment_provider).to eq(nil) expect(result.customer.stripe_customer).not_to be_present end @@ -807,96 +794,6 @@ end end - context 'with legacy vat_rate' do - let(:vat_rate) { 12.5 } - let(:params) do - { - external_id:, - name: 'Foo Bar', - currency: 'EUR', - billing_configuration: { - vat_rate:, - document_locale: 'fr' - } - } - end - - it 'assigns the vat_rate and creates a tax' do - result = customers_service.create_from_api(organization:, params:) - - aggregate_failures do - expect(result.customer.vat_rate).to eq(vat_rate) - expect(result.customer.taxes.count).to eq(1) - - tax = result.customer.taxes.first - expect(tax.rate).to eq(vat_rate) - end - end - - context 'when customer has multiple taxes' do - let(:customer) { create(:customer, organization:, external_id:) } - - before do - first_tax = create(:tax, organization:, rate: 14) - second_tax = create(:tax, organization:, rate: 15) - create(:customer_applied_tax, customer:, tax: first_tax) - create(:customer_applied_tax, customer:, tax: second_tax) - end - - it 'raises a validation error' do - result = customers_service.create_from_api(organization:, params:) - - aggregate_failures do - expect(result).not_to be_success - expect(result.error).to be_a(BaseService::ValidationFailure) - expect(result.error.messages[:vat_rate]).to eq(['multiple_taxes']) - end - end - end - - context 'when customer already has a tax' do - let(:customer) { create(:customer, organization:, external_id:) } - - before do - tax = create(:tax, organization:, rate: 14) - create(:customer_applied_tax, customer:, tax:) - end - - it 'creates a new tax' do - result = customers_service.create_from_api(organization:, params:) - - aggregate_failures do - expect(result.customer.vat_rate).to eq(vat_rate) - expect(result.customer.organization.taxes.count).to eq(2) - expect(result.customer.reload.taxes.count).to eq(1) - end - end - end - - context 'when tax exists but is not applied yet to the customer' do - let(:customer) { create(:customer, organization:, external_id:) } - let(:vat_rate) { 20 } - - before do - create(:tax, organization:, rate: 10, code: 'tax_10') - initial_tax = create(:tax, organization:, rate: 15, code: 'tax_15') - create(:tax, organization:, rate: 20, code: 'tax_20') - - create(:customer_applied_tax, customer:, tax: initial_tax) - end - - it 'updates the customer\'s tax' do - result = customers_service.create_from_api(organization:, params:) - - aggregate_failures do - expect(result.customer.vat_rate).to eq(vat_rate) - expect(result.customer.taxes.count).to eq(1) - expect(result.customer.taxes.first.code).to eq('tax_20') - end - end - end - end - context 'when organization has eu tax management' do let(:eu_auto_tax_service) { instance_double(Customers::EuAutoTaxesService) } diff --git a/spec/services/customers/update_service_spec.rb b/spec/services/customers/update_service_spec.rb index b926cb10445..47c15977ec7 100644 --- a/spec/services/customers/update_service_spec.rb +++ b/spec/services/customers/update_service_spec.rb @@ -23,9 +23,6 @@ tax_identification_number: '2246', net_payment_term: 8, external_id:, - billing_configuration: { - vat_rate: 20 - }, shipping_address: { city: 'Paris' } @@ -40,9 +37,6 @@ expect(updated_customer.name).to eq('Updated customer name') expect(updated_customer.tax_identification_number).to eq('2246') - billing = update_args[:billing_configuration] - expect(updated_customer.vat_rate).to eq(billing[:vat_rate]) - shipping_address = update_args[:shipping_address] expect(updated_customer.shipping_city).to eq(shipping_address[:city]) end @@ -74,24 +68,6 @@ end end - context 'without billing configuration namespace' do - let(:update_args) do - { - id: customer.id, - name: 'Updated customer name', - external_id:, - invoice_grace_period: 3, - vat_rate: 20 - } - end - - it 'updates billing information' do - result = customers_service.update(**update_args) - - expect(result.customer.vat_rate).to eq(update_args[:vat_rate]) - end - end - context 'with metadata' do let(:customer_metadata) { create(:customer_metadata, customer:) } let(:another_customer_metadata) { create(:customer_metadata, customer:, key: 'test', value: '1') } diff --git a/spec/services/organizations/update_service_spec.rb b/spec/services/organizations/update_service_spec.rb index e2c73759852..bfb6247851e 100644 --- a/spec/services/organizations/update_service_spec.rb +++ b/spec/services/organizations/update_service_spec.rb @@ -161,96 +161,6 @@ end end - context 'with legacy vat_rate' do - let(:vat_rate) { 12.5 } - let(:params) do - { - webhook_url: 'http://foo.bar', - legal_name: 'Foobar', - legal_number: '1234', - email: 'foo@bar.com', - address_line1: 'Line 1', - address_line2: 'Line 2', - state: 'Foobar', - zipcode: 'FOO1234', - city: 'Foobar', - country:, - timezone:, - logo:, - email_settings:, - billing_configuration: { - vat_rate:, - invoice_footer: 'invoice footer', - document_locale: 'fr', - invoice_grace_period: - } - } - end - - it 'assigns the vat_rate and creates a tax_rate' do - result = update_service.call - - aggregate_failures do - expect(result.organization.vat_rate).to eq(12.5) - - expect(result.organization.taxes.count).to eq(1) - - tax_rate = result.organization.taxes.first - expect(tax_rate.rate).to eq(12.5) - end - end - - context 'when organization already have a tax rate' do - before { create(:tax, organization:, rate: 14) } - - it 'create a new tax_rate' do - result = update_service.call - - aggregate_failures do - expect(result.organization.vat_rate).to eq(12.5) - - expect(result.organization.taxes.count).to eq(2) - expect(result.organization.taxes.applied_to_organization.count).to eq(1) - - tax_rate = result.organization.taxes.applied_to_organization.first - expect(tax_rate.rate).to eq(12.5) - end - end - - context 'with vat_rate equals to 0' do - let(:vat_rate) { 0 } - - it 'toggle the applied_to_organization flag' do - result = update_service.call - - aggregate_failures do - expect(result.organization.vat_rate).to eq(0) - - expect(result.organization.taxes.count).to eq(1) - expect(result.organization.taxes.applied_to_organization.count).to eq(0) - end - end - end - end - - context 'when organization have multiple tax rates' do - before do - create(:tax, organization:, rate: 14) - create(:tax, organization:, rate: 15) - end - - it 'raises a validation error' do - result = update_service.call - - aggregate_failures do - expect(result).not_to be_success - expect(result.error).to be_a(BaseService::ValidationFailure) - expect(result.error.messages[:vat_rate]).to eq(['multiple_taxes']) - end - end - end - end - context 'with eu tax management' do context 'with org within the EU' do let(:params) { {eu_tax_management: true, country: 'fr'} } diff --git a/spec/services/webhooks/invoices/generated_service_spec.rb b/spec/services/webhooks/invoices/generated_service_spec.rb index 26527926494..e704ed5bcbe 100644 --- a/spec/services/webhooks/invoices/generated_service_spec.rb +++ b/spec/services/webhooks/invoices/generated_service_spec.rb @@ -11,6 +11,6 @@ let(:organization) { create(:organization) } describe '.call' do - it_behaves_like 'creates webhook', 'invoice.generated', 'invoice', {'amount_cents' => Integer} + it_behaves_like 'creates webhook', 'invoice.generated', 'invoice', {'fees_amount_cents' => Integer} end end