adyen 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -3
- data/adyen.gemspec +2 -2
- data/lib/adyen/form.rb +29 -2
- data/spec/form_spec.rb +23 -18
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -15,10 +15,14 @@ automated test suite to assert the integration is working correctly.
|
|
15
15
|
|
16
16
|
== Installation
|
17
17
|
|
18
|
-
|
18
|
+
Add the following line to your <tt>environment.rb</tt> and run <tt>rake gems:install</tt>
|
19
|
+
to make the Adyen functionality available in your Rails project:
|
19
20
|
|
20
|
-
gem
|
21
|
-
|
21
|
+
config.gem 'adyen', :source => 'http://gemcutter.org
|
22
|
+
|
23
|
+
You can also install it as a Rails plugin (*deprecated*):
|
24
|
+
|
25
|
+
script/plugin install git://github.com/wvanbergen/adyen.git
|
22
26
|
|
23
27
|
== Usage
|
24
28
|
|
data/adyen.gemspec
CHANGED
data/lib/adyen/form.rb
CHANGED
@@ -5,6 +5,22 @@ module Adyen
|
|
5
5
|
|
6
6
|
extend ActionView::Helpers::TagHelper
|
7
7
|
|
8
|
+
def self.skins
|
9
|
+
@skins ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.add_skin(name, skin_code, shared_secret)
|
13
|
+
self.skins[name] = {:name => name, :skin_code => skin_code, :shared_secret => shared_secret }
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.skin_by_name(skin_name)
|
17
|
+
self.skins[skin_name]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.skin_by_code(skin_code)
|
21
|
+
self.skins.detect { |(name, skin)| skin[:skin_code] == skin_code }.last rescue nil
|
22
|
+
end
|
23
|
+
|
8
24
|
ACTION_URL = "https://%s.adyen.com/hpp/select.shtml"
|
9
25
|
|
10
26
|
def self.url(environment = nil)
|
@@ -34,6 +50,12 @@ module Adyen
|
|
34
50
|
attributes[:order_data] = Adyen::Encoding.gzip_base64(attributes.delete(:order_data_raw)) if attributes[:order_data_raw]
|
35
51
|
attributes[:ship_before_date] = Adyen::Formatter::DateTime.fmt_date(attributes[:ship_before_date])
|
36
52
|
attributes[:session_validity] = Adyen::Formatter::DateTime.fmt_time(attributes[:session_validity])
|
53
|
+
|
54
|
+
if attributes[:skin]
|
55
|
+
skin = Adyen::Form.skin_by_name(attributes.delete(:skin))
|
56
|
+
attributes[:skin_code] ||= skin[:skin_code]
|
57
|
+
attributes[:shared_secret] ||= skin[:shared_secret]
|
58
|
+
end
|
37
59
|
end
|
38
60
|
|
39
61
|
def self.payment_fields(attributes = {})
|
@@ -60,16 +82,21 @@ module Adyen
|
|
60
82
|
self.tag(:input, :type => 'hidden', :name => key.to_s.camelize(:lower), :value => value)
|
61
83
|
}.join("\n")
|
62
84
|
end
|
85
|
+
|
86
|
+
def self.lookup_shared_secret(skin_code)
|
87
|
+
skin = skin_by_code(skin_code)[:shared_secret] rescue nil
|
88
|
+
end
|
63
89
|
|
64
90
|
def self.redirect_signature_string(params)
|
65
91
|
params[:authResult].to_s + params[:pspReference].to_s + params[:merchantReference].to_s + params[:skinCode].to_s
|
66
92
|
end
|
67
93
|
|
68
|
-
def self.redirect_signature(params, shared_secret)
|
94
|
+
def self.redirect_signature(params, shared_secret = nil)
|
95
|
+
shared_secret ||= lookup_shared_secret(params[:skinCode])
|
69
96
|
Adyen::Encoding.hmac_base64(shared_secret, redirect_signature_string(params))
|
70
97
|
end
|
71
98
|
|
72
|
-
def self.redirect_signature_check(params, shared_secret)
|
99
|
+
def self.redirect_signature_check(params, shared_secret = nil)
|
73
100
|
params[:merchantSig] == redirect_signature(params, shared_secret)
|
74
101
|
end
|
75
102
|
|
data/spec/form_spec.rb
CHANGED
@@ -2,6 +2,10 @@ require "#{File.dirname(__FILE__)}/spec_helper.rb"
|
|
2
2
|
|
3
3
|
describe Adyen::Form do
|
4
4
|
|
5
|
+
before(:all) do
|
6
|
+
Adyen::Form.add_skin(:testing, '4aD37dJA', 'Kah942*$7sdp0)')
|
7
|
+
end
|
8
|
+
|
5
9
|
describe 'Action URLs' do
|
6
10
|
|
7
11
|
before(:each) do
|
@@ -32,9 +36,6 @@ describe Adyen::Form do
|
|
32
36
|
before(:each) do
|
33
37
|
# Example taken from integration manual
|
34
38
|
|
35
|
-
# Shared secret between you and Adyen, only valid for this skinCode!
|
36
|
-
@shared_secret = 'Kah942*$7sdp0)'
|
37
|
-
|
38
39
|
# Example get params sent back with redirect
|
39
40
|
@params = { :authResult => 'AUTHORISED', :pspReference => '1211992213193029',
|
40
41
|
:merchantReference => 'Internet Order 12345', :skinCode => '4aD37dJA',
|
@@ -46,19 +47,24 @@ describe Adyen::Form do
|
|
46
47
|
end
|
47
48
|
|
48
49
|
it "should calculate the signature correctly" do
|
49
|
-
Adyen::Form.redirect_signature(@params
|
50
|
+
Adyen::Form.redirect_signature(@params).should eql(@params[:merchantSig])
|
50
51
|
end
|
51
52
|
|
52
|
-
it "should check the signature correctly" do
|
53
|
-
Adyen::Form.redirect_signature_check(@params,
|
53
|
+
it "should check the signature correctly with explicit shared signature" do
|
54
|
+
Adyen::Form.redirect_signature_check(@params, 'Kah942*$7sdp0)').should be_true
|
54
55
|
end
|
55
56
|
|
57
|
+
it "should check the signature correctly using the stored shared secret" do
|
58
|
+
Adyen::Form.redirect_signature_check(@params).should be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
|
56
62
|
it "should detect a tampered field" do
|
57
|
-
Adyen::Form.redirect_signature_check(@params.merge(:pspReference => 'tampered')
|
63
|
+
Adyen::Form.redirect_signature_check(@params.merge(:pspReference => 'tampered')).should be_false
|
58
64
|
end
|
59
65
|
|
60
66
|
it "should detect a tampered signature" do
|
61
|
-
Adyen::Form.redirect_signature_check(@params.merge(:merchantSig => 'tampered')
|
67
|
+
Adyen::Form.redirect_signature_check(@params.merge(:merchantSig => 'tampered')).should be_false
|
62
68
|
end
|
63
69
|
|
64
70
|
end
|
@@ -66,10 +72,10 @@ describe Adyen::Form do
|
|
66
72
|
describe 'redirect URL generation' do
|
67
73
|
before(:each) do
|
68
74
|
@attributes = { :currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.today,
|
69
|
-
:merchant_reference => 'Internet Order 12345', :
|
75
|
+
:merchant_reference => 'Internet Order 12345', :skin => :testing,
|
70
76
|
:merchant_account => 'TestMerchant', :session_validity => 1.hour.from_now }
|
71
77
|
|
72
|
-
@redirect_url = Adyen::Form.redirect_url(@attributes
|
78
|
+
@redirect_url = Adyen::Form.redirect_url(@attributes)
|
73
79
|
end
|
74
80
|
|
75
81
|
it "should return an URL pointing to the adyen server" do
|
@@ -93,12 +99,12 @@ describe Adyen::Form do
|
|
93
99
|
|
94
100
|
before(:each) do
|
95
101
|
@attributes = { :currency_code => 'GBP', :payment_amount => 10000, :ship_before_date => Date.today,
|
96
|
-
:merchant_reference => 'Internet Order 12345', :
|
102
|
+
:merchant_reference => 'Internet Order 12345', :skin => :testing,
|
97
103
|
:merchant_account => 'TestMerchant', :session_validity => 1.hour.from_now }
|
98
104
|
end
|
99
105
|
|
100
106
|
it "should generate a valid payment form" do
|
101
|
-
content_tag(:form, Adyen::Form.hidden_fields(@attributes
|
107
|
+
content_tag(:form, Adyen::Form.hidden_fields(@attributes),
|
102
108
|
:action => Adyen::Form.url, :method => :post).should have_adyen_payment_form
|
103
109
|
end
|
104
110
|
end
|
@@ -108,9 +114,10 @@ describe Adyen::Form do
|
|
108
114
|
# This example is taken from the Adyen integration manual
|
109
115
|
|
110
116
|
before(:each) do
|
117
|
+
|
111
118
|
@attributes = { :currency_code => 'GBP', :payment_amount => 10000,
|
112
119
|
:ship_before_date => '2007-10-20', :merchant_reference => 'Internet Order 12345',
|
113
|
-
:
|
120
|
+
:skin => :testing, :merchant_account => 'TestMerchant',
|
114
121
|
:session_validity => '2007-10-11T11:00:00Z' }
|
115
122
|
|
116
123
|
Adyen::Form.do_attribute_transformations!(@attributes)
|
@@ -120,9 +127,9 @@ describe Adyen::Form do
|
|
120
127
|
signature_string = Adyen::Form.calculate_signature_string(@attributes)
|
121
128
|
signature_string.should eql("10000GBP2007-10-20Internet Order 123454aD37dJATestMerchant2007-10-11T11:00:00Z")
|
122
129
|
end
|
123
|
-
|
130
|
+
|
124
131
|
it "should calculate the signature correctly" do
|
125
|
-
signature = Adyen::Form.calculate_signature(@attributes
|
132
|
+
signature = Adyen::Form.calculate_signature(@attributes)
|
126
133
|
signature.should eql('x58ZcRVL1H6y+XSeBGrySJ9ACVo=')
|
127
134
|
end
|
128
135
|
|
@@ -138,10 +145,8 @@ describe Adyen::Form do
|
|
138
145
|
# Add the required recurrent payment attributes
|
139
146
|
@attributes.merge!(:recurring_contract => 'DEFAULT', :shopper_reference => 'grasshopper52', :shopper_email => 'gras.shopper@somewhere.org')
|
140
147
|
|
141
|
-
signature = Adyen::Form.calculate_signature(@attributes
|
148
|
+
signature = Adyen::Form.calculate_signature(@attributes)
|
142
149
|
signature.should eql('F2BQEYbE+EUhiRGuPtcD16Gm7JY=')
|
143
150
|
end
|
144
|
-
|
145
151
|
end
|
146
|
-
|
147
152
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adyen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Bergen
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-10-
|
13
|
+
date: 2009-10-21 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|