sisow_ideal 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -1
- data/lib/sisow_ideal/client.rb +15 -3
- data/lib/sisow_ideal/version.rb +1 -1
- data/spec/client_spec.rb +32 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -35,8 +35,11 @@ response = client.setup_transaction(
|
|
35
35
|
order.update_attributes(:trxid => response.trxid)
|
36
36
|
redirect_to response.url
|
37
37
|
|
38
|
-
# How to handle report on the
|
38
|
+
# How to handle report on the notifyurl
|
39
39
|
# For safety reasons sisow calls a notify url for updating payment status before redirecting back to the application
|
40
|
+
|
41
|
+
# You have 2 options:
|
42
|
+
# 1. Do a status request
|
40
43
|
order = Order.find_by_trxid(params[:trxid])
|
41
44
|
response = client.status_request(
|
42
45
|
:trxid => order.trxid,
|
@@ -44,6 +47,12 @@ response = client.status_request(
|
|
44
47
|
)
|
45
48
|
order.update_attributes(:status => response.status)
|
46
49
|
|
50
|
+
# 2. Validate the response
|
51
|
+
if client.valid_response?(params)
|
52
|
+
order = Order.find_by_trxid(params[:trxid])
|
53
|
+
order.update_attributes(:status => params[:status])
|
54
|
+
end
|
55
|
+
|
47
56
|
# When sisow redirects the user back you can check if the payment was succesfull bij finding the order object
|
48
57
|
@order = Order.find_by_trxid(params[:trxid])
|
49
58
|
```
|
data/lib/sisow_ideal/client.rb
CHANGED
@@ -35,7 +35,7 @@ module SisowIdeal
|
|
35
35
|
|
36
36
|
response = Hashie::Mash.new(
|
37
37
|
self.class.get('/TransactionRequest',
|
38
|
-
:query =>
|
38
|
+
:query => merge_options(options, sha1),
|
39
39
|
:format => :xml
|
40
40
|
).parsed_response)
|
41
41
|
|
@@ -61,7 +61,7 @@ module SisowIdeal
|
|
61
61
|
|
62
62
|
response = Hashie::Mash.new(
|
63
63
|
self.class.get('/StatusRequest',
|
64
|
-
:query =>
|
64
|
+
:query => merge_options(options, sha1),
|
65
65
|
:format => :xml
|
66
66
|
).parsed_response)
|
67
67
|
|
@@ -72,10 +72,22 @@ module SisowIdeal
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
def valid_response?(params)
|
76
|
+
sha1 = [
|
77
|
+
params.fetch(:trxid),
|
78
|
+
params.fetch(:ec),
|
79
|
+
params.fetch(:status),
|
80
|
+
@options.fetch(:merchantid),
|
81
|
+
@options.fetch(:merchantkey)
|
82
|
+
].join
|
83
|
+
|
84
|
+
Digest::SHA1.hexdigest(sha1) == params[:sha1]
|
85
|
+
end
|
86
|
+
|
75
87
|
private
|
76
88
|
|
77
89
|
# Merge options in query
|
78
|
-
def
|
90
|
+
def merge_options(hash, sha1)
|
79
91
|
@options.merge!(hash).merge!(:sha1 => Digest::SHA1.hexdigest(sha1))
|
80
92
|
end
|
81
93
|
|
data/lib/sisow_ideal/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -71,5 +71,37 @@ describe SisowIdeal::Client do
|
|
71
71
|
|
72
72
|
end
|
73
73
|
|
74
|
+
describe :valid_response? do
|
75
|
+
|
76
|
+
subject { @client.valid_response?(params) }
|
77
|
+
|
78
|
+
context 'invalid' do
|
79
|
+
|
80
|
+
let!(:params) { {
|
81
|
+
:trxid => '0050001157723256',
|
82
|
+
:ec => '123',
|
83
|
+
:status => 'Open',
|
84
|
+
:sha1 => 'f334d33574f5b9244f8e434a7e4bc3cee12f6284'
|
85
|
+
} }
|
86
|
+
|
87
|
+
it { subject.should be_false }
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'valid' do
|
92
|
+
|
93
|
+
let!(:params) { {
|
94
|
+
:trxid => '0050001157723256',
|
95
|
+
:ec => '1',
|
96
|
+
:status => 'Open',
|
97
|
+
:sha1 => 'f334d33574f5b9244f8e434a7e4bc3cee12f6284'
|
98
|
+
} }
|
99
|
+
|
100
|
+
it { subject.should be_true }
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
74
106
|
|
75
107
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sisow_ideal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|