From 5e7b2a97d1f620218133585712ff7b4eb953e2ba Mon Sep 17 00:00:00 2001 From: Samuel COLLON Date: Tue, 29 Oct 2024 17:33:38 +0100 Subject: [PATCH] add NPO IBE and NBU operations (#21) Co-authored-by: Frantisek Rokusek --- .tool-versions | 2 +- Gemfile | 2 +- Gemfile.lock | 3 +- README.md | 5 ++-- lib/cfonb.rb | 3 ++ lib/cfonb/operation_detail/ibe.rb | 16 ++++++++++ lib/cfonb/operation_detail/nbu.rb | 15 ++++++++++ lib/cfonb/operation_detail/npo.rb | 15 ++++++++++ spec/cfonb/operation_spec.rb | 50 +++++++++++++++++++++++++++++++ 9 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 lib/cfonb/operation_detail/ibe.rb create mode 100644 lib/cfonb/operation_detail/nbu.rb create mode 100644 lib/cfonb/operation_detail/npo.rb diff --git a/.tool-versions b/.tool-versions index 1be8ceb..5577b6b 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,3 @@ -ruby 3.2.2 +ruby 3.3.5 nodejs 20.11.0 python 3.9.12 diff --git a/Gemfile b/Gemfile index 4046953..f1b24f3 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '3.2.2' +ruby '3.3.5' group :development do # License diff --git a/Gemfile.lock b/Gemfile.lock index 59369cc..dec4bc5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -66,6 +66,7 @@ GEM PLATFORMS arm64-darwin-22 + arm64-darwin-23 x86_64-linux DEPENDENCIES @@ -76,7 +77,7 @@ DEPENDENCIES rubocop-rspec RUBY VERSION - ruby 3.2.2p53 + ruby 3.3.5p100 BUNDLED WITH 2.4.12 diff --git a/README.md b/README.md index 5f49f80..a28353b 100644 --- a/README.md +++ b/README.md @@ -51,13 +51,14 @@ CFONB::OperationDetail.register('FEE', self) | NPY | `debtor` | Name of the debtor or payer | | RCN | `reference`, `purpose` | Client reference and Payment nature/purpose | | REF | `operation_reference` | Bank operation reference | +| IBE | `creditor_identifier`, `creditor_identifier_type` | Creditor identifier and the type of identifier | +| NPO | `ultimate_debtor` | Name of the ultimate debtor or beneficiary | +| NBU | `ultimate_creditor` | Name of the ultimate creditor or payer | TODO: | Detail Code | Attributes | Description | | --- | --- | --- | | IPY | `debtor_identifier` | Identifier of the debtor or payer | -| NPO | `ultimate_debtor` | Name of the ultimate debtor or beneficiary | -| NBU | `ultimate_creditor` | Name of the ultimate creditor or payer | | RET | `unifi_code`, `sit_code`, `payback_label` | Payback informations | | CBE | `creditor_account` | Account of the creditor or beneficiary | | BDB | `creditor_bank` | Bank of the creditor or beneficiary | diff --git a/lib/cfonb.rb b/lib/cfonb.rb index 3541335..e20f0d0 100644 --- a/lib/cfonb.rb +++ b/lib/cfonb.rb @@ -27,6 +27,9 @@ require_relative 'cfonb/operation_detail/rcn' require_relative 'cfonb/operation_detail/ref' require_relative 'cfonb/operation_detail/fee' +require_relative 'cfonb/operation_detail/ibe' +require_relative 'cfonb/operation_detail/npo' +require_relative 'cfonb/operation_detail/nbu' module CFONB def self.parse(input, optimistic: false) diff --git a/lib/cfonb/operation_detail/ibe.rb b/lib/cfonb/operation_detail/ibe.rb new file mode 100644 index 0000000..da27c4f --- /dev/null +++ b/lib/cfonb/operation_detail/ibe.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module CFONB + module OperationDetail + class IBE + ATTRIBUTES = %i[creditor_identifier creditor_identifier_type].freeze + + def self.apply(operation, line) + operation.creditor_identifier = line.detail[0..34].strip + operation.creditor_identifier_type = line.detail[35..-1].strip + end + + CFONB::OperationDetail.register('IBE', self) + end + end +end diff --git a/lib/cfonb/operation_detail/nbu.rb b/lib/cfonb/operation_detail/nbu.rb new file mode 100644 index 0000000..ca18d04 --- /dev/null +++ b/lib/cfonb/operation_detail/nbu.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module CFONB + module OperationDetail + class NBU + ATTRIBUTES = %i[ultimate_creditor].freeze + + def self.apply(operation, line) + operation.ultimate_creditor = line.detail.strip + end + + CFONB::OperationDetail.register('NBU', self) + end + end +end diff --git a/lib/cfonb/operation_detail/npo.rb b/lib/cfonb/operation_detail/npo.rb new file mode 100644 index 0000000..15fd742 --- /dev/null +++ b/lib/cfonb/operation_detail/npo.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module CFONB + module OperationDetail + class NPO + ATTRIBUTES = %i[ultimate_debtor].freeze + + def self.apply(operation, line) + operation.ultimate_debtor = line.detail.strip + end + + CFONB::OperationDetail.register('NPO', self) + end + end +end diff --git a/spec/cfonb/operation_spec.rb b/spec/cfonb/operation_spec.rb index 880e6fe..8b43465 100644 --- a/spec/cfonb/operation_spec.rb +++ b/spec/cfonb/operation_spec.rb @@ -2,6 +2,7 @@ require 'cfonb' require 'ostruct' +require 'securerandom' describe CFONB::Operation do subject(:operation) { described_class.new(line) } @@ -191,6 +192,55 @@ expect(operation.fee).to eq(7.4) end end + + context 'with a IBE detail' do + let(:creditor_identifier) { SecureRandom.alphanumeric(35) } + let(:creditor_identifier_type) { SecureRandom.alphanumeric(35) } + + let(:detail) do + OpenStruct.new( + detail_code: 'IBE', + detail: "#{creditor_identifier}#{creditor_identifier_type}", + ) + end + + it 'adds the IBE information' do + operation.merge_detail(detail) + + expect(operation.creditor_identifier).to eq(creditor_identifier) + expect(operation.creditor_identifier_type).to eq(creditor_identifier_type) + end + end + + context 'with a NPO detail' do + let(:detail) do + OpenStruct.new( + detail_code: 'NPO', + detail: 'Patrick ', + ) + end + + it 'adds the NPO information' do + operation.merge_detail(detail) + + expect(operation.ultimate_debtor).to eq('Patrick') + end + end + + context 'with a NBU detail' do + let(:detail) do + OpenStruct.new( + detail_code: 'NBU', + detail: 'Patrick ', + ) + end + + it 'adds the NBU information' do + operation.merge_detail(detail) + + expect(operation.ultimate_creditor).to eq('Patrick') + end + end end describe '#type_code' do