ipizza 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/CHANGELOG.md +9 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +16 -14
  6. data/Guardfile +2 -2
  7. data/README.markdown +11 -7
  8. data/Rakefile +1 -1
  9. data/ipizza.gemspec +9 -9
  10. data/lib/ipizza.rb +3 -0
  11. data/lib/ipizza/authentication.rb +15 -0
  12. data/lib/ipizza/authentication_request.rb +1 -1
  13. data/lib/ipizza/authentication_response.rb +22 -9
  14. data/lib/ipizza/config.rb +3 -3
  15. data/lib/ipizza/payment.rb +4 -4
  16. data/lib/ipizza/payment_request.rb +1 -1
  17. data/lib/ipizza/payment_response.rb +15 -7
  18. data/lib/ipizza/provider.rb +8 -12
  19. data/lib/ipizza/provider/base.rb +90 -0
  20. data/lib/ipizza/provider/krediidipank.rb +1 -47
  21. data/lib/ipizza/provider/lhv.rb +4 -0
  22. data/lib/ipizza/provider/nordea/authentication_request.rb +2 -2
  23. data/lib/ipizza/provider/nordea/authentication_response.rb +7 -3
  24. data/lib/ipizza/provider/nordea/payment_request.rb +2 -2
  25. data/lib/ipizza/provider/nordea/payment_response.rb +4 -4
  26. data/lib/ipizza/provider/sampo.rb +1 -46
  27. data/lib/ipizza/provider/seb.rb +1 -78
  28. data/lib/ipizza/provider/swedbank.rb +1 -66
  29. data/lib/ipizza/request.rb +9 -2
  30. data/lib/ipizza/response.rb +7 -9
  31. data/lib/ipizza/util.rb +9 -5
  32. data/lib/ipizza/version.rb +2 -2
  33. data/spec/certificates/pangalink_danske_bank_cert.pem +22 -0
  34. data/spec/certificates/pangalink_danske_bank_key.pem +27 -0
  35. data/spec/certificates/pangalink_danske_user_key.pem +27 -0
  36. data/spec/certificates/pangalink_krediidipank_bank_cert.pem +22 -0
  37. data/spec/certificates/pangalink_krediidipank_bank_key.pem +27 -0
  38. data/spec/certificates/pangalink_krediidipank_user_key.pem +27 -0
  39. data/spec/certificates/pangalink_lhv_bank_cert.pem +22 -0
  40. data/spec/certificates/pangalink_lhv_bank_key.pem +27 -0
  41. data/spec/certificates/pangalink_lhv_user_key.pem +27 -0
  42. data/spec/certificates/pangalink_seb_bank_cert.pem +16 -0
  43. data/spec/certificates/pangalink_seb_bank_key.pem +15 -0
  44. data/spec/certificates/pangalink_seb_user_key.pem +15 -0
  45. data/spec/certificates/pangalink_swedbank_bank_cert.pem +22 -0
  46. data/spec/certificates/pangalink_swedbank_bank_key.pem +27 -0
  47. data/spec/certificates/pangalink_swedbank_user_key.pem +27 -0
  48. data/spec/config/config.yml +39 -6
  49. data/spec/config/plain_config.yml +3 -3
  50. data/spec/ipizza/authentication_response_spec.rb +11 -9
  51. data/spec/ipizza/config_spec.rb +9 -10
  52. data/spec/ipizza/provider/krediidipank_spec.rb +89 -0
  53. data/spec/ipizza/provider/lhv_spec.rb +89 -0
  54. data/spec/ipizza/provider/nordea/authentication_response_spec.rb +3 -3
  55. data/spec/ipizza/provider/sampo_spec.rb +85 -0
  56. data/spec/ipizza/provider/seb_spec.rb +60 -30
  57. data/spec/ipizza/provider/swedbank_spec.rb +63 -34
  58. data/spec/ipizza/provider_spec.rb +9 -1
  59. data/spec/ipizza/util_spec.rb +5 -1
  60. data/spec/spec_helper.rb +1 -1
  61. data/spec/support/pizza.rb +1 -1
  62. metadata +45 -25
  63. data/spec/certificates/bank.crt +0 -21
  64. data/spec/certificates/bank.csr +0 -17
  65. data/spec/certificates/bank.key +0 -27
  66. data/spec/certificates/bank.pub +0 -1
  67. data/spec/certificates/dealer.key +0 -30
  68. data/spec/certificates/dealer.pub +0 -1
  69. data/spec/certificates/seb_test_priv.pem +0 -16
  70. data/spec/certificates/seb_test_pub.crt +0 -20
  71. data/spec/certificates/seb_test_pub.pem +0 -20
  72. data/spec/certificates/swedbank_production.pem +0 -48
