Skip to content
This repository was archived by the owner on Jun 26, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ require:

AllCops:
NewCops: enable
TargetRubyVersion: 2.6
TargetRubyVersion: 2.7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason we're not in 3.0.3 land?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the version specified in the gemspec, and I think it's best if the gem can support as wide a range of Ruby versions as possible (albeit support for 2.7 will be dropped in 10 months)


Layout/LineLength:
Max: 120

Metrics/BlockLength:
Enabled: false

Style/Documentation:
Enabled: false

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
Enabled: true
EnforcedStyle: double_quotes
RSpec/ExampleLength:
Enabled: false

Layout/LineLength:
Max: 120

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probs copy the current rubocop yml we have in zfp and split(main zepto) repos

RSpec/MultipleExpectations:
Enabled: false
4 changes: 4 additions & 0 deletions lib/mt9.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

require "fixy"

require_relative "mt9/version"
require_relative "mt9/base_record"
require_relative "mt9/header_record"

module MT9
class Error < StandardError; end
Expand Down
14 changes: 14 additions & 0 deletions lib/mt9/base_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require_relative "formatters"

module MT9
class BaseRecord < Fixy::Record
include Fixy::Formatter::Alphanumeric
include Fixy::Formatter::Numeric

SPACE = " "

set_record_length 160
end
end
38 changes: 38 additions & 0 deletions lib/mt9/formatters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module Fixy
module Formatter
module Numeric
RESERVED_BANK_CODES = %w[99].freeze

def format_numeric(input, length)
input = input.to_s
raise ArgumentError, "Invalid Input (only digits are accepted)" unless input =~ /^\d+$/
raise ArgumentError, "Invalid Length (length must be #{length} not #{input.length})" if input.length != length

input
end

def format_file_type(input, _length)
input = input.to_s
unless MT9::HeaderRecord::FILE_TYPES.include?(input)
raise(
ArgumentError,
"Invalid filetype. Must be one of the following: #{MT9::HeaderRecord::FILE_TYPES.join(', ')}"
)
end

input
end

def format_account_number(input, length)
input = format_numeric(input, length)
if input.start_with?(*RESERVED_BANK_CODES)
raise ArgumentError, "Invalid account number. Cannot start with a reserved bank code"
end

input
end
end
end
end
30 changes: 30 additions & 0 deletions lib/mt9/header_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module MT9
class HeaderRecord < BaseRecord
DIRECT_CREDIT = "12"
DIRECT_DEBIT = "20"
FILE_TYPES = [DIRECT_CREDIT, DIRECT_DEBIT].freeze

attr_reader :file_type, :account_number, :due_date, :client_short_name

field :file_type, 2, "1-2", :file_type
field :account_number, 15, "3-17", :account_number

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we split this to

  • bank number 2
  • branch number 4
  • account number 7

or at least

  • bank + branch number 6
  • account number 7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do want to split up the account number, we'll have to split out the suffix as well. However for ease of use I think we should keep the branch/branch number, unique number and suffix together, as that is how most New Zealanders use it, and I don't see much benefit in doing so (apart from keeping close relation to the fields in the ASB docs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I dont hv experience of dealing wih NZ bank transfer

coz in our split app's bank_account model, we have branch_code and account_number (used as BSB and A/C), so I would imagine we could do sth similar for NZ

if we decide to use one field for all related account number in the gem, then we need to figure out the mapping in our adapter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we'll figure out that mapping in the app. It should be pretty simple (just concatenating the two numbers together). We'll already be doing the reverse (splitting the branch_code and account_number from a larger account number) as we've decided on only showing the account number in the UI/API when in NZ

field :filler1, 1, "18", :alphanumeric
field :due_date, 6, "19-24", :numeric
field :filler7, 7, "25-31", :alphanumeric
field :client_short_name, 20, "32-51", :alphanumeric
field :filler109, 109, "52-160", :alphanumeric

field_value :filler1, SPACE
field_value :filler7, SPACE * 7
field_value :filler109, SPACE * 109

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of "magic numbers" here. I would try to name them here and make them constants. i.e. 109 could be SOMETHING_FILLER_COUNT / MAYBE_FILLER_PADDING or something so when we use them, it kinda sort of gives us context what it is (and that we should not be able to change it easily):

Suggested change
field_value :filler109, SPACE * 109
field_value :filler109, SPACE * MAYBE_FILLER_PADDING


def initialize(file_type:, account_number:, due_date:, client_short_name:)
@file_type = file_type
@account_number = account_number
@due_date = due_date
@client_short_name = client_short_name
end
end
end
5 changes: 2 additions & 3 deletions mt9.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
"MT9 is a data standard used within the NZ banking industry for the creation of Bulk Payments and Receipts."
spec.homepage = "https://github.com/zeptofs/mt9"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.6.0"
spec.required_ruby_version = ">= 2.7.0"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -25,8 +25,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"
spec.add_dependency "fixy", "~> 0.0.9"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down