Skip to content

Commit

Permalink
Add reconstructed iban method on P_R and display this in case of miss…
Browse files Browse the repository at this point in the history
…ing rib
  • Loading branch information
pskl committed Oct 25, 2024
1 parent b9f7b32 commit 1096bd5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/models/asp/payment_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,16 @@ def eligible_for_rejected_or_unpaid_auto_retry?
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_requests_history.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
= 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(current_establishment)&.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
35 changes: 35 additions & 0 deletions spec/models/asp/payment_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 1096bd5

Please sign in to comment.