diff --git a/app/models/asp/payment_request.rb b/app/models/asp/payment_request.rb index d34585072..40e9f00d0 100644 --- a/app/models/asp/payment_request.rb +++ b/app/models/asp/payment_request.rb @@ -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 diff --git a/app/views/pfmps/_payment_requests_history.html.haml b/app/views/pfmps/_payment_requests_history.html.haml index 5f283d247..5a3094ec4 100644 --- a/app/views/pfmps/_payment_requests_history.html.haml +++ b/app/views/pfmps/_payment_requests_history.html.haml @@ -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) diff --git a/config/initializers/version.rb b/config/initializers/version.rb index c49524ac4..b7d5e45c2 100644 --- a/config/initializers/version.rb +++ b/config/initializers/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Aplypro - VERSION = "1.20.0" + VERSION = "1.20.1" end diff --git a/spec/models/asp/payment_request_spec.rb b/spec/models/asp/payment_request_spec.rb index c8437686d..8b35e891c 100644 --- a/spec/models/asp/payment_request_spec.rb +++ b/spec/models/asp/payment_request_spec.rb @@ -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