Skip to content

Commit

Permalink
Merge branch 'master' into lg/Add-IPY-Operation-detail
Browse files Browse the repository at this point in the history
  • Loading branch information
RDeckard committed Oct 29, 2024
2 parents 59840fd + 5e7b2a9 commit cebc226
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ CFONB::OperationDetail.register('FEE', self)
| RCN | `reference`, `purpose` | Client reference and Payment nature/purpose |
| REF | `operation_reference` | Bank operation reference |
| IPY | `debtor_identifier`, `debtor_identifier_type` | Debtor identifier and debtor identifier type |
| 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 |
Expand Down
3 changes: 3 additions & 0 deletions lib/cfonb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -3,6 +3,7 @@
require 'cfonb'
require 'securerandom'
require 'ostruct'
require 'securerandom'

describe CFONB::Operation do
subject(:operation) { described_class.new(line) }
Expand Down Expand Up @@ -212,6 +213,55 @@
expect(operation.debtor_identifier_type).to eq(debtor_identifier_type)
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 cebc226

Please sign in to comment.