@@ -3,7 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
 
4
4
  describe Ipizza::Config do
5
5
  describe '.load_from_file' do
6
-
7
6
  before(:each) do
8
7
  Ipizza::Config.load_from_file(File.expand_path(File.dirname(__FILE__) + '/../config/plain_config.yml'))
9
8
  end
@@ -14,20 +13,20 @@ describe Ipizza::Config do
14
13
  Ipizza::Provider::Swedbank.cancel_url.should == 'http://test.local/cancel'
15
14
  Ipizza::Provider::Swedbank.key_secret.should == 'foobar'
16
15
  Ipizza::Provider::Swedbank.snd_id.should == 'dealer'
17
- Ipizza::Provider::Swedbank.encoding.should == 'ISO-8859-4'
16
+ Ipizza::Provider::Swedbank.encoding.should == 'UTF-8'
18
17
 
19
18
  Ipizza::Provider::Seb.service_url.should == 'https://www.seb.ee/banklink'
20
19
  end
21
20
 
22
21
  it 'should load certificates from path relative to configuration file' do
23
- Ipizza::Provider::Swedbank.file_key.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/dealer.key')
24
- Ipizza::Provider::Swedbank.file_cert.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/bank.pub')
22
+ Ipizza::Provider::Swedbank.file_key.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/pangalink_swedbank_user_key.pem')
23
+ Ipizza::Provider::Swedbank.file_cert.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/pangalink_swedbank_bank_cert.pem')
25
24
  end
26
25
 
27
26
  it 'should load certificates from absolute file paths' do
28
27
  cfg = {'swedbank' => YAML::load_file(File.expand_path(File.dirname(__FILE__) + '/../config/config.yml'))['swedbank']}
29
- cfg['swedbank']['file_key'] = File.expand_path(File.dirname(__FILE__) + '/../certificates/dealer.key')
30
- cfg['swedbank']['file_cert'] = File.expand_path(File.dirname(__FILE__) + '/../certificates/bank.pub')
28
+ cfg['swedbank']['file_key'] = File.expand_path(File.dirname(__FILE__) + '/../certificates/pangalink_swedbank_user_key.pem')
29
+ cfg['swedbank']['file_cert'] = File.expand_path(File.dirname(__FILE__) + '/../certificates/pangalink_swedbank_bank_cert.pem')
31
30
 
32
31
  Tempfile::open('config.yml') do |tmp|
33
32
  tmp << cfg.to_yaml
@@ -35,8 +34,8 @@ describe Ipizza::Config do
35
34
 
36
35
  config = Ipizza::Config.load_from_file(File.expand_path(tmp.path))
37
36
 
38
- Ipizza::Provider::Swedbank.file_key.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/dealer.key')
39
- Ipizza::Provider::Swedbank.file_cert.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/bank.pub')
37
+ Ipizza::Provider::Swedbank.file_key.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/pangalink_swedbank_user_key.pem')
38
+ Ipizza::Provider::Swedbank.file_cert.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/pangalink_swedbank_bank_cert.pem')
40
39
  end
41
40
  end
42
41
  end
@@ -58,10 +57,10 @@ describe Ipizza::Config do
58
57
  it 'loads certificates from directory specified by certs_root' do
59
58
  Ipizza::Config.configure do |c|
60
59
  c.certs_root = File.expand_path(File.dirname(__FILE__) + '/../certificates')
61
- c.swedbank_file_cert = 'seb_test_pub.pem'
60
+ c.swedbank_file_cert = 'pangalink_seb_bank_cert.pem'
62
61
  end
63
62
 
64
- Ipizza::Provider::Swedbank.file_cert.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/seb_test_pub.pem')
63
+ Ipizza::Provider::Swedbank.file_cert.should == File.expand_path(File.dirname(__FILE__) + '/../certificates/pangalink_seb_bank_cert.pem')
65
64
  end
66
65
  end
67
66
  end
