tns_payments 0.0.11 → 0.0.12

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.
@@ -0,0 +1,114 @@
1
+ ---
2
+ recorded_with: VCR 2.9.3
3
+ http_interactions:
4
+ - request:
5
+ method: post
6
+ uri: https://merchant.<TNS_MERCHANT_ID>:<TNS_API_KEY>@secure.ap.tnspayments.com/api/rest/version/32/merchant/<TNS_MERCHANT_ID>/session
7
+ body:
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ Content-Type:
13
+ - Application/json;charset=UTF-8
14
+ Accept-Encoding:
15
+ - gzip, deflate
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ Content-Length:
22
+ - "149"
23
+ Content-Type:
24
+ - application/json;charset=UTF-8
25
+ Date:
26
+ - Mon, 11 Jan 2016 23:51:14 GMT
27
+ Pragma:
28
+ - no-cache
29
+ Expires:
30
+ - "0"
31
+ Set-Cookie:
32
+ - TS018aacab=01c9ad79a06dde739255b51ec92c260efb205ccd88a9961f27908e9f6e8ac7fbd285ec27f8; Path=/
33
+ Cache-Control:
34
+ - no-cache, no-store, must-revalidate
35
+ body:
36
+ string: "{\"merchant\":\"<TNS_MERCHANT_ID>\",\"result\":\"SUCCESS\",\"session\":{\"id\":\"SESSION0002019574105M4098673I82\",\"updateStatus\":\"NO_UPDATE\",\"version\":\"343a7dec01\"}}"
37
+ http_version:
38
+ recorded_at: Mon, 11 Jan 2016 23:51:15 GMT
39
+ - request:
40
+ method: put
41
+ uri: https://merchant.<TNS_MERCHANT_ID>:<TNS_API_KEY>@secure.ap.tnspayments.com/api/rest/version/32/merchant/<TNS_MERCHANT_ID>/session/SESSION0002019574105M4098673I82
42
+ body:
43
+ string: "{\"sourceOfFunds\":{\"type\":\"CARD\",\"provided\":{\"card\":{\"number\":\"4005550000000001\",\"expiry\":{\"month\":\"05\",\"year\":\"17\"},\"securityCode\":\"123\"}}}}"
44
+ headers:
45
+ Accept:
46
+ - "*/*"
47
+ Content-Length:
48
+ - "140"
49
+ Content-Type:
50
+ - Application/json;charset=UTF-8
51
+ Accept-Encoding:
52
+ - gzip, deflate
53
+ response:
54
+ status:
55
+ code: 200
56
+ message: OK
57
+ headers:
58
+ Content-Length:
59
+ - "337"
60
+ Content-Type:
61
+ - application/json;charset=UTF-8
62
+ Date:
63
+ - Mon, 11 Jan 2016 23:51:14 GMT
64
+ Pragma:
65
+ - no-cache
66
+ Expires:
67
+ - "0"
68
+ Set-Cookie:
69
+ - TS018aacab=01c9ad79a071a665b9d48249c765377f6f047b0259310dfdd45ee0e4b85a31907c7635ecee; Path=/
70
+ Cache-Control:
71
+ - no-cache, no-store, must-revalidate
72
+ body:
73
+ string: "{\"merchant\":\"<TNS_MERCHANT_ID>\",\"session\":{\"id\":\"SESSION0002019574105M4098673I82\",\"updateStatus\":\"SUCCESS\",\"version\":\"dff8884502\"},\"sourceOfFunds\":{\"provided\":{\"card\":{\"brand\":\"VISA\",\"expiry\":{\"month\":\"5\",\"year\":\"17\"},\"fundingMethod\":\"CREDIT\",\"number\":\"400555xxxxxx0001\",\"scheme\":\"VISA\",\"securityCode\":\"xxx\"}},\"type\":\"CARD\"},\"version\":\"32\"}"
74
+ http_version:
75
+ recorded_at: Mon, 11 Jan 2016 23:51:15 GMT
76
+ - request:
77
+ method: put
78
+ uri: https://merchant.<TNS_MERCHANT_ID>:<TNS_API_KEY>@secure.ap.tnspayments.com/api/rest/version/32/merchant/<TNS_MERCHANT_ID>/3DSecureId/65ccba0dc0797b93da4d0d0544d00cfcb8d54c4d
79
+ body:
80
+ string: "{\"apiOperation\":\"CHECK_3DS_ENROLLMENT\",\"3DSecure\":{\"authenticationRedirect\":{\"pageGenerationMode\":\"CUSTOMIZED\",\"responseUrl\":\"http://google.com\"}},\"session\":{\"id\":\"SESSION0002019574105M4098673I82\"},\"order\":{\"amount\":\"100.00\",\"currency\":\"EUR\"}}"
81
+ headers:
82
+ Accept:
83
+ - "*/*"
84
+ Content-Length:
85
+ - "243"
86
+ Content-Type:
87
+ - Application/json;charset=UTF-8
88
+ Accept-Encoding:
89
+ - gzip, deflate
90
+ response:
91
+ status:
92
+ code: 400
93
+ message: Bad Request
94
+ headers:
95
+ Content-Length:
96
+ - "173"
97
+ Content-Type:
98
+ - application/json;charset=UTF-8
99
+ Date:
100
+ - Mon, 11 Jan 2016 23:51:14 GMT
101
+ Pragma:
102
+ - no-cache
103
+ Expires:
104
+ - "0"
105
+ Set-Cookie:
106
+ - TS018aacab=01c9ad79a03296ec5867ae2026006a379b6119aa45e009c45c94d2794ff069cf0c583a0caf; Path=/
107
+ Cache-Control:
108
+ - no-cache, no-store, must-revalidate
109
+ X-Cnection:
110
+ - close
111
+ body:
112
+ string: "{\"error\":{\"cause\":\"INVALID_REQUEST\",\"explanation\":\"Merchant : Everyday Hero Pty Ltd is not configured to support 3D Secure operations for this card type.\"},\"result\":\"ERROR\"}"
113
+ http_version:
114
+ recorded_at: Mon, 11 Jan 2016 23:51:15 GMT
@@ -0,0 +1,112 @@
1
+ ---
2
+ recorded_with: VCR 2.9.3
3
+ http_interactions:
4
+ - request:
5
+ method: post
6
+ uri: https://merchant.<TNS_MERCHANT_ID>:<TNS_API_KEY>@secure.ap.tnspayments.com/api/rest/version/32/merchant/<TNS_MERCHANT_ID>/session
7
+ body:
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ Content-Type:
13
+ - Application/json;charset=UTF-8
14
+ Accept-Encoding:
15
+ - gzip, deflate
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ Content-Length:
22
+ - "149"
23
+ Content-Type:
24
+ - application/json;charset=UTF-8
25
+ Date:
26
+ - Mon, 11 Jan 2016 23:51:12 GMT
27
+ Pragma:
28
+ - no-cache
29
+ Expires:
30
+ - "0"
31
+ Set-Cookie:
32
+ - TS018aacab=01c9ad79a0c60f40c76dbf326595c6bc70d210a981d4645792f9f90d7743d0cfd0897f0124; Path=/
33
+ Cache-Control:
34
+ - no-cache, no-store, must-revalidate
35
+ body:
36
+ string: "{\"merchant\":\"<TNS_MERCHANT_ID>\",\"result\":\"SUCCESS\",\"session\":{\"id\":\"SESSION0002349344166L7073972K85\",\"updateStatus\":\"NO_UPDATE\",\"version\":\"43d96eab01\"}}"
37
+ http_version:
38
+ recorded_at: Mon, 11 Jan 2016 23:51:13 GMT
39
+ - request:
40
+ method: put
41
+ uri: https://merchant.<TNS_MERCHANT_ID>:<TNS_API_KEY>@secure.ap.tnspayments.com/api/rest/version/32/merchant/<TNS_MERCHANT_ID>/session/SESSION0002349344166L7073972K85
42
+ body:
43
+ string: "{\"sourceOfFunds\":{\"type\":\"CARD\",\"provided\":{\"card\":{\"number\":\"4005550000000001\",\"expiry\":{\"month\":\"5\",\"year\":\"17\"},\"securityCode\":\"123\"}}}}"
44
+ headers:
45
+ Accept:
46
+ - "*/*"
47
+ Content-Length:
48
+ - "139"
49
+ Content-Type:
50
+ - Application/json;charset=UTF-8
51
+ Accept-Encoding:
52
+ - gzip, deflate
53
+ response:
54
+ status:
55
+ code: 200
56
+ message: OK
57
+ headers:
58
+ Content-Length:
59
+ - "337"
60
+ Content-Type:
61
+ - application/json;charset=UTF-8
62
+ Date:
63
+ - Mon, 11 Jan 2016 23:51:13 GMT
64
+ Pragma:
65
+ - no-cache
66
+ Expires:
67
+ - "0"
68
+ Set-Cookie:
69
+ - TS018aacab=01c9ad79a01f8a0f43774fac25c77e314f73b74985f1ee45251c3e2ce336977766e6cf5335; Path=/
70
+ Cache-Control:
71
+ - no-cache, no-store, must-revalidate
72
+ body:
73
+ string: "{\"merchant\":\"<TNS_MERCHANT_ID>\",\"session\":{\"id\":\"SESSION0002349344166L7073972K85\",\"updateStatus\":\"SUCCESS\",\"version\":\"75b57d6e02\"},\"sourceOfFunds\":{\"provided\":{\"card\":{\"brand\":\"VISA\",\"expiry\":{\"month\":\"5\",\"year\":\"17\"},\"fundingMethod\":\"CREDIT\",\"number\":\"400555xxxxxx0001\",\"scheme\":\"VISA\",\"securityCode\":\"xxx\"}},\"type\":\"CARD\"},\"version\":\"32\"}"
74
+ http_version:
75
+ recorded_at: Mon, 11 Jan 2016 23:51:14 GMT
76
+ - request:
77
+ method: put
78
+ uri: https://merchant.<TNS_MERCHANT_ID>:<TNS_API_KEY>@secure.ap.tnspayments.com/api/rest/version/32/merchant/<TNS_MERCHANT_ID>/order/10000001602/transaction/PAY
79
+ body:
80
+ string: "{\"apiOperation\":\"PAY\",\"order\":{\"amount\":\"100.00\",\"currency\":\"EUR\",\"reference\":\"PAY\"},\"transaction\":{\"reference\":\"PAY\"},\"sourceOfFunds\":{\"type\":\"CARD\"},\"session\":{\"id\":\"SESSION0002349344166L7073972K85\"}}"
81
+ headers:
82
+ Accept:
83
+ - "*/*"
84
+ Content-Length:
85
+ - "202"
86
+ Content-Type:
87
+ - Application/json;charset=UTF-8
88
+ Accept-Encoding:
89
+ - gzip, deflate
90
+ response:
91
+ status:
92
+ code: 201
93
+ message: Created
94
+ headers:
95
+ Content-Length:
96
+ - "1610"
97
+ Content-Type:
98
+ - application/json;charset=UTF-8
99
+ Date:
100
+ - Mon, 11 Jan 2016 23:51:13 GMT
101
+ Pragma:
102
+ - no-cache
103
+ Expires:
104
+ - "0"
105
+ Set-Cookie:
106
+ - TS018aacab=01c9ad79a0a8dd38e9e052f9023b6c35ae14d889e0f74a18014dc274cd485b412b7c4282ea; Path=/
107
+ Cache-Control:
108
+ - no-cache, no-store, must-revalidate
109
+ body:
110
+ string: "{\"gatewayEntryPoint\":\"WEB_SERVICES_API\",\"merchant\":\"<TNS_MERCHANT_ID>\",\"order\":{\"amount\":100.00,\"creationTime\":\"2016-01-11T23:51:13.668Z\",\"currency\":\"EUR\",\"id\":\"10000001602\",\"reference\":\"PAY\",\"status\":\"CAPTURED\",\"totalAuthorizedAmount\":100.00,\"totalCapturedAmount\":100.00,\"totalRefundedAmount\":0.00},\"response\":{\"acquirerCode\":\"00\",\"acquirerMessage\":\"Approved\",\"cardSecurityCode\":{\"acquirerCode\":\"1\",\"gatewayCode\":\"NOT_PROCESSED\"},\"gatewayCode\":\"APPROVED\"},\"result\":\"SUCCESS\",\"risk\":{\"response\":{\"gatewayCode\":\"ACCEPTED\",\"review\":{\"decision\":\"NOT_REQUIRED\"},\"rule\":[{\"data\":\"400555\",\"name\":\"MERCHANT_BIN_RANGE\",\"recommendation\":\"NO_ACTION\",\"type\":\"MERCHANT_RULE\"},{\"data\":\"P\",\"name\":\"MERCHANT_CSC\",\"recommendation\":\"NO_ACTION\",\"type\":\"MERCHANT_RULE\"},{\"name\":\"SUSPECT_CARD_LIST\",\"recommendation\":\"NO_ACTION\",\"type\":\"MERCHANT_RULE\"},{\"name\":\"TRUSTED_CARD_LIST\",\"recommendation\":\"NO_ACTION\",\"type\":\"MERCHANT_RULE\"},{\"data\":\"400555\",\"name\":\"MSO_BIN_RANGE\",\"recommendation\":\"NO_ACTION\",\"type\":\"MSO_RULE\"},{\"data\":\"P\",\"name\":\"MSO_CSC\",\"recommendation\":\"NO_ACTION\",\"type\":\"MSO_RULE\"}]}},\"sourceOfFunds\":{\"provided\":{\"card\":{\"brand\":\"VISA\",\"expiry\":{\"month\":\"5\",\"year\":\"17\"},\"fundingMethod\":\"CREDIT\",\"issuer\":\"JPMORGAN CHASE BANK, N.A.\",\"number\":\"400555xxxxxx0001\",\"scheme\":\"VISA\"}},\"type\":\"CARD\"},\"timeOfRecord\":\"2016-01-11T23:51:13.668Z\",\"transaction\":{\"acquirer\":{\"batch\":1,\"id\":\"AIB\",\"merchantId\":\"011855511\"},\"amount\":100.00,\"authorizationCode\":\"029331\",\"currency\":\"EUR\",\"frequency\":\"SINGLE\",\"id\":\"PAY\",\"receipt\":\"AAAAC5BK7Q\",\"reference\":\"PAY\",\"source\":\"MOTO\",\"terminal\":\"31208585\",\"type\":\"PAYMENT\"},\"version\":\"32\"}"
111
+ http_version:
112
+ recorded_at: Mon, 11 Jan 2016 23:51:14 GMT
data/test/helper.rb CHANGED
@@ -2,3 +2,51 @@ require 'minitest/autorun'
2
2
  require 'tns_payments'
