Skip to content

Commit a7b328b

Browse files
authored
Fix: overdue invoices should not include invoices not ready to be paid (#3315)
Together AI have an error when triggering `DunningCampaigns::ProcessAttemptJob`: `BaseService::MethodNotAllowedFailure: invoices_not_ready_for_payment_processing` this happens because when selecting overdue invoices, we do not filter invoices that are ready for payment processing. - Added filter invoices to be ready_to_be_processed when filtering invoices for dunning_campaign process_attempt
1 parent 25ba960 commit a7b328b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

app/services/dunning_campaigns/process_attempt_service.rb

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def overdue_invoices
7272
customer
7373
.invoices
7474
.payment_overdue
75+
.where(ready_for_payment_processing: true)
7576
.where(currency: dunning_campaign_threshold.currency)
7677
end
7778
end

spec/services/dunning_campaigns/process_attempt_service_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@
171171
.and raise_error(BaseService::ServiceFailure)
172172
end
173173
end
174+
175+
context "when a customer has invoices that are not ready for payment processing" do
176+
let(:invoice_5) { create :invoice, organization:, customer:, currency:, payment_overdue: true, ready_for_payment_processing: false, total_amount_cents: 99_00 }
177+
178+
before { invoice_5 }
179+
180+
it "creates payment only for ready_for_processing invoice" do
181+
expect(result.payment_request).to eq payment_request
182+
expect(PaymentRequests::CreateService).to have_received(:call)
183+
.with(organization:,
184+
params: {
185+
external_customer_id: customer.external_id,
186+
lago_invoice_ids: [invoice_2.id]
187+
},
188+
dunning_campaign:)
189+
end
190+
end
174191
end
175192

176193
it "does nothing" do

0 commit comments

Comments
 (0)