Skip to content

Commit

Permalink
add NPO IBE and NBU operations
Browse files Browse the repository at this point in the history
  • Loading branch information
scollon-pl committed Oct 29, 2024
1 parent 7c68e7a commit 7715261
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ruby 3.2.2
ruby 3.3.5
nodejs 18.18.0
python 3.9.12
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ GEM

PLATFORMS
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
Expand All @@ -78,7 +79,7 @@ DEPENDENCIES
rubocop-rspec

RUBY VERSION
ruby 3.2.2p53
ruby 3.3.5p100

BUNDLED WITH
2.4.12
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,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 |
Expand Down
3 changes: 3 additions & 0 deletions lib/cfonb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions lib/cfonb/operation_detail/ibe.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions lib/cfonb/operation_detail/nbu.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions lib/cfonb/operation_detail/npo.rb
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions spec/cfonb/operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'cfonb'
require 'ostruct'
require 'securerandom'

describe CFONB::Operation do
subject(:operation) { described_class.new(line) }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7715261

Please sign in to comment.