@@ -0,0 +1,89 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Ipizza::Provider::Krediidipank do
4
+ let(:response_time) { Ipizza::Util.time_to_iso8601(Time.now) }
5
+ let(:bank_key) { File.expand_path('../../../certificates/pangalink_krediidipank_bank_key.pem', __FILE__) }
6
+
7
+ describe '#payment_request' do
8
+ let(:payment) { Ipizza::Payment.new(stamp: 1, amount: '123.34', refnum: 1, message: 'Payment message', currency: 'EUR') }
9
+
10
+ before(:each) do
11
+ req_time = Time.now
12
+ Time.stub!(:now).and_return(req_time)
13
+ end
14
+
15
+ it 'should sign the request' do
16
+ req = Ipizza::Provider::Krediidipank.new.payment_request(payment)
17
+ params = {
18
+ 'VK_SERVICE' => '1012',
19
+ 'VK_VERSION' => '008',
20
+ 'VK_SND_ID' => Ipizza::Provider::Krediidipank.snd_id,
21
+ 'VK_STAMP' => payment.stamp,
22
+ 'VK_AMOUNT' => sprintf('%.2f', payment.amount),
23
+ 'VK_CURR' => payment.currency,
24
+ 'VK_REF' => Ipizza::Util.sign_731(payment.refnum),
25
+ 'VK_MSG' => payment.message,
26
+ 'VK_RETURN' => Ipizza::Provider::Krediidipank.return_url,
27
+ 'VK_CANCEL' => Ipizza::Provider::Krediidipank.cancel_url,
28
+ 'VK_DATETIME' => Ipizza::Util.time_to_iso8601(Time.now)
29
+ }
30
+ signature = Ipizza::Util.sign(Ipizza::Provider::Krediidipank.file_key, Ipizza::Provider::Krediidipank.key_secret, Ipizza::Util.mac_data_string(params, Ipizza::Request::PARAM_ORDER['1012']))
31
+ req.sign_params['VK_MAC'].should == signature
32
+ end
33
+ end
34
+
35
+ describe '#payment_response' do
36
+ let(:params) {
37
+ {
38
+ 'VK_SERVICE' => '1111', 'VK_VERSION' => '008', 'VK_SND_ID' => 'KREP', 'VK_REC_ID' => 'sender',
39
+ 'VK_STAMP' => '20150111000004', 'VK_T_NO' => '1143', 'VK_AMOUNT' => '.17', 'VK_CURR' => 'EUR',
40
+ 'VK_REC_ACC' => 'EE411010002050618003', 'VK_REC_NAME' => 'ÕILIS OÜ',
41
+ 'VK_SND_ACC' => 'EE541010010046155012', 'VK_SND_NAME' => 'TÕÄGER Leõpäöld¸´¨¦',
42
+ 'VK_REF' => '201501110000048', 'VK_MSG' => 'Invoice #20150111000004', 'VK_T_DATETIME' => response_time,
43
+ 'VK_ENCODING' => 'UTF-8', 'VK_LANG' => 'EST', 'VK_AUTO' => 'N'
44
+ }
45
+ }
46
+
47
+ it 'should parse and verify the payment response from bank' do
48
+ signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['1111']))
49
+ Ipizza::Provider::Krediidipank.new.payment_response(params.merge('VK_MAC' => signature)).should be_valid
50
+ end
51
+ end
52
+
53
+ describe '#authentication_request' do
54
+ before(:each) do
55
+ req_time = Time.now
56
+ Time.stub!(:now).and_return(req_time)
57
+ end
58
+
59
+ it 'should sign the request' do
60
+ req = Ipizza::Provider::Krediidipank.new.authentication_request
61
+ params = {
62
+ 'VK_SERVICE' => '4011',
63
+ 'VK_VERSION' => '008',
64
+ 'VK_SND_ID' => Ipizza::Provider::Krediidipank.snd_id,
65
+ 'VK_RETURN' => Ipizza::Provider::Krediidipank.return_url,
66
+ 'VK_DATETIME' => Ipizza::Util.time_to_iso8601(Time.now),
67
+ 'VK_RID' => '',
68
+ 'VK_REPLY' => '3012'
69
+ }
70
+ signature = Ipizza::Util.sign(Ipizza::Provider::Krediidipank.file_key, Ipizza::Provider::Krediidipank.key_secret, Ipizza::Util.mac_data_string(params, Ipizza::Request::PARAM_ORDER['4011']))
71
+ req.sign_params['VK_MAC'].should == signature
72
+ end
73
+ end
74
+
75
+ describe '#authentication_response' do
76
+ let(:params) {
77
+ {
78
+ 'VK_SERVICE' => '3012', 'VK_VERSION' => '008', 'VK_USER' => 'dealer', 'VK_DATETIME' => response_time,
79
+ 'VK_SND_ID' => 'KREP', 'VK_REC_ID' => 'sender', 'VK_USER_NAME' => 'TÕÄGER Leõpäöld¸´¨¦', 'VK_USER_ID' => '35511280268',
80
+ 'VK_COUNTRY' => 'EE', 'VK_OTHER' => '', 'VK_TOKEN' => '7', 'VK_RID' => ''
81
+ }
82
+ }
83
+
84
+ it 'should parse and verify the authentication response from bank' do
85
+ signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['3012']))
86
+ Ipizza::Provider::Krediidipank.new.authentication_response(params.merge('VK_MAC' => signature)).should be_valid
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,89 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Ipizza::Provider::Lhv do
4
+ let(:response_time) { Ipizza::Util.time_to_iso8601(Time.now) }
5
+ let(:bank_key) { File.expand_path('../../../certificates/pangalink_lhv_bank_key.pem', __FILE__) }
6
+
7
+ describe '#payment_request' do
8
+ let(:payment) { Ipizza::Payment.new(stamp: 1, amount: '123.34', refnum: 1, message: 'Payment message', currency: 'EUR') }
9
+
10
+ before(:each) do
11
+ req_time = Time.now
12
+ Time.stub!(:now).and_return(req_time)
13
+ end
14
+
15
+ it 'should sign the request' do
16
+ req = Ipizza::Provider::Lhv.new.payment_request(payment)
17
+ params = {
18
+ 'VK_SERVICE' => '1012',
19
+ 'VK_VERSION' => '008',
20
+ 'VK_SND_ID' => Ipizza::Provider::Lhv.snd_id,
21
+ 'VK_STAMP' => payment.stamp,
22
+ 'VK_AMOUNT' => sprintf('%.2f', payment.amount),
23
+ 'VK_CURR' => payment.currency,
24
+ 'VK_REF' => Ipizza::Util.sign_731(payment.refnum),
25
+ 'VK_MSG' => payment.message,
26
+ 'VK_RETURN' => Ipizza::Provider::Lhv.return_url,
27
+ 'VK_CANCEL' => Ipizza::Provider::Lhv.cancel_url,
28
+ 'VK_DATETIME' => Ipizza::Util.time_to_iso8601(Time.now)
29
+ }
30
+ signature = Ipizza::Util.sign(Ipizza::Provider::Lhv.file_key, Ipizza::Provider::Lhv.key_secret, Ipizza::Util.mac_data_string(params, Ipizza::Request::PARAM_ORDER['1012']))
31
+ req.sign_params['VK_MAC'].should == signature
32
+ end
33
+ end
34
+
35
+ describe '#payment_response' do
36
+ let(:params) {
37
+ {
38
+ 'VK_SERVICE' => '1111', 'VK_VERSION' => '008', 'VK_SND_ID' => 'LHV', 'VK_REC_ID' => 'sender',
39
+ 'VK_STAMP' => '20150111000004', 'VK_T_NO' => '1143', 'VK_AMOUNT' => '.17', 'VK_CURR' => 'EUR',
40
+ 'VK_REC_ACC' => 'EE411010002050618003', 'VK_REC_NAME' => 'ÕILIS OÜ',
41
+ 'VK_SND_ACC' => 'EE541010010046155012', 'VK_SND_NAME' => 'TÕÄGER Leõpäöld¸´¨¦',
42
+ 'VK_REF' => '201501110000048', 'VK_MSG' => 'Invoice #20150111000004', 'VK_T_DATETIME' => response_time,
43
+ 'VK_ENCODING' => 'UTF-8', 'VK_LANG' => 'EST', 'VK_AUTO' => 'N'
44
+ }
45
+ }
46
+
47
+ it 'should parse and verify the payment response from bank' do
48
+ signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['1111']))
49
+ Ipizza::Provider::Lhv.new.payment_response(params.merge('VK_MAC' => signature)).should be_valid
50
+ end
51
+ end
52
+
53
+ describe '#authentication_request' do
54
+ before(:each) do
55
+ req_time = Time.now
56
+ Time.stub!(:now).and_return(req_time)
57
+ end
58
+
59
+ it 'should sign the request' do
60
+ req = Ipizza::Provider::Lhv.new.authentication_request
61
+ params = {
62
+ 'VK_SERVICE' => '4011',
63
+ 'VK_VERSION' => '008',
64
+ 'VK_SND_ID' => Ipizza::Provider::Lhv.snd_id,
65
+ 'VK_RETURN' => Ipizza::Provider::Lhv.return_url,
66
+ 'VK_DATETIME' => Ipizza::Util.time_to_iso8601(Time.now),
67
+ 'VK_RID' => '',
68
+ 'VK_REPLY' => '3012'
69
+ }
70
+ signature = Ipizza::Util.sign(Ipizza::Provider::Lhv.file_key, Ipizza::Provider::Lhv.key_secret, Ipizza::Util.mac_data_string(params, Ipizza::Request::PARAM_ORDER['4011']))
71
+ req.sign_params['VK_MAC'].should == signature
72
+ end
73
+ end
74
+
75
+ describe '#authentication_response' do
76
+ let(:params) {
77
+ {
78
+ 'VK_SERVICE' => '3012', 'VK_VERSION' => '008', 'VK_USER' => 'dealer', 'VK_DATETIME' => response_time,
79
+ 'VK_SND_ID' => 'LHV', 'VK_REC_ID' => 'sender', 'VK_USER_NAME' => 'TÕÄGER Leõpäöld¸´¨¦', 'VK_USER_ID' => '35511280268',
80
+ 'VK_COUNTRY' => 'EE', 'VK_OTHER' => '', 'VK_TOKEN' => '7', 'VK_RID' => ''
81
+ }
82
+ }
83
+
84
+ it 'should parse and verify the authentication response from bank' do
85
+ signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['3012']))
86
+ Ipizza::Provider::Lhv.new.authentication_response(params.merge('VK_MAC' => signature)).should be_valid
87
+ end
88
+ end
89
+ end
@@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
3
3
  describe Ipizza::Provider::Nordea::AuthenticationResponse do
