Skip to content

Commit

Permalink
Relance en paiement les PFMPs bloquées pour des motifs liés à l'adresse
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicolas1 committed Oct 24, 2024
1 parent 54b7e40 commit 9a2fce7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/ribs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def rib_is_readonly

def retry_rejected_or_unpaid_payment_request!
@student.pfmps.in_state(:validated).each do |pfmp|
if pfmp.latest_payment_request&.eligible_for_rejected_or_unpaid_auto_retry?
if pfmp.latest_payment_request&.eligible_for_rejected_or_unpaid_auto_retry?(%w[RIB BIC PAIEMENT])
p_r = PfmpManager.new(pfmp).create_new_payment_request!
p_r.mark_ready!
end
Expand Down
13 changes: 13 additions & 0 deletions app/jobs/sync/student_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ def fetch_student_data(schooling)
api.fetch_resource(:student, ine: schooling.student.ine)
.then { |data| map_student_attributes(data, api) }
.then { |attributes| schooling.student.update!(attributes) }

student = schooling.student
if !student.previous_changes.key?("address_line1") ||
!student.previous_changes.key?("address_line2") ||
!student.previous_changes.key?("address_city_insee_code") ||
!student.previous_changes.key?("address_country_code")
student.pfmps.in_state(:validated).each do |pfmp|
if pfmp.latest_payment_request&.eligible_for_rejected_or_unpaid_auto_retry?(%w[ADRESSE PAYS])
p_r = PfmpManager.new(pfmp).create_new_payment_request!
p_r.mark_ready!
end
end
end
end

def map_student_attributes(data, api)
Expand Down
4 changes: 2 additions & 2 deletions app/models/asp/payment_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ def eligible_for_incomplete_retry?
last_transition.metadata["incomplete_reasons"]["ready_state_validation"].intersect?(retryable_messages)
end

def eligible_for_rejected_or_unpaid_auto_retry?
def eligible_for_rejected_or_unpaid_auto_retry?(reasons)
return false unless in_state?(:rejected) || in_state?(:unpaid)

decorator = ActiveDecorator::Decorator.instance.decorate(self)
message = in_state?(:rejected) ? decorator.rejected_reason : decorator.unpaid_reason
%w[RIB BIC PAIEMENT].any? { |word| message.upcase.include?(word) }
reasons.any? { |word| message.upcase.include?(word) }
end
end
end
1 change: 1 addition & 0 deletions app/models/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Student < ApplicationRecord # rubocop:disable Metrics/ClassLength

sourced_from_external_api :birthdate,
:address_line1,
:address_line2,
:address_postal_code,
:address_city_insee_code,
:address_country_code,
Expand Down
8 changes: 4 additions & 4 deletions spec/models/asp/payment_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
let(:p_r) { create(:asp_payment_request, :rejected) }

it "returns false" do
expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?).to be false
expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?(%w[RIB BIC PAIEMENT])).to be false
end
end

Expand All @@ -180,15 +180,15 @@
end

it "returns true" do
expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?).to be true
expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?(%w[RIB BIC PAIEMENT])).to be true
end
end

context "when the payment request is in 'unpaid' state without a RIB reason" do
let(:p_r) { create(:asp_payment_request, :unpaid) }

it "returns false" do
expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?).to be false
expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?(%w[RIB BIC PAIEMENT])).to be false
end
end

Expand All @@ -198,7 +198,7 @@
end

it "returns true" do
expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?).to be true
expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?(%w[RIB BIC PAIEMENT])).to be true
end
end
end
Expand Down

0 comments on commit 9a2fce7

Please sign in to comment.