diff --git a/app/services/invoices/create_one_off_service.rb b/app/services/invoices/create_one_off_service.rb index 47e8bba88d2..447c0b820f9 100644 --- a/app/services/invoices/create_one_off_service.rb +++ b/app/services/invoices/create_one_off_service.rb @@ -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 diff --git a/app/services/invoices/create_pay_in_advance_charge_service.rb b/app/services/invoices/create_pay_in_advance_charge_service.rb index 57dae281bff..f289f6b2c1d 100644 --- a/app/services/invoices/create_pay_in_advance_charge_service.rb +++ b/app/services/invoices/create_pay_in_advance_charge_service.rb @@ -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) diff --git a/app/services/invoices/progressive_billing_service.rb b/app/services/invoices/progressive_billing_service.rb index f801cf457dc..64854f18e5f 100644 --- a/app/services/invoices/progressive_billing_service.rb +++ b/app/services/invoices/progressive_billing_service.rb @@ -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) diff --git a/spec/services/invoices/create_one_off_service_spec.rb b/spec/services/invoices/create_one_off_service_spec.rb index 339e034ae63..816644dd105 100644 --- a/spec/services/invoices/create_one_off_service_spec.rb +++ b/spec/services/invoices/create_one_off_service_spec.rb @@ -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 diff --git a/spec/services/invoices/create_pay_in_advance_charge_service_spec.rb b/spec/services/invoices/create_pay_in_advance_charge_service_spec.rb index d27b6a5d48e..86f67f5c05d 100644 --- a/spec/services/invoices/create_pay_in_advance_charge_service_spec.rb +++ b/spec/services/invoices/create_pay_in_advance_charge_service_spec.rb @@ -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 diff --git a/spec/services/invoices/progressive_billing_service_spec.rb b/spec/services/invoices/progressive_billing_service_spec.rb index 9b3095fa3b2..c779d7837d2 100644 --- a/spec/services/invoices/progressive_billing_service_spec.rb +++ b/spec/services/invoices/progressive_billing_service_spec.rb @@ -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 diff --git a/spec/services/invoices/subscription_service_spec.rb b/spec/services/invoices/subscription_service_spec.rb index 767c0f8d208..a539ecbd1c3 100644 --- a/spec/services/invoices/subscription_service_spec.rb +++ b/spec/services/invoices/subscription_service_spec.rb @@ -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