4
4
  before(:each) do
5
5
  @valid_params = {
6
- "B02K_CUSTNAME" => "Demo kasutaja", "B02K_IDNBR" => "87654321", "B02K_TIMESTMP" => "20020101204145428720",
7
- "B02K_STAMP" => "20101204155339", "B02K_KEYVERS" => "0001", "B02K_MAC" => "A061E22312D7D63FDC2B0B52E16BC971",
8
- "B02K_CUSTTYPE" => "01", "B02K_ALG" => "01", "B02K_CUSTID" => "37404280367", "B02K_VERS" => "0002"
6
+ 'B02K_CUSTNAME' => 'Demo kasutaja', 'B02K_IDNBR' => '87654321', 'B02K_TIMESTMP' => '20020101204145428720',
7
+ 'B02K_STAMP' => '20101204155339', 'B02K_KEYVERS' => '0001', 'B02K_MAC' => 'A061E22312D7D63FDC2B0B52E16BC971',
8
+ 'B02K_CUSTTYPE' => '01', 'B02K_ALG' => '01', 'B02K_CUSTID' => '37404280367', 'B02K_VERS' => '0002'
9
9
  }
10
10
  @response = Ipizza::Provider::Nordea::AuthenticationResponse.new(@valid_params)
11
11
  @response.verify(Ipizza::Provider::Nordea.file_key)
