Skip to content

Commit

Permalink
misc: Remove deprecated API fields (#2261)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
vincent-pochet authored Jul 15, 2024
1 parent e5460f1 commit feb86e5
Show file tree
Hide file tree
Showing 71 changed files with 36 additions and 829 deletions.
12 changes: 2 additions & 10 deletions app/controllers/api/v1/coupons_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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?
Expand Down Expand Up @@ -89,8 +83,6 @@ def input_params
:frequency_duration,
:expiration,
:expiration_at,
# NOTE: Legacy field
:expiration_date,
:reusable,
applies_to: [
plan_codes: [],
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/api/v1/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/api/v1/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions app/controllers/api/v1/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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?
Expand Down
16 changes: 4 additions & 12 deletions app/controllers/api/v1/wallets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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?
Expand Down Expand Up @@ -86,7 +80,6 @@ def input_params
:paid_credits,
:granted_credits,
:expiration_at,
:expiration_date, # NOTE: Legacy field
recurring_transaction_rules: [
:granted_credits,
:interval,
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion app/graphql/types/organizations/base_organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion app/graphql/types/organizations/billing_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 0 additions & 12 deletions app/legacy_inputs/coupon_legacy_input.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/legacy_inputs/subscription_legacy_input.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/legacy_inputs/wallet_legacy_input.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions app/serializers/v1/applied_coupon_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 1 addition & 9 deletions app/serializers/v1/coupon_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions app/serializers/v1/credit_note_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
8 changes: 1 addition & 7 deletions app/serializers/v1/credit_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 2 additions & 7 deletions app/serializers/v1/customer_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions app/serializers/v1/customers/usage_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
7 changes: 0 additions & 7 deletions app/serializers/v1/event_error_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions app/serializers/v1/fee_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions app/serializers/v1/invoice_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
13 changes: 0 additions & 13 deletions app/serializers/v1/legacy/applied_coupon_serializer.rb

This file was deleted.

Loading

0 comments on commit feb86e5

Please sign in to comment.