bambora-batch_upload 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +21 -2
- data/bambora-batch_upload.gemspec +2 -2
- data/lib/bambora/batch_upload.rb +46 -23
- data/lib/bambora/batch_upload/beanstream_send_batch.rb +7 -6
- data/lib/bambora/batch_upload/create_batch_file.rb +15 -5
- data/lib/bambora/batch_upload/exceptions.rb +16 -0
- data/lib/bambora/batch_upload/send_single_batch.rb +15 -8
- data/lib/bambora/batch_upload/version.rb +1 -1
- metadata +5 -6
- data/.rvmrc +0 -60
- data/Gemfile.lock +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ed4d50be5df4a6df523d8ccaff654ea6f38cb3e
|
4
|
+
data.tar.gz: d1a65d47fa70ab3bbb3dec4510674ffb2bfdd7f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16c71a0cf400eda46a8a526d10b11212cfab9153f10bbd1ad9d5845547b3869d6ef6b42e8bd529abfc7f1cceb12befff1e648c76346fb42a15f5834794171c0e
|
7
|
+
data.tar.gz: adf405388fc6e9cf7c70173f217741977d2fbc8885365fef6572c9383a6b98a95cbde12155123c3c504a13c7aa2bdf3e65c4f14246c5277e3639896f4e159a0c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Bambora::BatchUpload
|
2
2
|
|
3
|
-
Unofficial ruby wrapper for EFT batch uploads to Bambora.
|
3
|
+
Unofficial ruby wrapper for EFT and ACH batch uploads to Bambora.
|
4
4
|
|
5
|
-
|
5
|
+
## TODO
|
6
|
+
|
7
|
+
Add credit card batch upload.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -22,6 +24,8 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
27
|
+
See Bambora [Batch Payment API](https://dev.na.bambora.com/docs/references/batch_payment/#format-of-data-in-file) for reference.
|
28
|
+
|
25
29
|
To configure the upload, you must provide your merchant ID as well as Batch
|
26
30
|
Upload API Key. The default location for batch files (before uploading) is /tmp.
|
27
31
|
|
@@ -57,6 +61,21 @@ To create a batch file and then upload:
|
|
57
61
|
##more lines
|
58
62
|
#reader.push_into_file(...)
|
59
63
|
end
|
64
|
+
|
65
|
+
##for ACH
|
66
|
+
Bambora::BatchUpload.create_file("A") do |reader|
|
67
|
+
reader.push_into_file(payment_type: "D", amount: 100, reference: 34,
|
68
|
+
customer_code: "C6777B381C16434B82d40A8d23a19a68",
|
69
|
+
dynamic_descriptor: "Wesam Corp")
|
70
|
+
reader.push_into_file(payment_type: "D",
|
71
|
+
transit_routing_number: "123456789",
|
72
|
+
account_number: "123458",
|
73
|
+
account_code: "PC",
|
74
|
+
amount: 200,
|
75
|
+
reference: 667,
|
76
|
+
recipient: "Haddad"
|
77
|
+
)
|
78
|
+
end
|
60
79
|
|
61
80
|
#by default process date is next business day
|
62
81
|
Bambora::BatchUpload.do_upload(process_date) do |batch_id|
|
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["alwesam"]
|
10
10
|
spec.email = ["alwesam@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Ruby wrapper to upload
|
13
|
-
spec.description = %q{Ruby wrapper to upload
|
12
|
+
spec.summary = %q{Ruby wrapper to upload batch files.}
|
13
|
+
spec.description = %q{Ruby wrapper to upload batch files to Bambora.}
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
data/lib/bambora/batch_upload.rb
CHANGED
@@ -2,7 +2,6 @@ require_relative "batch_upload/version"
|
|
2
2
|
require_relative 'batch_upload/create_batch_file'
|
3
3
|
require_relative "batch_upload/send_single_batch"
|
4
4
|
require_relative "../extensions/date"
|
5
|
-
|
6
5
|
require 'ostruct'
|
7
6
|
require 'date'
|
8
7
|
|
@@ -25,10 +24,14 @@ module Bambora
|
|
25
24
|
SendSingleBatch.new(file_path,process_date).call(&block)
|
26
25
|
end
|
27
26
|
|
28
|
-
def self.create_file &block
|
27
|
+
def self.create_file txn_type, &block
|
29
28
|
raise "provide a block" unless block_given?
|
30
|
-
@file_path = CreateBatchFile.new(create_array(
|
31
|
-
|
29
|
+
@file_path = CreateBatchFile.new(create_array(txn_type,&block)).call
|
30
|
+
if @file_path.nil?
|
31
|
+
raise "No file generated!!!"
|
32
|
+
else
|
33
|
+
@file_path
|
34
|
+
end
|
32
35
|
end
|
33
36
|
|
34
37
|
def self.get_batch_upload_api_url
|
@@ -44,40 +47,60 @@ module Bambora
|
|
44
47
|
yield(self)
|
45
48
|
end
|
46
49
|
|
47
|
-
def self.create_array &block
|
48
|
-
reader = MakeArray.new
|
50
|
+
def self.create_array txn_type, &block
|
51
|
+
reader = MakeArray.new txn_type
|
49
52
|
yield(reader)
|
50
53
|
reader.array
|
51
54
|
end
|
52
55
|
|
53
56
|
class MakeArray
|
54
|
-
attr_accessor :array
|
55
|
-
def initialize
|
57
|
+
attr_accessor :array, :txn_type
|
58
|
+
def initialize(txn_type)
|
59
|
+
@txn_type = txn_type
|
60
|
+
@array = []
|
61
|
+
end
|
56
62
|
def push_into_file(params)
|
57
63
|
validate_args params
|
58
|
-
array << OpenStruct.new(txn_type:
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
array << OpenStruct.new(txn_type: @txn_type,
|
65
|
+
payment_type: params[:payment_type].to_s,
|
66
|
+
institution_number: params[:institution_number].to_s,
|
67
|
+
transit_number: params[:transit_number],
|
68
|
+
transit_routing_number: params[:transit_routing_number].to_s,
|
69
|
+
account_number: params[:account_number].to_s,
|
70
|
+
account_code: params[:account_code].to_s,
|
71
|
+
amount: params[:amount],
|
72
|
+
ref: (params[:reference] || 0 ).to_s,
|
73
|
+
recipient: params[:recipient].to_s,
|
74
|
+
customer_code: params[:customer_code].to_s,
|
75
|
+
descriptor: params[:dynamic_descriptor].to_s,
|
76
|
+
standard_entry_code: params[:standard_entry_code].to_s,
|
77
|
+
entry_detail_addenda: params[:entry_detail_addenda_record].to_s
|
67
78
|
)
|
68
79
|
end
|
69
80
|
private
|
70
81
|
def validate_args params
|
71
|
-
|
72
|
-
raise ArgumentError, "Must
|
82
|
+
unless @txn_type == "E" || @txn_type == "A"
|
83
|
+
raise ArgumentError, "Must specify transaction type: E (EFT) or A (ACH)"
|
73
84
|
end
|
74
85
|
unless params[:payment_type] == "D" || params[:payment_type] == "C"
|
75
86
|
raise ArgumentError, "Must provide payment type: C (credit) or D (debit)"
|
76
87
|
end
|
77
|
-
if params[:
|
78
|
-
|
79
|
-
|
80
|
-
|
88
|
+
if params[:amount].nil?
|
89
|
+
raise ArgumentError, "Must provide amount"
|
90
|
+
end
|
91
|
+
#banking info
|
92
|
+
if @txn_type == "E"
|
93
|
+
if params[:customer_code].nil? && (params[:transit_number].nil? ||
|
94
|
+
params[:institution_number].nil? ||
|
95
|
+
params[:account_number].nil?)
|
96
|
+
raise ArgumentError, "Must either provide customer code or transit, institution, and account #s"
|
97
|
+
end
|
98
|
+
else
|
99
|
+
if params[:customer_code].nil? && (params[:transit_routing_number].nil? ||
|
100
|
+
params[:account_code].nil? ||
|
101
|
+
params[:account_number].nil?)
|
102
|
+
raise ArgumentError, "Must either provide customer code or transit routing, account #s, and accounting code"
|
103
|
+
end
|
81
104
|
end
|
82
105
|
end
|
83
106
|
end
|
@@ -8,7 +8,6 @@ module Bambora::BatchUpload
|
|
8
8
|
attr_accessor :file_path
|
9
9
|
attr_accessor :process_date
|
10
10
|
attr_accessor :process_now
|
11
|
-
attr_accessor :failure_message
|
12
11
|
|
13
12
|
def initialize(file_path, process_date, process_now)
|
14
13
|
@file_path = file_path
|
@@ -24,15 +23,17 @@ module Bambora::BatchUpload
|
|
24
23
|
end
|
25
24
|
c.multipart_form_post = true
|
26
25
|
c.http_post(criteria_content,file_content)
|
27
|
-
response
|
26
|
+
response = JSON.parse(c.body)
|
27
|
+
response_code = c.response_code
|
28
28
|
if response["code"] == BATCH_PROCESS_SUCCESS
|
29
|
-
response["batch_id"]
|
29
|
+
response["batch_id"]
|
30
30
|
else
|
31
|
-
|
32
|
-
nil
|
31
|
+
raise BatchUploadError.new(code: response["code"], category: response["category"], message: response["message"], http_code: response_code)
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
34
|
+
|
35
|
+
private
|
36
|
+
|
36
37
|
def criteria_content
|
37
38
|
criteria_content = Curl::PostField.content("criteria",
|
38
39
|
"{'process_date':#{process_date_formatted},'process_now':#{process_now} }",
|
@@ -37,16 +37,26 @@ module Bambora::BatchUpload
|
|
37
37
|
def file_content
|
38
38
|
string = ""
|
39
39
|
txn_array.each do |txn|
|
40
|
-
string << "E,
|
41
|
-
string << "#{txn.
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
string << "#{txn.txn_type}," #E for EFT, A for ACH
|
41
|
+
string << "#{txn.payment_type}," #C for Credit, D for Debit
|
42
|
+
if txn.txn_type == "E"
|
43
|
+
string << "#{txn.institution_number},"
|
44
|
+
string << "#{txn.transit_number},"
|
45
|
+
string << "#{txn.account_number},"
|
46
|
+
else
|
47
|
+
string << "#{txn.transit_routing_number},"
|
48
|
+
string << "#{txn.account_number},"
|
49
|
+
string << "#{txn.account_code},"
|
50
|
+
end
|
45
51
|
string << "#{txn.amount},"
|
46
52
|
string << "#{txn.ref},"
|
47
53
|
string << "#{txn.recipient},"
|
48
54
|
string << "#{txn.customer_code},"
|
49
55
|
string << "#{txn.descriptor}"
|
56
|
+
if txn.txn_type == "A"
|
57
|
+
string << ",#{txn.standard_entry_code}," #add comma at beginning to separate from above
|
58
|
+
string << "#{txn.entry_detail_addenda}"
|
59
|
+
end
|
50
60
|
string << "\r\n"
|
51
61
|
end
|
52
62
|
string
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Bambora::BatchUpload
|
2
|
+
class BatchUploadError < StandardError
|
3
|
+
attr_reader :code, :category, :message, :http_code
|
4
|
+
def initialize args
|
5
|
+
@code = args[:code]
|
6
|
+
@category = args[:category]
|
7
|
+
@message = args[:message]
|
8
|
+
@http_code = args[:http_code]
|
9
|
+
end
|
10
|
+
def to_s
|
11
|
+
"Code: #{code}, Error Category: #{category}, Message: #{message}, HTTP response: #{http_code}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
class ConnectionError < StandardError
|
15
|
+
end
|
16
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'beanstream_send_batch'
|
2
|
+
require_relative 'exceptions'
|
2
3
|
|
3
4
|
module Bambora::BatchUpload
|
4
5
|
class SendSingleBatch
|
@@ -12,14 +13,20 @@ module Bambora::BatchUpload
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def call
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
begin
|
17
|
+
service = BeanstreamSendBatch.new(file_path,
|
18
|
+
process_date,
|
19
|
+
process_now)
|
20
|
+
batch_id = service.send
|
21
|
+
unless batch_id.nil?
|
22
|
+
yield(batch_id) if block_given?
|
23
|
+
end
|
24
|
+
rescue BatchUploadError #reraise error
|
25
|
+
raise
|
26
|
+
rescue JSON::ParserError => err
|
27
|
+
raise ConnectionError, "JSON parse Error: #{err.message}"
|
28
|
+
rescue => err #most likely api connection error
|
29
|
+
raise ConnectionError, "#{err.class}: #{err.message}"
|
23
30
|
end
|
24
31
|
end
|
25
32
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bambora-batch_upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alwesam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curb
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
-
description: Ruby wrapper to upload
|
83
|
+
description: Ruby wrapper to upload batch files to Bambora.
|
84
84
|
email:
|
85
85
|
- alwesam@gmail.com
|
86
86
|
executables: []
|
@@ -89,11 +89,9 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
-
- ".rvmrc"
|
93
92
|
- ".travis.yml"
|
94
93
|
- CODE_OF_CONDUCT.md
|
95
94
|
- Gemfile
|
96
|
-
- Gemfile.lock
|
97
95
|
- LICENSE.txt
|
98
96
|
- README.md
|
99
97
|
- Rakefile
|
@@ -104,6 +102,7 @@ files:
|
|
104
102
|
- lib/bambora/batch_upload.rb
|
105
103
|
- lib/bambora/batch_upload/beanstream_send_batch.rb
|
106
104
|
- lib/bambora/batch_upload/create_batch_file.rb
|
105
|
+
- lib/bambora/batch_upload/exceptions.rb
|
107
106
|
- lib/bambora/batch_upload/send_single_batch.rb
|
108
107
|
- lib/bambora/batch_upload/version.rb
|
109
108
|
- lib/extensions/date.rb
|
@@ -130,5 +129,5 @@ rubyforge_project:
|
|
130
129
|
rubygems_version: 2.5.2
|
131
130
|
signing_key:
|
132
131
|
specification_version: 4
|
133
|
-
summary: Ruby wrapper to upload
|
132
|
+
summary: Ruby wrapper to upload batch files.
|
134
133
|
test_files: []
|
data/.rvmrc
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
-
# development environment upon cd'ing into the directory
|
5
|
-
|
6
|
-
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
-
# Only full ruby name is supported here, for short names use:
|
8
|
-
# echo "rvm use 2.3.3@bambora" > .rvmrc
|
9
|
-
environment_id="ruby-2.3.3@bambora-batch_upload"
|
10
|
-
|
11
|
-
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
-
# rvmrc_rvm_version="1.29.2 (master)" # 1.10.1 seems like a safe start
|
13
|
-
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
-
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
-
# return 1
|
16
|
-
# }
|
17
|
-
|
18
|
-
# First we attempt to load the desired environment directly from the environment
|
19
|
-
# file. This is very fast and efficient compared to running through the entire
|
20
|
-
# CLI and selector. If you want feedback on which environment was used then
|
21
|
-
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
-
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
-
then
|
25
|
-
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
-
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
27
|
-
do
|
28
|
-
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
29
|
-
then \. "${__hook}" || true
|
30
|
-
fi
|
31
|
-
done
|
32
|
-
unset __hook
|
33
|
-
if (( ${rvm_use_flag:=1} >= 1 )) # display automatically
|
34
|
-
then
|
35
|
-
if [[ $- == *i* ]] # check for interactive shells
|
36
|
-
then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)\n" # show the user the ruby and gemset they are using in green
|
37
|
-
else printf "%b" "Using: $GEM_HOME\n" # don't use colors in non-interactive shells
|
38
|
-
fi
|
39
|
-
fi
|
40
|
-
else
|
41
|
-
# If the environment file has not yet been created, use the RVM CLI to select.
|
42
|
-
rvm --create use "$environment_id" || {
|
43
|
-
echo "Failed to create RVM environment '${environment_id}'."
|
44
|
-
return 1
|
45
|
-
}
|
46
|
-
fi
|
47
|
-
|
48
|
-
# If you use bundler, this might be useful to you:
|
49
|
-
# if [[ -s Gemfile ]] && {
|
50
|
-
# ! builtin command -v bundle >/dev/null ||
|
51
|
-
# builtin command -v bundle | GREP_OPTIONS="" \command \grep $rvm_path/bin/bundle >/dev/null
|
52
|
-
# }
|
53
|
-
# then
|
54
|
-
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
55
|
-
# gem install bundler
|
56
|
-
# fi
|
57
|
-
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
58
|
-
# then
|
59
|
-
# bundle install | GREP_OPTIONS="" \command \grep -vE '^Using|Your bundle is complete'
|
60
|
-
# fi
|
data/Gemfile.lock
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
bambora-batch_upload (0.1.1)
|
5
|
-
curb (= 0.9.3)
|
6
|
-
holidays
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
curb (0.9.3)
|
12
|
-
diff-lcs (1.3)
|
13
|
-
holidays (6.2.0)
|
14
|
-
rake (10.5.0)
|
15
|
-
rspec (3.7.0)
|
16
|
-
rspec-core (~> 3.7.0)
|
17
|
-
rspec-expectations (~> 3.7.0)
|
18
|
-
rspec-mocks (~> 3.7.0)
|
19
|
-
rspec-core (3.7.0)
|
20
|
-
rspec-support (~> 3.7.0)
|
21
|
-
rspec-expectations (3.7.0)
|
22
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
-
rspec-support (~> 3.7.0)
|
24
|
-
rspec-mocks (3.7.0)
|
25
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
-
rspec-support (~> 3.7.0)
|
27
|
-
rspec-support (3.7.0)
|
28
|
-
|
29
|
-
PLATFORMS
|
30
|
-
ruby
|
31
|
-
|
32
|
-
DEPENDENCIES
|
33
|
-
bambora-batch_upload!
|
34
|
-
bundler (~> 1.16)
|
35
|
-
rake (~> 10.0)
|
36
|
-
rspec (~> 3.0)
|
37
|
-
|
38
|
-
BUNDLED WITH
|
39
|
-
1.16.0
|