@@ -1,4 +1,89 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  describe Ipizza::Provider::Sampo do
4
+ let(:response_time) { Ipizza::Util.time_to_iso8601(Time.now) }
5
+ let(:bank_key) { File.expand_path('../../../certificates/pangalink_danske_bank_key.pem', __FILE__) }
6
+
7
+ describe '#payment_request' do
8
+ let(:payment) { Ipizza::Payment.new(stamp: 1, amount: '123.34', refnum: 1, message: 'Payment message', currency: 'EUR') }
9
+
10
+ before(:each) do
11
+ req_time = Time.now
12
+ Time.stub!(:now).and_return(req_time)
13
+ end
14
+
15
+ it 'should sign the request' do
16
+ req = Ipizza::Provider::Sampo.new.payment_request(payment)
17
+ params = {
18
+ 'VK_SERVICE' => '1012',
19
+ 'VK_VERSION' => '008',
20
+ 'VK_SND_ID' => Ipizza::Provider::Sampo.snd_id,
21
+ 'VK_STAMP' => payment.stamp,
22
+ 'VK_AMOUNT' => sprintf('%.2f', payment.amount),
23
+ 'VK_CURR' => payment.currency,
24
+ 'VK_REF' => Ipizza::Util.sign_731(payment.refnum),
25
+ 'VK_MSG' => payment.message,
26
+ 'VK_RETURN' => Ipizza::Provider::Sampo.return_url,
27
+ 'VK_CANCEL' => Ipizza::Provider::Sampo.cancel_url,
28
+ 'VK_DATETIME' => Ipizza::Util.time_to_iso8601(Time.now)
29
+ }
30
+ signature = Ipizza::Util.sign(Ipizza::Provider::Sampo.file_key, Ipizza::Provider::Sampo.key_secret, Ipizza::Util.mac_data_string(params, Ipizza::Request::PARAM_ORDER['1012']))
31
+ req.sign_params['VK_MAC'].should == signature
32
+ end
33
+ end
34
+
35
+ describe '#payment_response' do
36
+ let(:params) {
37
+ {
38
+ 'VK_SERVICE' => '1111', 'VK_VERSION' => '008', 'VK_SND_ID' => 'SAMPOPANK', 'VK_REC_ID' => 'sender',
39
+ 'VK_STAMP' => '20150111000004', 'VK_T_NO' => '1143', 'VK_AMOUNT' => '.17', 'VK_CURR' => 'EUR',
40
+ 'VK_REC_ACC' => 'EE411010002050618003', 'VK_REC_NAME' => 'ÕILIS OÜ',
41
+ 'VK_SND_ACC' => 'EE541010010046155012', 'VK_SND_NAME' => 'TÕÄGER Leõpäöld¸´¨¦',
42
+ 'VK_REF' => '201501110000048', 'VK_MSG' => 'Invoice #20150111000004', 'VK_T_DATETIME' => response_time,
43
+ 'VK_ENCODING' => 'UTF-8', 'VK_LANG' => 'EST', 'VK_AUTO' => 'N'
44
+ }
45
+ }
46
+
47
+ it 'should parse and verify the payment response from bank' do
48
+ signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['1111']))
49
+ Ipizza::Provider::Sampo.new.payment_response(params.merge('VK_MAC' => signature)).should be_valid
50
+ end
51
+ end
52
+
53
+ describe '#authentication_request' do
54
+ before(:each) do
55
+ req_time = Time.now
56
+ Time.stub!(:now).and_return(req_time)
57
+ end
58
+
59
+ it 'should sign the request' do
60
+ req = Ipizza::Provider::Sampo.new.authentication_request
61
+ params = {
62
+ 'VK_SERVICE' => '4011',
63
+ 'VK_VERSION' => '008',
64
+ 'VK_SND_ID' => Ipizza::Provider::Sampo.snd_id,
65
+ 'VK_RETURN' => Ipizza::Provider::Sampo.return_url,
66
+ 'VK_DATETIME' => Ipizza::Util.time_to_iso8601(Time.now),
67
+ 'VK_RID' => '',
68
+ 'VK_REPLY' => '3012'
69
+ }
70
+ signature = Ipizza::Util.sign(Ipizza::Provider::Sampo.file_key, Ipizza::Provider::Sampo.key_secret, Ipizza::Util.mac_data_string(params, Ipizza::Request::PARAM_ORDER['4011']))
71
+ req.sign_params['VK_MAC'].should == signature
72
+ end
73
+ end
74
+
75
+ describe '#authentication_response' do
76
+ let(:params) {
77
+ {
78
+ 'VK_SERVICE' => '3012', 'VK_VERSION' => '008', 'VK_USER' => 'dealer', 'VK_DATETIME' => response_time,
79
+ 'VK_SND_ID' => 'SAMPOPANK', 'VK_REC_ID' => 'sender', 'VK_USER_NAME' => 'TÕÄGER Leõpäöld¸´¨¦', 'VK_USER_ID' => '35511280268',
80
+ 'VK_COUNTRY' => 'EE', 'VK_OTHER' => '', 'VK_TOKEN' => '7', 'VK_RID' => ''
81
+ }
82
+ }
83
+
84
+ it 'should parse and verify the authentication response from bank' do
85
+ signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['3012']))
86
+ Ipizza::Provider::Sampo.new.authentication_response(params.merge('VK_MAC' => signature)).should be_valid
87
+ end
88
+ end
4
89
  end