3
3
 
4
4
  include TNSPayments
5
+
6
+ require 'dotenv'
7
+ Dotenv.load
8
+
9
+ require 'webmock/minitest'
10
+
11
+ require 'vcr'
12
+ VCR.configure do |config|
13
+ config.cassette_library_dir = 'test/cassettes'
14
+ config.hook_into :webmock
15
+ config.default_cassette_options = {
16
+ :match_requests_on => [:method, :uri, :body, :host],
17
+ :record => :once,
18
+ }
19
+ ENV.keys.grep(/TNS_(3DS_)?(MERCHANT_ID|API_KEY)/).each do |key|
20
+ config.filter_sensitive_data("<#{key}>") { ENV.fetch(key) }
21
+ end
22
+ end
23
+
24
+ def tns
25
+ @tns ||= TNSPayments.new(
26
+ :merchant_id => ENV.fetch("TNS_MERCHANT_ID"),
27
+ :api_key => ENV.fetch("TNS_API_KEY")
28
+ )
29
+ end
30
+
31
+ def tns_3ds
32
+ @tns_3ds ||= TNSPayments.new(
33
+ :merchant_id => ENV.fetch("TNS_3DS_MERCHANT_ID"),
34
+ :api_key => ENV.fetch("TNS_3DS_API_KEY")
35
+ )
36
+ end
37
+
38
+ def with_3ds_enabled_tns
39
+ yield(tns_3ds)
40
+ end
41
+
42
+ def with_3ds_disabled_tns
43
+ yield(tns)
44
+ end
45
+
46
+ def with_cassette
47
+ caller[0] =~ /`([^']*)'/
48
+
49
+ VCR.use_cassette($1.to_s) do
50
+ yield
51
+ end
52
+ end
@@ -0,0 +1,187 @@
1
+ require 'helper'
2
+ require 'ostruct'
3
+ require 'digest'
4
+ require 'tns_payments/test_support/card_session'
5
+
6
+ class TNSPayments::OperationsTest < MiniTest::Unit::TestCase
7
+ def test_available
8
+ with_cassette do
9
+ assert tns.available?
10
+ end
11
+ end
12
+
13
+ def test_mastercard_successful_purchase
14
+ order_id = 1
15
+
16
+ with_cassette do
17
+ session = TestSupport::CardSession.sample(:mastercard, tns)
18
+ transaction = create_transaction(order_id)
19
+ result = tns.purchase(transaction, session)
20
+ response = result.response
21
+
22
+ assert result.success?
23
+ assert_equal 'CAPTURED', response['order']['status']
24
+ assert_equal 'MASTERCARD', response['sourceOfFunds']['provided']['card']['brand']
25
+ end
26
+ end
27
+
28
+ def test_visa_successful_purchase
29
+ order_id = 2
30
+
31
+ with_cassette do
32
+ session = TestSupport::CardSession.sample(:visa, tns)
33
+ transaction = create_transaction(order_id)
34
+ result = tns.purchase(transaction, session)
35
+ response = result.response
36
+
37
+ assert result.success?
38
+ assert_equal 'CAPTURED', response['order']['status']
39
+ assert_equal 'VISA', response['sourceOfFunds']['provided']['card']['brand']
40
+ end
41
+ end
42
+
43
+ def test_amex_successful_purchase
44
+ order_id = 3
45
+
46
+ with_cassette do
47
+ session = TestSupport::CardSession.sample(:amex, tns)
48
+ transaction = create_transaction(order_id)
49
+ result = tns.purchase(transaction, session)
50
+ response = result.response
51
+
52
+ assert result.success?
53
+ assert_equal 'CAPTURED', response['order']['status']
54
+ assert_equal 'AMEX', response['sourceOfFunds']['provided']['card']['brand']
55
+ end
56
+ end
57
+
58
+ def test_unsuccessful_purchase
59
+ order_id = 10
60
+
61
+ with_cassette do
62
+ transaction = create_transaction(order_id)
63
+ result = tns.purchase(transaction, "LOLSESSIONTOKEN")
64
+ response = result.response
65
+
66
+ refute result.success?
67
+ end
68
+ end
69
+
70
+ def test_refund_successful_purchase
71
+ order_id = 4
72
+
73
+ with_cassette do
74
+ session = TestSupport::CardSession.sample(:visa, tns)
75
+ payment_transaction = create_transaction(order_id)
76
+ result = tns.purchase(payment_transaction, session)
77
+ response = result.response
78
+ assert result.success?
79
+
80
+ refund_transaction = create_refund_transaction(order_id)
81
+ result = tns.refund(refund_transaction)
82
+ response = result.response
83
+ assert result.success?
84
+ end
85
+ end
86
+
87
+ def test_tokenise_creditcard_from_session_for_later_purchase
88
+ order_id = 5
89
+
90
+ with_cassette do
91
+ session = TestSupport::CardSession.sample(:visa, tns)
92
+ result = tns.create_credit_card_token(session)
93
+ response = result.response
94
+
95
+ assert result.success?
96
+ token = response['token']
97
+ refute_nil token
98
+
99
+ transaction = create_transaction(order_id)
100
+ assert tns.purchase(transaction, token).success?
101
+ end
102
+ end
103
+
104
+ def test_deleting_tokenised_card
105
+ successful_order_id = 6
106
+ failed_order_id = 7
107
+ successful_transaction = create_transaction(successful_order_id)
108
+ failed_transaction = create_transaction(failed_order_id)
109
+
110
+ with_cassette do
111
+ session = TestSupport::CardSession.sample(:visa, tns)
112
+ token = tns.create_credit_card_token(session).response['token']
113
+
114
+ assert tns.purchase(successful_transaction, token).success?
115
+ assert tns.delete_credit_card_token(token).success?
116
+ refute tns.purchase(failed_transaction, token).success?
117
+ end
118
+ end
119
+
120
+ def test_card_enrolled_for_3ds
121
+ order_id = 8
122
+
123
+ with_3ds_enabled_tns do |tns|
124
+ with_cassette do
125
+ session = TestSupport::CardSession.sample(:visa_enrolled_3ds, tns)
126
+ transaction = create_transaction(order_id, :currency => "GBP")
127
+
128
+ result = tns.check_enrollment(transaction, session, "http://google.com")
129
+ assert result.success?
130
+ assert_equal 'CARD_ENROLLED', result.response['3DSecure']['summaryStatus']
131
+ end
132
+ end
133
+ end
134
+
135
+ def test_card_not_enrolled_for_3ds
136
+ order_id = 9
137
+
138
+ with_3ds_enabled_tns do |tns|
139
+ with_cassette do
140
+ session = TestSupport::CardSession.sample(:visa_not_enrolled_3ds, tns)
141
+ transaction = create_transaction(order_id, :currency => "GBP")
142
+
143
+ result = tns.check_enrollment(transaction, session, "http://google.com")
144
+ assert result.success?
145
+ assert_equal 'CARD_NOT_ENROLLED', result.response['3DSecure']['summaryStatus']
146
+ end
147
+ end
148
+ end
149
+
150
+ def test_unsupported_3ds_gateway
151
+ order_id = 10
152
+
153
+ with_3ds_disabled_tns do |tns|
154
+ with_cassette do
155
+ session = TestSupport::CardSession.sample(:visa_not_enrolled_3ds, tns)
156
+ transaction = create_transaction(order_id, :currency => "EUR")
157
+
158
+ result = tns.check_enrollment(transaction, session, "http://google.com")
159
+ refute result.success?
160
+ end
161
+ end
162
+ end
163
+
164
+ private
165
+
166
+ def create_transaction(order_id, options = {})
167
+ transaction_id = options.fetch(:transaction_id) { "PAY" }
168
+ currency = options.fetch(:currency) { "EUR" }
169
+
170
+ OpenStruct.new(
171
+ :amount => "100.00",
172
+ :currency => currency,
173
+ :order_id => prefix(order_id),
174
+ :transaction_id => transaction_id,
175
+ :reference => "PAY",
176
+ :three_domain_id => Digest::SHA1.hexdigest(prefix(order_id).to_s)
177
+ )
178
+ end
179
+
180
+ def create_refund_transaction(order_id)
181
+ create_transaction(order_id, :transaction_id => "REFUND")
182
+ end
183
+
184
+ def prefix(order_id)
185
+ 1_600 + order_id
186
+ end
187
+ end