multicash 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +88 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/multicash.rb +16 -0
- data/lib/multicash/account.rb +28 -0
- data/lib/multicash/ammount.rb +21 -0
- data/lib/multicash/credit_transfer.rb +56 -0
- data/lib/multicash/labels/credit_transfer.rb +113 -0
- data/lib/multicash/labels/payment_order.rb +46 -0
- data/lib/multicash/payment.rb +37 -0
- data/lib/multicash/payment_order.rb +77 -0
- data/lib/multicash/transfer.rb +92 -0
- data/lib/multicash/transfer_labels_builder.rb +10 -0
- data/lib/multicash/utils.rb +25 -0
- data/multicash.gemspec +84 -0
- data/spec/account_spec.rb +23 -0
- data/spec/ammount_spec.rb +17 -0
- data/spec/credit_transfer_spec.rb +55 -0
- data/spec/fixtures/transfer.yml +10 -0
- data/spec/labels/credit_transfer_spec.rb +66 -0
- data/spec/payment_order_spec.rb +38 -0
- data/spec/payment_spec.rb +26 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/transfer_spec.rb +61 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: efe6e3a2cb9bd7f818c0d4e59d719194df1c22c6
|
4
|
+
data.tar.gz: cea5c784b06dced9a2f9aed5fbc26a10886b1582
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f78b6d80f5685cb233178167b96b406cf04edfcea05ba8c0169d04bee3194d1f7c1519b802b8da945745dd62a3f4aea6590988ec4c894f029e12d2256779af22
|
7
|
+
data.tar.gz: 070bedfa76709f050a0516d05fc2b5c719b1f3e09d06fc00b861722bf00284784678deebae27632c68115a99556811122a8e72f729e3b7db0d66cdb5a1474f96
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
gem "activemodel", "~> 4.0.2"
|
9
|
+
|
10
|
+
group :development do
|
11
|
+
gem "rspec"
|
12
|
+
gem "rdoc", "~> 3.12"
|
13
|
+
gem "bundler", "~> 1.0"
|
14
|
+
gem "jeweler", "~> 2.0.1"
|
15
|
+
gem "simplecov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (4.0.2)
|
5
|
+
activesupport (= 4.0.2)
|
6
|
+
builder (~> 3.1.0)
|
7
|
+
activesupport (4.0.2)
|
8
|
+
i18n (~> 0.6, >= 0.6.4)
|
9
|
+
minitest (~> 4.2)
|
10
|
+
multi_json (~> 1.3)
|
11
|
+
thread_safe (~> 0.1)
|
12
|
+
tzinfo (~> 0.3.37)
|
13
|
+
addressable (2.3.5)
|
14
|
+
atomic (1.1.14)
|
15
|
+
builder (3.1.4)
|
16
|
+
descendants_tracker (0.0.3)
|
17
|
+
diff-lcs (1.2.5)
|
18
|
+
docile (1.1.2)
|
19
|
+
faraday (0.9.0)
|
20
|
+
multipart-post (>= 1.2, < 3)
|
21
|
+
git (1.2.6)
|
22
|
+
github_api (0.11.1)
|
23
|
+
addressable (~> 2.3)
|
24
|
+
descendants_tracker (~> 0.0.1)
|
25
|
+
faraday (~> 0.8, < 0.10)
|
26
|
+
hashie (>= 1.2)
|
27
|
+
multi_json (>= 1.7.5, < 2.0)
|
28
|
+
nokogiri (~> 1.6.0)
|
29
|
+
oauth2
|
30
|
+
hashie (2.0.5)
|
31
|
+
highline (1.6.20)
|
32
|
+
i18n (0.6.9)
|
33
|
+
jeweler (2.0.1)
|
34
|
+
builder
|
35
|
+
bundler (>= 1.0)
|
36
|
+
git (>= 1.2.5)
|
37
|
+
github_api
|
38
|
+
highline (>= 1.6.15)
|
39
|
+
nokogiri (>= 1.5.10)
|
40
|
+
rake
|
41
|
+
rdoc
|
42
|
+
json (1.8.1)
|
43
|
+
jwt (0.1.11)
|
44
|
+
multi_json (>= 1.5)
|
45
|
+
mini_portile (0.5.2)
|
46
|
+
minitest (4.7.5)
|
47
|
+
multi_json (1.8.4)
|
48
|
+
multi_xml (0.5.5)
|
49
|
+
multipart-post (2.0.0)
|
50
|
+
nokogiri (1.6.1)
|
51
|
+
mini_portile (~> 0.5.0)
|
52
|
+
oauth2 (0.9.3)
|
53
|
+
faraday (>= 0.8, < 0.10)
|
54
|
+
jwt (~> 0.1.8)
|
55
|
+
multi_json (~> 1.3)
|
56
|
+
multi_xml (~> 0.5)
|
57
|
+
rack (~> 1.2)
|
58
|
+
rack (1.5.2)
|
59
|
+
rake (10.1.1)
|
60
|
+
rdoc (3.12.2)
|
61
|
+
json (~> 1.4)
|
62
|
+
rspec (2.14.1)
|
63
|
+
rspec-core (~> 2.14.0)
|
64
|
+
rspec-expectations (~> 2.14.0)
|
65
|
+
rspec-mocks (~> 2.14.0)
|
66
|
+
rspec-core (2.14.7)
|
67
|
+
rspec-expectations (2.14.4)
|
68
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
69
|
+
rspec-mocks (2.14.4)
|
70
|
+
simplecov (0.8.2)
|
71
|
+
docile (~> 1.1.0)
|
72
|
+
multi_json
|
73
|
+
simplecov-html (~> 0.8.0)
|
74
|
+
simplecov-html (0.8.0)
|
75
|
+
thread_safe (0.1.3)
|
76
|
+
atomic
|
77
|
+
tzinfo (0.3.38)
|
78
|
+
|
79
|
+
PLATFORMS
|
80
|
+
ruby
|
81
|
+
|
82
|
+
DEPENDENCIES
|
83
|
+
activemodel (~> 4.0.2)
|
84
|
+
bundler (~> 1.0)
|
85
|
+
jeweler (~> 2.0.1)
|
86
|
+
rdoc (~> 3.12)
|
87
|
+
rspec
|
88
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Anton Yordanov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= multicash
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to multicash
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2014 Anton Yordanov. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "multicash"
|
18
|
+
gem.homepage = "http://github.com/anotin-yordanov/multicash"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Generate payment order under the multicash spec}
|
21
|
+
gem.description = %Q{Generate payment order under the multicash spec}
|
22
|
+
gem.email = "anton.yordnaov@gmail.com"
|
23
|
+
gem.authors = ["Anton Yordanov"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'rspec'
|
32
|
+
test.pattern = 'spec/**/*_spec.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Code coverage detail"
|
37
|
+
task :simplecov do
|
38
|
+
ENV['COVERAGE'] = "true"
|
39
|
+
Rake::Task['test'].execute
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rdoc/task'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "multicash #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/multicash.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'active_model/validations'
|
3
|
+
require 'active_model/naming'
|
4
|
+
require "multicash/utils"
|
5
|
+
require "multicash/account"
|
6
|
+
require "multicash/ammount"
|
7
|
+
require "multicash/labels/payment_order"
|
8
|
+
require "multicash/payment"
|
9
|
+
require "multicash/labels/credit_transfer"
|
10
|
+
require "multicash/transfer_labels_builder"
|
11
|
+
require "multicash/transfer"
|
12
|
+
require "multicash/credit_transfer"
|
13
|
+
require "multicash/payment_order"
|
14
|
+
|
15
|
+
module Multicash
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Multicash
|
2
|
+
class Account
|
3
|
+
extend ActiveModel::Naming
|
4
|
+
include ActiveModel::Validations
|
5
|
+
include Multicash::Utils
|
6
|
+
|
7
|
+
attr_accessor :name, :city, :address, :iban, :bank_name
|
8
|
+
attr_reader :bae, :errors
|
9
|
+
|
10
|
+
validates :name, presence: true, allow_blank: false
|
11
|
+
validates :city, presence: true, allow_blank: false
|
12
|
+
validates :address, presence: true, allow_blank: false
|
13
|
+
validates :iban, presence: true, format: /[A-Z0-9]{2}\d{2}[A-Z0-9]{4}\d{4}[A-Z0-9]{10}/
|
14
|
+
|
15
|
+
def initialize attributes = {}
|
16
|
+
@name = attributes[:name]
|
17
|
+
@city = attributes[:city] || "CITY"
|
18
|
+
@address = attributes[:address] || "ADDRESS"
|
19
|
+
@bank_name = attributes[:bank_name] || "BANK NAME"
|
20
|
+
@iban = attributes[:iban]
|
21
|
+
@errors = ActiveModel::Errors.new(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
def bae
|
25
|
+
calc_bae(iban)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Multicash
|
2
|
+
class Ammount
|
3
|
+
extend ActiveModel::Naming
|
4
|
+
include ActiveModel::Validations
|
5
|
+
|
6
|
+
CURRENCIES = %w{AUD BGN CAD CHF DKK EUR GBP JPY NOK RUR SEK TRL USD}
|
7
|
+
CURRENCY_FORMAT = /\A\d{1,11}.\d{2}\z/
|
8
|
+
|
9
|
+
attr_accessor :value, :currency
|
10
|
+
attr_reader :errors
|
11
|
+
|
12
|
+
validates :value, format: { with: CURRENCY_FORMAT }
|
13
|
+
validates :currency, presence: true, inclusion: {in: CURRENCIES}
|
14
|
+
|
15
|
+
def initialize value: 0.00, currency: 'BGN'
|
16
|
+
@value = value
|
17
|
+
@currency = currency
|
18
|
+
@errors = ActiveModel::Errors.new(self)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# check this https://github.com/iulianu/iban-tools
|
2
|
+
|
3
|
+
# Create new transfer for payment order and puts correct labels according the Multicash spec
|
4
|
+
module Multicash
|
5
|
+
class CreditTransfer < Transfer
|
6
|
+
|
7
|
+
attr_reader :message_id
|
8
|
+
|
9
|
+
def initialize attributes = {}
|
10
|
+
super
|
11
|
+
|
12
|
+
@message_id = 'CRED'
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate
|
16
|
+
return self.errors.full_messages unless self.valid
|
17
|
+
|
18
|
+
"#{self.header}#{self.body}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def header
|
22
|
+
line = "{1:F01"
|
23
|
+
line << self.ordering_bae
|
24
|
+
line << "XXXX0000000000}"
|
25
|
+
line << "{2:I103"
|
26
|
+
line << self.destination_bae
|
27
|
+
line << "XXXXN0000}"
|
28
|
+
line
|
29
|
+
end
|
30
|
+
|
31
|
+
def body
|
32
|
+
transfer_labels = Multicash::TransferLabelsBuilder.build(self)
|
33
|
+
lines = []
|
34
|
+
lines << "{4:"
|
35
|
+
lines << transfer_labels.label_20
|
36
|
+
lines << transfer_labels.label_23B
|
37
|
+
lines << transfer_labels.label_32A
|
38
|
+
lines << transfer_labels.label_50K
|
39
|
+
lines << transfer_labels.label_52D
|
40
|
+
lines << transfer_labels.label_57D
|
41
|
+
lines << transfer_labels.label_59
|
42
|
+
lines << transfer_labels.label_70
|
43
|
+
lines << transfer_labels.label_70_footer
|
44
|
+
lines << transfer_labels.label_71A
|
45
|
+
lines << transfer_labels.label_72
|
46
|
+
lines << transfer_labels.label_72_footer
|
47
|
+
lines << "-}"
|
48
|
+
|
49
|
+
lines.join("\n")
|
50
|
+
end
|
51
|
+
|
52
|
+
def order_reference
|
53
|
+
"#{today}000000000#{reference_counter}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Multicash
|
2
|
+
module Labels
|
3
|
+
class CreditTransfer
|
4
|
+
|
5
|
+
include Multicash::Utils
|
6
|
+
attr_reader :transfer
|
7
|
+
|
8
|
+
def initialize transfer
|
9
|
+
@transfer = transfer
|
10
|
+
end
|
11
|
+
|
12
|
+
def label_20
|
13
|
+
label = ":20:"
|
14
|
+
value = sprintf("%010d", transfer.order_reference)
|
15
|
+
|
16
|
+
"#{label}#{value}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def label_23B
|
20
|
+
label = ":23B:"
|
21
|
+
value = ""
|
22
|
+
value << transfer.message_id
|
23
|
+
|
24
|
+
"#{label}#{value}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def label_32A
|
28
|
+
label = ':32A:'
|
29
|
+
value = ""
|
30
|
+
value << transfer.today
|
31
|
+
value << transfer.currency
|
32
|
+
value << print_currency_with_comma(transfer.ammount, -15)
|
33
|
+
|
34
|
+
"#{label}#{print_string((value), -22)}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def label_50K
|
38
|
+
label = ":50K:"
|
39
|
+
value = "/"
|
40
|
+
value << transfer.ordering_iban
|
41
|
+
value << "\n"
|
42
|
+
value << transfer.ordering_name
|
43
|
+
|
44
|
+
"#{label}#{value}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def label_52D
|
48
|
+
label = ":52D:"
|
49
|
+
value = print_string(transfer.ordering_bae, -35)
|
50
|
+
value << "\n"
|
51
|
+
value << print_string(transfer.ordering_bank_name, -35)
|
52
|
+
|
53
|
+
"#{label}#{value}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def label_57D
|
57
|
+
label = ":57D:"
|
58
|
+
value = print_string(transfer.destination_bae, -35)
|
59
|
+
value << "\n"
|
60
|
+
value << print_string(transfer.destination_bank_name, -35)
|
61
|
+
|
62
|
+
"#{label}#{value}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def label_59
|
66
|
+
label = ":59:"
|
67
|
+
value = '/'
|
68
|
+
value << transfer.destination_iban
|
69
|
+
value << "\n"
|
70
|
+
value << print_string(transfer.destination_name, -35)
|
71
|
+
|
72
|
+
"#{label}#{value}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def label_70
|
76
|
+
label = ":70:"
|
77
|
+
value = print_string(transfer.payment_details, -35)
|
78
|
+
|
79
|
+
"#{label}#{value}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def label_70_footer
|
83
|
+
value = "\n/"
|
84
|
+
value << "/NTYPE/000000000000"
|
85
|
+
value << "\n/"
|
86
|
+
value << "/OPNAT/J"
|
87
|
+
|
88
|
+
value
|
89
|
+
end
|
90
|
+
|
91
|
+
def label_71A
|
92
|
+
label = ":71A:"
|
93
|
+
value = ""
|
94
|
+
value << transfer.payment_charges
|
95
|
+
|
96
|
+
"#{label}#{value}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def label_72
|
100
|
+
label = ":72:"
|
101
|
+
value = print_string(transfer.payment_system, -35)
|
102
|
+
|
103
|
+
"#{label}#{value}"
|
104
|
+
end
|
105
|
+
|
106
|
+
def label_72_footer
|
107
|
+
value = "/BAEREF/000000000000000000"
|
108
|
+
value << "\n/"
|
109
|
+
value << "/PROL/NORM"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Multicash
|
2
|
+
module Labels
|
3
|
+
class PaymentOrder
|
4
|
+
include Multicash::Utils
|
5
|
+
attr_reader :payment_order
|
6
|
+
|
7
|
+
def initialize payment_order
|
8
|
+
@payment_order = payment_order
|
9
|
+
end
|
10
|
+
|
11
|
+
def label_20
|
12
|
+
label = ":20:"
|
13
|
+
value = ""
|
14
|
+
value << payment_order.date
|
15
|
+
value << sprintf("%010d", print_string(payment_order.transfers.size, -22))
|
16
|
+
|
17
|
+
|
18
|
+
"#{label}#{value}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def label_12
|
22
|
+
label = ":12:"
|
23
|
+
value = sprintf("%03d", payment_order.transfers.size)
|
24
|
+
|
25
|
+
"#{label}#{value}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def label_77E
|
29
|
+
label = ":77E:"
|
30
|
+
value = ":B01:"
|
31
|
+
value << payment_order.date
|
32
|
+
|
33
|
+
"#{label}#{value}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def label_B1T
|
37
|
+
label = ":B1T:006"
|
38
|
+
value = ""
|
39
|
+
value << payment_order.currency
|
40
|
+
value << print_currency_with_comma(payment_order.total_ammount.to_s, -9)
|
41
|
+
|
42
|
+
"#{label}#{value}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Multicash
|
2
|
+
class Payment
|
3
|
+
extend ActiveModel::Naming
|
4
|
+
include ActiveModel::Validations
|
5
|
+
|
6
|
+
CHARGES = %w{SHA OUR BEN}
|
7
|
+
|
8
|
+
attr_accessor :ammount, :details, :charges
|
9
|
+
attr_reader :errors, :payment_system, :ammount_value, :ammount_currency
|
10
|
+
|
11
|
+
def initialize attributes = {}
|
12
|
+
@ammount = attributes[:ammount]
|
13
|
+
@details = attributes[:details]
|
14
|
+
@charges = attributes[:charges]
|
15
|
+
@errors = ActiveModel::Errors.new(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
validate :valid_ammount
|
19
|
+
validates :ammount, presence: true
|
20
|
+
validates :details, presence: true
|
21
|
+
validates :charges, presence: true, inclusion: { in: CHARGES }
|
22
|
+
|
23
|
+
def ammount_value
|
24
|
+
ammount.value
|
25
|
+
end
|
26
|
+
|
27
|
+
def ammount_currency
|
28
|
+
ammount.currency
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid_ammount
|
32
|
+
unless self.ammount.valid?
|
33
|
+
self.errors.add(:ammount, self.ammount.errors.full_messages)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Multicash
|
2
|
+
class PaymentOrder
|
3
|
+
attr_accessor :reference, :transfers_number
|
4
|
+
attr_reader :transfers, :total_ammount, :currency, :ordering_bae, :date, :errors
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@currency = nil
|
8
|
+
@date = Time.now.strftime('%y%m%d')
|
9
|
+
@errors = []
|
10
|
+
@ordering_bae = nil
|
11
|
+
@transfers = []
|
12
|
+
@total_ammount = 0.00
|
13
|
+
end
|
14
|
+
|
15
|
+
def << (transfer)
|
16
|
+
if transfer.valid?
|
17
|
+
@transfers << transfer
|
18
|
+
@total_ammount += (transfer.ammount.to_f)
|
19
|
+
@currency ||= transfer.currency
|
20
|
+
@ordering_bae ||= transfer.ordering_bae
|
21
|
+
else
|
22
|
+
errors.add(:transfer, transfer.errors.full_messages)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def header
|
27
|
+
first_line = "{1:F01"
|
28
|
+
first_line << self.ordering_bae
|
29
|
+
first_line << "XXXX0000000000}"
|
30
|
+
first_line << "{2:I198"
|
31
|
+
first_line << self.ordering_bae
|
32
|
+
first_line << "XXXXN0000}"
|
33
|
+
|
34
|
+
"#{first_line}#{header_body}\x0c"
|
35
|
+
end
|
36
|
+
|
37
|
+
def header_body
|
38
|
+
payment_labels = Multicash::Labels::PaymentOrder.new(self)
|
39
|
+
|
40
|
+
lines = []
|
41
|
+
lines << "{4:"
|
42
|
+
lines << payment_labels.label_20
|
43
|
+
lines << payment_labels.label_12
|
44
|
+
lines << payment_labels.label_77E
|
45
|
+
lines << payment_labels.label_B1T
|
46
|
+
|
47
|
+
lines.join("\n") + "\n-}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def body
|
51
|
+
lines = []
|
52
|
+
transfers.reverse.each_with_index do |transfer|
|
53
|
+
if transfer.valid?
|
54
|
+
transfer.reference_counter += 1
|
55
|
+
lines << transfer.generate
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
lines.join("\x0C")
|
60
|
+
end
|
61
|
+
|
62
|
+
def generate
|
63
|
+
"#{header}#{body}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def save_to_file
|
67
|
+
return false unless self.errors.blank?
|
68
|
+
|
69
|
+
bank_file = File.join(Dir.tmpdir, "#{Time.now.strftime('%Y-%m-%d')}.txt")
|
70
|
+
File.open(bank_file, "w+", cr_newline: true, external_encoding: Encoding::CP1251) do |file|
|
71
|
+
file.write generate.encode("CP1251")
|
72
|
+
end
|
73
|
+
|
74
|
+
bank_file
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Multicash
|
2
|
+
class Transfer
|
3
|
+
extend ActiveModel::Naming
|
4
|
+
include ActiveModel::Validations
|
5
|
+
|
6
|
+
MESSAGE_IDS = %w{CRED}
|
7
|
+
PAYMENT_SYSTEMS = %w{DTYPE PORD OPER RINGS BISER}
|
8
|
+
|
9
|
+
|
10
|
+
attr_accessor :ordering_account, :destination_account, :payment, :payment_system, :reference_counter
|
11
|
+
attr_reader :errors, :today, :reference_counter, :currency, :ammount, :payment_details, :payment_charges, :order_reference,
|
12
|
+
:ordering_iban, :ordering_bae, :ordering_name, :ordering_bank_name, :destination_iban, :destination_bae, :destination_name, :destination_bank_name
|
13
|
+
|
14
|
+
def initialize attributes = {}
|
15
|
+
@ordering_account = attributes[:ordering_account]
|
16
|
+
@destination_account = attributes[:destination_account]
|
17
|
+
@payment = attributes[:payment]
|
18
|
+
@payment_system = attributes[:payment_system]
|
19
|
+
@errors = ActiveModel::Errors.new(self)
|
20
|
+
@today = Time.now.strftime('%y%m%d')
|
21
|
+
@reference_counter = 0
|
22
|
+
end
|
23
|
+
|
24
|
+
validate :validate_associated
|
25
|
+
# validates :payment_system, presence: true #, format: {with: /DTYPE|PORD|OPER|RINGS|BISER/}
|
26
|
+
|
27
|
+
def ammount
|
28
|
+
payment.ammount_value.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def currency
|
32
|
+
payment.ammount_currency
|
33
|
+
end
|
34
|
+
|
35
|
+
def destination_bank_name
|
36
|
+
@destination_bank_name = "DESTINATION BANK NAME"
|
37
|
+
end
|
38
|
+
|
39
|
+
def destination_name
|
40
|
+
destination_account.name
|
41
|
+
end
|
42
|
+
|
43
|
+
def destination_iban
|
44
|
+
destination_account.iban
|
45
|
+
end
|
46
|
+
|
47
|
+
def destination_bae
|
48
|
+
destination_account.bae
|
49
|
+
end
|
50
|
+
|
51
|
+
def ordering_bank_name
|
52
|
+
@ordering_bank_name = "ORDERING BANK NAME"
|
53
|
+
end
|
54
|
+
|
55
|
+
def ordering_name
|
56
|
+
ordering_account.name
|
57
|
+
end
|
58
|
+
|
59
|
+
def ordering_bae
|
60
|
+
ordering_account.bae
|
61
|
+
end
|
62
|
+
|
63
|
+
def ordering_iban
|
64
|
+
ordering_account.iban
|
65
|
+
end
|
66
|
+
|
67
|
+
def order_reference
|
68
|
+
@order_reference
|
69
|
+
end
|
70
|
+
|
71
|
+
def payment_details
|
72
|
+
payment.details
|
73
|
+
end
|
74
|
+
|
75
|
+
def payment_charges
|
76
|
+
payment.charges
|
77
|
+
end
|
78
|
+
|
79
|
+
def payment_system
|
80
|
+
@payment_system.is_a?(Array) ? "/#{@payment_system.join("/")}" : "/#{@payment_system}"
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def validate_associated
|
87
|
+
[:ordering_account, :destination_account, :payment].each do |associated|
|
88
|
+
self.errors.add(associated, send(associated).errors.full_messages) unless self.send(associated).valid?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Multicash
|
2
|
+
module Utils
|
3
|
+
|
4
|
+
def print_string value, lenght, fill_with = ''
|
5
|
+
sprintf("%#{fill_with}#{lenght}s", value)
|
6
|
+
end
|
7
|
+
|
8
|
+
def print_number value, lenght
|
9
|
+
sprintf("%#{lenght}d", value)
|
10
|
+
end
|
11
|
+
|
12
|
+
def print_currency value, lenght
|
13
|
+
sprintf("%#{lenght}.2f", value)
|
14
|
+
end
|
15
|
+
|
16
|
+
def print_currency_with_comma value, lenght
|
17
|
+
value = sprintf("%#{lenght}.2f", value)
|
18
|
+
value_with_comma = value.gsub('.', ',')
|
19
|
+
end
|
20
|
+
|
21
|
+
def calc_bae iban
|
22
|
+
iban[4, 8]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/multicash.gemspec
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: multicash 0.0.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "multicash"
|
9
|
+
s.version = "0.0.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = ["Anton Yordanov"]
|
13
|
+
s.date = "2014-02-03"
|
14
|
+
s.description = "Generate payment order under the multicash spec"
|
15
|
+
s.email = "anton.yordnaov@gmail.com"
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"lib/multicash.rb",
|
30
|
+
"lib/multicash/account.rb",
|
31
|
+
"lib/multicash/ammount.rb",
|
32
|
+
"lib/multicash/credit_transfer.rb",
|
33
|
+
"lib/multicash/labels/credit_transfer.rb",
|
34
|
+
"lib/multicash/labels/payment_order.rb",
|
35
|
+
"lib/multicash/payment.rb",
|
36
|
+
"lib/multicash/payment_order.rb",
|
37
|
+
"lib/multicash/transfer.rb",
|
38
|
+
"lib/multicash/transfer_labels_builder.rb",
|
39
|
+
"lib/multicash/utils.rb",
|
40
|
+
"multicash.gemspec",
|
41
|
+
"spec/account_spec.rb",
|
42
|
+
"spec/ammount_spec.rb",
|
43
|
+
"spec/credit_transfer_spec.rb",
|
44
|
+
"spec/fixtures/transfer.yml",
|
45
|
+
"spec/labels/credit_transfer_spec.rb",
|
46
|
+
"spec/payment_order_spec.rb",
|
47
|
+
"spec/payment_spec.rb",
|
48
|
+
"spec/spec_helper.rb",
|
49
|
+
"spec/transfer_spec.rb"
|
50
|
+
]
|
51
|
+
s.homepage = "http://github.com/anotin-yordanov/multicash"
|
52
|
+
s.licenses = ["MIT"]
|
53
|
+
s.require_paths = ["lib"]
|
54
|
+
s.rubygems_version = "2.1.11"
|
55
|
+
s.summary = "Generate payment order under the multicash spec"
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
s.specification_version = 4
|
59
|
+
|
60
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
61
|
+
s.add_runtime_dependency(%q<activemodel>, ["~> 4.0.2"])
|
62
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
64
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
65
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
66
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<activemodel>, ["~> 4.0.2"])
|
69
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
70
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
71
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
72
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
73
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
74
|
+
end
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<activemodel>, ["~> 4.0.2"])
|
77
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
79
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
80
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
81
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Multicash::Account" do
|
4
|
+
let(:account_attributes) {
|
5
|
+
{ name: 'Jonh Doe',
|
6
|
+
city: 'City',
|
7
|
+
address: 'Address',
|
8
|
+
iban: 'BG11UBBS10021041615811',
|
9
|
+
bank_name: 'Bank name'
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
context "validations" do
|
14
|
+
it "valid when required attributes are submited" do
|
15
|
+
expect(Multicash::Account.new(account_attributes)).to be_valid
|
16
|
+
end
|
17
|
+
|
18
|
+
it "not be valid if required attributes are missing" do
|
19
|
+
account_attributes.delete(:iban)
|
20
|
+
expect(Multicash::Account.new(account_attributes)).to_not be_valid
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Multicash::Ammount" do
|
4
|
+
context "validations" do
|
5
|
+
it "valid when all required attributes are submited" do
|
6
|
+
expect(Multicash::Ammount.new(value: 222.12, currency: 'BGN')).to be_valid
|
7
|
+
end
|
8
|
+
|
9
|
+
it "not be valid when currency is not in allowed format" do
|
10
|
+
expect(Multicash::Ammount.new(value: 222.122, currency: 'BGN')).to_not be_valid
|
11
|
+
end
|
12
|
+
|
13
|
+
it "not be valid when currency is not in allowed range" do
|
14
|
+
expect(Multicash::Ammount.new(value: 222.122, currency: 'VVN')).to_not be_valid
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Multicash::CreditTransfer" do
|
4
|
+
let(:ordering_account) { Multicash::Account.new({ name: 'Company',
|
5
|
+
city: 'Ordering City',
|
6
|
+
address: 'Ordering Address',
|
7
|
+
iban: 'BG84UNCR70001521287097',
|
8
|
+
bank_name: 'Bank name'})
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:destination_account) { Multicash::Account.new({ name: 'Jonh Doe',
|
12
|
+
city: 'Destination City',
|
13
|
+
address: 'Destination Address',
|
14
|
+
iban: 'BG84UNCR70001521287097',
|
15
|
+
bank_name: 'Destination Bank name'})
|
16
|
+
}
|
17
|
+
|
18
|
+
let(:ammount) { Multicash::Ammount.new(value: 222.12, currency: 'BGN') }
|
19
|
+
let(:payment) { Multicash::Payment.new( ammount: ammount, details: 'Details', charges: 'SHA') }
|
20
|
+
|
21
|
+
context "validations" do
|
22
|
+
it "valid with correct message_id" do
|
23
|
+
expect(Multicash::CreditTransfer.new(ordering_account: ordering_account,
|
24
|
+
destination_account: destination_account,
|
25
|
+
payment: payment,
|
26
|
+
payment_system: 'BISER')
|
27
|
+
).to be_valid
|
28
|
+
expect(Multicash::CreditTransfer.new(ordering_account: ordering_account,
|
29
|
+
destination_account: destination_account,
|
30
|
+
payment: payment,
|
31
|
+
payment_system: 'BISER').message_id
|
32
|
+
).to eq('CRED')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "generate" do
|
37
|
+
it "correct header" do
|
38
|
+
transfer = Multicash::CreditTransfer.new(ordering_account: ordering_account,
|
39
|
+
destination_account: destination_account,
|
40
|
+
payment: payment,
|
41
|
+
payment_system: 'BISER')
|
42
|
+
|
43
|
+
expect(transfer.header.size).to eq(54)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "correct extended body" do
|
47
|
+
transfer = Multicash::CreditTransfer.new(ordering_account: ordering_account,
|
48
|
+
destination_account: destination_account,
|
49
|
+
payment: payment,
|
50
|
+
payment_system: 'BISER')
|
51
|
+
|
52
|
+
transfer.header + transfer.body
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
transfer:
|
2
|
+
payment_sysytem: BISERA
|
3
|
+
ordering_name: Company name
|
4
|
+
ordering_iban: BG11UNCR70001617678011
|
5
|
+
destination_name: Ivan Ivanov
|
6
|
+
destination_iban: BG11UBBS10021041615811
|
7
|
+
payment_amount: 5000.00
|
8
|
+
currency: BGN
|
9
|
+
payment_details1: Big prize
|
10
|
+
charges: SHA
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# require File.expand_path(File.dirname("../#{__FILE__}") + '/spec_helper')
|
2
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
3
|
+
|
4
|
+
describe "Multicash::Labels::CreditTransfer" do
|
5
|
+
let(:ordering_account) { Multicash::Account.new({ name: 'Jonh Doe',
|
6
|
+
city: 'Ordering City',
|
7
|
+
address: 'Ordering Address',
|
8
|
+
iban: 'BG11UBBS10021041615812',
|
9
|
+
bank_name: 'Bank name'})
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:destination_account) { Multicash::Account.new({ name: 'Jonh Doe',
|
13
|
+
city: 'Destination City',
|
14
|
+
address: 'Destination Address',
|
15
|
+
iban: 'BG11UBBS100210416158115',
|
16
|
+
bank_name: 'Destination Bank name'})
|
17
|
+
}
|
18
|
+
|
19
|
+
let(:ammount) { Multicash::Ammount.new(value: 222.12, currency: 'BGN') }
|
20
|
+
let(:payment) { Multicash::Payment.new(ammount: ammount, details: 'Details', charges: 'SHA') }
|
21
|
+
let(:credit_transfer) { Multicash::CreditTransfer.new(ordering_account: ordering_account,
|
22
|
+
destination_account: destination_account,
|
23
|
+
payment: payment,
|
24
|
+
payment_sysytem: ['BISER'])
|
25
|
+
}
|
26
|
+
|
27
|
+
context "labels" do
|
28
|
+
let(:transfer_labels) { Multicash::Labels::CreditTransfer.new(credit_transfer) }
|
29
|
+
|
30
|
+
specify "label_20" do
|
31
|
+
expect(transfer_labels.label_20.size).to eq(20) # + 4 for label
|
32
|
+
end
|
33
|
+
|
34
|
+
specify "label_23B" do
|
35
|
+
expect(transfer_labels.label_23B.size).to eq(9) # + 4 for label
|
36
|
+
end
|
37
|
+
|
38
|
+
specify "label_32A" do
|
39
|
+
expect(transfer_labels.label_32A.size).to eq(29) # + 4 for label
|
40
|
+
end
|
41
|
+
|
42
|
+
specify "label_50K" do
|
43
|
+
expect(transfer_labels.label_50K.size).to eq(37)
|
44
|
+
end
|
45
|
+
|
46
|
+
specify "label_52D" do
|
47
|
+
expect(transfer_labels.label_52D.size).to eq(76)
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "label_57D" do
|
51
|
+
expect(transfer_labels.label_57D.size).to eq(76)
|
52
|
+
end
|
53
|
+
|
54
|
+
specify "label_59" do
|
55
|
+
expect(transfer_labels.label_59.size).to eq(64) # 4 + 1 + 22 + 1 + 35
|
56
|
+
end
|
57
|
+
|
58
|
+
specify "label_71A" do
|
59
|
+
expect(transfer_labels.label_70.size).to eq(39)
|
60
|
+
end
|
61
|
+
|
62
|
+
specify "label_72" do
|
63
|
+
expect(transfer_labels.label_72.size).to eq(39)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Multicash::PaymentOrder" do
|
4
|
+
let(:ordering_account) { Multicash::Account.new({ name: 'Име на наредителя',
|
5
|
+
city: 'Град на наредителя',
|
6
|
+
address: 'Адрес на наредителя',
|
7
|
+
iban: 'BG84UNCR70001521287097',
|
8
|
+
bank_name: 'Банка на наредителя'})
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:destination_account) { Multicash::Account.new({ name: 'Име на получателя',
|
12
|
+
city: 'Град на получателя',
|
13
|
+
address: 'Адрес на плучателя',
|
14
|
+
iban: 'BG11UBBS100210416158115',
|
15
|
+
bank_name: 'Банка на плучателя'})
|
16
|
+
}
|
17
|
+
|
18
|
+
let(:ammount) { Multicash::Ammount.new(value: 222.12, currency: 'BGN') }
|
19
|
+
let(:payment) { Multicash::Payment.new( ammount: ammount, details: 'Details', charges: 'SHA') }
|
20
|
+
let(:transfer) { Multicash::CreditTransfer.new(ordering_account: ordering_account,
|
21
|
+
destination_account: destination_account,
|
22
|
+
payment: payment,
|
23
|
+
payment_system: 'BISER')
|
24
|
+
}
|
25
|
+
|
26
|
+
context "generate" do
|
27
|
+
subject { Multicash::PaymentOrder.new }
|
28
|
+
|
29
|
+
specify "save to file" do
|
30
|
+
subject << transfer
|
31
|
+
subject << transfer
|
32
|
+
file_name = subject.save_to_file
|
33
|
+
|
34
|
+
|
35
|
+
expect(File.exist?(file_name)).to be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Multicash::Payment" do
|
4
|
+
let(:attributes) {
|
5
|
+
{ ammount: Multicash::Ammount.new(value: 222.12, currency: 'BGN'),
|
6
|
+
details: 'Payment details',
|
7
|
+
charges: 'SHA',
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
context "validations" do
|
12
|
+
it "valid when required attributes are submited" do
|
13
|
+
expect(Multicash::Payment.new(attributes)).to be_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
it "not be valid if ammount is not valid" do
|
17
|
+
attributes[:ammount] = Multicash::Ammount.new(value: 222.12222222, currency: 'BGN')
|
18
|
+
expect(Multicash::Payment.new(attributes)).to_not be_valid
|
19
|
+
end
|
20
|
+
|
21
|
+
it "not be valid if charges are not in allowed range" do
|
22
|
+
attributes[:charges] = 'FRR'
|
23
|
+
expect(Multicash::Payment.new(attributes)).to_not be_valid
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_profile 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
require 'rspec'
|
21
|
+
require 'multicash'
|
22
|
+
|
23
|
+
# Requires supporting files with custom matchers and macros, etc,
|
24
|
+
# in ./support/ and its subdirectories.
|
25
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Multicash::Transfer" do
|
4
|
+
let(:ordering_account) { Multicash::Account.new({ name: 'Jonh Doe',
|
5
|
+
city: 'Ordering City',
|
6
|
+
address: 'Ordering Address',
|
7
|
+
iban: 'BG11UBBS10021041615812',
|
8
|
+
bank_name: 'Bank name'})
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:destination_account) { Multicash::Account.new({ name: 'Jonh Doe',
|
12
|
+
city: 'Destination City',
|
13
|
+
address: 'Destination Address',
|
14
|
+
iban: 'BG11UBBS100210416158115',
|
15
|
+
bank_name: 'Destination Bank name'})
|
16
|
+
}
|
17
|
+
|
18
|
+
let(:ammount) { Multicash::Ammount.new(value: 222.12, currency: 'BGN') }
|
19
|
+
let(:payment) { Multicash::Payment.new( ammount: ammount, details: 'Details', charges: 'SHA') }
|
20
|
+
|
21
|
+
context "validations" do
|
22
|
+
it "valid on valid initilization objects" do
|
23
|
+
expect(Multicash::Transfer.new( ordering_account: ordering_account,
|
24
|
+
destination_account: destination_account,
|
25
|
+
payment: payment,
|
26
|
+
payment_system: ['BISER'])
|
27
|
+
).to be_valid
|
28
|
+
end
|
29
|
+
|
30
|
+
it "invalid on invalid ordering_account" do
|
31
|
+
ordering_account.name = ''
|
32
|
+
|
33
|
+
expect(Multicash::Transfer.new(ordering_account: ordering_account,
|
34
|
+
destination_account: destination_account,
|
35
|
+
payment: payment,
|
36
|
+
payment_system: ['BISER'])
|
37
|
+
).to_not be_valid
|
38
|
+
end
|
39
|
+
|
40
|
+
it "invalid on invalid destination_account" do
|
41
|
+
destination_account.name = ''
|
42
|
+
|
43
|
+
expect(Multicash::Transfer.new(ordering_account: ordering_account,
|
44
|
+
destination_account: destination_account,
|
45
|
+
payment: payment,
|
46
|
+
payment_system: ['BISER'])
|
47
|
+
).to_not be_valid
|
48
|
+
end
|
49
|
+
|
50
|
+
it "invalid on invalid payment" do
|
51
|
+
payment.ammount.value = 'fffff'
|
52
|
+
|
53
|
+
expect(Multicash::Transfer.new(ordering_account: ordering_account,
|
54
|
+
destination_account: destination_account,
|
55
|
+
payment: payment,
|
56
|
+
payment_sysytem: ['BISER'])
|
57
|
+
).to_not be_valid
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multicash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Yordanov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Generate payment order under the multicash spec
|
98
|
+
email: anton.yordnaov@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files:
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.rdoc
|
104
|
+
files:
|
105
|
+
- .document
|
106
|
+
- .rspec
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.rdoc
|
111
|
+
- Rakefile
|
112
|
+
- VERSION
|
113
|
+
- lib/multicash.rb
|
114
|
+
- lib/multicash/account.rb
|
115
|
+
- lib/multicash/ammount.rb
|
116
|
+
- lib/multicash/credit_transfer.rb
|
117
|
+
- lib/multicash/labels/credit_transfer.rb
|
118
|
+
- lib/multicash/labels/payment_order.rb
|
119
|
+
- lib/multicash/payment.rb
|
120
|
+
- lib/multicash/payment_order.rb
|
121
|
+
- lib/multicash/transfer.rb
|
122
|
+
- lib/multicash/transfer_labels_builder.rb
|
123
|
+
- lib/multicash/utils.rb
|
124
|
+
- multicash.gemspec
|
125
|
+
- spec/account_spec.rb
|
126
|
+
- spec/ammount_spec.rb
|
127
|
+
- spec/credit_transfer_spec.rb
|
128
|
+
- spec/fixtures/transfer.yml
|
129
|
+
- spec/labels/credit_transfer_spec.rb
|
130
|
+
- spec/payment_order_spec.rb
|
131
|
+
- spec/payment_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/transfer_spec.rb
|
134
|
+
homepage: http://github.com/anotin-yordanov/multicash
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.1.11
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Generate payment order under the multicash spec
|
158
|
+
test_files: []
|