@@ -1,59 +1,89 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  describe Ipizza::Provider::Seb do
4
+ let(:response_time) { Ipizza::Util.time_to_iso8601(Time.now) }
5
+ let(:bank_key) { File.expand_path('../../../certificates/pangalink_seb_bank_key.pem', __FILE__) }
6
+
4
7
  describe '#payment_request' do
5
-
8
+ let(:payment) { Ipizza::Payment.new(stamp: 1, amount: '123.34', refnum: 1, message: 'Payment message', currency: 'EUR') }
9
+
6
10
  before(:each) do
7
- @payment = Ipizza::Payment.new(:stamp => 1, :amount => '123.34', :refnum => 1, :message => 'Payment message', :currency => 'EUR')
11
+ req_time = Time.now
12
+ Time.stub!(:now).and_return(req_time)
8
13
  end
9
-
14
+
10
15
  it 'should sign the request' do
11
- req = Ipizza::Provider::Seb.new.payment_request(@payment)
12
- req.sign_params['VK_MAC'].should == 'aVCFvsLJiczQw9VoYMdtoQKj5fXkP8OI+JfQN8bFGKZGxC/X5gVIIi/Bh9AyB6JXwbeMOfUlnvuJIukpmBpDg3dEWkv4xGwKdfacqwYkgSC17OBb7VmZ+B4d6HYaO088wxH1FBSVa87HKFJ7ScTEJfd3ZEZly9WzTPHiFWvpRGDxAYtuO5nfGMcscxOQ0B0cbrIcLKvqLho25hIgns3+lvRDWsOb9lFH//7U8OBOC9SuXCBwvC4Fng3wqmBSKRJgAqvQ40Y4XpBGt3U/ix26Vs1cP8lOGHUyqzrqKbcmvqqhgWzqpa0JoK6im/MhBePyNnHVoC8Pqw4ZwZb4YrrPXw=='
16
+ req = Ipizza::Provider::Seb.new.payment_request(payment)
17
+ params = {
18
+ 'VK_SERVICE' => '1012',
19
+ 'VK_VERSION' => '008',
20
+ 'VK_SND_ID' => Ipizza::Provider::Seb.snd_id,
21
+ 'VK_STAMP' => payment.stamp,
22
+ 'VK_AMOUNT' => sprintf('%.2f', payment.amount),
23
+ 'VK_CURR' => payment.currency,
24
+ 'VK_REF' => Ipizza::Util.sign_731(payment.refnum),
25
+ 'VK_MSG' => payment.message,
26
+ 'VK_RETURN' => Ipizza::Provider::Seb.return_url,
27
+ 'VK_CANCEL' => Ipizza::Provider::Seb.cancel_url,
28
+ 'VK_DATETIME' => Ipizza::Util.time_to_iso8601(Time.now)
29
+ }
30
+ signature = Ipizza::Util.sign(Ipizza::Provider::Seb.file_key, Ipizza::Provider::Seb.key_secret, Ipizza::Util.mac_data_string(params, Ipizza::Request::PARAM_ORDER['1012']))
31
+ req.sign_params['VK_MAC'].should == signature
13
32
  end
