tns_payments 0.0.5 → 0.0.6
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/tns_payments/connection.rb +23 -5
- data/lib/tns_payments/request.rb +1 -1
- data/lib/tns_payments/version.rb +1 -1
- data/test/unit/conntection_test.rb +61 -10
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -4,8 +4,7 @@ module TNSPayments
|
|
4
4
|
class Connection
|
5
5
|
CREDIT_CARD_TOKEN_FORMAT = /^9\d{15}/
|
6
6
|
|
7
|
-
attr_accessor :host
|
8
|
-
attr_reader :api_key, :merchant_id
|
7
|
+
attr_accessor :api_key, :host, :merchant_id
|
9
8
|
attr_writer :session_token
|
10
9
|
|
11
10
|
def available?
|
@@ -13,9 +12,8 @@ module TNSPayments
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def initialize options
|
16
|
-
|
17
|
-
|
18
|
-
self.host = options.fetch(:host) { 'https://secure.ap.tnspayments.com' }
|
15
|
+
self.api_key, self.merchant_id = options[:api_key], options[:merchant_id]
|
16
|
+
self.host = options.fetch(:host) { 'https://secure.ap.tnspayments.com' }
|
19
17
|
end
|
20
18
|
|
21
19
|
def payment_form_url
|
@@ -65,6 +63,26 @@ module TNSPayments
|
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
66
|
+
def check_enrollment transaction, token, postback_url
|
67
|
+
params = {
|
68
|
+
'3DSecure' => {'authenticationRedirect' => {'pageGenerationMode' => 'CUSTOMIZED', 'responseUrl' => postback_url}},
|
69
|
+
'apiOperation' => 'CHECK_3DS_ENROLLMENT',
|
70
|
+
'cardDetails' => card_details(token),
|
71
|
+
'transaction' => {'amount' => transaction.amount.to_s, 'currency' => transaction.currency}
|
72
|
+
}
|
73
|
+
|
74
|
+
request :put, "/merchant/#{merchant_id}/3DSecureId/#{transaction.three_domain_id}", params
|
75
|
+
end
|
76
|
+
|
77
|
+
def process_acs_result three_domain_id, pa_res
|
78
|
+
params = {
|
79
|
+
'3DSecure' => {'paRes' => pa_res},
|
80
|
+
'apiOperation' => 'PROCESS_ACS_RESULT'
|
81
|
+
}
|
82
|
+
|
83
|
+
request :post, "/merchant/#{merchant_id}/3DSecureId/#{three_domain_id}", params
|
84
|
+
end
|
85
|
+
|
68
86
|
private
|
69
87
|
|
70
88
|
def card_details token
|
data/lib/tns_payments/request.rb
CHANGED
data/lib/tns_payments/version.rb
CHANGED
@@ -3,9 +3,7 @@ require 'webmock/minitest'
|
|
3
3
|
|
4
4
|
class TNSPayments::ConnectionTest < MiniTest::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
@
|
7
|
-
@merchant_id = 'MERCHANT'
|
8
|
-
@gateway = Connection.new :api_key => @api_key, :merchant_id => @merchant_id
|
6
|
+
@gateway = Connection.new :api_key => '123api456', :merchant_id => 'MERCHANT'
|
9
7
|
end
|
10
8
|
|
11
9
|
def test_available_is_true_when_tns_gateway_is_operating
|
@@ -102,6 +100,27 @@ class TNSPayments::ConnectionTest < MiniTest::Unit::TestCase
|
|
102
100
|
end
|
103
101
|
end
|
104
102
|
|
103
|
+
def test_successful_check_enrollment_request_returns_card_enrolled
|
104
|
+
transaction = mock_transaction
|
105
|
+
transaction.expect :three_domain_id, 'randomstring'
|
106
|
+
stub_successful_session_token_request
|
107
|
+
token = @gateway.session_token
|
108
|
+
stub_successful_check_enrollment_request transaction, token, 'http://google.com/'
|
109
|
+
response = @gateway.check_enrollment transaction, token, 'http://google.com/'
|
110
|
+
assert_equal 'CARD_ENROLLED', response.response['response']['3DSecure']['gatewayCode']
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_successful_process_acs_result_request_returns_authorized
|
114
|
+
# transaction = mock_transaction
|
115
|
+
# transaction.expect :three_domain_id, 'randomstring'
|
116
|
+
# stub_successful_session_token_request
|
117
|
+
# token = @gateway.session_token
|
118
|
+
|
119
|
+
stub_successful_process_acs_result_request 'three_domain_id', 'pa_res'
|
120
|
+
response = @gateway.process_acs_result 'three_domain_id', 'pa_res'
|
121
|
+
assert_equal 'AUTHENTICATION_SUCCESSFUL', response.response['response']['3DSecure']['gatewayCode']
|
122
|
+
end
|
123
|
+
|
105
124
|
private
|
106
125
|
|
107
126
|
def stub_availability_request
|
@@ -112,7 +131,7 @@ private
|
|
112
131
|
def stub_successful_refund_request transaction
|
113
132
|
stub_refund_request(transaction).
|
114
133
|
to_return :status => 200, :headers => {}, :body => <<-EOS
|
115
|
-
{"merchant":"#{@merchant_id}","order":{"id":#{transaction.order_id},"totalAuthorizedAmount":0.00,"totalCapturedAmount":0.00,"totalRefundedAmount":0.00},
|
134
|
+
{"merchant":"#{@gateway.merchant_id}","order":{"id":#{transaction.order_id},"totalAuthorizedAmount":0.00,"totalCapturedAmount":0.00,"totalRefundedAmount":0.00},
|
116
135
|
"response":{"acquirerCode":"00","gatewayCode":"APPROVED"},"result":"SUCCESS","transaction":{"acquirer":{"id":"STGEORGE"},
|
117
136
|
"amount":#{transaction.amount},"authorizationCode":"000582","batch":20110707,"currency":"AUD","id":"#{transaction.transaction_id}",
|
118
137
|
"receipt":"110707000582","source":"INTERNET","terminal":"08845778","type":"REFUND"}}
|
@@ -170,7 +189,7 @@ private
|
|
170
189
|
end
|
171
190
|
|
172
191
|
def stub_session_token_request
|
173
|
-
stub_request(:post, /https:\/\/:#{@api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@merchant_id}\/session/).
|
192
|
+
stub_request(:post, /https:\/\/:#{@gateway.api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@gateway.merchant_id}\/session/).
|
174
193
|
with :headers => {
|
175
194
|
'Accept' => '*/*',
|
176
195
|
'Accept-Encoding' => 'gzip, deflate',
|
@@ -180,7 +199,7 @@ private
|
|
180
199
|
end
|
181
200
|
|
182
201
|
def stub_session_token_purchase_request transaction, token
|
183
|
-
stub_request(:put, /https:\/\/:#{@api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@merchant_id}\/order\/#{transaction.order_id}\/transaction\/#{transaction.transaction_id}/).
|
202
|
+
stub_request(:put, /https:\/\/:#{@gateway.api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@gateway.merchant_id}\/order\/#{transaction.order_id}\/transaction\/#{transaction.transaction_id}/).
|
184
203
|
with :body => JSON.generate({
|
185
204
|
'apiOperation' => 'PAY',
|
186
205
|
'order' => {'reference' => transaction.reference.to_s},
|
@@ -196,7 +215,7 @@ private
|
|
196
215
|
end
|
197
216
|
|
198
217
|
def stub_credit_card_token_purchase_request transaction, token
|
199
|
-
stub_request(:put, /https:\/\/:#{@api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@merchant_id}\/order\/#{transaction.order_id}\/transaction\/#{transaction.transaction_id}/).
|
218
|
+
stub_request(:put, /https:\/\/:#{@gateway.api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@gateway.merchant_id}\/order\/#{transaction.order_id}\/transaction\/#{transaction.transaction_id}/).
|
200
219
|
with :body => JSON.generate({
|
201
220
|
'apiOperation' => 'PAY',
|
202
221
|
'order' => {'reference' => transaction.reference.to_s},
|
@@ -212,7 +231,7 @@ private
|
|
212
231
|
end
|
213
232
|
|
214
233
|
def stub_refund_request transaction
|
215
|
-
stub_request(:put, /https:\/\/:#{@api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@merchant_id}\/order\/#{transaction.order_id}\/transaction\/#{transaction.transaction_id}/).
|
234
|
+
stub_request(:put, /https:\/\/:#{@gateway.api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@gateway.merchant_id}\/order\/#{transaction.order_id}\/transaction\/#{transaction.transaction_id}/).
|
216
235
|
with :body => JSON.generate({
|
217
236
|
'apiOperation' => 'REFUND',
|
218
237
|
'transaction' => {'amount' => transaction.amount.to_s, 'currency' => transaction.currency, 'reference' => transaction.transaction_id.to_s}
|
@@ -226,7 +245,7 @@ private
|
|
226
245
|
end
|
227
246
|
|
228
247
|
def stub_create_credit_card_token_request token
|
229
|
-
stub_request(:post, /https:\/\/:#{@api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@merchant_id}\/token/).
|
248
|
+
stub_request(:post, /https:\/\/:#{@gateway.api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@gateway.merchant_id}\/token/).
|
230
249
|
with :body => JSON.generate({
|
231
250
|
'cardDetails' => {'session' => token}
|
232
251
|
}),
|
@@ -237,7 +256,7 @@ private
|
|
237
256
|
end
|
238
257
|
|
239
258
|
def stub_delete_credit_card_token_request token
|
240
|
-
stub_request(:delete, /https:\/\/:#{@api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@merchant_id}\/token\/#{token}/).
|
259
|
+
stub_request(:delete, /https:\/\/:#{@gateway.api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@gateway.merchant_id}\/token\/#{token}/).
|
241
260
|
with :body => {},
|
242
261
|
:headers => {
|
243
262
|
'Accept' => '*/*',
|
@@ -245,6 +264,38 @@ private
|
|
245
264
|
}
|
246
265
|
end
|
247
266
|
|
267
|
+
def stub_successful_check_enrollment_request transaction, token, postback_url
|
268
|
+
stub_request(:put, /https:\/\/:#{@gateway.api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@gateway.merchant_id}\/3DSecureId\/#{transaction.three_domain_id}/).
|
269
|
+
with(:body => JSON.generate({
|
270
|
+
'3DSecure' => {'authenticationRedirect' => {'pageGenerationMode' => 'CUSTOMIZED', 'responseUrl' => postback_url}},
|
271
|
+
'apiOperation' => 'CHECK_3DS_ENROLLMENT',
|
272
|
+
'cardDetails' => {'session' => token},
|
273
|
+
'transaction' => {'amount' => transaction.amount.to_s, 'currency' => transaction.currency}
|
274
|
+
}),
|
275
|
+
:headers => {
|
276
|
+
'Accept' => '*/*',
|
277
|
+
'Accept-Encoding' => 'gzip, deflate',
|
278
|
+
'Content-Length' => '237',
|
279
|
+
'Content-Type' => 'Application/json;charset=UTF-8'
|
280
|
+
}).
|
281
|
+
to_return :status => 200, :headers => {}, :body => "{\"3DSecure\":{\"authenticationRedirect\":{\"customized\":{\"acsUrl\":\"https://secure.ap.tnspayments.com:443/acs/MastercardACS/4272b87b-2cc0-4232-a96e-e678ecbe7455\",\"paReq\":\"eAFVkd1ugkAQhe9NfAfCfV1ghVIzrNFq1aY/pNqY9I7AKCQCukILfZ2+SZ+sswq1vePMcGbPfAPDKt1p7yiPSZ55utkzdA2zMI+SbOvpr6u7K1cfim4HVrFEnCwxLCUKeMTjMdiilkSezrlpmJbh6gL80QseBDTjBE3rWcBaSS4ZxkFWCAjCw3jxJGyLG44NrJGQolxMhGnxvu1cu8DOGrIgRTGlMXUU1NocZa49FBGwUx3CvMwKWQvXcoC1Akq5E3FR7AeMITnJGJOvF+YpMNUDdknjlyrXkfaqkkg8R9HmrZotNx8pn8b17HNdGfexX64nfQ+Y+gOioEBhqa25aWsWH3BnYFPeUx2CVCUSs7GvfX8RA4MWPJdgr14anYWpGn8LQGwlwW9XaRVgtc8zpJEE8/cb2CX27VwhDQuCZ7f0bige7xOSpqGmJITJ5AYRbwQwZWXN3QjJ6axU+XfubucHAPGz0w==\"}},\"summaryStatus\":\"CARD_ENROLLED\",\"xid\":\"OddfZxGSfwm3EhyGzWx0JhPuWD4=\"},\"3DSecureId\":\"#{transaction.three_domain_id}\",\"merchant\":\"#{@gateway.merchant_id}\",\"response\":{\"3DSecure\":{\"gatewayCode\":\"CARD_ENROLLED\"}}}"
|
282
|
+
end
|
283
|
+
|
284
|
+
def stub_successful_process_acs_result_request three_domain_id, pa_res
|
285
|
+
stub_request(:post, /https:\/\/:#{@gateway.api_key}@secure\.ap\.tnspayments\.com\/api\/rest\/version\/4\/merchant\/#{@gateway.merchant_id}\/3DSecureId\/#{three_domain_id}/).
|
286
|
+
with(:body => JSON.generate({
|
287
|
+
'3DSecure' => {'paRes' => pa_res},
|
288
|
+
'apiOperation' => 'PROCESS_ACS_RESULT'
|
289
|
+
}),
|
290
|
+
:headers => {
|
291
|
+
'Accept' => '*/*',
|
292
|
+
'Accept-Encoding' => 'gzip, deflate',
|
293
|
+
'Content-Length' => '67',
|
294
|
+
'Content-Type' => 'Application/json;charset=UTF-8'
|
295
|
+
}).
|
296
|
+
to_return :status => 200, :headers => {}, :body => "{\"response\":{\"3DSecure\":{\"gatewayCode\":\"AUTHENTICATION_SUCCESSFUL\"}}}"
|
297
|
+
end
|
298
|
+
|
248
299
|
def mock_transaction
|
249
300
|
mock = MiniTest::Mock.new
|
250
301
|
mock.expect :amount, 100
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tns_payments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tim Cooper
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-04-02 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|