sage_pay 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -2
- data/lib/sage_pay.rb +1 -1
- data/lib/sage_pay/server/signature_verification_details.rb +4 -6
- data/lib/sage_pay/server/transaction_notification.rb +15 -6
- data/lib/sage_pay/server/transaction_registration.rb +1 -1
- data/sage_pay.gemspec +2 -2
- data/spec/integration/sage_pay/server_spec.rb +6 -3
- data/spec/sage_pay/server/signature_verification_details_spec.rb +1 -11
- data/spec/sage_pay/server/transaction_notification_spec.rb +14 -2
- data/spec/sage_pay/server/transaction_registration_spec.rb +0 -10
- data/spec/sage_pay_spec.rb +2 -2
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
3
|
+
## 0.2.2
|
4
|
+
|
5
|
+
* Incorporate additional fields I'd missed from the notification. That'll make
|
6
|
+
it easier to find payments from the notification.
|
7
|
+
|
8
|
+
## 0.2.1
|
4
9
|
|
5
10
|
* [FIX] SagePay think it's OK to have curly braces in a URL query string.
|
6
11
|
Ruby's URI library thinks otherwise. No matter who's right, one of these is
|
7
12
|
easier to change than the other.
|
8
13
|
|
9
|
-
|
14
|
+
## 0.2.0
|
10
15
|
|
11
16
|
* Initial release. This should support the full workflow for making payments,
|
12
17
|
but the notification side hasn't been tested again SagePay in the wild so
|
data/lib/sage_pay.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
module SagePay
|
2
2
|
module Server
|
3
3
|
class SignatureVerificationDetails
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :vendor, :security_key
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@vps_tx_id = transaction_registration_response.vps_tx_id
|
10
|
-
@security_key = transaction_registration_response.security_key
|
6
|
+
def initialize(vendor, security_key)
|
7
|
+
@vendor = vendor
|
8
|
+
@security_key = security_key
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
@@ -1,14 +1,18 @@
|
|
1
1
|
module SagePay
|
2
2
|
module Server
|
3
3
|
class TransactionNotification
|
4
|
-
attr_reader :vps_protocol, :
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:card_type, :last_4_digits,
|
4
|
+
attr_reader :vps_protocol, :tx_type, :vendor_tx_code, :vps_tx_id,
|
5
|
+
:status, :status_detail, :tx_auth_no, :avs_cv2, :address_result,
|
6
|
+
:post_code_result, :cv2_result, :gift_aid, :threed_secure_status,
|
7
|
+
:cavv, :address_status, :payer_status,:card_type, :last_4_digits,
|
8
|
+
:vps_signature
|
8
9
|
|
9
10
|
def self.from_params(params, signature_verification_details = nil)
|
10
11
|
key_converter = {
|
11
12
|
"VPSProtocol" => :vps_protocol,
|
13
|
+
"TxType" => :tx_type,
|
14
|
+
"VendorTxCode" => :vendor_tx_code,
|
15
|
+
"VPSTxId" => :vps_tx_id,
|
12
16
|
"Status" => :status,
|
13
17
|
"StatusDetail" => :status_detail,
|
14
18
|
"TxAuthNo" => :tx_auth_no,
|
@@ -39,6 +43,11 @@ module SagePay
|
|
39
43
|
}
|
40
44
|
|
41
45
|
value_converter = {
|
46
|
+
:tx_type => {
|
47
|
+
"PAYMENT" => :payment,
|
48
|
+
"DEFERRED" => :deferred,
|
49
|
+
"AUTHENTICATE" => :authenticate
|
50
|
+
},
|
42
51
|
:status => {
|
43
52
|
"OK" => :ok,
|
44
53
|
"NOTAUTHED" => :not_authed,
|
@@ -105,8 +114,8 @@ module SagePay
|
|
105
114
|
# We need to calculate the VPS signature from the values passed in as
|
106
115
|
# additional params from the original registration and notification.
|
107
116
|
fields_used_in_signature = [
|
108
|
-
|
109
|
-
|
117
|
+
params["VPSTxId"],
|
118
|
+
params["VendorTxCode"],
|
110
119
|
params["Status"],
|
111
120
|
params["TxAuthNo"],
|
112
121
|
signature_verification_details.vendor,
|
@@ -59,7 +59,7 @@ module SagePay
|
|
59
59
|
elsif @response.failed?
|
60
60
|
raise RuntimeError, "Transaction registration failed"
|
61
61
|
else
|
62
|
-
SignatureVerificationDetails.new(
|
62
|
+
@signature_verification_details ||= SignatureVerificationDetails.new(vendor, @response.security_key)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
data/sage_pay.gemspec
CHANGED
@@ -7,8 +7,8 @@ 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.
|
11
|
-
s.date = '2010-04-
|
10
|
+
s.version = '0.2.2'
|
11
|
+
s.date = '2010-04-25'
|
12
12
|
s.rubyforge_project = 'sage_pay'
|
13
13
|
|
14
14
|
## Make sure your summary is short. The description may be as long
|
@@ -37,9 +37,14 @@ if run_integration_specs?
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should allow us to follow the next URL and the response should be successful" do
|
40
|
-
pending "URI#parse claims that the URL SagePay hands us isn't a valid URI."
|
41
40
|
registration = @payment.register!
|
42
41
|
uri = URI.parse(registration.next_url)
|
42
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
43
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
44
|
+
http.use_ssl = true if uri.scheme == "https"
|
45
|
+
http.start { |http|
|
46
|
+
http.request(request)
|
47
|
+
}
|
43
48
|
end
|
44
49
|
|
45
50
|
it "should allow us to retrieve signature verification details" do
|
@@ -47,10 +52,8 @@ if run_integration_specs?
|
|
47
52
|
sig_details = @payment.signature_verification_details
|
48
53
|
|
49
54
|
sig_details.should_not be_nil
|
50
|
-
sig_details.vps_tx_id.should_not be_nil
|
51
55
|
sig_details.security_key.should_not be_nil
|
52
56
|
sig_details.vendor.should_not be_nil
|
53
|
-
sig_details.vendor_tx_code.should_not be_nil
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
@@ -3,23 +3,13 @@ require 'spec_helper'
|
|
3
3
|
include SagePay::Server
|
4
4
|
describe SignatureVerificationDetails do
|
5
5
|
before(:each) do
|
6
|
-
|
7
|
-
transaction_registration_response = mock("Transaction registration response", :vps_tx_id => "sage pay transaction id", :security_key => "security key")
|
8
|
-
@sig_details = SignatureVerificationDetails.new(transaction_registration, transaction_registration_response)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should take the vendor_tx_code from the transaction registration" do
|
12
|
-
@sig_details.vendor_tx_code.should == "vendor transaction id"
|
6
|
+
@sig_details = SignatureVerificationDetails.new("vendor", "security key")
|
13
7
|
end
|
14
8
|
|
15
9
|
it "should take the vendor from the transaction registration" do
|
16
10
|
@sig_details.vendor.should == "vendor"
|
17
11
|
end
|
18
12
|
|
19
|
-
it "should take the vps_tx_id from the transaction registration response" do
|
20
|
-
@sig_details.vps_tx_id.should == "sage pay transaction id"
|
21
|
-
end
|
22
|
-
|
23
13
|
it "should take the security_key from the transaction registration response" do
|
24
14
|
@sig_details.security_key.should == "security key"
|
25
15
|
end
|
@@ -13,8 +13,6 @@ describe TransactionNotification do
|
|
13
13
|
context "with an OK status" do
|
14
14
|
before(:each) do
|
15
15
|
signature_verification_details = mock("Signature verification details",
|
16
|
-
:vps_tx_id => "{728A5721-B45F-4570-937E-90A16B0A5000}",
|
17
|
-
:vendor_tx_code => "unique-tx-code",
|
18
16
|
:vendor => "rubaidh",
|
19
17
|
:security_key => "17F13DCBD8"
|
20
18
|
)
|
@@ -22,6 +20,8 @@ describe TransactionNotification do
|
|
22
20
|
@params = {
|
23
21
|
"VPSProtocol" => "2.23",
|
24
22
|
"TxType" => "PAYMENT",
|
23
|
+
"VendorTxCode" => "unique-tx-code",
|
24
|
+
"VPSTxId" => "{728A5721-B45F-4570-937E-90A16B0A5000}",
|
25
25
|
"Status" => "OK",
|
26
26
|
"StatusDetail" => "2000 : Card processed successfully.", # FIXME: Make this match reality
|
27
27
|
"TxAuthNo" => "1234567890",
|
@@ -54,6 +54,18 @@ describe TransactionNotification do
|
|
54
54
|
@notification.vps_protocol.should == "2.23"
|
55
55
|
end
|
56
56
|
|
57
|
+
it "should report the tx_type as :payment" do
|
58
|
+
@notification.tx_type.should == :payment
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should report the vendor_tx_code as the vendor tx code supplied" do
|
62
|
+
@notification.vendor_tx_code.should == 'unique-tx-code'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should report the vps_tx_id as the vps_tx_id supplied" do
|
66
|
+
@notification.vps_tx_id.should == "{728A5721-B45F-4570-937E-90A16B0A5000}"
|
67
|
+
end
|
68
|
+
|
57
69
|
it "should report the status as :ok" do
|
58
70
|
@notification.status.should == :ok
|
59
71
|
end
|
@@ -595,16 +595,6 @@ describe TransactionRegistration do
|
|
595
595
|
@transaction_registration.register!
|
596
596
|
end
|
597
597
|
|
598
|
-
it "should know the SagePay transaction id" do
|
599
|
-
sig_details = @transaction_registration.signature_verification_details
|
600
|
-
sig_details.vps_tx_id.should == "sage pay transaction id"
|
601
|
-
end
|
602
|
-
|
603
|
-
it "should know the vendor transaction id" do
|
604
|
-
sig_details = @transaction_registration.signature_verification_details
|
605
|
-
sig_details.vendor_tx_code.should == "vendor transaction id"
|
606
|
-
end
|
607
|
-
|
608
598
|
it "should know the vendor" do
|
609
599
|
sig_details = @transaction_registration.signature_verification_details
|
610
600
|
sig_details.vendor.should == "vendor"
|
data/spec/sage_pay_spec.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Graeme Mathieson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-25 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|