14
33
  end
15
34
 
16
35
  describe '#payment_response' do
17
- before(:each) do
18
- @params = {
19
- 'VK_T_NO' => '1143', 'VK_REF' => '201107010000048', 'VK_SND_NAME' => 'TÕÄGER Leõpäöld¸´¨¦', 'VK_REC_ID' => 'testvpos',
20
- 'appname' => 'UN3MIN', 'keel' => 'EST', 'VK_T_DATE' => '01.07.2011', 'VK_SND_ACC' => '10010046155012', 'VK_STAMP' => '20110701000004',
21
- 'VK_CHARSET' => 'UTF-8', 'VK_RETURN' => 'https://store.kraftal.com/return/seb', 'VK_LANG' => '', 'VK_REC_NAME' => 'ALLAS ALLAR',
22
- 'VK_AMOUNT' => '.17', 'VK_SERVICE' => '1101', 'VK_AUTO' => 'N', 'VK_MSG' => 'Edicy invoice #20110701000004', 'act' => 'UPOSTEST2',
23
- 'VK_SND_ID' => 'EYP', 'VK_VERSION' => '008', 'VK_REC_ACC' => '10002050618003', 'VK_CURR' => 'EUR',
24
- 'VK_MAC' => 'fj7moIwqMbvhmftFs5/5muOD1Dj5sRIlTUUcXGbzNKGFCrRz/N2ZpprFlO+8el7BNnGAoqCc2b4V2BrJ5XRsyYtLy1Gi4W8eSqwxbjBefDo21PFXpTmXYYJVy98fIWmWhOIBPMnEq6BlVf100GlV1C3OL+2mBU/ZjtPQG+B7OHo='
36
+ let(:params) {
37
+ {
38
+ 'VK_SERVICE' => '1111', 'VK_VERSION' => '008', 'VK_SND_ID' => 'EYP', 'VK_REC_ID' => 'sender',
39
+ 'VK_STAMP' => '20150111000004', 'VK_T_NO' => '1143', 'VK_AMOUNT' => '.17', 'VK_CURR' => 'EUR',
40
+ 'VK_REC_ACC' => 'EE411010002050618003', 'VK_REC_NAME' => 'ÕILIS ',
41
+ 'VK_SND_ACC' => 'EE541010010046155012', 'VK_SND_NAME' => 'TÕÄGER Leõpäöld¸´¨¦',
42
+ 'VK_REF' => '201501110000048', 'VK_MSG' => 'Invoice #20150111000004', 'VK_T_DATETIME' => response_time,
43
+ 'VK_ENCODING' => 'UTF-8', 'VK_LANG' => 'EST', 'VK_AUTO' => 'N'
25
44
  }
26
- end
27
-
45
+ }
46
+
28
47
  it 'should parse and verify the payment response from bank' do
29
- Ipizza::Provider::Seb.new.payment_response(@params).should be_valid
48
+ signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['1111']))
49
+ Ipizza::Provider::Seb.new.payment_response(params.merge('VK_MAC' => signature)).should be_valid
30
50
  end
