Skip to content

Commit

Permalink
cover draft invoice number when tax error
Browse files Browse the repository at this point in the history
  • Loading branch information
lovrocolic committed Oct 11, 2024
1 parent f181636 commit 2b9ff9e
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/services/invoices/create_one_off_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def call
if tax_error?(fees_result)
invoice.fees_amount_cents = invoice.fees.sum(:amount_cents)
invoice.sub_total_excluding_taxes_amount_cents = invoice.fees_amount_cents
invoice.ensure_number
invoice.failed!

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def call
Credits::AppliedCouponsService.call(invoice:) if invoice.fees_amount_cents&.positive?

if tax_error?(fee_result)
invoice.ensure_number
invoice.failed!
invoice.fees.each { |f| SendWebhookJob.perform_later('fee.created', f) }
create_error_detail(fee_result.error.messages.dig(:tax_error)&.first)
Expand Down
1 change: 1 addition & 0 deletions app/services/invoices/progressive_billing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def call

unless taxes_result.success?
create_error_detail(taxes_result.error.code)
invoice.ensure_number
invoice.failed!

return result.service_failure!(code: 'tax_error', message: taxes_result.error.code)
Expand Down
1 change: 1 addition & 0 deletions spec/services/invoices/create_one_off_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
aggregate_failures do
expect(result).to be_success
expect(result.invoice.status).to eq('failed')
expect(result.invoice.number).to end_with '-DRAFT'
expect(result.invoice.error_details.count).to eq(1)
expect(result.invoice.error_details.first.details['tax_error']).to eq('taxDateTooFarInFuture')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
invoice = customer.invoices.order(created_at: :desc).first

expect(invoice.status).to eq('failed')
expect(invoice.number).to end_with '-DRAFT'
expect(invoice.error_details.count).to eq(1)
expect(invoice.error_details.first.details['tax_error']).to eq('taxDateTooFarInFuture')
end
Expand Down
1 change: 1 addition & 0 deletions spec/services/invoices/progressive_billing_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
invoice = customer.invoices.order(created_at: :desc).first

expect(invoice.status).to eq('failed')
expect(invoice.number).to end_with '-DRAFT'
expect(invoice.error_details.count).to eq(1)
expect(invoice.error_details.first.details['tax_error']).to eq('taxDateTooFarInFuture')
end
Expand Down
1 change: 1 addition & 0 deletions spec/services/invoices/subscription_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
invoice = customer.invoices.order(created_at: :desc).first

expect(invoice.status).to eq('failed')
expect(invoice.number).to end_with '-DRAFT'
expect(invoice.error_details.count).to eq(1)
expect(invoice.error_details.first.details['tax_error']).to eq('taxDateTooFarInFuture')
end
Expand Down

0 comments on commit 2b9ff9e

Please sign in to comment.