Skip to content

Commit

Permalink
feat(dunning): Dunning Campaign processing skip customers completed (#…
Browse files Browse the repository at this point in the history
…2869)

## Roadmap

👉 https://getlago.canny.io/feature-requests/p/set-up-payment-retry-logic

👉
https://getlago.canny.io/feature-requests/p/send-reminders-for-overdue-invoices

 ## Context

We want to automate dunning process so that our users don't have to look
at each customer to maximize their chances of being paid retrying
payments of overdue balances and sending email reminders.

We are extending dunning campaigns management to edit and delete
campaigns.

 ## Description

On dunning campaign execution skip customers with dunning campaign
completed flag set to true.
  • Loading branch information
ancorcruz authored Nov 26, 2024
1 parent 174dd8b commit b714613
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/services/dunning_campaigns/bulk_process_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def call

def eligible_customers
Customer
.with_dunning_campaign_not_completed
.joins(:organization)
.where(exclude_from_dunning_campaign: false)
.where("organizations.premium_integrations @> ARRAY[?]::varchar[]", ['auto_dunning'])
Expand All @@ -30,6 +31,7 @@ def initialize(customer)
end

def call
return result if customer.dunning_campaign_completed?
return result unless threshold
return result if max_attempts_reached?
return result unless days_between_attempts_satisfied?
Expand Down
11 changes: 11 additions & 0 deletions spec/services/dunning_campaigns/bulk_process_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@
.with(customer:, dunning_campaign_threshold:)
end

context "when the customer has completed the dunning campaign" do
let(:customer) do
create :customer, organization:, currency:, dunning_campaign_completed: true
end

it "does not queue a job for the customer" do
result
expect(DunningCampaigns::ProcessAttemptJob).not_to have_been_enqueued
end
end

context "when organization does not have auto_dunning feature enabled" do
let(:organization) { create(:organization, premium_integrations: []) }

Expand Down

0 comments on commit b714613

Please sign in to comment.