rspayd 0.0.4 → 0.0.5
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 +7 -0
- data/.travis.yml +8 -0
- data/README.md +2 -0
- data/lib/rspayd.rb +1 -0
- data/lib/rspayd/czech_bank_account_number_parser.rb +39 -0
- data/lib/rspayd/czech_payment.rb +18 -7
- data/lib/rspayd/version.rb +1 -1
- data/test/czech_bank_account_number_parser_test.rb +19 -0
- data/test/czech_payment_test.rb +37 -0
- metadata +54 -69
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 584696a7ebcdad4aca9d23a86532e03805bb1603
|
4
|
+
data.tar.gz: 5146cbf7d11b78c28ad55f69baa30ff841fa8e79
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3975c93c27dbed403a304f41ce47cf594b6499b1141fa00365ff21e6fe73b6d6f30b0b2fc59e64e1b172c3a9ba4af542510ccddb696b3ac9fdbd0646ac74b310
|
7
|
+
data.tar.gz: 2f7bcbf70157458500148a1782fc341d7f24017b98c7fe06a13f02dd028bd9739bf23a8580e9f47fe2b21115686d2b6b7a7f2590af0f38c2107e369f6985cdd1
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Rspayd
|
2
2
|
|
3
|
+
[](https://travis-ci.org/kraxnet/rspayd)
|
4
|
+
|
3
5
|
SPAYD (Short Payment Descriptor) is a format used by CBA (Česká bankovní asociace) for QR Payment (QR Platba). This gem generates payment info in SPAYD format.
|
4
6
|
|
5
7
|
Great for use with ruby QR code gem [rqrcode](http://whomwah.github.com/rqrcode/).
|
data/lib/rspayd.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require File.expand_path(File.join(File.dirname(__FILE__), 'rspayd/version'))
|
3
3
|
require File.expand_path(File.join(File.dirname(__FILE__), 'rspayd/payment'))
|
4
4
|
require File.expand_path(File.join(File.dirname(__FILE__), 'rspayd/czech_payment'))
|
5
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'rspayd/czech_bank_account_number_parser'))
|
5
6
|
|
6
7
|
module Rspayd
|
7
8
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Rspayd
|
4
|
+
class CzechBankAccountNumberParser
|
5
|
+
|
6
|
+
attr_reader :bank_account_number
|
7
|
+
|
8
|
+
def initialize(bank_account_number)
|
9
|
+
@bank_account_number = bank_account_number
|
10
|
+
end
|
11
|
+
|
12
|
+
def bank_code
|
13
|
+
bank_account_number_parts[1].strip
|
14
|
+
end
|
15
|
+
|
16
|
+
def account_prefix
|
17
|
+
if bank_account_number_account_number_parts_reversed[1]
|
18
|
+
bank_account_number_account_number_parts_reversed[1].strip
|
19
|
+
else
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def account_number
|
25
|
+
bank_account_number_account_number_parts_reversed[0].strip
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def bank_account_number_parts
|
31
|
+
bank_account_number.split('/')
|
32
|
+
end
|
33
|
+
|
34
|
+
def bank_account_number_account_number_parts_reversed
|
35
|
+
bank_account_number_parts[0].split('-').reverse
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/lib/rspayd/czech_payment.rb
CHANGED
@@ -13,12 +13,23 @@ module Rspayd
|
|
13
13
|
attr_reader :accountPrefix, :accountNumber, :bankCode, :vs, :ss
|
14
14
|
|
15
15
|
def initialize(options)
|
16
|
-
options = Hash[options.map{|(k,v)| [k.to_sym,v]}]
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
options = Hash[options.map { |(k, v)| [k.to_sym, v] }]
|
17
|
+
|
18
|
+
if options[:accountNumber] && options[:accountNumber].match('/')
|
19
|
+
czech_bank_account_number_parser = CzechBankAccountNumberParser.new(options[:accountNumber])
|
20
|
+
|
21
|
+
@accountPrefix = czech_bank_account_number_parser.account_prefix || ''
|
22
|
+
@accountNumber = czech_bank_account_number_parser.account_number
|
23
|
+
@bankCode = czech_bank_account_number_parser.bank_code
|
24
|
+
else
|
25
|
+
@accountPrefix = options[:accountPrefix] || ''
|
26
|
+
@accountNumber = options[:accountNumber]
|
27
|
+
@bankCode = options[:bankCode]
|
28
|
+
end
|
29
|
+
|
30
|
+
@vs = options[:vs]
|
31
|
+
@ss = options[:ss]
|
32
|
+
|
22
33
|
super
|
23
34
|
end
|
24
35
|
|
@@ -26,7 +37,7 @@ module Rspayd
|
|
26
37
|
def iban
|
27
38
|
return @iban if @iban
|
28
39
|
base = "#{bankCode}#{accountPrefix.rjust(6,'0')}#{accountNumber.rjust(10,'0')}"
|
29
|
-
checksum = 98 - ("#{base}123500".to_i % 97)
|
40
|
+
checksum = (98 - ("#{base}123500".to_i % 97)).to_s.rjust(2,'0')
|
30
41
|
"CZ#{checksum}#{base}"
|
31
42
|
end
|
32
43
|
|
data/lib/rspayd/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CzechBankAccountNumberParserTest < MiniTest::Unit::TestCase
|
4
|
+
def test_bank_account_number_parsing_with_prefix
|
5
|
+
parser = Rspayd::CzechBankAccountNumberParser.new('111222-1122334455/1234')
|
6
|
+
|
7
|
+
assert_equal '111222', parser.account_prefix
|
8
|
+
assert_equal '1122334455', parser.account_number
|
9
|
+
assert_equal '1234', parser.bank_code
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_bank_account_number_parsing_without_prefix
|
13
|
+
parser = Rspayd::CzechBankAccountNumberParser.new('1122334455/1234')
|
14
|
+
|
15
|
+
assert_nil parser.account_prefix
|
16
|
+
assert_equal '1122334455', parser.account_number
|
17
|
+
assert_equal '1234', parser.bank_code
|
18
|
+
end
|
19
|
+
end
|
data/test/czech_payment_test.rb
CHANGED
@@ -13,6 +13,17 @@ class CzechPaymentTest < MiniTest::Unit::TestCase
|
|
13
13
|
assert_equal 'SPD*1.0*ACC:CZ9555000000000810883001*AM:430.00*CC:CZK*MSG:PLATBA ZA DOMENU*X-VS:31030001', result
|
14
14
|
end
|
15
15
|
|
16
|
+
def test_simple_czech_payment_using_full_account_number
|
17
|
+
result = Rspayd::CzechPayment.generate_string(
|
18
|
+
:accountNumber => '810883001/5500',
|
19
|
+
:amount => 430.00,
|
20
|
+
:vs => '31030001',
|
21
|
+
:message => 'Platba za domenu'
|
22
|
+
)
|
23
|
+
|
24
|
+
assert_equal 'SPD*1.0*ACC:CZ9555000000000810883001*AM:430.00*CC:CZK*MSG:PLATBA ZA DOMENU*X-VS:31030001', result
|
25
|
+
end
|
26
|
+
|
16
27
|
def test_czech_payment_with_account_prefix
|
17
28
|
result = Rspayd::CzechPayment.generate_string(
|
18
29
|
:accountPrefix => '7755',
|
@@ -25,6 +36,16 @@ class CzechPaymentTest < MiniTest::Unit::TestCase
|
|
25
36
|
assert_equal 'SPD*1.0*ACC:CZ5607100077550077628031*AM:500.00*CC:CZK*X-VS:1234567890', result
|
26
37
|
end
|
27
38
|
|
39
|
+
def test_czech_payment_with_account_prefix_using_full_account_number
|
40
|
+
result = Rspayd::CzechPayment.generate_string(
|
41
|
+
:accountNumber => '7755-77628031/0710',
|
42
|
+
:amount => 500.00,
|
43
|
+
:vs => '1234567890'
|
44
|
+
)
|
45
|
+
|
46
|
+
assert_equal 'SPD*1.0*ACC:CZ5607100077550077628031*AM:500.00*CC:CZK*X-VS:1234567890', result
|
47
|
+
end
|
48
|
+
|
28
49
|
def test_sample_payment
|
29
50
|
result = Rspayd::CzechPayment.generate_string(
|
30
51
|
:iban => 'CZ5855000000001265098001',
|
@@ -38,4 +59,20 @@ class CzechPaymentTest < MiniTest::Unit::TestCase
|
|
38
59
|
|
39
60
|
assert_equal 'SPD*1.0*ACC:CZ5855000000001265098001*AM:480.50*CC:CZK*RF:7004139146*DT:20120524*MSG:PLATBA ZA ZBOZI*X-SS:1234567890', result
|
40
61
|
end
|
62
|
+
|
63
|
+
def test_iban_checksum_prepend
|
64
|
+
result = Rspayd::CzechPayment.new(
|
65
|
+
:accountNumber => '2950281886',
|
66
|
+
:bankCode => '2010'
|
67
|
+
)
|
68
|
+
assert_equal 'CZ0420100000002950281886', result.iban
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_striping_spaces_from_account_number
|
72
|
+
result = Rspayd::CzechPayment.new(
|
73
|
+
:accountNumber => '1230 - 2950281888 / 2010'
|
74
|
+
)
|
75
|
+
assert_equal 'CZ2920100012302950281888', result.iban
|
76
|
+
end
|
77
|
+
|
41
78
|
end
|
metadata
CHANGED
@@ -1,107 +1,92 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspayd
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 4
|
10
|
-
version: 0.0.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Jiri Kubicek
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
type: :development
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
-
none: false
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 3
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
31
|
-
prerelease: false
|
11
|
+
date: 2014-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
32
14
|
name: rake
|
33
|
-
|
34
|
-
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
35
20
|
type: :development
|
36
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
hash: 3
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
version: "0"
|
45
21
|
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
46
28
|
name: minitest
|
47
|
-
|
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'
|
48
41
|
description: Gem for generating spayd content
|
49
|
-
email:
|
42
|
+
email:
|
50
43
|
- jiri.kubicek@kraxnet.cz
|
51
44
|
executables: []
|
52
|
-
|
53
45
|
extensions: []
|
54
|
-
|
55
46
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
47
|
+
files:
|
58
48
|
- .gitignore
|
49
|
+
- .travis.yml
|
59
50
|
- Gemfile
|
60
51
|
- LICENSE
|
61
52
|
- README.md
|
62
53
|
- Rakefile
|
63
54
|
- lib/rspayd.rb
|
55
|
+
- lib/rspayd/czech_bank_account_number_parser.rb
|
64
56
|
- lib/rspayd/czech_payment.rb
|
65
57
|
- lib/rspayd/payment.rb
|
66
58
|
- lib/rspayd/version.rb
|
67
59
|
- rspayd.gemspec
|
60
|
+
- test/czech_bank_account_number_parser_test.rb
|
68
61
|
- test/czech_payment_test.rb
|
69
62
|
- test/payment_test.rb
|
70
63
|
- test/test_helper.rb
|
71
|
-
homepage:
|
64
|
+
homepage: ''
|
72
65
|
licenses: []
|
73
|
-
|
66
|
+
metadata: {}
|
74
67
|
post_install_message:
|
75
68
|
rdoc_options: []
|
76
|
-
|
77
|
-
require_paths:
|
69
|
+
require_paths:
|
78
70
|
- lib
|
79
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ">="
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
hash: 3
|
94
|
-
segments:
|
95
|
-
- 0
|
96
|
-
version: "0"
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
97
81
|
requirements: []
|
98
|
-
|
99
82
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 2.1.11
|
101
84
|
signing_key:
|
102
|
-
specification_version:
|
103
|
-
summary: SPAYD (Short Payment Descriptor) is a format used by CBA (Ceska bankovni
|
104
|
-
|
85
|
+
specification_version: 4
|
86
|
+
summary: SPAYD (Short Payment Descriptor) is a format used by CBA (Ceska bankovni
|
87
|
+
asociace) for QR Payment (QR Platba). This gem generates payment info in SPAYD format.
|
88
|
+
test_files:
|
89
|
+
- test/czech_bank_account_number_parser_test.rb
|
105
90
|
- test/czech_payment_test.rb
|
106
91
|
- test/payment_test.rb
|
107
92
|
- test/test_helper.rb
|