Skip to content

Commit

Permalink
Add info to pfmp show page (#1180)
Browse files Browse the repository at this point in the history
- Add montant réel
- Add rib info
  • Loading branch information
pskl authored Oct 25, 2024
1 parent 8e30143 commit 5f8cb3a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
15 changes: 13 additions & 2 deletions app/models/asp/payment_request.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module ASP
class PaymentRequest < ApplicationRecord
class PaymentRequest < ApplicationRecord # rubocop:disable Metrics/ClassLength
TRANSITION_CLASS = ASP::PaymentRequestTransition
STATE_MACHINE_CLASS = ASP::PaymentRequestStateMachine

Expand Down Expand Up @@ -127,11 +127,22 @@ def eligible_for_incomplete_retry?
end

def eligible_for_rejected_or_unpaid_auto_retry?
return false unless in_state?(:rejected) || in_state?(:unpaid)
return false unless in_state?(:rejected, :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) }
end

def reconstructed_iban
return nil unless in_state?(:paid)

coordpaie = last_transition.metadata["PAIEMENT"]["COORDPAIE"]
zonebban = coordpaie["ZONEBBAN"]
cle = coordpaie["CLECONTROL"]
code_pays = coordpaie["CODEISOPAYS"]

"#{code_pays}#{cle}#{zonebban}"
end
end
end
2 changes: 1 addition & 1 deletion app/views/pfmps/_payment_panel.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
de plafond maximum par an
%div.fr-mb-1w
= number_to_currency pfmp.previously_locked_amount
engagés par les PFMPs précédemment déclarées.
engagés par les PFMPs précédemment déclarées et validées.
6 changes: 5 additions & 1 deletion app/views/pfmps/_payment_requests_history.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
= render partial: "payment_requests/badges", locals: { payment_request: payment_request }
.fr-mt-1w
= payment_request.status_explanation
- if payment_request.in_state?(:paid)
.fr-mt-2w.gray-text
Montant réellement versé :
= number_to_currency(payment_request.last_transition.metadata['PAIEMENT']['MTNET'].to_f)
.fr-mt-2w.gray-text
Coordonnées bancaires utilisées :
= payment_request.rib&.iban || payment_request.student.rib&.iban || "manquantes"
= payment_request.rib&.iban || payment_request.reconstructed_iban || payment_request.student.rib(current_establishment)&.iban || "manquantes"
.fr-mt-2w.gray-text
Dernière mise à jour le
= l(payment_request.last_transition&.updated_at || payment_request.updated_at, format: :long)
2 changes: 1 addition & 1 deletion config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Aplypro
VERSION = "1.20.0"
VERSION = "1.20.1"
end
37 changes: 36 additions & 1 deletion spec/models/asp/payment_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
end

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

it "returns false" do
expect(p_r.eligible_for_rejected_or_unpaid_auto_retry?).to be false
Expand All @@ -202,4 +202,39 @@
end
end
end

describe "#reconstructed_iban" do
let(:payment_request) { create(:asp_payment_request, :paid) }
let(:metadata) do
{
"PAIEMENT" => {
"COORDPAIE" => {
"ZONEBBAN" => "20041010180452191K015",
"CLECONTROL" => "51",
"CODEISOPAYS" => "FR"
}
}
}
end

before do
allow(payment_request).to receive(:last_transition).and_return(
instance_double(ASP::PaymentRequestTransition, metadata: metadata)
)
end

context "when the payment request is in 'paid' state" do
it "returns the reconstructed IBAN" do
expect(payment_request.reconstructed_iban).to eq "FR5120041010180452191K015"
end
end

context "when the payment request is not in 'paid' state" do
let(:payment_request) { create(:asp_payment_request, :pending) }

it "returns nil" do
expect(payment_request.reconstructed_iban).to be_nil
end
end
end
end

0 comments on commit 5f8cb3a

Please sign in to comment.