Skip to content

Update Bin Numbers of Korean domestic cards

Jagdeep Singh edited this page Nov 1, 2019 · 2 revisions

1. Download the list

You can download the xlsx file containing the list of bin numbers from here.

2. Install dependencies

Install gem creek by running gem install creek.

3. Read the xlsx and update config.yml

require 'creek'

filepath = '/path/to/card_bin_20191001.xlsx'
creek = Creek::Book.new(filepath)

# Select the sheet
sheet = creek.sheets[0]

# Find the column with Bin Numbers
bin_key = sheet.simple_rows.first.key("Bin Number")

# Extract all the Bin Numbers and sort them
bin_numbers = sheet.simple_rows.to_a[1...sheet.simple_rows.count].map { |row| row[bin_key] }.sort

# Read existing config
lines = File.readlines('/path/to/paygate-ruby/data/config.yml')
header_row_idx = lines.index { |l| l =~ /\:bin_numbers\:/ }
spaces = lines[header_row_idx + 1].split('-')[0].size # Indentation

target_filepath = '/path/to/paygate-ruby/data/config.yml'

File.open(target_filepath, 'w+') do |f|
  # Write existing configuration
  lines[0..header_row_idx].each do |l|
    f.puts l
  end

  # Rewrite all Bin Numbers
  bin_numbers.each do |num|
    f.puts "#{' ' * spaces}- '#{num}'"
  end
end

The script assumes that Bin Numbers will always be at the end of config.yml.