rspayd 0.0.3 → 0.0.4
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.
- data/README.md +1 -1
- data/Rakefile +10 -0
- data/lib/rspayd/czech_payment.rb +41 -0
- data/lib/rspayd/payment.rb +43 -0
- data/lib/rspayd/version.rb +1 -1
- data/lib/rspayd.rb +2 -48
- data/rspayd.gemspec +3 -0
- data/test/czech_payment_test.rb +41 -0
- data/test/payment_test.rb +17 -0
- data/test/test_helper.rb +4 -0
- metadata +42 -9
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
|
|
27
27
|
:vs=>"31030001",
|
28
28
|
:message => "Platba za domenu"
|
29
29
|
)
|
30
|
-
=> SPD*1.0*
|
30
|
+
=> SPD*1.0*ACC:CZ9555000000000810883001*AM:430.00*CC:CZK*X-VS:31030001*MSG:PLATBA ZA DOMENU
|
31
31
|
|
32
32
|
## Contributing
|
33
33
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Rspayd
|
4
|
+
class CzechPayment < Payment
|
5
|
+
|
6
|
+
# Specifická rozšíření pro ČR:
|
7
|
+
# accountPrefix - Předčíslí čísla účtu, na který se mají poslat prostředky.
|
8
|
+
# accountNumber - Číslo účtu, na který se mají poslat prostředky.
|
9
|
+
# bankCode - Kód banky účtu, na který se mají poslat prostředky.
|
10
|
+
# vs - Variabilní symbol.
|
11
|
+
# ss - Specifický symbol.
|
12
|
+
|
13
|
+
attr_reader :accountPrefix, :accountNumber, :bankCode, :vs, :ss
|
14
|
+
|
15
|
+
def initialize(options)
|
16
|
+
options = Hash[options.map{|(k,v)| [k.to_sym,v]}]
|
17
|
+
@accountPrefix = options[:accountPrefix] || ''
|
18
|
+
@accountNumber = options[:accountNumber]
|
19
|
+
@bankCode = options[:bankCode]
|
20
|
+
@vs = options[:vs]
|
21
|
+
@ss = options[:ss]
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
# generates czech IBAN from accountPrefix, accountNumber and bankCode
|
26
|
+
def iban
|
27
|
+
return @iban if @iban
|
28
|
+
base = "#{bankCode}#{accountPrefix.rjust(6,'0')}#{accountNumber.rjust(10,'0')}"
|
29
|
+
checksum = 98 - ("#{base}123500".to_i % 97)
|
30
|
+
"CZ#{checksum}#{base}"
|
31
|
+
end
|
32
|
+
|
33
|
+
# SPAYD string for payment
|
34
|
+
def to_s
|
35
|
+
out = [ super ]
|
36
|
+
out << "*X-VS:#{vs}" if vs
|
37
|
+
out << "*X-SS:#{ss}" if ss
|
38
|
+
out.join
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
module Rspayd
|
4
|
+
class Payment
|
5
|
+
|
6
|
+
# iban - Číslo účtu, na který se mají poslat prostředky, ve formátu IBAN.
|
7
|
+
# amount - Částka platby.
|
8
|
+
# currency - Měna platby.
|
9
|
+
# rf - Identifikátor platby pro příjemce.
|
10
|
+
# dt - Datum splatnosti.
|
11
|
+
# message - Zpráva pro příjemce.
|
12
|
+
|
13
|
+
attr_reader :iban, :amount, :currency, :rf, :dt, :message
|
14
|
+
|
15
|
+
def initialize(options)
|
16
|
+
options = Hash[options.map{|(k,v)| [k.to_sym,v]}]
|
17
|
+
@iban = options[:iban]
|
18
|
+
@amount = options[:amount]
|
19
|
+
@currency = options[:currency] || 'CZK'
|
20
|
+
@rf = options[:rf]
|
21
|
+
@dt = options[:dt]
|
22
|
+
@message = options[:message]
|
23
|
+
end
|
24
|
+
|
25
|
+
# SPAYD string for payment
|
26
|
+
def to_s
|
27
|
+
out = []
|
28
|
+
out << "SPD*1.0"
|
29
|
+
out << "*ACC:#{iban}"
|
30
|
+
out << "*AM:#{'%.2f' % amount}" if amount
|
31
|
+
out << "*CC:#{currency}" if currency
|
32
|
+
out << "*RF:#{rf}" if rf
|
33
|
+
out << "*DT:#{dt}" if dt
|
34
|
+
out << "*MSG:#{message.upcase}" if message
|
35
|
+
out.join
|
36
|
+
end
|
37
|
+
|
38
|
+
# generates SPAYD string for payment
|
39
|
+
def self.generate_string(options)
|
40
|
+
new(options).to_s
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/rspayd/version.rb
CHANGED
data/lib/rspayd.rb
CHANGED
@@ -1,53 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require File.expand_path(File.join(File.dirname(__FILE__), 'rspayd/version'))
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'rspayd/payment'))
|
4
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'rspayd/czech_payment'))
|
3
5
|
|
4
6
|
module Rspayd
|
5
|
-
class CzechPayment
|
6
|
-
|
7
|
-
# accountPrefix - Předčíslí čísla účtu, na který se mají poslat prostředky.
|
8
|
-
# accountNumber - Číslo účtu, na který se mají poslat prostředky.
|
9
|
-
# bankCode - Kód banky účtu, na který se mají poslat prostředky.
|
10
|
-
# amount - Částka platby.
|
11
|
-
# currency - Měna platby.
|
12
|
-
# vs - Variabilní symbol.
|
13
|
-
# message - Zpráva pro příjemce
|
14
|
-
|
15
|
-
attr_reader :accountPrefix, :accountNumber, :bankCode, :amount, :currency, :vs, :message
|
16
|
-
|
17
|
-
def initialize(options)
|
18
|
-
options = Hash[options.map{|(k,v)| [k.to_sym,v]}]
|
19
|
-
@accountPrefix = options[:accountPrefix] || ''
|
20
|
-
@accountNumber = options[:accountNumber]
|
21
|
-
@bankCode = options[:bankCode]
|
22
|
-
@amount = options[:amount]
|
23
|
-
@currency = options[:currency] || 'CZK'
|
24
|
-
@vs = options[:vs]
|
25
|
-
@message = options[:message]
|
26
|
-
end
|
27
|
-
|
28
|
-
# generates czech IBAN from accountPrefix, accountNumber and bankCode
|
29
|
-
def iban
|
30
|
-
base = "#{bankCode}#{accountPrefix.rjust(6,'0')}#{accountNumber.rjust(10,'0')}"
|
31
|
-
checksum = 98 - ("#{base}123500".to_i % 97)
|
32
|
-
"CZ#{checksum}#{base}"
|
33
|
-
end
|
34
|
-
|
35
|
-
# SPAYD string for payment
|
36
|
-
def to_s
|
37
|
-
out = []
|
38
|
-
out << "SPD*1.0"
|
39
|
-
out << "*ACC:#{iban}"
|
40
|
-
out << "*AM:#{'%.2f' % amount}" if amount
|
41
|
-
out << "*CC:#{currency}" if currency
|
42
|
-
out << "*X-VS:#{vs}" if vs
|
43
|
-
out << "*MSG:#{message.upcase}" if message
|
44
|
-
out.join
|
45
|
-
end
|
46
|
-
|
47
|
-
# generates SPAYD string for payment
|
48
|
-
def self.generate_string(options)
|
49
|
-
new(options).to_s
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
7
|
end
|
data/rspayd.gemspec
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CzechPaymentTest < MiniTest::Unit::TestCase
|
4
|
+
def test_simple_czech_payment
|
5
|
+
result = Rspayd::CzechPayment.generate_string(
|
6
|
+
:accountNumber => '810883001',
|
7
|
+
:bankCode => '5500',
|
8
|
+
:amount => 430.00,
|
9
|
+
:vs => '31030001',
|
10
|
+
:message => 'Platba za domenu'
|
11
|
+
)
|
12
|
+
|
13
|
+
assert_equal 'SPD*1.0*ACC:CZ9555000000000810883001*AM:430.00*CC:CZK*MSG:PLATBA ZA DOMENU*X-VS:31030001', result
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_czech_payment_with_account_prefix
|
17
|
+
result = Rspayd::CzechPayment.generate_string(
|
18
|
+
:accountPrefix => '7755',
|
19
|
+
:accountNumber => '77628031',
|
20
|
+
:bankCode => '0710',
|
21
|
+
:amount => 500.00,
|
22
|
+
:vs => '1234567890'
|
23
|
+
)
|
24
|
+
|
25
|
+
assert_equal 'SPD*1.0*ACC:CZ5607100077550077628031*AM:500.00*CC:CZK*X-VS:1234567890', result
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_sample_payment
|
29
|
+
result = Rspayd::CzechPayment.generate_string(
|
30
|
+
:iban => 'CZ5855000000001265098001',
|
31
|
+
:amount => 480.5,
|
32
|
+
:currency => 'CZK',
|
33
|
+
:rf => '7004139146',
|
34
|
+
:dt => '20120524',
|
35
|
+
:message => 'Platba za zbozi',
|
36
|
+
:ss => 1234567890
|
37
|
+
)
|
38
|
+
|
39
|
+
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
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PaymentTest < MiniTest::Unit::TestCase
|
4
|
+
def test_sample_payment
|
5
|
+
result = Rspayd::Payment.generate_string(
|
6
|
+
:iban => 'CZ5855000000001265098001',
|
7
|
+
:amount => 480.5,
|
8
|
+
:currency => 'CZK',
|
9
|
+
:rf => '7004139146',
|
10
|
+
:dt => '20120524',
|
11
|
+
:message => 'Platba za zbozi'
|
12
|
+
)
|
13
|
+
|
14
|
+
assert_equal 'SPD*1.0*ACC:CZ5855000000001265098001*AM:480.50*CC:CZK*RF:7004139146*DT:20120524*MSG:PLATBA ZA ZBOZI', result
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspayd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jiri Kubicek
|
@@ -15,9 +15,36 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-
|
19
|
-
dependencies:
|
20
|
-
|
18
|
+
date: 2013-08-01 00:00:00 Z
|
19
|
+
dependencies:
|
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
|
32
|
+
name: rake
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
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
|
+
prerelease: false
|
46
|
+
name: minitest
|
47
|
+
version_requirements: *id002
|
21
48
|
description: Gem for generating spayd content
|
22
49
|
email:
|
23
50
|
- jiri.kubicek@kraxnet.cz
|
@@ -34,8 +61,13 @@ files:
|
|
34
61
|
- README.md
|
35
62
|
- Rakefile
|
36
63
|
- lib/rspayd.rb
|
64
|
+
- lib/rspayd/czech_payment.rb
|
65
|
+
- lib/rspayd/payment.rb
|
37
66
|
- lib/rspayd/version.rb
|
38
67
|
- rspayd.gemspec
|
68
|
+
- test/czech_payment_test.rb
|
69
|
+
- test/payment_test.rb
|
70
|
+
- test/test_helper.rb
|
39
71
|
homepage: ""
|
40
72
|
licenses: []
|
41
73
|
|
@@ -69,6 +101,7 @@ rubygems_version: 1.8.17
|
|
69
101
|
signing_key:
|
70
102
|
specification_version: 3
|
71
103
|
summary: SPAYD (Short Payment Descriptor) is a format used by CBA (Ceska bankovni asociace) for QR Payment (QR Platba). This gem generates payment info in SPAYD format.
|
72
|
-
test_files:
|
73
|
-
|
74
|
-
|
104
|
+
test_files:
|
105
|
+
- test/czech_payment_test.rb
|
106
|
+
- test/payment_test.rb
|
107
|
+
- test/test_helper.rb
|