Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dunning): Remove dunning_campaign_completed flag #2890

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(dunning): Stop execution if max attempts reached
rsempe committed Nov 28, 2024

Verified

This commit was signed with the committer’s verified signature.
wazelin Sergei Mikhailov
commit 663f6d9adc3f2dd2d93663c1aebca085bf6c5ae9
5 changes: 5 additions & 0 deletions app/services/dunning_campaigns/process_attempt_service.rb
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ def call
return result unless applicable_dunning_campaign?
return result unless dunning_campaign_threshold_reached?
return result unless days_between_attempts_passed?
return result if max_attempts_reached?

ActiveRecord::Base.transaction do
payment_request_result = PaymentRequests::CreateService.call(
@@ -63,6 +64,10 @@ def days_between_attempts_passed?
(customer.last_dunning_campaign_attempt_at + dunning_campaign.days_between_attempts.days).past?
end

def max_attempts_reached?
customer.last_dunning_campaign_attempt >= dunning_campaign.max_attempts
end

def overdue_invoices
customer
.invoices
17 changes: 17 additions & 0 deletions spec/services/dunning_campaigns/process_attempt_service_spec.rb
Original file line number Diff line number Diff line change
@@ -74,6 +74,23 @@
end
end

context "when dunning campaign max attempt is reached" do
let(:customer) do
create(
:customer,
organization:,
currency:,
last_dunning_campaign_attempt: dunning_campaign.max_attempts,
last_dunning_campaign_attempt_at: dunning_campaign.days_between_attempts.days.ago
)
end

it "does nothing" do
result
expect(PaymentRequests::CreateService).not_to have_received(:call)
end
end

context "when the campaign threshold is not reached" do
let(:dunning_campaign_threshold) do
create :dunning_campaign_threshold, dunning_campaign:, currency:, amount_cents: 99_01