31
51
  end
32
52
 
33
53
  describe '#authentication_request' do
34
54
  before(:each) do
35
- Time.stub!(:now).and_return(Time.parse('Mar 30 1981'))
36
- Date.stub!(:today).and_return(Date.parse('Mar 30 1981'))
55
+ req_time = Time.now
56
+ Time.stub!(:now).and_return(req_time)
37
57
  end
38
-
58
+
39
59
  it 'should sign the request' do
40
60
  req = Ipizza::Provider::Seb.new.authentication_request
41
- req.sign_params['VK_MAC'].should == '0ZBLzC3XddTNZ4YBNJlPsJ/RDK4g7Utot9L3lvaxD9J0dfKfN4FUnife3oAQjhyc8lOi5MeBdjekN5mW7KXEMcOSTR9kCJTLZcJg1nMHTDjZcLu9FTAk2wcSrc8kUgigh22vBA38wQfbsZvong5ETYanH8RchZUp72tmO2rFmKzdD8bsnubg6l3m5NxoFv+2F6RsxzwtpkCNaKBpIH4iyWIYFWX7H3hTiUWlAXwKp8GP8OYPr1wUDbP2jVxOwpv7MW3g/heKfu3INBSazsvD22WhsNeKPKmqjJDIiJvo5QRhYq5Shze28oWQyCixMfw2UW7pk0gOtYJkrlwEEo22zQ=='
61
+ params = {
62
+ 'VK_SERVICE' => '4011',
63
+ 'VK_VERSION' => '008',
64
+ 'VK_SND_ID' => Ipizza::Provider::Seb.snd_id,
65
+ 'VK_RETURN' => Ipizza::Provider::Seb.return_url,
66
+ 'VK_DATETIME' => Ipizza::Util.time_to_iso8601(Time.now),
67
+ 'VK_RID' => '',
68
+ 'VK_REPLY' => '3012'
69
+ }
70
+ signature = Ipizza::Util.sign(Ipizza::Provider::Seb.file_key, Ipizza::Provider::Seb.key_secret, Ipizza::Util.mac_data_string(params, Ipizza::Request::PARAM_ORDER['4011']))
71
+ req.sign_params['VK_MAC'].should == signature
42
72
  end
43
73
  end
44
74
 
45
75
  describe '#authentication_response' do
46
- before(:each) do
47
- @params = {
48
- 'VK_TIME' => '00:56:37', 'VK_USER' => '', 'VK_INFO' => 'NIMI:tõõger , LeõpäöldžŽšŠ;ISIK:35511280268',
49
- 'VK_DATE' => '24.10.2010', 'VK_CHARSET' => 'UTF-8', 'VK_RETURN' => 'http://rkas-aktide-is.local/ipizza/auth',
50
- 'VK_LANG' => 'EST', 'VK_SERVICE'=>'3002', 'VK_RID' => '', 'VK_SND_ID' => 'EYP', 'VK_VERSION' => '008',
51
- 'VK_MAC' => 'BeYfkTTj9HNCoMSVbBHSYujFpdcPfo3Ee56ZwaHzYwLj3/QMsb3b5cA7Z1GjeW2VLIoWVtOZmjWN9N74NtH7mu0Nv3RUYep6DJcsZvejs9uklpCLFS1bzInGlQKh3Q04Vttss6dLxgoRJu7lT3hvPKUPHtBZ2RZMHByLuwqNqC4='
76
+ let(:params) {
77
+ {
78
+ 'VK_SERVICE' => '3012', 'VK_VERSION' => '008', 'VK_USER' => 'dealer', 'VK_DATETIME' => response_time,
79
+ 'VK_SND_ID' => 'EYP', 'VK_REC_ID' => 'sender', 'VK_USER_NAME' => 'TÕÄGER Leõpäöld¸´¨¦', 'VK_USER_ID' => '35511280268',
80
+ 'VK_COUNTRY' => 'EE', 'VK_OTHER' => '', 'VK_TOKEN' => '7', 'VK_RID' => ''
52
81
  }
53
- end
54
-
82
+ }
83
+
55
84
  it 'should parse and verify the authentication response from bank' do
56
- Ipizza::Provider::Seb.new.authentication_response(@params).should be_valid
85
+ signature = Ipizza::Util.sign(bank_key, nil, Ipizza::Util.mac_data_string(params, Ipizza::Response::PARAM_ORDER['3012']))
86
+ Ipizza::Provider::Seb.new.authentication_response(params.merge('VK_MAC' => signature)).should be_valid
57
87
  end
58
88
  end
59
- end
89
+ end