sage_pay 0.2.8.2 → 0.2.9
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/CHANGELOG.md +4 -0
- data/lib/sage_pay/server/refund_response.rb +4 -0
- data/lib/sage_pay/server/registration_response.rb +2 -24
- data/lib/sage_pay/server/repeat.rb +50 -0
- data/lib/sage_pay/server/repeat_response.rb +49 -0
- data/lib/sage_pay/server/response.rb +20 -1
- data/lib/sage_pay/server.rb +9 -1
- data/lib/sage_pay.rb +3 -1
- data/sage_pay.gemspec +3 -1
- data/spec/sage_pay/server/registration_response_spec.rb +9 -9
- data/spec/sage_pay_spec.rb +2 -2
- metadata +4 -3
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
module SagePay
|
2
2
|
module Server
|
3
3
|
class RefundResponse < Response
|
4
|
+
attr_accessor_if_ok :vps_tx_id, :tx_auth_no
|
5
|
+
|
4
6
|
self.key_converter = key_converter.merge({
|
5
7
|
"VPSTxId" => :vps_tx_id,
|
6
8
|
"TxAuthNo" => :tx_auth_no
|
7
9
|
})
|
8
10
|
|
11
|
+
self.value_converter[:status]["NOTAUTHED"] = :not_authed
|
12
|
+
|
9
13
|
def vps_tx_id
|
10
14
|
if ok?
|
11
15
|
@vps_tx_id
|
@@ -1,35 +1,13 @@
|
|
1
1
|
module SagePay
|
2
2
|
module Server
|
3
3
|
class RegistrationResponse < Response
|
4
|
+
attr_accessor_if_ok :vps_tx_id, :security_key, :next_url
|
5
|
+
|
4
6
|
self.key_converter = key_converter.merge({
|
5
7
|
"VPSTxId" => :vps_tx_id,
|
6
8
|
"SecurityKey" => :security_key,
|
7
9
|
"NextURL" => :next_url
|
8
10
|
})
|
9
|
-
|
10
|
-
def vps_tx_id
|
11
|
-
if ok?
|
12
|
-
@vps_tx_id
|
13
|
-
else
|
14
|
-
raise RuntimeError, "Unable to retrieve the transaction id as the status was not OK."
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def security_key
|
19
|
-
if ok?
|
20
|
-
@security_key
|
21
|
-
else
|
22
|
-
raise RuntimeError, "Unable to retrieve the security key as the status was not OK."
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def next_url
|
27
|
-
if ok?
|
28
|
-
@next_url
|
29
|
-
else
|
30
|
-
raise RuntimeError, "Unable to retrieve the next URL as the status was not OK."
|
31
|
-
end
|
32
|
-
end
|
33
11
|
end
|
34
12
|
end
|
35
13
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module SagePay
|
2
|
+
module Server
|
3
|
+
class Repeat < Command
|
4
|
+
attr_accessor :amount, :currency, :description, :related_transaction, :cv2
|
5
|
+
|
6
|
+
validates_presence_of :amount, :currency, :description, :related_transaction
|
7
|
+
|
8
|
+
validates_length_of :currency, :is => 3
|
9
|
+
validates_length_of :description, :maximum => 100
|
10
|
+
|
11
|
+
validates_inclusion_of :tx_type, :allow_blank => true, :in => [ :repeat ]
|
12
|
+
|
13
|
+
validates_true_for :amount, :key => :amount_minimum_value, :logic => lambda { amount.nil? || amount >= BigDecimal.new("0.01") }, :message => "is less than the minimum value (0.01)"
|
14
|
+
validates_true_for :amount, :key => :amount_maximum_value, :logic => lambda { amount.nil? || amount <= BigDecimal.new("100000") }, :message => "is greater than the maximum value (100,000.00)"
|
15
|
+
|
16
|
+
def initialize(attributes = {})
|
17
|
+
@tx_type = :repeat
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def post_params
|
22
|
+
params = super.merge({
|
23
|
+
"Amount" => ("%.2f" % amount),
|
24
|
+
"Currency" => currency,
|
25
|
+
"Description" => description
|
26
|
+
}).merge(related_transaction.post_params)
|
27
|
+
|
28
|
+
params["CV2"] = cv2 if cv2.present?
|
29
|
+
|
30
|
+
params
|
31
|
+
end
|
32
|
+
|
33
|
+
def amount=(value)
|
34
|
+
@amount = blank?(value) ? nil : BigDecimal.new(value.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def response_from_response_body(response_body)
|
38
|
+
RepeatResponse.from_response_body(response_body)
|
39
|
+
end
|
40
|
+
|
41
|
+
def live_service
|
42
|
+
"repeat"
|
43
|
+
end
|
44
|
+
|
45
|
+
def simulator_service
|
46
|
+
"VendorRepeatTx"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SagePay
|
2
|
+
module Server
|
3
|
+
class RepeatResponse < Response
|
4
|
+
attr_accessor_if_ok :vps_tx_id, :tx_auth_no, :security_key,
|
5
|
+
:avs_cv2, :address_result, :post_code_result, :cv2_result
|
6
|
+
|
7
|
+
|
8
|
+
self.key_converter = key_converter.merge({
|
9
|
+
"VPSTxId" => :vps_tx_id,
|
10
|
+
"TxAuthNo" => :tx_auth_no,
|
11
|
+
"SecurityKey" => :security_key,
|
12
|
+
"AVSCV2" => :avs_cv2,
|
13
|
+
"AddressResult" => :address_result,
|
14
|
+
"PostCodeResult" => :post_code_result,
|
15
|
+
"CV2Result" => :cv2_result
|
16
|
+
})
|
17
|
+
|
18
|
+
self.value_converter[:status]["NOTAUTHED"] = :not_authed
|
19
|
+
self.value_converter = value_converter.merge({
|
20
|
+
:avs_cv2 => {
|
21
|
+
"ALL MATCH" => :all_match,
|
22
|
+
"SECURITY CODE MATCH ONLY" => :security_code_match_only,
|
23
|
+
"ADDRESS MATCH ONLY" => :address_match_only,
|
24
|
+
"NO DATA MATCHES" => :no_data_matches,
|
25
|
+
"DATA NOT CHECKED" => :data_not_checked
|
26
|
+
},
|
27
|
+
:address_result => match_converter,
|
28
|
+
:post_code_result => match_converter,
|
29
|
+
:cv2_result => match_converter,
|
30
|
+
})
|
31
|
+
|
32
|
+
def avs_cv2_matched?
|
33
|
+
avs_cv2 == :all_match
|
34
|
+
end
|
35
|
+
|
36
|
+
def address_matched?
|
37
|
+
address_result == :matched
|
38
|
+
end
|
39
|
+
|
40
|
+
def post_code_matched?
|
41
|
+
post_code_result == :matched
|
42
|
+
end
|
43
|
+
|
44
|
+
def cv2_matched?
|
45
|
+
cv2_result == :matched
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SagePay
|
2
2
|
module Server
|
3
3
|
class Response
|
4
|
-
class_inheritable_hash :key_converter, :value_converter, :instance_writer => false
|
4
|
+
class_inheritable_hash :key_converter, :value_converter, :match_converter, :instance_writer => false
|
5
5
|
|
6
6
|
self.key_converter = {
|
7
7
|
"VPSProtocol" => :vps_protocol,
|
@@ -18,8 +18,27 @@ module SagePay
|
|
18
18
|
}
|
19
19
|
}
|
20
20
|
|
21
|
+
self.match_converter = {
|
22
|
+
"NOTPROVIDED" => :not_provided,
|
23
|
+
"NOTCHECKED" => :not_checked,
|
24
|
+
"MATCHED" => :matched,
|
25
|
+
"NOTMATCHED" => :not_matched
|
26
|
+
}
|
27
|
+
|
21
28
|
attr_reader :vps_protocol, :status, :status_detail
|
22
29
|
|
30
|
+
def self.attr_accessor_if_ok(*attrs)
|
31
|
+
attrs.each do |attr|
|
32
|
+
define_method(attr) do
|
33
|
+
if ok?
|
34
|
+
instance_variable_get("@#{attr}")
|
35
|
+
else
|
36
|
+
raise RuntimeError, "Unable to retrieve #{attr} as the status was #{status} (not OK)."
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
23
42
|
def self.from_response_body(response_body)
|
24
43
|
attributes = {}
|
25
44
|
|
data/lib/sage_pay/server.rb
CHANGED
@@ -18,7 +18,7 @@ module SagePay
|
|
18
18
|
# The notification URL is only relevant to registration options, but the
|
19
19
|
# rest are relevant to all requests.
|
20
20
|
def self.default_options
|
21
|
-
|
21
|
+
default_registration_options.except(:notification_url)
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.related_transaction(attributes = {})
|
@@ -67,5 +67,13 @@ module SagePay
|
|
67
67
|
|
68
68
|
SagePay::Server::Refund.new(defaults.merge(attributes))
|
69
69
|
end
|
70
|
+
|
71
|
+
def self.repeat(attributes = {})
|
72
|
+
defaults = {
|
73
|
+
:vendor_tx_code => TransactionCode.random,
|
74
|
+
}.merge(default_options)
|
75
|
+
|
76
|
+
SagePay::Server::Repeat.new(defaults.merge(attributes))
|
77
|
+
end
|
70
78
|
end
|
71
79
|
end
|
data/lib/sage_pay.rb
CHANGED
@@ -7,7 +7,7 @@ require 'md5'
|
|
7
7
|
require 'uuid'
|
8
8
|
|
9
9
|
module SagePay
|
10
|
-
VERSION = '0.2.
|
10
|
+
VERSION = '0.2.9'
|
11
11
|
end
|
12
12
|
|
13
13
|
require 'validatable-ext'
|
@@ -27,4 +27,6 @@ require 'sage_pay/server/release'
|
|
27
27
|
require 'sage_pay/server/abort'
|
28
28
|
require 'sage_pay/server/refund'
|
29
29
|
require 'sage_pay/server/refund_response'
|
30
|
+
require 'sage_pay/server/repeat'
|
31
|
+
require 'sage_pay/server/repeat_response'
|
30
32
|
require 'sage_pay/server'
|
data/sage_pay.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
## If your rubyforge_project name is different, then edit it and comment out
|
8
8
|
## the sub! line in the Rakefile
|
9
9
|
s.name = 'sage_pay'
|
10
|
-
s.version = '0.2.
|
10
|
+
s.version = '0.2.9'
|
11
11
|
s.date = '2010-04-25'
|
12
12
|
s.rubyforge_project = 'sage_pay'
|
13
13
|
|
@@ -67,6 +67,8 @@ gateway for accepting credit card payments through your web app.
|
|
67
67
|
lib/sage_pay/server/registration_response.rb
|
68
68
|
lib/sage_pay/server/related_transaction.rb
|
69
69
|
lib/sage_pay/server/release.rb
|
70
|
+
lib/sage_pay/server/repeat.rb
|
71
|
+
lib/sage_pay/server/repeat_response.rb
|
70
72
|
lib/sage_pay/server/response.rb
|
71
73
|
lib/sage_pay/server/signature_verification_details.rb
|
72
74
|
lib/sage_pay/server/transaction_code.rb
|
@@ -49,19 +49,19 @@ StatusDetail=4000 : The VendorName is invalid or the account is not active.
|
|
49
49
|
it "should raise an error if we try to ask for the transaction id" do
|
50
50
|
lambda {
|
51
51
|
@response.vps_tx_id
|
52
|
-
}.should raise_error RuntimeError, "Unable to retrieve
|
52
|
+
}.should raise_error RuntimeError, "Unable to retrieve vps_tx_id as the status was invalid (not OK)."
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should raise an error if we try to ask for the security key" do
|
56
56
|
lambda {
|
57
57
|
@response.security_key
|
58
|
-
}.should raise_error RuntimeError, "Unable to retrieve
|
58
|
+
}.should raise_error RuntimeError, "Unable to retrieve security_key as the status was invalid (not OK)."
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should raise an error if we try to ask for the next URL" do
|
62
62
|
lambda {
|
63
63
|
@response.next_url
|
64
|
-
}.should raise_error RuntimeError, "Unable to retrieve
|
64
|
+
}.should raise_error RuntimeError, "Unable to retrieve next_url as the status was invalid (not OK)."
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -104,19 +104,19 @@ StatusDetail=5000 : Your request had too many toes.
|
|
104
104
|
it "should raise an error if we try to ask for the transaction id" do
|
105
105
|
lambda {
|
106
106
|
@response.vps_tx_id
|
107
|
-
}.should raise_error RuntimeError, "Unable to retrieve
|
107
|
+
}.should raise_error RuntimeError, "Unable to retrieve vps_tx_id as the status was malformed (not OK)."
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should raise an error if we try to ask for the security key" do
|
111
111
|
lambda {
|
112
112
|
@response.security_key
|
113
|
-
}.should raise_error RuntimeError, "Unable to retrieve
|
113
|
+
}.should raise_error RuntimeError, "Unable to retrieve security_key as the status was malformed (not OK)."
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should raise an error if we try to ask for the next URL" do
|
117
117
|
lambda {
|
118
118
|
@response.next_url
|
119
|
-
}.should raise_error RuntimeError, "Unable to retrieve
|
119
|
+
}.should raise_error RuntimeError, "Unable to retrieve next_url as the status was malformed (not OK)."
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -159,19 +159,19 @@ StatusDetail=5000 : SagePay blew up.
|
|
159
159
|
it "should raise an error if we try to ask for the transaction id" do
|
160
160
|
lambda {
|
161
161
|
@response.vps_tx_id
|
162
|
-
}.should raise_error RuntimeError, "Unable to retrieve
|
162
|
+
}.should raise_error RuntimeError, "Unable to retrieve vps_tx_id as the status was error (not OK)."
|
163
163
|
end
|
164
164
|
|
165
165
|
it "should raise an error if we try to ask for the security key" do
|
166
166
|
lambda {
|
167
167
|
@response.security_key
|
168
|
-
}.should raise_error RuntimeError, "Unable to retrieve
|
168
|
+
}.should raise_error RuntimeError, "Unable to retrieve security_key as the status was error (not OK)."
|
169
169
|
end
|
170
170
|
|
171
171
|
it "should raise an error if we try to ask for the next URL" do
|
172
172
|
lambda {
|
173
173
|
@response.next_url
|
174
|
-
}.should raise_error RuntimeError, "Unable to retrieve
|
174
|
+
}.should raise_error RuntimeError, "Unable to retrieve next_url as the status was error (not OK)."
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
data/spec/sage_pay_spec.rb
CHANGED
metadata
CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.2.8.2
|
8
|
+
- 9
|
9
|
+
version: 0.2.9
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Graeme Mathieson
|
@@ -89,6 +88,8 @@ files:
|
|
89
88
|
- lib/sage_pay/server/registration_response.rb
|
90
89
|
- lib/sage_pay/server/related_transaction.rb
|
91
90
|
- lib/sage_pay/server/release.rb
|
91
|
+
- lib/sage_pay/server/repeat.rb
|
92
|
+
- lib/sage_pay/server/repeat_response.rb
|
92
93
|
- lib/sage_pay/server/response.rb
|
93
94
|
- lib/sage_pay/server/signature_verification_details.rb
|
94
95
|
- lib/sage_pay/server/transaction_code.rb
|