net_registry 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +28 -0
- data/LICENSE.txt +23 -0
- data/README.md +108 -0
- data/Rakefile +2 -0
- data/lib/net_registry/card.rb +42 -0
- data/lib/net_registry/client.rb +83 -0
- data/lib/net_registry/errors.rb +27 -0
- data/lib/net_registry/helpers.rb +29 -0
- data/lib/net_registry/response.rb +61 -0
- data/lib/net_registry/response_builder.rb +203 -0
- data/lib/net_registry/transaction.rb +48 -0
- data/lib/net_registry/version.rb +27 -0
- data/lib/net_registry.rb +36 -0
- data/net_registry.gemspec +53 -0
- data/spec/card_spec.rb +73 -0
- data/spec/client_spec.rb +265 -0
- data/spec/response_builder_spec.rb +326 -0
- data/spec/response_spec.rb +89 -0
- data/spec/spec_helper.rb +103 -0
- data/spec/transaction_spec.rb +97 -0
- metadata +130 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright (c) 2015 Car Next Door
|
2
|
+
# Author: Ray Tung
|
3
|
+
#
|
4
|
+
# MIT License
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
module NetRegistry
|
26
|
+
class Transaction
|
27
|
+
attr_accessor :settlement_date,
|
28
|
+
:amount,
|
29
|
+
:reference,
|
30
|
+
:bank_reference,
|
31
|
+
:command,
|
32
|
+
:time,
|
33
|
+
:number,
|
34
|
+
:rrn,
|
35
|
+
:merchant_id,
|
36
|
+
:receipt
|
37
|
+
|
38
|
+
def card=(card)
|
39
|
+
raise TypeError, "Invalid class" if !card.is_a? NetRegistry::Card
|
40
|
+
@card = card
|
41
|
+
end
|
42
|
+
|
43
|
+
def card
|
44
|
+
@card ||= NetRegistry::Card.new
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (c) 2015 Car Next Door
|
2
|
+
# Author: Ray Tung
|
3
|
+
#
|
4
|
+
# MIT License
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
module NetRegistry
|
26
|
+
VERSION = "0.0.2"
|
27
|
+
end
|
data/lib/net_registry.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Copyright (c) 2015 Car Next Door
|
2
|
+
# Author: Ray Tung
|
3
|
+
#
|
4
|
+
# MIT License
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
require "net_registry/version"
|
26
|
+
require "net_registry/client"
|
27
|
+
require "net_registry/response"
|
28
|
+
require "net_registry/response_builder"
|
29
|
+
require "net_registry/helpers"
|
30
|
+
require "net_registry/errors"
|
31
|
+
require "net_registry/transaction"
|
32
|
+
require "net_registry/card"
|
33
|
+
|
34
|
+
module NetRegistry
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# Copyright (c) 2015 Car Next Door
|
4
|
+
# Author: Ray Tung
|
5
|
+
#
|
6
|
+
# MIT License
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
# the following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be
|
17
|
+
# included in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
|
27
|
+
lib = File.expand_path('../lib', __FILE__)
|
28
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
29
|
+
require 'net_registry/version'
|
30
|
+
|
31
|
+
Gem::Specification.new do |spec|
|
32
|
+
spec.name = "net_registry"
|
33
|
+
spec.version = NetRegistry::VERSION
|
34
|
+
spec.authors = ["Ray Tung"]
|
35
|
+
spec.email = ["ray@carnextdoor.com.au"]
|
36
|
+
spec.summary = %q{This gem serves as a Ruby wrapper for the NetRegistry Payment Gateway's
|
37
|
+
API.}
|
38
|
+
spec.description = %q{This gem serves as a Ruby wrapper for the NetRegistry Payment Gateway's
|
39
|
+
API. Official documentation can be found at http://www.netregistry.com.au/ee-images/uploads/support/NR-ecom-gateway8.pdf. Source can be found on https://github.com/carnextnoor/net_registry}
|
40
|
+
spec.homepage = ""
|
41
|
+
spec.license = "MIT"
|
42
|
+
|
43
|
+
spec.files = `git ls-files -z`.split("\x0")
|
44
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
45
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
46
|
+
spec.require_paths = ["lib"]
|
47
|
+
spec.required_ruby_version = '>= 2.0'
|
48
|
+
|
49
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
50
|
+
spec.add_development_dependency "rake"
|
51
|
+
spec.add_development_dependency "rspec"
|
52
|
+
spec.add_development_dependency "webmock"
|
53
|
+
end
|
data/spec/card_spec.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright (c) 2015 Car Next Door
|
2
|
+
# Author: Ray Tung
|
3
|
+
#
|
4
|
+
# MIT License
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
require "spec_helper"
|
26
|
+
|
27
|
+
RSpec.describe NetRegistry::Card do
|
28
|
+
let(:card) { NetRegistry::Card.new }
|
29
|
+
describe "#number" do
|
30
|
+
it "assigns number" do
|
31
|
+
number = "111111111111"
|
32
|
+
expect(card.number).to be_nil
|
33
|
+
card.number = number
|
34
|
+
expect(card.number).to eq(number)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#description" do
|
39
|
+
it "assigns description" do
|
40
|
+
desc = "VISA"
|
41
|
+
expect(card.description).to be_nil
|
42
|
+
card.description= desc
|
43
|
+
expect(card.description).to eq(desc)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#expiry" do
|
48
|
+
it "assigns expiry" do
|
49
|
+
expiry = "10/15"
|
50
|
+
expect(card.expiry).to be_nil
|
51
|
+
card.expiry = expiry
|
52
|
+
expect(card.expiry).to eq(expiry)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#ccv" do
|
57
|
+
it "assigns CCV" do
|
58
|
+
ccv = "935"
|
59
|
+
expect(card.ccv).to be_nil
|
60
|
+
card.ccv = ccv
|
61
|
+
expect(card.ccv).to eq(ccv)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#type" do
|
66
|
+
it "assigns type" do
|
67
|
+
type = "9"
|
68
|
+
expect(card.type).to be_nil
|
69
|
+
card.type = type
|
70
|
+
expect(card.type).to eq(type)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
# Copyright (c) 2015 Car Next Door
|
2
|
+
# Author: Ray Tung
|
3
|
+
#
|
4
|
+
# MIT License
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
require "spec_helper"
|
26
|
+
|
27
|
+
RSpec.describe NetRegistry::Client do
|
28
|
+
let(:username) { "username" }
|
29
|
+
let(:password) { "password" }
|
30
|
+
let(:client) { NetRegistry::Client.new(merchant_id: username, password: password) }
|
31
|
+
let(:params) do
|
32
|
+
{
|
33
|
+
AMOUNT: "100.0",
|
34
|
+
CCNUM: "111111111111",
|
35
|
+
CCEXP: "10/15",
|
36
|
+
TXNREF: "0007311428202312"
|
37
|
+
}
|
38
|
+
end
|
39
|
+
let(:body) { params.merge!(LOGIN: "#{username}/#{password}")}
|
40
|
+
let(:status_success_response) do
|
41
|
+
<<-STATUS
|
42
|
+
card_number=#{params[:CCNUM]}
|
43
|
+
settlement_date=31/07/00
|
44
|
+
response_text=INVALID TRANSACTION
|
45
|
+
amount=#{params[:AMOUNT]}
|
46
|
+
status=complete
|
47
|
+
txnref=#{params[:TXNREF]}
|
48
|
+
bank_ref=000731000024
|
49
|
+
card_desc=VISA
|
50
|
+
response_code=12
|
51
|
+
card_expiry=01/01
|
52
|
+
MID=24
|
53
|
+
card_type=6
|
54
|
+
time=20000731 14:28:20
|
55
|
+
command=purchase
|
56
|
+
result=0
|
57
|
+
.
|
58
|
+
done=1
|
59
|
+
STATUS
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:purchase_success_response) do
|
63
|
+
<<-PURCHASE
|
64
|
+
training_mode=0
|
65
|
+
pld=0
|
66
|
+
approved=0
|
67
|
+
settlement_date=31/07/00
|
68
|
+
transaction_no=332546
|
69
|
+
status=declined
|
70
|
+
version=V1.0
|
71
|
+
operator_no=22546
|
72
|
+
refund_mode=0
|
73
|
+
merchant_index=24
|
74
|
+
response_code=12
|
75
|
+
receipt_array=ARRAY(0x8221b9c)
|
76
|
+
cashout_amount=0
|
77
|
+
account_type=CREDIT A/C
|
78
|
+
rrn=000782000024
|
79
|
+
response_text=INVALID TRANSACTION
|
80
|
+
txn_ref=0007311458332546
|
81
|
+
card_no=4111111111111111
|
82
|
+
total_amount=100
|
83
|
+
card_desc=VISA
|
84
|
+
card_expiry=01/01
|
85
|
+
card_type=6
|
86
|
+
result=0
|
87
|
+
Reciept follows
|
88
|
+
Transaction No: 00332546
|
89
|
+
|
90
|
+
TYRELL CORPORATION
|
91
|
+
MERCH ID 99999999
|
92
|
+
TERM ID Y9TB99
|
93
|
+
COUNTRY CODE AU
|
94
|
+
31/07/00 14:32
|
95
|
+
RRN 000782000024
|
96
|
+
VISA
|
97
|
+
411111111
|
98
|
+
CREDIT A/C 01/01
|
99
|
+
AUTHORISATION��NO:
|
100
|
+
DECLINED 12
|
101
|
+
PURCHASE $1.00
|
102
|
+
TOTAL AUD $1.00
|
103
|
+
PLEASE RETAIN AS RECORD
|
104
|
+
OF PURCHASE
|
105
|
+
(SUBJECT TO CARDHOLDER'S
|
106
|
+
ACCEPTANCE)
|
107
|
+
|
108
|
+
.
|
109
|
+
done=1
|
110
|
+
PURCHASE
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#initialize" do
|
114
|
+
it { expect(client.merchant_id).to eq(username) }
|
115
|
+
it { expect(client.password).to eq(password) }
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#purchase" do
|
119
|
+
context "parameter is a hash" do
|
120
|
+
it "should not raise any errors" do
|
121
|
+
stub_request(:post, /https:\/\/paygate\.ssllock\.net\/external2\.pl/)
|
122
|
+
.with(body: body.merge!(COMMAND: "purchase"))
|
123
|
+
.to_return(status: 200, body: purchase_success_response, headers: {})
|
124
|
+
expect { client.purchase(params) }.not_to raise_error
|
125
|
+
end
|
126
|
+
it "has key :AMOUNT with nil as value" do
|
127
|
+
response = client.purchase(params.merge!(AMOUNT: nil))
|
128
|
+
expect(response.class).to eq(NetRegistry::Response)
|
129
|
+
expect(response.text).to eq("AMOUNT not found")
|
130
|
+
expect(response.code).to eq(-1)
|
131
|
+
expect(response.status).to eq("failed")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "has key :AMOUNT with empty string as value" do
|
135
|
+
response = client.purchase(params.merge!(AMOUNT: ""))
|
136
|
+
expect(response.class).to eq(NetRegistry::Response)
|
137
|
+
expect(response.text).to eq("AMOUNT not found")
|
138
|
+
expect(response.code).to eq(-1)
|
139
|
+
expect(response.status).to eq("failed")
|
140
|
+
end
|
141
|
+
|
142
|
+
it "has key :AMOUNT with a non-empty value" do
|
143
|
+
stub_request(:post, /https:\/\/paygate\.ssllock\.net\/external2\.pl/)
|
144
|
+
.with(body: body.merge!(COMMAND: "purchase"))
|
145
|
+
.to_return(status: 200, body: purchase_success_response, headers: {})
|
146
|
+
|
147
|
+
response = client.purchase(params)
|
148
|
+
expect(response.class).to eq(NetRegistry::Response)
|
149
|
+
expect(response.text).to eq("INVALID TRANSACTION")
|
150
|
+
expect(response.code).to eq(12)
|
151
|
+
expect(response.status).to eq("declined")
|
152
|
+
end
|
153
|
+
|
154
|
+
it "has key :CCNUM with nil as value" do
|
155
|
+
response = client.purchase(params.merge!(CCNUM: nil))
|
156
|
+
expect(response.class).to eq(NetRegistry::Response)
|
157
|
+
expect(response.text).to eq("CCNUM not found")
|
158
|
+
expect(response.code).to eq(-1)
|
159
|
+
expect(response.status).to eq("failed")
|
160
|
+
end
|
161
|
+
|
162
|
+
it "has key :CCNUM with empty string as value" do
|
163
|
+
response = client.purchase(params.merge!(CCNUM: ""))
|
164
|
+
expect(response.class).to eq(NetRegistry::Response)
|
165
|
+
expect(response.text).to eq("CCNUM not found")
|
166
|
+
expect(response.code).to eq(-1)
|
167
|
+
expect(response.status).to eq("failed")
|
168
|
+
end
|
169
|
+
|
170
|
+
it "has key :CCNUM with a non-empty value" do
|
171
|
+
stub_request(:post, /https:\/\/paygate\.ssllock\.net\/external2\.pl/)
|
172
|
+
.with(body: body.merge!(COMMAND: "purchase"))
|
173
|
+
.to_return(status: 200, body: purchase_success_response, headers: {})
|
174
|
+
response = client.purchase(params)
|
175
|
+
expect(response.class).to eq(NetRegistry::Response)
|
176
|
+
expect(response.text).to eq("INVALID TRANSACTION")
|
177
|
+
expect(response.code).to eq(12)
|
178
|
+
expect(response.status).to eq("declined")
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
context "parameter is anything but a hash" do
|
184
|
+
it { expect { client.purchase(1) }.to raise_error(TypeError) }
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "#refund" do
|
189
|
+
context "parameter is a hash" do
|
190
|
+
it "does not raise error" do
|
191
|
+
stub_request(:post, /https:\/\/paygate\.ssllock\.net\/external2\.pl/)
|
192
|
+
.with(body: body.merge!(COMMAND: "refund"))
|
193
|
+
.to_return(status: 200, body: purchase_success_response, headers: {})
|
194
|
+
expect { client.refund(params) }.not_to raise_error
|
195
|
+
end
|
196
|
+
it "has key :AMOUNT with nil as value" do
|
197
|
+
response = client.refund(params.merge!(AMOUNT: nil))
|
198
|
+
expect(response.class).to eq(NetRegistry::Response)
|
199
|
+
expect(response.text).to eq("AMOUNT not found")
|
200
|
+
expect(response.code).to eq(-1)
|
201
|
+
expect(response.status).to eq("failed")
|
202
|
+
end
|
203
|
+
|
204
|
+
it "has key :AMOUNT with empty string as value" do
|
205
|
+
response = client.refund(params.merge!(AMOUNT: ""))
|
206
|
+
expect(response.class).to eq(NetRegistry::Response)
|
207
|
+
expect(response.text).to eq("AMOUNT not found")
|
208
|
+
expect(response.code).to eq(-1)
|
209
|
+
expect(response.status).to eq("failed")
|
210
|
+
end
|
211
|
+
|
212
|
+
it "has key :AMOUNT with a non-empty value" do
|
213
|
+
stub_request(:post, /https:\/\/paygate\.ssllock\.net\/external2\.pl/)
|
214
|
+
.with(body: body.merge!(COMMAND: "refund"))
|
215
|
+
.to_return(status: 200, body: purchase_success_response, headers: {})
|
216
|
+
response = client.refund(params)
|
217
|
+
expect(response.class).to eq(NetRegistry::Response)
|
218
|
+
expect(response.text).to eq("INVALID TRANSACTION")
|
219
|
+
expect(response.code).to eq(12)
|
220
|
+
expect(response.status).to eq("declined")
|
221
|
+
end
|
222
|
+
|
223
|
+
it "has key :TXNREF with nil as value" do
|
224
|
+
response = client.refund(params.merge!(TXNREF: nil))
|
225
|
+
expect(response.class).to eq(NetRegistry::Response)
|
226
|
+
expect(response.text).to eq("TXNREF not found")
|
227
|
+
expect(response.code).to eq(-1)
|
228
|
+
expect(response.status).to eq("failed")
|
229
|
+
end
|
230
|
+
|
231
|
+
it "has key :TXNREF with empty string as value" do
|
232
|
+
response = client.refund(params.merge!(TXNREF: ""))
|
233
|
+
expect(response.class).to eq(NetRegistry::Response)
|
234
|
+
expect(response.text).to eq("TXNREF not found")
|
235
|
+
expect(response.code).to eq(-1)
|
236
|
+
expect(response.status).to eq("failed")
|
237
|
+
end
|
238
|
+
|
239
|
+
it "has key :TXNREF with a non-empty value" do
|
240
|
+
stub_request(:post, /https:\/\/paygate\.ssllock\.net\/external2\.pl/)
|
241
|
+
.with(body: body.merge!(COMMAND: "refund"))
|
242
|
+
.to_return(status: 200, body: purchase_success_response, headers: {})
|
243
|
+
response = client.refund(params)
|
244
|
+
expect(response.class).to eq(NetRegistry::Response)
|
245
|
+
expect(response.text).to eq("INVALID TRANSACTION")
|
246
|
+
expect(response.code).to eq(12)
|
247
|
+
expect(response.status).to eq("declined")
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
context "parameter is anything but a hash" do
|
253
|
+
it { expect { client.refund(1) }.to raise_error(TypeError) }
|
254
|
+
end
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "#status" do
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
describe "#preauth" do
|
263
|
+
|
264
|
+
end
|
265
|
+
end
|