adyen-ruby-api-library 7.2.0 → 7.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/adyen/client.rb +59 -36
- data/lib/adyen/version.rb +1 -1
- data/spec/checkout-oauth_spec.rb +621 -0
- data/spec/client_spec.rb +24 -19
- data/spec/management-oauth_spec.rb +62 -0
- data/spec/spec_helper.rb +5 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f92203448587aeac3de504e35af2298e7b279dbec39272caf1b3502f79a6f77
|
4
|
+
data.tar.gz: 2366da0ada0249bbeae5d3f21f051150f2e687054122e782e4f671128a8fb471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f10ac14eb9a75e8fd4c587f0419503982e59bcb5344c3a5bc771110bead40b163cd6d1051dc5fbe17cb1ccfd4e8021206f74e0bc057a1b1504a75489c8ad5b22
|
7
|
+
data.tar.gz: 6fdc37b92694ef969c8dce58fd1a89fa9a6e1e8c3b033ceb48532a5c452a8f28d484e9f6869ac55c4c9f18b3ecc5417090dd1c90bc41152a1034a1c091bd80c8
|
data/README.md
CHANGED
@@ -215,6 +215,18 @@ statusRequest =
|
|
215
215
|
response = adyen.terminal_cloud_api.sync(statusRequest)
|
216
216
|
```
|
217
217
|
|
218
|
+
## OAuth usage (for Partners)
|
219
|
+
If you are using our OAuth service to make API requests on your customer's behalf, and you already got your Access Token as explained in the [OAuth Integration Guide](https://docs.adyen.com/development-resources/oauth/integration/#page-introduction), you can setup your Client like in the following example:
|
220
|
+
|
221
|
+
~~~~ruby
|
222
|
+
adyen = Adyen::Client.new
|
223
|
+
|
224
|
+
adyen.oauth_token = "oauth_token"
|
225
|
+
|
226
|
+
~~~~
|
227
|
+
|
228
|
+
The APIs available to use through OAuth in this library depend on the [OAuth Scopes](https://docs.adyen.com/development-resources/oauth/scopes/) defined when [Registering your OAuth client](https://docs.adyen.com/development-resources/oauth/integration/#step-1-register-your-client).
|
229
|
+
|
218
230
|
## Feedback
|
219
231
|
We value your input! Help us enhance our API Libraries and improve the integration experience by providing your feedback. Please take a moment to fill out [our feedback form](https://forms.gle/A4EERrR6CWgKWe5r9) to share your thoughts, suggestions or ideas.
|
220
232
|
|
data/lib/adyen/client.rb
CHANGED
@@ -12,16 +12,24 @@ require_relative './result'
|
|
12
12
|
|
13
13
|
module Adyen
|
14
14
|
class Client
|
15
|
-
attr_accessor :ws_user, :ws_password, :api_key, :client, :adapter
|
16
|
-
attr_reader :env, :connection_options
|
15
|
+
attr_accessor :ws_user, :ws_password, :api_key, :oauth_token, :client, :adapter
|
16
|
+
attr_reader :env, :connection_options, :adapter_options
|
17
17
|
|
18
|
-
def initialize(ws_user: nil, ws_password: nil, api_key: nil, env: :live, adapter: nil, mock_port: 3001,
|
19
|
-
live_url_prefix: nil, mock_service_url_base: nil, connection_options: nil)
|
18
|
+
def initialize(ws_user: nil, ws_password: nil, api_key: nil, oauth_token: nil, env: :live, adapter: nil, mock_port: 3001,
|
19
|
+
live_url_prefix: nil, mock_service_url_base: nil, connection_options: nil, adapter_options: nil)
|
20
20
|
@ws_user = ws_user
|
21
21
|
@ws_password = ws_password
|
22
22
|
@api_key = api_key
|
23
|
+
@oauth_token = oauth_token
|
23
24
|
@env = env
|
24
25
|
@adapter = adapter || Faraday.default_adapter
|
26
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.1')
|
27
|
+
# for faraday 2.1 and higher
|
28
|
+
@adapter_options = adapter_options || Faraday.default_adapter_options
|
29
|
+
else
|
30
|
+
# for faraday 1.x and 2.0
|
31
|
+
@adapter_options = adapter_options || {}
|
32
|
+
end
|
25
33
|
@mock_service_url_base = mock_service_url_base || "http://localhost:#{mock_port}"
|
26
34
|
@live_url_prefix = live_url_prefix
|
27
35
|
@connection_options = connection_options || Faraday::ConnectionOptions.new
|
@@ -113,44 +121,16 @@ module Adyen
|
|
113
121
|
# get URL for requested endpoint
|
114
122
|
url = service_url(service, action.is_a?(String) ? action : action.fetch(:url), version)
|
115
123
|
|
116
|
-
|
117
|
-
# will use api_key if present, otherwise ws_user and ws_password
|
118
|
-
if @api_key.nil?
|
119
|
-
if service == 'PaymentSetupAndVerification'
|
120
|
-
raise Adyen::AuthenticationError.new('Checkout service requires API-key', request_data),
|
121
|
-
'Checkout service requires API-key'
|
122
|
-
elsif @ws_password.nil? || @ws_user.nil?
|
123
|
-
raise Adyen::AuthenticationError.new(
|
124
|
-
'No authentication found - please set api_key or ws_user and ws_password',
|
125
|
-
request_data
|
126
|
-
),
|
127
|
-
'No authentication found - please set api_key or ws_user and ws_password'
|
128
|
-
else
|
129
|
-
auth_type = 'basic'
|
130
|
-
end
|
131
|
-
else
|
132
|
-
auth_type = 'api-key'
|
133
|
-
end
|
124
|
+
auth_type = auth_type(service, request_data)
|
134
125
|
|
135
126
|
# initialize Faraday connection object
|
136
127
|
conn = Faraday.new(url, @connection_options) do |faraday|
|
137
|
-
faraday.adapter @adapter
|
128
|
+
faraday.adapter @adapter, **@adapter_options
|
138
129
|
faraday.headers['Content-Type'] = 'application/json'
|
139
130
|
faraday.headers['User-Agent'] = "#{Adyen::NAME}/#{Adyen::VERSION}"
|
140
131
|
|
141
|
-
# set
|
142
|
-
|
143
|
-
when 'basic'
|
144
|
-
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
145
|
-
# for faraday 2.0 and higher
|
146
|
-
faraday.request :authorization, :basic, @ws_user, @ws_password
|
147
|
-
else
|
148
|
-
# for faraday 1.x
|
149
|
-
faraday.basic_auth(@ws_user, @ws_password)
|
150
|
-
end
|
151
|
-
when 'api-key'
|
152
|
-
faraday.headers['x-api-key'] = @api_key
|
153
|
-
end
|
132
|
+
# set header based on auth_type and service
|
133
|
+
auth_header(auth_type, faraday)
|
154
134
|
|
155
135
|
# add optional headers if specified in request
|
156
136
|
# will overwrite default headers if overlapping
|
@@ -298,6 +278,49 @@ module Adyen
|
|
298
278
|
def terminal_cloud_api
|
299
279
|
@terminal_cloud_api ||= Adyen::TerminalCloudAPI.new(self)
|
300
280
|
end
|
281
|
+
|
282
|
+
private
|
283
|
+
|
284
|
+
def auth_header(auth_type, faraday)
|
285
|
+
case auth_type
|
286
|
+
when "basic"
|
287
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
288
|
+
# for faraday 2.0 and higher
|
289
|
+
faraday.request :authorization, :basic, @ws_user, @ws_password
|
290
|
+
else
|
291
|
+
# for faraday 1.x
|
292
|
+
faraday.basic_auth(@ws_user, @ws_password)
|
293
|
+
end
|
294
|
+
when "api-key"
|
295
|
+
faraday.headers["x-api-key"] = @api_key
|
296
|
+
when "oauth"
|
297
|
+
faraday.headers["Authorization"] = "Bearer #{@oauth_token}"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def auth_type(service, request_data)
|
302
|
+
# make sure valid authentication has been provided
|
303
|
+
validate_auth_type(service, request_data)
|
304
|
+
# Will prioritize authentication methods in this order:
|
305
|
+
# api-key, oauth, basic
|
306
|
+
return "api-key" unless @api_key.nil?
|
307
|
+
return "oauth" unless @oauth_token.nil?
|
308
|
+
"basic"
|
309
|
+
end
|
310
|
+
|
311
|
+
def validate_auth_type(service, request_data)
|
312
|
+
# ensure authentication has been provided
|
313
|
+
if @api_key.nil? && @oauth_token.nil? && (@ws_password.nil? || @ws_user.nil?)
|
314
|
+
raise Adyen::AuthenticationError.new(
|
315
|
+
'No authentication found - please set api_key, oauth_token, or ws_user and ws_password',
|
316
|
+
request_data
|
317
|
+
)
|
318
|
+
end
|
319
|
+
if service == "PaymentSetupAndVerification" && @api_key.nil? && @oauth_token.nil? && @ws_password.nil? && @ws_user.nil?
|
320
|
+
raise Adyen::AuthenticationError.new('Checkout service requires API-key or oauth_token', request_data),
|
321
|
+
'Checkout service requires API-key or oauth_token'
|
322
|
+
end
|
323
|
+
end
|
301
324
|
end
|
302
325
|
end
|
303
326
|
# rubocop:enable all
|
data/lib/adyen/version.rb
CHANGED
@@ -0,0 +1,621 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
# rubocop:disable Metrics/BlockLength
|
5
|
+
RSpec.describe "Adyen::Checkout OAuth authentication", service: "checkout" do
|
6
|
+
before(:all) do
|
7
|
+
@shared_values = {
|
8
|
+
client: create_client(:oauth),
|
9
|
+
service: "Checkout",
|
10
|
+
}
|
11
|
+
@auth_header = { "Authorization": "Bearer #{@shared_values[:client].oauth_token}" }
|
12
|
+
end
|
13
|
+
|
14
|
+
# must be created manually because every field in the response is an array
|
15
|
+
it "makes a payment_methods call", focus: true do
|
16
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment_methods.json"))
|
17
|
+
|
18
|
+
response_body = json_from_file("mocks/responses/Checkout/payment_methods.json")
|
19
|
+
|
20
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentMethods", @shared_values[:client].checkout.version)
|
21
|
+
WebMock.stub_request(:post, url).
|
22
|
+
with(
|
23
|
+
body: request_body,
|
24
|
+
headers: @auth_header
|
25
|
+
).
|
26
|
+
to_return(
|
27
|
+
body: response_body
|
28
|
+
)
|
29
|
+
|
30
|
+
result = @shared_values[:client].checkout.payments_api.payment_methods(request_body)
|
31
|
+
response_hash = result.response
|
32
|
+
|
33
|
+
expect(result.status).
|
34
|
+
to eq(200)
|
35
|
+
expect(response_hash).
|
36
|
+
to eq(JSON.parse(response_body))
|
37
|
+
expect(response_hash).
|
38
|
+
to be_a Adyen::HashWithAccessors
|
39
|
+
expect(response_hash).
|
40
|
+
to be_a_kind_of Hash
|
41
|
+
end
|
42
|
+
|
43
|
+
it "makes a paymentMethods/balance call" do
|
44
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment_methods_balance.json"))
|
45
|
+
|
46
|
+
response_body = json_from_file("mocks/responses/Checkout/payment_methods_balance.json")
|
47
|
+
|
48
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentMethods/balance", @shared_values[:client].checkout.version)
|
49
|
+
WebMock.stub_request(:post, url).
|
50
|
+
with(
|
51
|
+
body: request_body,
|
52
|
+
headers: @auth_header
|
53
|
+
).
|
54
|
+
to_return(
|
55
|
+
body: response_body
|
56
|
+
)
|
57
|
+
|
58
|
+
result = @shared_values[:client].checkout.orders_api.get_balance_of_gift_card(request_body)
|
59
|
+
# result.response is already a Ruby hash (rather than an unparsed JSON string)
|
60
|
+
response_hash = result.response
|
61
|
+
|
62
|
+
expect(result.status).
|
63
|
+
to eq(200)
|
64
|
+
expect(response_hash).
|
65
|
+
to eq(JSON.parse(response_body))
|
66
|
+
expect(response_hash).
|
67
|
+
to be_a Adyen::HashWithAccessors
|
68
|
+
expect(response_hash).
|
69
|
+
to be_a_kind_of Hash
|
70
|
+
expect(response_hash["balance"]).
|
71
|
+
to eq("100")
|
72
|
+
end
|
73
|
+
|
74
|
+
# must be created manually due to payments/details format
|
75
|
+
it "makes a payments/details call" do
|
76
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment-details.json"))
|
77
|
+
|
78
|
+
response_body = json_from_file("mocks/responses/Checkout/payment-details.json")
|
79
|
+
|
80
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/details", @shared_values[:client].checkout.version)
|
81
|
+
WebMock.stub_request(:post, url).
|
82
|
+
with(
|
83
|
+
body: request_body,
|
84
|
+
headers: @auth_header
|
85
|
+
).
|
86
|
+
to_return(
|
87
|
+
body: response_body
|
88
|
+
)
|
89
|
+
|
90
|
+
result = @shared_values[:client].checkout.payments_api.payments_details(request_body)
|
91
|
+
# result.response is already a Ruby hash (rather than an unparsed JSON string)
|
92
|
+
response_hash = result.response
|
93
|
+
|
94
|
+
expect(result.status).
|
95
|
+
to eq(200)
|
96
|
+
expect(response_hash).
|
97
|
+
to eq(JSON.parse(response_body))
|
98
|
+
expect(response_hash).
|
99
|
+
to be_a Adyen::HashWithAccessors
|
100
|
+
expect(response_hash).
|
101
|
+
to be_a_kind_of Hash
|
102
|
+
expect(response_hash["resultCode"]).
|
103
|
+
to eq("RedirectShopper")
|
104
|
+
expect(response_hash.resultCode).
|
105
|
+
to eq("RedirectShopper")
|
106
|
+
end
|
107
|
+
|
108
|
+
# must be created manually due to payments/result format
|
109
|
+
it "makes a payments/result call" do
|
110
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment-result.json"))
|
111
|
+
|
112
|
+
response_body = json_from_file("mocks/responses/Checkout/payment-result.json")
|
113
|
+
|
114
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/result", @shared_values[:client].checkout.version)
|
115
|
+
WebMock.stub_request(:post, url).
|
116
|
+
with(
|
117
|
+
body: request_body,
|
118
|
+
headers: @auth_header
|
119
|
+
).
|
120
|
+
to_return(
|
121
|
+
body: response_body
|
122
|
+
)
|
123
|
+
|
124
|
+
result = @shared_values[:client].checkout.classic_checkout_sdk_api.verify_payment_result(request_body)
|
125
|
+
response_hash = result.response
|
126
|
+
|
127
|
+
expect(result.status).
|
128
|
+
to eq(200)
|
129
|
+
expect(response_hash).
|
130
|
+
to eq(JSON.parse(response_body))
|
131
|
+
expect(response_hash).
|
132
|
+
to be_a Adyen::HashWithAccessors
|
133
|
+
expect(response_hash).
|
134
|
+
to be_a_kind_of Hash
|
135
|
+
expect(response_hash["resultCode"]).
|
136
|
+
to eq("Authorised")
|
137
|
+
expect(response_hash.resultCode).
|
138
|
+
to eq("Authorised")
|
139
|
+
end
|
140
|
+
|
141
|
+
# must be created manually due to paymentsLinks format
|
142
|
+
it "makes a paymentLinks call" do
|
143
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment_links.json"))
|
144
|
+
|
145
|
+
response_body = json_from_file("mocks/responses/Checkout/payment_links.json")
|
146
|
+
|
147
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentLinks", @shared_values[:client].checkout.version)
|
148
|
+
WebMock.stub_request(:post, url).
|
149
|
+
with(
|
150
|
+
body: request_body,
|
151
|
+
headers: @auth_header
|
152
|
+
).
|
153
|
+
to_return(
|
154
|
+
body: response_body
|
155
|
+
)
|
156
|
+
|
157
|
+
result = @shared_values[:client].checkout.payment_links_api.payment_links(request_body)
|
158
|
+
response_hash = result.response
|
159
|
+
|
160
|
+
expect(result.status).
|
161
|
+
to eq(200)
|
162
|
+
expect(response_hash).
|
163
|
+
to eq(JSON.parse(response_body))
|
164
|
+
expect(response_hash).
|
165
|
+
to be_a Adyen::HashWithAccessors
|
166
|
+
expect(response_hash).
|
167
|
+
to be_a_kind_of Hash
|
168
|
+
end
|
169
|
+
|
170
|
+
# must be created manually due to paymentsLinks/{linkId} format
|
171
|
+
it "makes a get paymentLinks/{linkId} call" do
|
172
|
+
response_body = json_from_file("mocks/responses/Checkout/get-payment-link.json")
|
173
|
+
|
174
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentLinks/1", @shared_values[:client].checkout.version)
|
175
|
+
WebMock.stub_request(:get, url).
|
176
|
+
with(
|
177
|
+
headers: @auth_header
|
178
|
+
).
|
179
|
+
to_return(
|
180
|
+
body: response_body
|
181
|
+
)
|
182
|
+
|
183
|
+
result = @shared_values[:client].checkout.payment_links_api.get_payment_link("1")
|
184
|
+
response_hash = result.response
|
185
|
+
|
186
|
+
expect(result.status).
|
187
|
+
to eq(200)
|
188
|
+
expect(response_hash).
|
189
|
+
to eq(JSON.parse(response_body))
|
190
|
+
expect(response_hash).
|
191
|
+
to be_a Adyen::HashWithAccessors
|
192
|
+
expect(response_hash).
|
193
|
+
to be_a_kind_of Hash
|
194
|
+
expect(response_hash["status"]).
|
195
|
+
to eq("active")
|
196
|
+
expect(response_hash.id).
|
197
|
+
to eq("MockId")
|
198
|
+
end
|
199
|
+
|
200
|
+
# must be created manually due to paymentsLinks/{linkId} format
|
201
|
+
it "makes a patch paymentLinks/{linkId} call" do
|
202
|
+
request_body = {
|
203
|
+
:status => "expired",
|
204
|
+
}
|
205
|
+
|
206
|
+
response_body = json_from_file("mocks/responses/Checkout/update-payment-link.json")
|
207
|
+
|
208
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "paymentLinks/1", @shared_values[:client].checkout.version)
|
209
|
+
WebMock.stub_request(:patch, url).
|
210
|
+
with(
|
211
|
+
body: request_body,
|
212
|
+
headers: @auth_header
|
213
|
+
).
|
214
|
+
to_return(
|
215
|
+
body: response_body
|
216
|
+
)
|
217
|
+
|
218
|
+
result = @shared_values[:client].checkout.payment_links_api.update_payment_link(request_body, "1")
|
219
|
+
response_hash = result.response
|
220
|
+
|
221
|
+
expect(result.status).
|
222
|
+
to eq(200)
|
223
|
+
expect(response_hash).
|
224
|
+
to eq(JSON.parse(response_body))
|
225
|
+
expect(response_hash).
|
226
|
+
to be_a Adyen::HashWithAccessors
|
227
|
+
expect(response_hash).
|
228
|
+
to be_a_kind_of Hash
|
229
|
+
expect(response_hash["status"]).
|
230
|
+
to eq("expired")
|
231
|
+
expect(response_hash.id).
|
232
|
+
to eq("MockId")
|
233
|
+
end
|
234
|
+
|
235
|
+
it "makes an orders call" do
|
236
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/orders.json"))
|
237
|
+
|
238
|
+
response_body = json_from_file("mocks/responses/Checkout/orders.json")
|
239
|
+
|
240
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "orders", @shared_values[:client].checkout.version)
|
241
|
+
WebMock.stub_request(:post, url).
|
242
|
+
with(
|
243
|
+
body: request_body,
|
244
|
+
headers: @auth_header
|
245
|
+
).
|
246
|
+
to_return(
|
247
|
+
body: response_body
|
248
|
+
)
|
249
|
+
|
250
|
+
result = @shared_values[:client].checkout.orders_api.orders(request_body)
|
251
|
+
response_hash = result.response
|
252
|
+
|
253
|
+
expect(result.status).
|
254
|
+
to eq(200)
|
255
|
+
expect(response_hash).
|
256
|
+
to eq(JSON.parse(response_body))
|
257
|
+
expect(response_hash).
|
258
|
+
to be_a Adyen::HashWithAccessors
|
259
|
+
expect(response_hash).
|
260
|
+
to be_a_kind_of Hash
|
261
|
+
expect(response_hash["remainingAmount"]["value"]).
|
262
|
+
to eq(100)
|
263
|
+
end
|
264
|
+
|
265
|
+
it "makes an orders/cancel call" do
|
266
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/orders_cancel.json"))
|
267
|
+
|
268
|
+
response_body = json_from_file("mocks/responses/Checkout/orders_cancel.json")
|
269
|
+
|
270
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "orders/cancel", @shared_values[:client].checkout.version)
|
271
|
+
WebMock.stub_request(:post, url).
|
272
|
+
with(
|
273
|
+
body: request_body,
|
274
|
+
headers: @auth_header
|
275
|
+
).
|
276
|
+
to_return(
|
277
|
+
body: response_body
|
278
|
+
)
|
279
|
+
|
280
|
+
result = @shared_values[:client].checkout.orders_api.cancel_order(request_body)
|
281
|
+
response_hash = result.response
|
282
|
+
|
283
|
+
expect(result.status).
|
284
|
+
to eq(200)
|
285
|
+
expect(response_hash).
|
286
|
+
to eq(JSON.parse(response_body))
|
287
|
+
expect(response_hash).
|
288
|
+
to be_a Adyen::HashWithAccessors
|
289
|
+
expect(response_hash).
|
290
|
+
to be_a_kind_of Hash
|
291
|
+
expect(response_hash["resultCode"]).
|
292
|
+
to eq("cancelled")
|
293
|
+
end
|
294
|
+
|
295
|
+
it "makes an applePay/sessions call" do
|
296
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/apple_pay_sessions.json"))
|
297
|
+
|
298
|
+
response_body = json_from_file("mocks/responses/Checkout/apple_pay_sessions.json")
|
299
|
+
|
300
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "applePay/sessions", @shared_values[:client].checkout.version)
|
301
|
+
WebMock.stub_request(:post, url).
|
302
|
+
with(
|
303
|
+
body: request_body,
|
304
|
+
headers: @auth_header
|
305
|
+
).
|
306
|
+
to_return(
|
307
|
+
body: response_body
|
308
|
+
)
|
309
|
+
|
310
|
+
result = @shared_values[:client].checkout.utility_api.get_apple_pay_session(request_body)
|
311
|
+
response_hash = result.response
|
312
|
+
|
313
|
+
expect(result.status).
|
314
|
+
to eq(200)
|
315
|
+
expect(response_hash).
|
316
|
+
to eq(JSON.parse(response_body))
|
317
|
+
expect(response_hash).
|
318
|
+
to be_a Adyen::HashWithAccessors
|
319
|
+
expect(response_hash).
|
320
|
+
to be_a_kind_of Hash
|
321
|
+
expect(response_hash["data"]).
|
322
|
+
to eq("LARGE_BLOB_HERE")
|
323
|
+
end
|
324
|
+
|
325
|
+
it "makes a sessions call" do
|
326
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/sessions.json"))
|
327
|
+
|
328
|
+
response_body = json_from_file("mocks/responses/Checkout/sessions-success.json")
|
329
|
+
|
330
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "sessions", @shared_values[:client].checkout.version)
|
331
|
+
WebMock.stub_request(:post, url).
|
332
|
+
with(
|
333
|
+
body: request_body,
|
334
|
+
headers: @auth_header
|
335
|
+
)
|
336
|
+
.to_return(body: response_body, status: 201)
|
337
|
+
|
338
|
+
result = @shared_values[:client].checkout.payments_api.sessions(request_body)
|
339
|
+
response_hash = result.response
|
340
|
+
|
341
|
+
expect(result.status).
|
342
|
+
to eq(201)
|
343
|
+
expect(response_hash).
|
344
|
+
to eq(JSON.parse(response_body))
|
345
|
+
expect(response_hash).
|
346
|
+
to be_a Adyen::HashWithAccessors
|
347
|
+
expect(response_hash).
|
348
|
+
to be_a_kind_of Hash
|
349
|
+
end
|
350
|
+
|
351
|
+
it "makes a capture call" do
|
352
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/capture.json"))
|
353
|
+
|
354
|
+
response_body = json_from_file("mocks/responses/Checkout/capture.json")
|
355
|
+
|
356
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/captures", @shared_values[:client].checkout.version)
|
357
|
+
WebMock.stub_request(:post, url).
|
358
|
+
with(
|
359
|
+
body: request_body,
|
360
|
+
headers: @auth_header
|
361
|
+
)
|
362
|
+
.to_return(body: response_body, status: 201)
|
363
|
+
|
364
|
+
result = @shared_values[:client].checkout.modifications_api.capture_authorised_payment(request_body, "12345")
|
365
|
+
response_hash = result.response
|
366
|
+
|
367
|
+
expect(result.status).
|
368
|
+
to eq(201)
|
369
|
+
expect(response_hash).
|
370
|
+
to eq(JSON.parse(response_body))
|
371
|
+
expect(response_hash).
|
372
|
+
to be_a Adyen::HashWithAccessors
|
373
|
+
expect(response_hash).
|
374
|
+
to be_a_kind_of Hash
|
375
|
+
expect(response_hash.reference).
|
376
|
+
to eq("123456789")
|
377
|
+
expect(response_hash.pspReference).
|
378
|
+
to eq("12345")
|
379
|
+
end
|
380
|
+
|
381
|
+
it "makes a psp specific cancel call" do
|
382
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/psp_cancel.json"))
|
383
|
+
|
384
|
+
response_body = json_from_file("mocks/responses/Checkout/psp_cancel.json")
|
385
|
+
|
386
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/cancels", @shared_values[:client].checkout.version)
|
387
|
+
WebMock.stub_request(:post, url).
|
388
|
+
with(
|
389
|
+
body: request_body,
|
390
|
+
headers: @auth_header
|
391
|
+
)
|
392
|
+
.to_return(body: response_body, status: 201)
|
393
|
+
|
394
|
+
result = @shared_values[:client].checkout.modifications_api.cancel_authorised_payment_by_psp_reference(request_body, "12345")
|
395
|
+
response_hash = result.response
|
396
|
+
|
397
|
+
expect(result.status).
|
398
|
+
to eq(201)
|
399
|
+
expect(response_hash).
|
400
|
+
to eq(JSON.parse(response_body))
|
401
|
+
expect(response_hash).
|
402
|
+
to be_a Adyen::HashWithAccessors
|
403
|
+
expect(response_hash).
|
404
|
+
to be_a_kind_of Hash
|
405
|
+
expect(response_hash.reference).
|
406
|
+
to eq("123456789")
|
407
|
+
expect(response_hash.pspReference).
|
408
|
+
to eq("12345")
|
409
|
+
end
|
410
|
+
|
411
|
+
it "makes a psp specific refunds call" do
|
412
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/refund.json"))
|
413
|
+
|
414
|
+
response_body = json_from_file("mocks/responses/Checkout/refund.json")
|
415
|
+
|
416
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/refunds", @shared_values[:client].checkout.version)
|
417
|
+
WebMock.stub_request(:post, url).
|
418
|
+
with(
|
419
|
+
body: request_body,
|
420
|
+
headers: @auth_header
|
421
|
+
)
|
422
|
+
.to_return(body: response_body, status: 201)
|
423
|
+
|
424
|
+
result = @shared_values[:client].checkout.modifications_api.refund_captured_payment(request_body, "12345")
|
425
|
+
response_hash = result.response
|
426
|
+
|
427
|
+
expect(result.status).
|
428
|
+
to eq(201)
|
429
|
+
expect(response_hash).
|
430
|
+
to eq(JSON.parse(response_body))
|
431
|
+
expect(response_hash).
|
432
|
+
to be_a Adyen::HashWithAccessors
|
433
|
+
expect(response_hash).
|
434
|
+
to be_a_kind_of Hash
|
435
|
+
expect(response_hash.reference).
|
436
|
+
to eq("123456789")
|
437
|
+
expect(response_hash.pspReference).
|
438
|
+
to eq("12345")
|
439
|
+
end
|
440
|
+
|
441
|
+
it "makes a psp specific reversals call" do
|
442
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/psp_cancel.json"))
|
443
|
+
|
444
|
+
response_body = json_from_file("mocks/responses/Checkout/psp_cancel.json")
|
445
|
+
|
446
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/reversals", @shared_values[:client].checkout.version)
|
447
|
+
WebMock.stub_request(:post, url).
|
448
|
+
with(
|
449
|
+
body: request_body,
|
450
|
+
headers: @auth_header
|
451
|
+
)
|
452
|
+
.to_return(body: response_body, status: 201)
|
453
|
+
|
454
|
+
result = @shared_values[:client].checkout.modifications_api.refund_or_cancel_payment(request_body, "12345")
|
455
|
+
response_hash = result.response
|
456
|
+
|
457
|
+
expect(result.status).
|
458
|
+
to eq(201)
|
459
|
+
expect(response_hash).
|
460
|
+
to eq(JSON.parse(response_body))
|
461
|
+
expect(response_hash).
|
462
|
+
to be_a Adyen::HashWithAccessors
|
463
|
+
expect(response_hash).
|
464
|
+
to be_a_kind_of Hash
|
465
|
+
expect(response_hash.reference).
|
466
|
+
to eq("123456789")
|
467
|
+
expect(response_hash.pspReference).
|
468
|
+
to eq("12345")
|
469
|
+
end
|
470
|
+
|
471
|
+
it "makes a psp specific amountUpdates call" do
|
472
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/amount_updates.json"))
|
473
|
+
|
474
|
+
response_body = json_from_file("mocks/responses/Checkout/amount_updates.json")
|
475
|
+
|
476
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "payments/12345/amountUpdates", @shared_values[:client].checkout.version)
|
477
|
+
WebMock.stub_request(:post, url).
|
478
|
+
with(
|
479
|
+
body: request_body,
|
480
|
+
headers: @auth_header
|
481
|
+
)
|
482
|
+
.to_return(body: response_body, status: 201)
|
483
|
+
|
484
|
+
result = @shared_values[:client].checkout.modifications_api.update_authorised_amount(request_body, "12345")
|
485
|
+
response_hash = result.response
|
486
|
+
|
487
|
+
expect(result.status).
|
488
|
+
to eq(201)
|
489
|
+
expect(response_hash).
|
490
|
+
to eq(JSON.parse(response_body))
|
491
|
+
expect(response_hash).
|
492
|
+
to be_a Adyen::HashWithAccessors
|
493
|
+
expect(response_hash).
|
494
|
+
to be_a_kind_of Hash
|
495
|
+
expect(response_hash.reference).
|
496
|
+
to eq("123456789")
|
497
|
+
expect(response_hash.pspReference).
|
498
|
+
to eq("12345")
|
499
|
+
end
|
500
|
+
|
501
|
+
it "makes a generic cancel call" do
|
502
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/generic_cancel.json"))
|
503
|
+
|
504
|
+
response_body = json_from_file("mocks/responses/Checkout/generic_cancel.json")
|
505
|
+
|
506
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "cancels", @shared_values[:client].checkout.version)
|
507
|
+
WebMock.stub_request(:post, url).
|
508
|
+
with(
|
509
|
+
body: request_body,
|
510
|
+
headers: @auth_header
|
511
|
+
)
|
512
|
+
.to_return(body: response_body, status: 201)
|
513
|
+
|
514
|
+
result = @shared_values[:client].checkout.modifications_api.cancel_authorised_payment(request_body)
|
515
|
+
response_hash = result.response
|
516
|
+
|
517
|
+
expect(result.status).
|
518
|
+
to eq(201)
|
519
|
+
expect(response_hash).
|
520
|
+
to eq(JSON.parse(response_body))
|
521
|
+
expect(response_hash).
|
522
|
+
to be_a Adyen::HashWithAccessors
|
523
|
+
expect(response_hash).
|
524
|
+
to be_a_kind_of Hash
|
525
|
+
expect(response_hash.reference).
|
526
|
+
to eq("123456789")
|
527
|
+
expect(response_hash.pspReference).
|
528
|
+
to eq("12345")
|
529
|
+
end
|
530
|
+
|
531
|
+
it "makes a get storedPaymentMethods call" do
|
532
|
+
response_body = json_from_file("mocks/responses/Checkout/stored_payment_methods.json")
|
533
|
+
|
534
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "storedPaymentMethods?merchantAccount=TestMerchantAccount&shopperReference=test-1234", @shared_values[:client].checkout.version)
|
535
|
+
WebMock.stub_request(:get, url).
|
536
|
+
with(
|
537
|
+
headers: @auth_header
|
538
|
+
).
|
539
|
+
to_return(
|
540
|
+
body: response_body
|
541
|
+
)
|
542
|
+
|
543
|
+
result = @shared_values[:client].checkout.recurring_api.get_tokens_for_stored_payment_details(query_params: {"merchantAccount" => "TestMerchantAccount", "shopperReference" => "test-1234"})
|
544
|
+
response_hash = result.response
|
545
|
+
|
546
|
+
expect(result.status).
|
547
|
+
to eq(200)
|
548
|
+
expect(response_hash).
|
549
|
+
to eq(JSON.parse(response_body))
|
550
|
+
expect(response_hash).
|
551
|
+
to be_a Adyen::HashWithAccessors
|
552
|
+
expect(response_hash).
|
553
|
+
to be_a_kind_of Hash
|
554
|
+
expect(response_hash["shopperReference"]).
|
555
|
+
to eq("test-1234")
|
556
|
+
end
|
557
|
+
|
558
|
+
it "makes a delete storedPaymentMethods call" do
|
559
|
+
|
560
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "storedPaymentMethods/RL8FW7WZM6KXWD82?merchantAccount=TestMerchantAccount&shopperReference=test-1234", @shared_values[:client].checkout.version)
|
561
|
+
WebMock.stub_request(:delete, url).
|
562
|
+
with(
|
563
|
+
headers: @auth_header
|
564
|
+
).
|
565
|
+
to_return(
|
566
|
+
body: "{}"
|
567
|
+
)
|
568
|
+
|
569
|
+
result = @shared_values[:client].checkout.recurring_api.delete_token_for_stored_payment_details("RL8FW7WZM6KXWD82", query_params:{"merchantAccount" => "TestMerchantAccount", "shopperReference" => "test-1234"})
|
570
|
+
response_hash = result.response
|
571
|
+
|
572
|
+
expect(result.status).
|
573
|
+
to eq(200)
|
574
|
+
end
|
575
|
+
|
576
|
+
it "tests sending the application headers" do
|
577
|
+
response_body = json_from_file("mocks/responses/Checkout/stored_payment_methods.json")
|
578
|
+
|
579
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "storedPaymentMethods?merchantAccount=TestMerchantAccount&shopperReference=test-1234", @shared_values[:client].checkout.version)
|
580
|
+
WebMock.stub_request(:get, url).
|
581
|
+
with(
|
582
|
+
headers: @auth_header
|
583
|
+
).
|
584
|
+
to_return(
|
585
|
+
body: response_body
|
586
|
+
)
|
587
|
+
|
588
|
+
result = @shared_values[:client].checkout.recurring_api.get_tokens_for_stored_payment_details(query_params:{"merchantAccount" => "TestMerchantAccount", "shopperReference" => "test-1234"})
|
589
|
+
expect(
|
590
|
+
a_request(:get, "http://localhost:3001/v70/storedPaymentMethods?merchantAccount=TestMerchantAccount&shopperReference=test-1234")
|
591
|
+
.with(headers: {
|
592
|
+
'Accept' => '*/*',
|
593
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
594
|
+
'Adyen-Library-Name' => 'adyen-ruby-api-library',
|
595
|
+
'Adyen-Library-Version' => Adyen::VERSION,
|
596
|
+
'Content-Type' => 'application/json',
|
597
|
+
'User-Agent' => 'adyen-ruby-api-library/' + Adyen::VERSION,
|
598
|
+
'Authorization'=>'Bearer oauth_token'
|
599
|
+
})
|
600
|
+
).to have_been_made.once
|
601
|
+
end
|
602
|
+
|
603
|
+
# must be created manually because every field in the response is an array
|
604
|
+
it "makes a LIVE paymentMethods call" do
|
605
|
+
request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment_methods.json"))
|
606
|
+
|
607
|
+
response_body = json_from_file("mocks/responses/Checkout/payment_methods.json")
|
608
|
+
|
609
|
+
adyen = Adyen::Client.new
|
610
|
+
adyen.api_key = 'AF5XXXXXXXXXXXXXXXXXXXX'
|
611
|
+
adyen.env = :live
|
612
|
+
adyen.live_url_prefix = "prefix"
|
613
|
+
url = adyen.service_url("Checkout", "paymentMethods", @shared_values[:client].checkout.version)
|
614
|
+
|
615
|
+
expect(url).
|
616
|
+
to eq("https://prefix-checkout-live.adyenpayments.com/checkout/v70/paymentMethods")
|
617
|
+
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
# rubocop:enable Metrics/BlockLength
|
data/spec/client_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Adyen do
|
4
|
-
before(:
|
4
|
+
before(:each) do
|
5
5
|
@shared_values = {
|
6
|
-
client:
|
6
|
+
client: Adyen::Client.new(env: :test)
|
7
7
|
}
|
8
8
|
end
|
9
9
|
|
@@ -32,6 +32,11 @@ RSpec.describe Adyen do
|
|
32
32
|
.to raise_error(Adyen::AuthenticationError)
|
33
33
|
end
|
34
34
|
|
35
|
+
it "fails a checkout call without oauth token" do
|
36
|
+
expect{ @shared_values[:client].checkout.payments_api.payment_methods("{}") }.
|
37
|
+
to raise_error(Adyen::AuthenticationError)
|
38
|
+
end
|
39
|
+
|
35
40
|
it 'fails a checkout call without api key' do
|
36
41
|
expect { @shared_values[:client].checkout.payments_api.payment_methods('{}') }
|
37
42
|
.to raise_error(Adyen::AuthenticationError)
|
@@ -125,52 +130,52 @@ RSpec.describe Adyen do
|
|
125
130
|
client.checkout.payments_api.payments_details(request_body)
|
126
131
|
end
|
127
132
|
|
128
|
-
it "checks the creation of checkout url" do
|
133
|
+
it "checks the creation of checkout url" do
|
129
134
|
client = Adyen::Client.new(api_key: "api_key", env: :test)
|
130
135
|
expect(client.service_url("Checkout", "paymentMethods", "70")).
|
131
136
|
to eq("https://checkout-test.adyen.com/v70/paymentMethods")
|
132
|
-
end
|
137
|
+
end
|
133
138
|
|
134
|
-
it "checks the creation of checkout url" do
|
139
|
+
it "checks the creation of checkout url" do
|
135
140
|
client = Adyen::Client.new(api_key: "api_key", env: :live, live_url_prefix: "YourLiveUrlPrefix")
|
136
141
|
expect(client.service_url("Checkout", "paymentMethods", "70")).
|
137
142
|
to eq("https://YourLiveUrlPrefix-checkout-live.adyenpayments.com/checkout/v70/paymentMethods")
|
138
|
-
end
|
139
|
-
it "checks the creation of lem url" do
|
143
|
+
end
|
144
|
+
it "checks the creation of lem url" do
|
140
145
|
client = Adyen::Client.new(api_key: "api_key", env: :live)
|
141
146
|
expect(client.service_url("LegalEntityManagement", "businessLines", "3")).
|
142
147
|
to eq("https://kyc-live.adyen.com/lem/v3/businessLines")
|
143
|
-
end
|
148
|
+
end
|
144
149
|
|
145
|
-
it "checks the creation of balancePlatform url" do
|
150
|
+
it "checks the creation of balancePlatform url" do
|
146
151
|
client = Adyen::Client.new(api_key: "api_key", env: :live)
|
147
152
|
expect(client.service_url("BalancePlatform", "legalEntities", "1")).
|
148
153
|
to eq("https://balanceplatform-api-live.adyen.com/bcl/v1/legalEntities")
|
149
|
-
end
|
154
|
+
end
|
150
155
|
|
151
|
-
it "checks the creation of balancePlatform url" do
|
156
|
+
it "checks the creation of balancePlatform url" do
|
152
157
|
client = Adyen::Client.new(api_key: "api_key", env: :test)
|
153
158
|
expect(client.service_url("BalancePlatform", "legalEntities", "1")).
|
154
159
|
to eq("https://balanceplatform-api-test.adyen.com/bcl/v1/legalEntities")
|
155
|
-
end
|
160
|
+
end
|
156
161
|
|
157
|
-
it "checks the creation of transfers url" do
|
162
|
+
it "checks the creation of transfers url" do
|
158
163
|
client = Adyen::Client.new(api_key: "api_key", env: :test)
|
159
164
|
expect(client.service_url("Transfers", "transactions", "1")).
|
160
165
|
to eq("https://balanceplatform-api-test.adyen.com/btl/v1/transactions")
|
161
|
-
end
|
166
|
+
end
|
162
167
|
|
163
|
-
it "checks the creation of management url" do
|
168
|
+
it "checks the creation of management url" do
|
164
169
|
client = Adyen::Client.new(api_key: "api_key", env: :test)
|
165
170
|
expect(client.service_url("Management", "companies", "1")).
|
166
171
|
to eq("https://management-test.adyen.com/v1/companies")
|
167
|
-
end
|
172
|
+
end
|
168
173
|
|
169
|
-
it "checks the creation of binLookup url" do
|
174
|
+
it "checks the creation of binLookup url" do
|
170
175
|
client = Adyen::Client.new(api_key: "api_key", env: :test)
|
171
176
|
expect(client.service_url("BinLookup", "getCostEstimate", "54")).
|
172
177
|
to eq("https://pal-test.adyen.com/pal/servlet/BinLookup/v54/getCostEstimate")
|
173
|
-
end
|
178
|
+
end
|
174
179
|
|
175
180
|
it "check the creation of storedValue url" do
|
176
181
|
client = Adyen::Client.new(api_key: "api_key", env: :test)
|
@@ -253,6 +258,6 @@ RSpec.describe Adyen do
|
|
253
258
|
client = Adyen::Client.new(api_key: 'api_key', env: :test)
|
254
259
|
expect(client.service_url('TerminalCloudAPI', 'connectedTerminals', nil))
|
255
260
|
.to eq('https://terminal-api-test.adyen.com/connectedTerminals')
|
256
|
-
|
261
|
+
|
257
262
|
end
|
258
263
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
# rubocop:disable Metrics/BlockLength
|
5
|
+
|
6
|
+
RSpec.describe "Adyen::Management OAuth Authentication", service: "Management" do
|
7
|
+
before(:all) do
|
8
|
+
@shared_values = {
|
9
|
+
client: create_client(:oauth),
|
10
|
+
service: "Management",
|
11
|
+
}
|
12
|
+
@auth_header = { "Authorization": "Bearer #{@shared_values[:client].oauth_token}" }
|
13
|
+
end
|
14
|
+
|
15
|
+
# must be created manually because every field in the response is an array
|
16
|
+
it "makes a companies GET call" do
|
17
|
+
response_body = json_from_file("mocks/responses/Management/get_companies.json")
|
18
|
+
|
19
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "companies", @shared_values[:client].management.version)
|
20
|
+
WebMock.stub_request(:get, url).
|
21
|
+
with(
|
22
|
+
headers: @auth_header
|
23
|
+
).
|
24
|
+
to_return(
|
25
|
+
body: response_body
|
26
|
+
)
|
27
|
+
|
28
|
+
result = @shared_values[:client].management.account_company_level_api.list_company_accounts()
|
29
|
+
response_hash = result.response
|
30
|
+
|
31
|
+
expect(result.status).
|
32
|
+
to eq(200)
|
33
|
+
expect(response_hash).
|
34
|
+
to eq(JSON.parse(response_body))
|
35
|
+
expect(response_hash).
|
36
|
+
to be_a Adyen::HashWithAccessors
|
37
|
+
expect(response_hash).
|
38
|
+
to be_a_kind_of Hash
|
39
|
+
end
|
40
|
+
|
41
|
+
it "makes a create_store POST call" do
|
42
|
+
request_body = JSON.parse(json_from_file("mocks/responses/LegalEntityManagement/create_business_line.json"))
|
43
|
+
|
44
|
+
response_body = json_from_file("mocks/responses/LegalEntityManagement/create_business_line.json")
|
45
|
+
|
46
|
+
url = @shared_values[:client].service_url(@shared_values[:service], "merchants/merchantID/stores", @shared_values[:client].management.version)
|
47
|
+
WebMock.stub_request(:post, url).
|
48
|
+
with(
|
49
|
+
body: request_body,
|
50
|
+
headers: @auth_header
|
51
|
+
).
|
52
|
+
to_return(
|
53
|
+
body: response_body
|
54
|
+
)
|
55
|
+
|
56
|
+
result = @shared_values[:client].management.account_store_level_api.create_store_by_merchant_id(request_body, 'merchantID')
|
57
|
+
response_hash = result.response
|
58
|
+
|
59
|
+
expect(result.status).
|
60
|
+
to eq(200)
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -29,6 +29,8 @@ def create_test(client, service, method_name, parent_object)
|
|
29
29
|
# authentication headers
|
30
30
|
if !client.api_key.nil?
|
31
31
|
headers['x-api-key'] = client.api_key
|
32
|
+
elsif !client.oauth_token.nil?
|
33
|
+
headers["Authorization"] = "Bearer #{client.oauth_token}"
|
32
34
|
elsif !client.ws_user.nil? && !client.ws_password.nil?
|
33
35
|
auth_header = "Basic #{Base64.encode64("#{client.ws_user}:#{client.ws_password}")}"
|
34
36
|
headers['Authorization'] = auth_header.strip
|
@@ -79,13 +81,15 @@ def generate_tests(client, service, test_sets, parent_object)
|
|
79
81
|
end
|
80
82
|
|
81
83
|
# create and return a client for testing
|
82
|
-
# auth_type must be one of [:basic, :api_key]
|
84
|
+
# auth_type must be one of [:basic, :api_key, :oauth]
|
83
85
|
def create_client(auth_type)
|
84
86
|
client = Adyen::Client.new
|
85
87
|
client.env = :mock
|
86
88
|
if auth_type == :basic
|
87
89
|
client.ws_user = 'user'
|
88
90
|
client.ws_password = 'password'
|
91
|
+
elsif auth_type == :oauth
|
92
|
+
client.oauth_token = 'oauth_token'
|
89
93
|
elsif auth_type == :api_key
|
90
94
|
client.api_key = 'api_key'
|
91
95
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adyen-ruby-api-library
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09
|
11
|
+
date: 2023-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- spec/balance_control_spec.rb
|
204
204
|
- spec/balance_platform_spec.rb
|
205
205
|
- spec/bin_lookup_spec.rb
|
206
|
+
- spec/checkout-oauth_spec.rb
|
206
207
|
- spec/checkout_spec.rb
|
207
208
|
- spec/client_spec.rb
|
208
209
|
- spec/data_protection_spec.rb
|
@@ -212,6 +213,7 @@ files:
|
|
212
213
|
- spec/hash_with_accessors_spec.rb
|
213
214
|
- spec/hop_spec.rb
|
214
215
|
- spec/lem_spec.rb
|
216
|
+
- spec/management-oauth_spec.rb
|
215
217
|
- spec/management_spec.rb
|
216
218
|
- spec/mocks/requests/Account/check_account_holder.json
|
217
219
|
- spec/mocks/requests/Account/close_account.json
|