banklink_lv 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +92 -0
- data/README +69 -69
- data/README.rdoc +69 -69
- data/Rakefile +3 -38
- data/banklink_lv.gemspec +27 -20
- data/lib/banklink_lv/banklink.rb +134 -134
- data/lib/banklink_lv/base.rb +8 -8
- data/lib/banklink_lv/helper.rb +112 -110
- data/lib/banklink_lv/notification.rb +166 -166
- data/lib/banklink_lv/swedbank.rb +48 -48
- data/lib/banklink_lv/version.rb +2 -2
- data/lib/banklink_lv.rb +5 -9
- data/pkg/banklink_lv-0.0.3.gem +0 -0
- data/test/banklink_common_test.rb +15 -13
- data/test/banklink_helper_test.rb +22 -20
- data/test/banklink_notification_test.rb +42 -40
- data/test/database.yml +2 -2
- data/test/debug.log +6 -6
- data/test/schema.rb +1 -1
- data/test/string_utf8_test.rb +9 -0
- data/test/test_helper.rb +4 -2
- metadata +88 -50
- data/banklink_lv-1.0.1.gem +0 -0
- data/install.rb +0 -1
- data/lib/app/helpers/banklink_helper.rb +0 -26
- data/lib/banklink_lv/core_ext.rb +0 -730
- data/test/banklink_view_helper_test.rb +0 -17
- data/test/core_ext_test.rb +0 -7
- data/uninstall.rb +0 -1
@@ -1,167 +1,167 @@
|
|
1
|
-
module Banklink
|
2
|
-
|
3
|
-
class Notification
|
4
|
-
include Banklink::Common
|
5
|
-
attr_accessor :params
|
6
|
-
attr_accessor :raw
|
7
|
-
|
8
|
-
# set this to an array in the subclass, to specify which IPs are allowed to send requests
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(post, options = {})
|
12
|
-
@options = options
|
13
|
-
empty!
|
14
|
-
parse(post)
|
15
|
-
end
|
16
|
-
|
17
|
-
def gross_cents
|
18
|
-
(gross.to_f * 100.0).round
|
19
|
-
end
|
20
|
-
|
21
|
-
# This combines the gross and currency and returns a proper Money object.
|
22
|
-
# this requires the money library located at http://dist.leetsoft.com/api/money
|
23
|
-
def amount
|
24
|
-
return gross_cents
|
25
|
-
end
|
26
|
-
|
27
|
-
# reset the notification.
|
28
|
-
def empty!
|
29
|
-
@params = Hash.new
|
30
|
-
@raw = ""
|
31
|
-
end
|
32
|
-
|
33
|
-
# Check if the request comes from an official IP
|
34
|
-
def valid_sender?(ip)
|
35
|
-
return true if Rails.env == :test || production_ips.blank?
|
36
|
-
production_ips.include?(ip)
|
37
|
-
end
|
38
|
-
|
39
|
-
# A helper method to parse the raw post of the request & return
|
40
|
-
# the right Notification subclass based on the sender id.
|
41
|
-
#def self.get_notification(http_raw_data)
|
42
|
-
# params = ActiveMerchant::Billing::Integrations::Notification.new(http_raw_data).params
|
43
|
-
# Banklink.get_class(params)::Notification.new(http_raw_data)
|
44
|
-
#end
|
45
|
-
|
46
|
-
def get_data_string
|
47
|
-
generate_data_string(params['VK_SERVICE'], params)
|
48
|
-
end
|
49
|
-
|
50
|
-
def bank_signature_valid?(bank_signature, service_msg_number, sigparams)
|
51
|
-
SwedbankLv.get_bank_public_key.verify(OpenSSL::Digest::SHA1.new, bank_signature, generate_data_string(service_msg_number, sigparams))
|
52
|
-
end
|
53
|
-
|
54
|
-
def complete?
|
55
|
-
params['VK_SERVICE'] == '1101'
|
56
|
-
end
|
57
|
-
|
58
|
-
def wait?
|
59
|
-
params['VK_SERVICE'] == '1201'
|
60
|
-
end
|
61
|
-
|
62
|
-
def failed?
|
63
|
-
params['VK_SERVICE'] == '1901'
|
64
|
-
end
|
65
|
-
|
66
|
-
def currency
|
67
|
-
params['VK_CURR']
|
68
|
-
end
|
69
|
-
|
70
|
-
# The order id we passed to the form helper.
|
71
|
-
def item_id
|
72
|
-
params['VK_STAMP']
|
73
|
-
end
|
74
|
-
|
75
|
-
def transaction_id
|
76
|
-
params['VK_T_NO']
|
77
|
-
end
|
78
|
-
|
79
|
-
def sender_name
|
80
|
-
params['VK_SND_NAME']
|
81
|
-
end
|
82
|
-
|
83
|
-
def sender_bank_account
|
84
|
-
params['VK_SND_ACC']
|
85
|
-
end
|
86
|
-
|
87
|
-
def reciever_name
|
88
|
-
params['VK_REC_NAME']
|
89
|
-
end
|
90
|
-
|
91
|
-
def reciever_bank_account
|
92
|
-
params['VK_REC_ACC']
|
93
|
-
end
|
94
|
-
|
95
|
-
# When was this payment received by the client.
|
96
|
-
# We're expecting a dd.mm.yyyy format.
|
97
|
-
def received_at
|
98
|
-
date = params['VK_T_DATE']
|
99
|
-
return nil unless date
|
100
|
-
day, month, year = *date.split('.').map(&:to_i)
|
101
|
-
Date.civil(year, month, day)
|
102
|
-
end
|
103
|
-
|
104
|
-
def signature
|
105
|
-
Base64.decode64(params['VK_MAC'])
|
106
|
-
end
|
107
|
-
|
108
|
-
# The money amount we received, string.
|
109
|
-
def gross
|
110
|
-
params['VK_AMOUNT']
|
111
|
-
end
|
112
|
-
|
113
|
-
# Was this a test transaction?
|
114
|
-
def test?
|
115
|
-
params['VK_REC_ID'] == 'testvpos'
|
116
|
-
end
|
117
|
-
|
118
|
-
# TODO what should be here?
|
119
|
-
def status
|
120
|
-
complete? ? 'Completed' : 'Failed'
|
121
|
-
end
|
122
|
-
|
123
|
-
# If our request was sent automatically by the bank (true) or manually
|
124
|
-
# by the user triggering the callback by pressing a "return" button (false).
|
125
|
-
def automatic?
|
126
|
-
params['VK_AUTO'].upcase == 'Y'
|
127
|
-
end
|
128
|
-
|
129
|
-
def success?
|
130
|
-
acknowledge && complete?
|
131
|
-
end
|
132
|
-
|
133
|
-
# We don't actually acknowledge the notification by making another request ourself,
|
134
|
-
# instead, we check the notification by checking the signature that came with the notification.
|
135
|
-
# This method has to be called when handling the notification & deciding whether to process the order.
|
136
|
-
# Example:
|
137
|
-
#
|
138
|
-
# def notify
|
139
|
-
# notify = Notification.new(params)
|
140
|
-
#
|
141
|
-
# if notify.acknowledge
|
142
|
-
# ... process order ... if notify.complete?
|
143
|
-
# else
|
144
|
-
# ... log possible hacking attempt ...
|
145
|
-
# end
|
146
|
-
def acknowledge
|
147
|
-
bank_signature_valid?(signature, params['VK_SERVICE'], params)
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
private
|
152
|
-
|
153
|
-
# Take the posted data and move the relevant data into a hash
|
154
|
-
def parse(post)
|
155
|
-
@raw = post.to_s
|
156
|
-
puts "====== FROM BANK ======"
|
157
|
-
for line in @raw.split('&')
|
158
|
-
key, value = *line.scan( %r{^([A-Za-z0-9_.]+)\=(.*)$} ).flatten
|
159
|
-
params[key] = CGI.unescape(value)
|
160
|
-
|
161
|
-
puts "<#{key}> #{params[key]}"
|
162
|
-
end
|
163
|
-
puts "======================="
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
1
|
+
module Banklink
|
2
|
+
|
3
|
+
class Notification
|
4
|
+
include Banklink::Common
|
5
|
+
attr_accessor :params
|
6
|
+
attr_accessor :raw
|
7
|
+
|
8
|
+
# set this to an array in the subclass, to specify which IPs are allowed to send requests
|
9
|
+
attr_accessor :production_ips
|
10
|
+
|
11
|
+
def initialize(post, options = {})
|
12
|
+
@options = options
|
13
|
+
empty!
|
14
|
+
parse(post)
|
15
|
+
end
|
16
|
+
|
17
|
+
def gross_cents
|
18
|
+
(gross.to_f * 100.0).round
|
19
|
+
end
|
20
|
+
|
21
|
+
# This combines the gross and currency and returns a proper Money object.
|
22
|
+
# this requires the money library located at http://dist.leetsoft.com/api/money
|
23
|
+
def amount
|
24
|
+
return gross_cents
|
25
|
+
end
|
26
|
+
|
27
|
+
# reset the notification.
|
28
|
+
def empty!
|
29
|
+
@params = Hash.new
|
30
|
+
@raw = ""
|
31
|
+
end
|
32
|
+
|
33
|
+
# Check if the request comes from an official IP
|
34
|
+
def valid_sender?(ip)
|
35
|
+
return true if Rails.env == :test || production_ips.blank?
|
36
|
+
production_ips.include?(ip)
|
37
|
+
end
|
38
|
+
|
39
|
+
# A helper method to parse the raw post of the request & return
|
40
|
+
# the right Notification subclass based on the sender id.
|
41
|
+
#def self.get_notification(http_raw_data)
|
42
|
+
# params = ActiveMerchant::Billing::Integrations::Notification.new(http_raw_data).params
|
43
|
+
# Banklink.get_class(params)::Notification.new(http_raw_data)
|
44
|
+
#end
|
45
|
+
|
46
|
+
def get_data_string
|
47
|
+
generate_data_string(params['VK_SERVICE'], params)
|
48
|
+
end
|
49
|
+
|
50
|
+
def bank_signature_valid?(bank_signature, service_msg_number, sigparams)
|
51
|
+
SwedbankLv.get_bank_public_key.verify(OpenSSL::Digest::SHA1.new, bank_signature, generate_data_string(service_msg_number, sigparams))
|
52
|
+
end
|
53
|
+
|
54
|
+
def complete?
|
55
|
+
params['VK_SERVICE'] == '1101'
|
56
|
+
end
|
57
|
+
|
58
|
+
def wait?
|
59
|
+
params['VK_SERVICE'] == '1201'
|
60
|
+
end
|
61
|
+
|
62
|
+
def failed?
|
63
|
+
params['VK_SERVICE'] == '1901'
|
64
|
+
end
|
65
|
+
|
66
|
+
def currency
|
67
|
+
params['VK_CURR']
|
68
|
+
end
|
69
|
+
|
70
|
+
# The order id we passed to the form helper.
|
71
|
+
def item_id
|
72
|
+
params['VK_STAMP']
|
73
|
+
end
|
74
|
+
|
75
|
+
def transaction_id
|
76
|
+
params['VK_T_NO']
|
77
|
+
end
|
78
|
+
|
79
|
+
def sender_name
|
80
|
+
params['VK_SND_NAME']
|
81
|
+
end
|
82
|
+
|
83
|
+
def sender_bank_account
|
84
|
+
params['VK_SND_ACC']
|
85
|
+
end
|
86
|
+
|
87
|
+
def reciever_name
|
88
|
+
params['VK_REC_NAME']
|
89
|
+
end
|
90
|
+
|
91
|
+
def reciever_bank_account
|
92
|
+
params['VK_REC_ACC']
|
93
|
+
end
|
94
|
+
|
95
|
+
# When was this payment received by the client.
|
96
|
+
# We're expecting a dd.mm.yyyy format.
|
97
|
+
def received_at
|
98
|
+
date = params['VK_T_DATE']
|
99
|
+
return nil unless date
|
100
|
+
day, month, year = *date.split('.').map(&:to_i)
|
101
|
+
Date.civil(year, month, day)
|
102
|
+
end
|
103
|
+
|
104
|
+
def signature
|
105
|
+
Base64.decode64(params['VK_MAC'])
|
106
|
+
end
|
107
|
+
|
108
|
+
# The money amount we received, string.
|
109
|
+
def gross
|
110
|
+
params['VK_AMOUNT']
|
111
|
+
end
|
112
|
+
|
113
|
+
# Was this a test transaction?
|
114
|
+
def test?
|
115
|
+
params['VK_REC_ID'] == 'testvpos'
|
116
|
+
end
|
117
|
+
|
118
|
+
# TODO what should be here?
|
119
|
+
def status
|
120
|
+
complete? ? 'Completed' : 'Failed'
|
121
|
+
end
|
122
|
+
|
123
|
+
# If our request was sent automatically by the bank (true) or manually
|
124
|
+
# by the user triggering the callback by pressing a "return" button (false).
|
125
|
+
def automatic?
|
126
|
+
params['VK_AUTO'].upcase == 'Y'
|
127
|
+
end
|
128
|
+
|
129
|
+
def success?
|
130
|
+
acknowledge && complete?
|
131
|
+
end
|
132
|
+
|
133
|
+
# We don't actually acknowledge the notification by making another request ourself,
|
134
|
+
# instead, we check the notification by checking the signature that came with the notification.
|
135
|
+
# This method has to be called when handling the notification & deciding whether to process the order.
|
136
|
+
# Example:
|
137
|
+
#
|
138
|
+
# def notify
|
139
|
+
# notify = Notification.new(params)
|
140
|
+
#
|
141
|
+
# if notify.acknowledge
|
142
|
+
# ... process order ... if notify.complete?
|
143
|
+
# else
|
144
|
+
# ... log possible hacking attempt ...
|
145
|
+
# end
|
146
|
+
def acknowledge
|
147
|
+
bank_signature_valid?(signature, params['VK_SERVICE'], params)
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
# Take the posted data and move the relevant data into a hash
|
154
|
+
def parse(post)
|
155
|
+
@raw = post.to_s
|
156
|
+
puts "====== FROM BANK ======"
|
157
|
+
for line in @raw.split('&')
|
158
|
+
key, value = *line.scan( %r{^([A-Za-z0-9_.]+)\=(.*)$} ).flatten
|
159
|
+
params[key] = CGI.unescape(value)
|
160
|
+
|
161
|
+
puts "<#{key}> #{params[key]}"
|
162
|
+
end
|
163
|
+
puts "======================="
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
167
|
|
data/lib/banklink_lv/swedbank.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
module SwedbankLv
|
2
|
-
|
3
|
-
# Raw X509 certificate of the bank, string format.
|
4
|
-
mattr_accessor :bank_certificate
|
5
|
-
mattr_accessor :test_bank_certificate
|
6
|
-
# RSA public key of the bank, taken from the X509 certificate of the bank. OpenSSL container.
|
7
|
-
def self.get_bank_public_key
|
8
|
-
if Rails.env == 'production'
|
9
|
-
cert = self.bank_certificate
|
10
|
-
else
|
11
|
-
cert = self.test_bank_certificate
|
12
|
-
end
|
13
|
-
OpenSSL::X509::Certificate.new(cert.gsub(/ /, '')).public_key
|
14
|
-
end
|
15
|
-
|
16
|
-
mattr_accessor :private_key
|
17
|
-
mattr_accessor :test_private_key
|
18
|
-
# Our RSA private key. OpenSSL container.
|
19
|
-
def self.get_private_key
|
20
|
-
if Rails.env == 'production'
|
21
|
-
private_key = self.private_key
|
22
|
-
else
|
23
|
-
private_key = self.test_private_key
|
24
|
-
end
|
25
|
-
OpenSSL::PKey::RSA.new(private_key.gsub(/ /, ''))
|
26
|
-
end
|
27
|
-
|
28
|
-
mattr_accessor :test_url
|
29
|
-
mattr_accessor :production_url
|
30
|
-
def self.service_url
|
31
|
-
mode = Rails.env
|
32
|
-
case mode
|
33
|
-
when 'production'
|
34
|
-
self.production_url
|
35
|
-
when 'test'
|
36
|
-
self.test_url
|
37
|
-
when 'development'
|
38
|
-
self.production_url
|
39
|
-
else
|
40
|
-
self.production_url
|
41
|
-
# raise StandardError, "Integration mode set to an invalid value: #{mode}"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.notification(post)
|
46
|
-
Notification.new(post)
|
47
|
-
end
|
48
|
-
|
1
|
+
module SwedbankLv
|
2
|
+
|
3
|
+
# Raw X509 certificate of the bank, string format.
|
4
|
+
mattr_accessor :bank_certificate
|
5
|
+
mattr_accessor :test_bank_certificate
|
6
|
+
# RSA public key of the bank, taken from the X509 certificate of the bank. OpenSSL container.
|
7
|
+
def self.get_bank_public_key
|
8
|
+
if Rails.env == 'production'
|
9
|
+
cert = self.bank_certificate
|
10
|
+
else
|
11
|
+
cert = self.test_bank_certificate
|
12
|
+
end
|
13
|
+
OpenSSL::X509::Certificate.new(cert.gsub(/ /, '')).public_key
|
14
|
+
end
|
15
|
+
|
16
|
+
mattr_accessor :private_key
|
17
|
+
mattr_accessor :test_private_key
|
18
|
+
# Our RSA private key. OpenSSL container.
|
19
|
+
def self.get_private_key
|
20
|
+
if Rails.env == 'production'
|
21
|
+
private_key = self.private_key
|
22
|
+
else
|
23
|
+
private_key = self.test_private_key
|
24
|
+
end
|
25
|
+
OpenSSL::PKey::RSA.new(private_key.gsub(/ /, ''))
|
26
|
+
end
|
27
|
+
|
28
|
+
mattr_accessor :test_url
|
29
|
+
mattr_accessor :production_url
|
30
|
+
def self.service_url
|
31
|
+
mode = Rails.env
|
32
|
+
case mode
|
33
|
+
when 'production'
|
34
|
+
self.production_url
|
35
|
+
when 'test'
|
36
|
+
self.test_url
|
37
|
+
when 'development'
|
38
|
+
self.production_url
|
39
|
+
else
|
40
|
+
self.production_url
|
41
|
+
# raise StandardError, "Integration mode set to an invalid value: #{mode}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.notification(post)
|
46
|
+
Notification.new(post)
|
47
|
+
end
|
48
|
+
|
49
49
|
end
|
data/lib/banklink_lv/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module BanklinkLv
|
2
|
-
VERSION = "0.0.
|
1
|
+
module BanklinkLv
|
2
|
+
VERSION = "0.0.3"
|
3
3
|
end
|
data/lib/banklink_lv.rb
CHANGED
@@ -1,31 +1,27 @@
|
|
1
1
|
require 'banklink_lv/version'
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rails"
|
4
|
+
require "active_support/dependencies"
|
4
5
|
|
5
6
|
require 'net/http'
|
6
7
|
require 'net/https'
|
7
8
|
require 'uri'
|
8
9
|
|
9
10
|
require 'digest'
|
10
|
-
require 'md5'
|
11
|
+
require 'digest/md5'
|
11
12
|
require 'openssl'
|
12
13
|
|
13
|
-
require 'iconv'
|
14
14
|
require 'cgi'
|
15
15
|
|
16
|
-
require 'banklink_lv/core_ext'
|
17
16
|
require 'banklink_lv/banklink'
|
18
17
|
require 'banklink_lv/base'
|
19
18
|
require 'banklink_lv/helper'
|
20
19
|
require 'banklink_lv/swedbank'
|
21
20
|
require 'banklink_lv/notification'
|
22
|
-
require 'app/helpers/banklink_helper'
|
23
|
-
|
24
|
-
#include ActiveSupport
|
25
21
|
|
26
22
|
%w{ models controllers helpers }.each do |dir|
|
27
23
|
path = File.join(File.dirname(__FILE__), 'app', dir)
|
28
24
|
$LOAD_PATH << path
|
29
|
-
#ActiveSupport::Dependencies.load_paths << path
|
30
|
-
#ActiveSupport::Dependencies.load_once_paths.delete(path)
|
25
|
+
# ActiveSupport::Dependencies.load_paths << path
|
26
|
+
# ActiveSupport::Dependencies.load_once_paths.delete(path)
|
31
27
|
end
|
Binary file
|
@@ -1,14 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/test_helper'
|
4
|
+
|
5
|
+
class BanklinkCommonTest < Test::Unit::TestCase
|
6
|
+
include Banklink::Common
|
7
|
+
|
8
|
+
def test_should_decide_string_lenght
|
9
|
+
assert_equal "007", func_p("ĀĒŪĪĻĶŠ")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_generate_data_string
|
13
|
+
assert_equal "003foo003bar003goo006tooboo00510565003LVL003dsa005Āžēīū", generate_data_string(1002, PARAMS_1002)
|
14
|
+
end
|
15
|
+
|
14
16
|
end
|
@@ -1,21 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
options
|
10
|
-
options[:
|
11
|
-
options[:
|
12
|
-
options[:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/test_helper'
|
4
|
+
|
5
|
+
class BanklinkHelperTest < Test::Unit::TestCase
|
6
|
+
include Banklink
|
7
|
+
|
8
|
+
def test_should_create_fields_for_1002
|
9
|
+
options = {}
|
10
|
+
options[:amount] = '1.55'
|
11
|
+
options[:currency] = 'LVL'
|
12
|
+
options[:return] = 'http://default/'
|
13
|
+
options[:reference] = '54'
|
14
|
+
options[:message] = 'Pay for smtx'
|
15
|
+
|
16
|
+
helper = Helper.new(300, '300', options)
|
17
|
+
helper.form_fields.each do |field, value|
|
18
|
+
puts "<#{field}> #{value}"
|
19
|
+
end
|
20
|
+
assert_equal 12, helper.form_fields.size
|
21
|
+
end
|
22
|
+
|
21
23
|
end
|
@@ -1,41 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
assert_equal
|
19
|
-
assert_equal
|
20
|
-
assert_equal
|
21
|
-
assert_equal "
|
22
|
-
assert_equal '
|
23
|
-
assert_equal
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/test_helper'
|
4
|
+
|
5
|
+
class BanklinkNotificationTest < Test::Unit::TestCase
|
6
|
+
include Banklink
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@swedbank = Banklink::Notification.new(http_raw_data)
|
10
|
+
end
|
11
|
+
|
12
|
+
# TODO: fix test
|
13
|
+
def test_acknowledgement
|
14
|
+
assert_equal false, @swedbank.acknowledge
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_accessors
|
18
|
+
assert_equal true, @swedbank.complete?
|
19
|
+
assert_equal 'Completed', @swedbank.status
|
20
|
+
assert_equal "88", @swedbank.item_id
|
21
|
+
assert_equal "2774", @swedbank.transaction_id
|
22
|
+
assert_equal '33', @swedbank.gross
|
23
|
+
assert_equal "EEK", @swedbank.currency
|
24
|
+
assert_equal '26.11.2007', @swedbank.received_at.strftime("%d.%m.%Y")
|
25
|
+
assert_equal true, @swedbank.test?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_compositions
|
29
|
+
assert_equal 3300, @swedbank.amount
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_acknowledgement_fail_with_params_changed
|
33
|
+
@swedbank = Banklink::Notification.new(http_raw_data.gsub('VK_AMOUNT=33', 'VK_AMOUNT=100'))
|
34
|
+
assert_equal false, @swedbank.acknowledge
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def http_raw_data
|
40
|
+
"VK_SERVICE=1101&VK_VERSION=008&VK_SND_ID=EYP&VK_REC_ID=testvpos&VK_STAMP=88&VK_T_NO=2774&VK_AMOUNT=33&VK_CURR=EEK&VK_REC_ACC=10002050618003&VK_REC_NAME=ALLAS+ALLAR&VK_SND_ACC=10010046155012&VK_SND_NAME=t%C3%B5%C3%B5ger+%2C+Le%C3%B5p%C3%A4%C3%B6ld%C5%BE%C5%BD%C5%A1%C5%A0&VK_REF=123&VK_MSG=Porgandid&VK_T_DATE=26.11.2007&VK_MAC=LyCZRncu%2F%2BOi5nwzOkI6C9UMFohN6tSl3tLFyIJyNp2lGKBrDKZ2H8b%2BadU3XalzS7MwnAj8r%2FRhLpbsGNE5ysNyM4CKkSrsVzxoXbt9%2BB1foH9Rlp9LCeoR2H774f8UcMe9RVsE%2B%2BZfrEZzzXYyR1PXDCVOShQOAxlD9pbh8nk%3D&VK_LANG=EST&VK_RETURN=http%3A%2F%2F90.190.110.154%2Fseb_est%2Fnotify&VK_AUTO=N&VK_CHARSET=UTF-8&keel=EST&appname=UN3MIN&act=UPOSTEST2"
|
41
|
+
end
|
42
|
+
|
41
43
|
end
|
data/test/database.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
sqlite:
|
2
|
-
:adapter: sqlite
|
1
|
+
sqlite:
|
2
|
+
:adapter: sqlite
|
3
3
|
:dbfile: vendor/plugins/banklink_lv/test/banklink_lv_plugin.sqlite.db
|
data/test/debug.log
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
[1m[35mSQL (0.0ms)[0m SELECT name
|
2
|
-
FROM sqlite_master
|
3
|
-
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
4
|
-
|
5
|
-
[1m[36mSQL (0.0ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
6
|
-
[1m[35mSQL (80.0ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
1
|
+
[1m[35mSQL (0.0ms)[0m SELECT name
|
2
|
+
FROM sqlite_master
|
3
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
4
|
+
|
5
|
+
[1m[36mSQL (0.0ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
6
|
+
[1m[35mSQL (80.0ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
data/test/schema.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
ActiveRecord::Schema.define(:version => 0) do
|
1
|
+
ActiveRecord::Schema.define(:version => 0) do
|
2
2
|
end
|