Skip to content

Commit

Permalink
add some style refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lovrocolic committed Jan 9, 2024
1 parent b153d12 commit 58d9731
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
22 changes: 7 additions & 15 deletions app/services/fees/subscription_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,13 @@ def initialize_fee(new_amount_cents)
units = adjusted_fee.units
unit_amount_cents = adjusted_fee.unit_amount_cents.round
amount_cents = adjusted_fee.adjusted_units? ? (units * new_amount_cents) : (units * unit_amount_cents)
Fee.new(
invoice:,
subscription:,
amount_cents: amount_cents.round,
amount_currency: plan.amount_currency,
fee_type: :subscription,
invoiceable_type: 'Subscription',
invoiceable: subscription,
units:,
properties: boundaries.to_h,
payment_status: :pending,
taxes_amount_cents: 0,
unit_amount_cents: adjusted_fee.adjusted_units? ? new_amount_cents : unit_amount_cents,
invoice_display_name: adjusted_fee.invoice_display_name,
)

base_fee.amount_cents = amount_cents.round
base_fee.units = units
base_fee.unit_amount_cents = adjusted_fee.adjusted_units? ? new_amount_cents : unit_amount_cents
base_fee.invoice_display_name = adjusted_fee.invoice_display_name

base_fee
end

def adjusted_fee
Expand Down
4 changes: 2 additions & 2 deletions spec/scenarios/invoices/adjusted_subscription_fees_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
around { |test| lago_premium!(&test) }

context 'with adjusted units' do
it 'creates invoice numbers correctly' do
it 'creates invoices correctly' do
# NOTE: Jul 19th: create the subscription
travel_to(subscription_at) do
create_subscription(
Expand Down Expand Up @@ -84,7 +84,7 @@
context 'with adjusted amount' do
let(:unit_amount_cents) { 15_000 }

it 'creates invoice numbers correctly' do
it 'creates invoices correctly' do
# NOTE: Jul 19th: create the subscription
travel_to(subscription_at) do
create_subscription(
Expand Down

0 comments on commit 58d9731

Please sign in to comment.