banklink_lv 0.0.2

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/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ # Specify your gem's dependencies in banklink_lv.gemspec
2
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Arturs Braucs
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 ADDED
@@ -0,0 +1,70 @@
1
+ = Swedbank Banklink
2
+
3
+ Payment system integration for Latvian banks what uses banklink API.
4
+
5
+ == Supported banks
6
+
7
+ Swedbank (Latvia)
8
+
9
+ == Installation
10
+
11
+ === From Ruby Gems
12
+
13
+ Not yet in RubyGems
14
+
15
+ === From Git
16
+
17
+ Insert this into your Gemfile
18
+
19
+ gem "banklink_lv", :git => 'git://github.com/CreativeMobile/Banklink-LV.git'
20
+
21
+ === Configurations
22
+
23
+ Insert this in your config file:
24
+
25
+ SwedbankLv.private_key = File.read("#{Rails.root}/path/to/your_private_key")
26
+ SwedbankLv.bank_certificate = File.read("#{Rails.root}/path/to/bank_public_key")
27
+ SwedbankLv.production_url = "https://ib.swedbank.lv/banklink"
28
+
29
+ SwedbankLv.test_private_key = File.read("#{Rails.root}/path/to/your_test_private_key")
30
+ SwedbankLv.test_bank_certificate = File.read("#{Rails.root}/path/to/test_bank_public_key")
31
+ SwedbankLv.test_url = "https://ib.swedbank.lv/banklink"
32
+
33
+ Helper for view:
34
+
35
+ options = {}
36
+ options[:amount] = '0.01'
37
+ options[:currency] = 'LVL'
38
+ options[:return] = 'http://yourapp.com/'
39
+ options[:reference] = '454'
40
+ options[:message] = 'Testing banklink'
41
+ @helper = Banklink::Helper.new(TRANS_ID, YOUR_SENDER_ID, options)
42
+
43
+ Then create Notification controller for notify. Then you can notify:
44
+
45
+ notify = Banklink::Notification.new(request.raw_post)
46
+ @text
47
+ if notify.acknowledge
48
+ if notify.complete?
49
+ @text = "Thanks!"
50
+ elsif notify.failed?
51
+ @text = "You didn't paid!"
52
+ else
53
+ @text = "Wait or other status"
54
+ end
55
+ else
56
+ @text = "Stmx went wrong"
57
+ end
58
+
59
+ Thats all!
60
+
61
+
62
+ == Testing
63
+
64
+ You can run the tests from this gem with (inside the banklink_lv directory):
65
+
66
+ rake
67
+
68
+ == Maintainer
69
+
70
+ This gem is maintained by {Arturs Braucs @ Creative Mobile}[mailto:arturs@creo.mobi]
data/README.rdoc ADDED
@@ -0,0 +1,70 @@
1
+ = Swedbank Banklink
2
+
3
+ Payment system integration for Latvian banks what uses banklink API.
4
+
5
+ == Supported banks
6
+
7
+ Swedbank (Latvia)
8
+
9
+ == Installation
10
+
11
+ === From Ruby Gems
12
+
13
+ Not yet in RubyGems
14
+
15
+ === From Git
16
+
17
+ Insert this into your Gemfile
18
+
19
+ gem "banklink_lv", :git => 'git://github.com/CreativeMobile/Banklink-LV.git'
20
+
21
+ === Configurations
22
+
23
+ Insert this in your config file:
24
+
25
+ SwedbankLv.private_key = File.read("#{Rails.root}/path/to/your_private_key")
26
+ SwedbankLv.bank_certificate = File.read("#{Rails.root}/path/to/bank_public_key")
27
+ SwedbankLv.production_url = "https://ib.swedbank.lv/banklink"
28
+
29
+ SwedbankLv.test_private_key = File.read("#{Rails.root}/path/to/your_test_private_key")
30
+ SwedbankLv.test_bank_certificate = File.read("#{Rails.root}/path/to/test_bank_public_key")
31
+ SwedbankLv.test_url = "https://ib.swedbank.lv/banklink"
32
+
33
+ Helper for view:
34
+
35
+ options = {}
36
+ options[:amount] = '0.01'
37
+ options[:currency] = 'LVL'
38
+ options[:return] = 'http://yourapp.com/'
39
+ options[:reference] = '454'
40
+ options[:message] = 'Testing banklink'
41
+ @helper = Banklink::Helper.new(TRANS_ID, YOUR_SENDER_ID, options)
42
+
43
+ Then create Notification controller for notify. Then you can notify:
44
+
45
+ notify = Banklink::Notification.new(request.raw_post)
46
+ @text
47
+ if notify.acknowledge
48
+ if notify.complete?
49
+ @text = "Thanks!"
50
+ elsif notify.failed?
51
+ @text = "You didn't paid!"
52
+ else
53
+ @text = "Wait or other status"
54
+ end
55
+ else
56
+ @text = "Stmx went wrong"
57
+ end
58
+
59
+ Thats all!
60
+
61
+
62
+ == Testing
63
+
64
+ You can run the tests from this gem with (inside the banklink_lv directory):
65
+
66
+ rake
67
+
68
+ == Maintainer
69
+
70
+ This gem is maintained by {Arturs Braucs @ Creative Mobile}[mailto:arturs@creo.mobi]
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/GemPackageTask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the banklink_lv plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
16
+
17
+ desc 'Generate documentation for the banklink_lv plugin.'
18
+ Rake::RDocTask.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'BanklinkLv'
21
+ rdoc.options << '--line-numbers' << '--inline-source'
22
+ rdoc.rdoc_files.include('README')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
25
+
26
+ PKG_FILES = FileList[
27
+ '[a-zA-Z]*',
28
+ 'lib/**/*',
29
+ 'rails/**/*',
30
+ 'tasks/**/*',
31
+ 'test/**/*'
32
+ ]
33
+
34
+ spec = Gem::Specification.new do |s|
35
+ s.name = "banklink_lv"
36
+ s.version = "0.0.1"
37
+ s.author = "Arturs Braucs"
38
+ s.email = "arturs.braucs@gmail.com"
39
+ s.homepage = "http://creo.mobi"
40
+ s.platform = Gem::Platform::RUBY
41
+ s.summary = "Banklink integration in your website without active merchant (Latvia)"
42
+ s.files = PKG_FILES.to_a
43
+ s.require_path = "lib"
44
+ s.has_rdoc = false
45
+ s.extra_rdoc_files = ["README"]
46
+ end
47
+
48
+ desc 'Turn this plugin into a gem.'
49
+ Rake::GemPackageTask.new(spec) do |pkg|
50
+ pkg.gem_spec = spec
51
+ end
Binary file
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "banklink_lv/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "banklink_lv"
7
+ s.version = BanklinkLv::VERSION
8
+ s.author = "Arturs Braucs"
9
+ s.email = "arturs.braucs@gmail.com"
10
+ s.homepage = "https://github.com/CreativeMobile/Banklink-LV"
11
+ s.platform = Gem::Platform::RUBY
12
+ s.summary = "Banklink integration in your website without active merchant (Latvia)"
13
+ s.require_path = "lib"
14
+ s.has_rdoc = false
15
+ s.extra_rdoc_files = ["README"]
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'banklink_lv'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,26 @@
1
+ module Banklink
2
+ module ActionViewHelper
3
+ include Banklink
4
+
5
+ def payment_service_for(order, account, options = {}, &proc)
6
+ raise ArgumentError, "Missing block" unless block_given?
7
+
8
+ result = []
9
+ result << form_tag(SwedbankLv.service_url, options.delete(:html) || {})
10
+
11
+ service = Helper.new(order, account, options)
12
+
13
+ result << capture(service, &proc)
14
+
15
+ service.form_fields.each do |field, value|
16
+ result << hidden_field_tag(field, value)
17
+ end
18
+
19
+ result << '</form>'
20
+ result= result.join("\n")
21
+
22
+ concat(result.respond_to?(:html_safe) ? result.html_safe : result)
23
+ nil
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,135 @@
1
+ module Banklink
2
+
3
+ # Detect bank module from params
4
+ #def self.get_class(params)
5
+ # case params['VK_SND_ID']
6
+ # when 'EYP' then SebEst
7
+ # when 'SAMPOPANK' then SampoEst
8
+ # when 'HP' then SwedbankEst
9
+
10
+ # Swedbank uses same sender id for different countries, currently can't detect Lithuanian
11
+ # use:
12
+ # notify = SwedbankLtu::Notification.new(params)
13
+ #when 'HP' then SwedbankLtu
14
+
15
+ #when '70440' then SebLtu
16
+ #when 'SMPOLT22' then DanskeLtu
17
+ #when 'SNORLT22' then SnorasLtu
18
+ #when '112029720' then DnbnordLtu
19
+ #when '70100' then UbLtu
20
+
21
+ # else raise(ArgumentError, "unknown sender id: #{params['VK_SND_ID']}")
22
+ # end
23
+ #end
24
+
25
+ # Define required fields for each service message.
26
+ # We need to know this in order to calculate VK_MAC
27
+ # from a given hash of parameters.
28
+ # Order of the parameters is important.
29
+ mattr_accessor :required_service_params
30
+ self.required_service_params = {
31
+ 1001 => [
32
+ 'VK_SERVICE',
33
+ 'VK_VERSION',
34
+ 'VK_SND_ID',
35
+ 'VK_STAMP',
36
+ 'VK_AMOUNT',
37
+ 'VK_CURR',
38
+ 'VK_ACC',
39
+ 'VK_NAME',
40
+ 'VK_REF',
41
+ 'VK_MSG'],
42
+ 1002 => [
43
+ 'VK_SERVICE',
44
+ 'VK_VERSION',
45
+ 'VK_SND_ID',
46
+ 'VK_STAMP',
47
+ 'VK_AMOUNT',
48
+ 'VK_CURR',
49
+ 'VK_REF',
50
+ 'VK_MSG' ],
51
+ 1101 => [
52
+ 'VK_SERVICE',
53
+ 'VK_VERSION',
54
+ 'VK_SND_ID',
55
+ 'VK_REC_ID',
56
+ 'VK_STAMP',
57
+ 'VK_T_NO',
58
+ 'VK_AMOUNT',
59
+ 'VK_CURR',
60
+ 'VK_REC_ACC',
61
+ 'VK_REC_NAME',
62
+ 'VK_SND_ACC',
63
+ 'VK_SND_NAME',
64
+ 'VK_REF',
65
+ 'VK_MSG',
66
+ 'VK_T_DATE'],
67
+ 1201 => [
68
+ 'VK_SERVICE',
69
+ 'VK_VERSION',
70
+ 'VK_SND_ID',
71
+ 'VK_REC_ID',
72
+ 'VK_STAMP',
73
+ 'VK_AMOUNT',
74
+ 'VK_CURR',
75
+ 'VK_REC_ACC',
76
+ 'VK_REC_NAME',
77
+ 'VK_SND_ACC',
78
+ 'VK_SND_NAME',
79
+ 'VK_REF',
80
+ 'VK_MSG'],
81
+ 1901 => [
82
+ 'VK_SERVICE',
83
+ 'VK_VERSION',
84
+ 'VK_SND_ID',
85
+ 'VK_REC_ID',
86
+ 'VK_STAMP',
87
+ 'VK_REF',
88
+ 'VK_MSG']
89
+ }
90
+
91
+ # Calculation using method VK_VERSION=008:
92
+ # VK_MAC is RSA signature of the request fields coded into BASE64.
93
+ # VK_MAC will be calculated using secret key of the sender using RSA. Signature will
94
+ # be calculated for string that consists of all field lengths and contents in the query. Also
95
+ # empty fields are used in calculation – lenght “000”. Unnumbered (optional) fields are
96
+ # not used in calculation.
97
+ # MAC(x1,x2,...,xn) := RSA( SHA-1(p(x1 )|| x1|| p(x2 )|| x2 || ... ||p( xn )||xn),d,n)
98
+ # where:
99
+ # || is string concatenation mark
100
+ # x1, x2, ..., xn are parameters of the query
101
+ # p(x) is length of the field x represented by three digits
102
+ # d is RSA secret exponent
103
+ # n is RSA modulus
104
+ module Common
105
+ # p(x) is length of the field x represented by three digits
106
+ def func_p(val)
107
+ sprintf("%03i", val.length_utf8)
108
+ end
109
+
110
+ # Generate a string to be signed out of service message parameters.
111
+ # p(x1 )|| x1|| p(x2 )|| x2 || ... ||p( xn )||xn
112
+ # || is string concatenation mark
113
+ # p(x) is length of the field x represented by three digits
114
+ # Parameters val1, val2, value3 would be turned into:
115
+ # '003val1003val2006value3'
116
+ def generate_data_string(service_msg_number, sigparams)
117
+ str = ''
118
+ Banklink.required_service_params[Integer(service_msg_number)].each do |param|
119
+ val = sigparams[param].to_s # nil goes to ''
120
+ str << func_p(val) << val
121
+ end
122
+ str
123
+ end
124
+
125
+ def generate_signature(service_msg_number, sigparams)
126
+ # privkey = self.class.parent.get_private_key
127
+ privkey = SwedbankLv.get_private_key
128
+ privkey.sign(OpenSSL::Digest::SHA1.new, generate_data_string(service_msg_number, sigparams))
129
+ end
130
+
131
+ def generate_mac(service_msg_number, sigparams)
132
+ Base64.encode64(generate_signature(service_msg_number, sigparams)).gsub(/\n/,'')
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ def to_params
3
+ map{ |k, v| URI.escape("#{k}=#{v}") }.join("&")
4
+ end
5
+ end
6
+
7
+ module BanklinkLv
8
+
9
+ end