adyen-ruby-api-library 11.0.0 → 11.2.0

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql.yml +4 -4
  3. data/.github/workflows/label_new_issues.yml +1 -1
  4. data/.github/workflows/release.yml +2 -2
  5. data/.github/workflows/ruby.yml +11 -3
  6. data/.github/workflows/rubygems_release.yml +2 -2
  7. data/.github/workflows/stale.yml +1 -1
  8. data/AGENTS.md +73 -0
  9. data/README.md +5 -0
  10. data/VERSION +1 -1
  11. data/lib/adyen/client.rb +30 -9
  12. data/lib/adyen/errors.rb +6 -0
  13. data/lib/adyen/services/balancePlatform/sca_association_management_api.rb +46 -0
  14. data/lib/adyen/services/balancePlatform/sca_device_management_api.rb +46 -0
  15. data/lib/adyen/services/balancePlatform.rb +10 -0
  16. data/lib/adyen/services/capital/grant_accounts_api.rb +26 -0
  17. data/lib/adyen/services/capital/grant_offers_api.rb +36 -0
  18. data/lib/adyen/services/capital/grants_api.rb +76 -0
  19. data/lib/adyen/services/capital.rb +34 -0
  20. data/lib/adyen/services/checkout/recurring_api.rb +10 -0
  21. data/lib/adyen/services/legalEntityManagement/legal_entities_api.rb +10 -0
  22. data/lib/adyen/services/payment/modifications_api.rb +1 -1
  23. data/lib/adyen/services/payment/payments_api.rb +1 -1
  24. data/lib/adyen/services/payment.rb +2 -2
  25. data/lib/adyen/services/recurring/recurring_api.rb +1 -1
  26. data/lib/adyen/services/recurring.rb +1 -1
  27. data/lib/adyen/version.rb +1 -1
  28. data/lib/adyen-ruby-api-library.rb +1 -0
  29. data/renovate.json +3 -1
  30. data/spec/capital_spec.rb +186 -0
  31. data/spec/checkout_spec.rb +13 -0
  32. data/spec/client_spec.rb +235 -64
  33. data/spec/data_protection_spec.rb +2 -2
  34. data/spec/disputes_spec.rb +3 -3
  35. data/spec/lem_spec.rb +75 -0
  36. data/spec/mocks/responses/Capital/get-grant-account-success.json +20 -0
  37. data/spec/mocks/responses/Capital/get-grant-disbursement-success.json +26 -0
  38. data/spec/mocks/responses/Capital/get-grant-disbursements-success.json +30 -0
  39. data/spec/mocks/responses/Capital/get-grant-offer-success.json +31 -0
  40. data/spec/mocks/responses/Capital/get-grant-success.json +22 -0
  41. data/spec/mocks/responses/Capital/grant-offers-success.json +19 -0
  42. data/spec/mocks/responses/Capital/grants-success.json +26 -0
  43. data/spec/mocks/responses/Capital/request-grant.json +31 -0
  44. data/spec/mocks/responses/Capital/update-grant-disbursement-success.json +26 -0
  45. data/spec/mocks/responses/LegalEntityManagement/get_legal_entity.json +14 -0
  46. data/templates/api-single.mustache +1 -1
  47. data/templates/api.mustache +1 -1
  48. metadata +23 -6
  49. data/Makefile +0 -79
  50. /data/spec/mocks/requests/{DataProtectionService → DataProtection}/request_subject_erasure.json +0 -0
  51. /data/spec/mocks/requests/{DisputesService → Disputes}/retrieve_applicable_defense_reasons.json +0 -0
  52. /data/spec/mocks/responses/{DataProtectionService → DataProtection}/request_subject_erasure.json +0 -0
  53. /data/spec/mocks/responses/{DisputesService → Disputes}/retrieve_applicable_defense_reasons.json +0 -0
data/spec/client_spec.rb CHANGED
@@ -32,8 +32,8 @@ 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("{}") }.
35
+ it 'fails a checkout call without oauth token' do
36
+ expect { @shared_values[:client].checkout.payments_api.payment_methods('{}') }.
37
37
  to raise_error(Adyen::AuthenticationError)
38
38
  end
39
39
 
@@ -43,6 +43,40 @@ RSpec.describe Adyen do
43
43
  @shared_values[:client].api_key = 'api_key'
44
44
  end
45
45
 
46
+ describe 'service name resolution' do
47
+ let(:client) { Adyen::Client.new(env: :mock, mock_service_url_base: 'https://mock.test') }
48
+
49
+ it 'is Checkout service when using checkout.payments_api' do
50
+ expect(client.checkout.payments_api.service)
51
+ .to eq('Checkout')
52
+ end
53
+
54
+ it 'is Checkout service when using checkout.recurring_api' do
55
+ expect(client.checkout.recurring_api.service)
56
+ .to eq('Checkout')
57
+ end
58
+
59
+ it 'is Recurring service when using recurring.recurring_api' do
60
+ expect(client.recurring.recurring_api.service)
61
+ .to eq('Recurring')
62
+ end
63
+
64
+ it 'is Payment service when using payment.payments_api' do
65
+ expect(client.payment.payments_api.service)
66
+ .to eq('Payment')
67
+ end
68
+
69
+ it 'is Payment service when using payment.modifications_api' do
70
+ expect(client.payment.modifications_api.service)
71
+ .to eq('Payment')
72
+ end
73
+
74
+ it 'is Payout service when using payout.instant_payouts_api' do
75
+ expect(client.payout.instant_payouts_api.service)
76
+ .to eq('Payout')
77
+ end
78
+ end
79
+
46
80
  it 'uses the specified mock service URL' do
47
81
  client = Adyen::Client.new(env: :mock, mock_service_url_base: 'https://mock.test')
48
82
  expect(client.service_url_base('Account'))
@@ -115,11 +149,11 @@ RSpec.describe Adyen do
115
149
 
116
150
  # test with Ruby 3.2+ only (where Faraday requestOptions timeout is supported)
117
151
  it 'initiates a Faraday connection with the provided options' do
118
- skip "Only runs on Ruby >= 3.2" unless RUBY_VERSION >= '3.2'
152
+ skip 'Only runs on Ruby >= 3.2' unless RUBY_VERSION >= '3.2'
119
153
  connection_options = Faraday::ConnectionOptions.new(
120
154
  request: {
121
- open_timeout: 5,
122
- timeout: 10
155
+ open_timeout: 5,
156
+ timeout: 10
123
157
  }
124
158
  )
125
159
  expect(Faraday::ConnectionOptions).not_to receive(:new)
@@ -142,63 +176,63 @@ RSpec.describe Adyen do
142
176
 
143
177
  # test with Ruby 3.2+ only (where Faraday requestOptions timeout is supported)
144
178
  it 'initiates a Faraday connection with the expected default timeouts' do
145
- skip "Only runs on Ruby >= 3.2" unless RUBY_VERSION >= '3.2'
179
+ skip 'Only runs on Ruby >= 3.2' unless RUBY_VERSION >= '3.2'
146
180
  client = Adyen::Client.new(env: :test)
147
181
  expect(client.connection_options[:request][:open_timeout]).to eq(30)
148
182
  expect(client.connection_options[:request][:timeout]).to eq(60)
149
183
  end
150
184
 
151
- it "checks the creation of checkout url" do
152
- client = Adyen::Client.new(api_key: "api_key", env: :test)
153
- expect(client.service_url("Checkout", "paymentMethods", "71")).
154
- to eq("https://checkout-test.adyen.com/v71/paymentMethods")
185
+ it 'checks the creation of checkout url' do
186
+ client = Adyen::Client.new(api_key: 'api_key', env: :test)
187
+ expect(client.service_url('Checkout', 'paymentMethods', '71')).
188
+ to eq('https://checkout-test.adyen.com/v71/paymentMethods')
155
189
  end
156
190
 
157
- it "checks the creation of checkout url" do
158
- client = Adyen::Client.new(api_key: "api_key", env: :live, live_url_prefix: "YourLiveUrlPrefix")
159
- expect(client.service_url("Checkout", "paymentMethods", "71")).
160
- to eq("https://YourLiveUrlPrefix-checkout-live.adyenpayments.com/checkout/v71/paymentMethods")
191
+ it 'checks the creation of checkout url' do
192
+ client = Adyen::Client.new(api_key: 'api_key', env: :live, live_url_prefix: 'YourLiveUrlPrefix')
193
+ expect(client.service_url('Checkout', 'paymentMethods', '71')).
194
+ to eq('https://YourLiveUrlPrefix-checkout-live.adyenpayments.com/checkout/v71/paymentMethods')
161
195
  end
162
- it "checks the creation of lem url" do
163
- client = Adyen::Client.new(api_key: "api_key", env: :live)
164
- expect(client.service_url("LegalEntityManagement", "businessLines", "3")).
165
- to eq("https://kyc-live.adyen.com/lem/v3/businessLines")
196
+ it 'checks the creation of lem url' do
197
+ client = Adyen::Client.new(api_key: 'api_key', env: :live)
198
+ expect(client.service_url('LegalEntityManagement', 'businessLines', '3')).
199
+ to eq('https://kyc-live.adyen.com/lem/v3/businessLines')
166
200
  end
167
201
 
168
- it "checks the creation of balancePlatform url" do
169
- client = Adyen::Client.new(api_key: "api_key", env: :live)
170
- expect(client.service_url("BalancePlatform", "legalEntities", "1")).
171
- to eq("https://balanceplatform-api-live.adyen.com/bcl/v1/legalEntities")
202
+ it 'checks the creation of balancePlatform url' do
203
+ client = Adyen::Client.new(api_key: 'api_key', env: :live)
204
+ expect(client.service_url('BalancePlatform', 'legalEntities', '1')).
205
+ to eq('https://balanceplatform-api-live.adyen.com/bcl/v1/legalEntities')
172
206
  end
173
207
 
174
- it "checks the creation of balancePlatform url" do
175
- client = Adyen::Client.new(api_key: "api_key", env: :test)
176
- expect(client.service_url("BalancePlatform", "legalEntities", "1")).
177
- to eq("https://balanceplatform-api-test.adyen.com/bcl/v1/legalEntities")
208
+ it 'checks the creation of balancePlatform url' do
209
+ client = Adyen::Client.new(api_key: 'api_key', env: :test)
210
+ expect(client.service_url('BalancePlatform', 'legalEntities', '1')).
211
+ to eq('https://balanceplatform-api-test.adyen.com/bcl/v1/legalEntities')
178
212
  end
179
213
 
180
- it "checks the creation of transfers url" do
181
- client = Adyen::Client.new(api_key: "api_key", env: :test)
182
- expect(client.service_url("Transfers", "transactions", "1")).
183
- to eq("https://balanceplatform-api-test.adyen.com/btl/v1/transactions")
214
+ it 'checks the creation of transfers url' do
215
+ client = Adyen::Client.new(api_key: 'api_key', env: :test)
216
+ expect(client.service_url('Transfers', 'transactions', '1')).
217
+ to eq('https://balanceplatform-api-test.adyen.com/btl/v1/transactions')
184
218
  end
185
219
 
186
- it "checks the creation of management url" do
187
- client = Adyen::Client.new(api_key: "api_key", env: :test)
188
- expect(client.service_url("Management", "companies", "1")).
189
- to eq("https://management-test.adyen.com/v1/companies")
220
+ it 'checks the creation of management url' do
221
+ client = Adyen::Client.new(api_key: 'api_key', env: :test)
222
+ expect(client.service_url('Management', 'companies', '1')).
223
+ to eq('https://management-test.adyen.com/v1/companies')
190
224
  end
191
225
 
192
- it "checks the creation of binLookup url" do
193
- client = Adyen::Client.new(api_key: "api_key", env: :test)
194
- expect(client.service_url("BinLookup", "getCostEstimate", "54")).
195
- to eq("https://pal-test.adyen.com/pal/servlet/BinLookup/v54/getCostEstimate")
226
+ it 'checks the creation of binLookup url' do
227
+ client = Adyen::Client.new(api_key: 'api_key', env: :test)
228
+ expect(client.service_url('BinLookup', 'getCostEstimate', '54')).
229
+ to eq('https://pal-test.adyen.com/pal/servlet/BinLookup/v54/getCostEstimate')
196
230
  end
197
231
 
198
- it "check the creation of storedValue url" do
199
- client = Adyen::Client.new(api_key: "api_key", env: :test)
200
- expect(client.service_url("StoredValue", "issue", "46")).
201
- to eq("https://pal-test.adyen.com/pal/servlet/StoredValue/v46/issue")
232
+ it 'check the creation of storedValue url' do
233
+ client = Adyen::Client.new(api_key: 'api_key', env: :test)
234
+ expect(client.service_url('StoredValue', 'issue', '46')).
235
+ to eq('https://pal-test.adyen.com/pal/servlet/StoredValue/v46/issue')
202
236
  end
203
237
 
204
238
  it 'checks the creation of checkout url' do
@@ -206,6 +240,7 @@ RSpec.describe Adyen do
206
240
  expect(client.service_url('Checkout', 'paymentMethods', '70'))
207
241
  .to eq('https://YourLiveUrlPrefix-checkout-live.adyenpayments.com/checkout/v70/paymentMethods')
208
242
  end
243
+
209
244
  it 'checks the creation of lem url' do
210
245
  client = Adyen::Client.new(api_key: 'api_key', env: :live)
211
246
  expect(client.service_url('LegalEntityManagement', 'businessLines', '3'))
@@ -276,19 +311,18 @@ RSpec.describe Adyen do
276
311
  client = Adyen::Client.new(api_key: 'api_key', env: :test)
277
312
  expect(client.service_url('TerminalCloudAPI', 'connectedTerminals', nil))
278
313
  .to eq('https://terminal-api-test.adyen.com/connectedTerminals')
279
-
280
314
  end
281
-
315
+
282
316
  it 'checks the initialization of the terminal region' do
283
317
  client = Adyen::Client.new(api_key: 'api_key', env: :test, terminal_region: 'eu')
284
318
  expect(client.service_url('TerminalCloudAPI', 'connectedTerminals', nil))
285
- .to eq('https://terminal-api-test-eu.adyen.com/connectedTerminals')
319
+ .to eq('https://terminal-api-test-eu.adyen.com/connectedTerminals')
286
320
  end
287
321
 
288
322
  it 'checks the initialization of the terminal region set to nil per default' do
289
323
  client = Adyen::Client.new(api_key: 'api_key', env: :test)
290
324
  expect(client.service_url('TerminalCloudAPI', 'connectedTerminals', nil))
291
- .to eq('https://terminal-api-test.adyen.com/connectedTerminals')
325
+ .to eq('https://terminal-api-test.adyen.com/connectedTerminals')
292
326
  end
293
327
 
294
328
  it 'checks the creation of PosMobile sessions url' do
@@ -300,17 +334,42 @@ RSpec.describe Adyen do
300
334
  it 'correctly maps Disputes to DisputesService and generates valid URL' do
301
335
  client = Adyen::Client.new(env: :test)
302
336
  expect(client.service_url_base('Disputes'))
303
- .to eq('https://ca-test.adyen.com/ca/services/DisputesService')
304
- end
337
+ .to eq('https://ca-test.adyen.com/ca/services/DisputeService')
338
+ end
339
+
340
+ it 'checks the creation of DataProtection url' do
341
+ client = Adyen::Client.new(env: :test)
342
+ expect(client.service_url_base('DataProtection'))
343
+ .to eq('https://ca-test.adyen.com/ca/services/DataProtectionService')
344
+ end
345
+
346
+ it 'checks the creation of SessionAuthentication url for the test env' do
347
+ client = Adyen::Client.new(env: :test)
348
+ expect(client.service_url_base('SessionAuthentication'))
349
+ .to eq('https://test.adyen.com/authe/api')
350
+ end
351
+
352
+ it 'checks the creation of SessionAuthentication url for the live env' do
353
+ client = Adyen::Client.new(env: :live)
354
+ expect(client.service_url_base('SessionAuthentication'))
355
+ .to eq('https://authe-live.adyen.com/authe/api')
356
+ end
357
+
358
+ it 'checks the creation of Recurring API url for the test env' do
359
+ client = Adyen::Client.new(env: :test)
360
+ expect(client.service_url_base('Recurring'))
361
+ .to eq('https://pal-test.adyen.com/pal/servlet/Recurring')
362
+ end
363
+
305
364
 
306
365
  it 'raises FormatError on 400 response and checks content' do
307
366
  client = Adyen::Client.new(api_key: 'api_key', env: :test)
308
367
  mock_faraday_connection = double(Faraday::Connection)
309
368
  error_body = {
310
369
  status: 400,
311
- errorCode: "702",
312
- message: "Structure of CreateCheckoutSessionRequest contains the following unknown fields: [paymentMethod]",
313
- errorType: "validation"
370
+ errorCode: '702',
371
+ message: 'Structure of CreateCheckoutSessionRequest contains the following unknown fields: [paymentMethod]',
372
+ errorType: 'validation'
314
373
  }
315
374
  mock_response = Faraday::Response.new(status: 400, body: error_body)
316
375
 
@@ -331,12 +390,12 @@ RSpec.describe Adyen do
331
390
  client = Adyen::Client.new(api_key: 'api_key', env: :test)
332
391
  mock_faraday_connection = double(Faraday::Connection)
333
392
  error_body = {
334
- type: "https://docs.adyen.com/errors/validation",
335
- title: "The request is missing required fields or contains invalid data.",
393
+ type: 'https://docs.adyen.com/errors/validation',
394
+ title: 'The request is missing required fields or contains invalid data.',
336
395
  status: 422,
337
- detail: "It is mandatory to specify a legalEntityId when creating a new account holder.",
338
- invalidFields: [{ "name" => "legalEntityId", "message" => "legalEntityId is not provided" }],
339
- errorCode: "30_011"
396
+ detail: 'It is mandatory to specify a legalEntityId when creating a new account holder.',
397
+ invalidFields: [{ 'name' => 'legalEntityId', 'message' => 'legalEntityId is not provided' }],
398
+ errorCode: '30_011'
340
399
  }
341
400
  mock_response = Faraday::Response.new(status: 422, body: error_body)
342
401
 
@@ -359,11 +418,11 @@ RSpec.describe Adyen do
359
418
  mock_faraday_connection = double(Faraday::Connection)
360
419
  error_body = {
361
420
  status: 422,
362
- errorCode: "14_030",
363
- message: "Return URL is missing.",
364
- errorType: "validation",
365
- pspReference: "8816118280275544"
366
- }
421
+ errorCode: '14_030',
422
+ message: 'Return URL is missing.',
423
+ errorType: 'validation',
424
+ pspReference: '8816118280275544'
425
+ }
367
426
  mock_response = Faraday::Response.new(status: 422, body: error_body)
368
427
 
369
428
  allow(Faraday).to receive(:new).and_return(mock_faraday_connection)
@@ -384,9 +443,9 @@ RSpec.describe Adyen do
384
443
  mock_faraday_connection = double(Faraday::Connection)
385
444
  error_body = {
386
445
  status: 500,
387
- errorCode: "999",
388
- message: "Unexpected error.",
389
- errorType: "server error"
446
+ errorCode: '999',
447
+ message: 'Unexpected error.',
448
+ errorType: 'server error'
390
449
  }
391
450
  mock_response = Faraday::Response.new(status: 500, body: error_body)
392
451
 
@@ -401,4 +460,116 @@ RSpec.describe Adyen do
401
460
  expect(error.msg).to eq('Unexpected error. ErrorCode: 999')
402
461
  end
403
462
  end
463
+
464
+ it 'raises NotFoundError on 404 response and checks content' do
465
+ client = Adyen::Client.new(api_key: 'api_key', env: :test)
466
+ mock_faraday_connection = double(Faraday::Connection)
467
+ error_body = '701 Version 71 is not supported, latest version: 68'
468
+ mock_response = Faraday::Response.new(status: 404, body: error_body)
469
+
470
+ allow(Faraday).to receive(:new).and_return(mock_faraday_connection)
471
+ allow(mock_faraday_connection).to receive_message_chain(:headers, :[]=)
472
+ allow(mock_faraday_connection).to receive(:post).and_return(mock_response)
473
+
474
+ expect {
475
+ client.checkout.payments_api.payments({})
476
+ }.to raise_error(Adyen::NotFoundError) do |error|
477
+ expect(error.code).to eq(404)
478
+ expect(error.msg).to eq('Not found error')
479
+ end
480
+ end
481
+
482
+ it 'raises NotFoundError on 404 response with an invalid JSON body' do
483
+ client = Adyen::Client.new(api_key: 'api_key', env: :test)
484
+ mock_faraday_connection = double(Faraday::Connection)
485
+ error_body = 'this is an error message'
486
+ mock_response = Faraday::Response.new(status: 404, body: error_body)
487
+
488
+ allow(Faraday).to receive(:new).and_return(mock_faraday_connection)
489
+ allow(mock_faraday_connection).to receive_message_chain(:headers, :[]=)
490
+ allow(mock_faraday_connection).to receive(:post).and_return(mock_response)
491
+
492
+ expect {
493
+ client.payment.payments_api.authorise({})
494
+ }.to raise_error(Adyen::NotFoundError) do |error|
495
+ expect(error.code).to eq(404)
496
+ expect(error.msg).to eq('Not found error')
497
+ end
498
+ end
499
+
500
+ it 'ensures User-Agent is present in request headers' do
501
+ client = Adyen::Client.new(api_key: 'api_key', env: :test)
502
+ mock_response = Faraday::Response.new(status: 200, body: '{}')
503
+
504
+ mock_conn = instance_double(Faraday::Connection)
505
+ expect(Faraday).to receive(:new).and_yield(mock_conn).and_return(mock_conn)
506
+ allow(mock_conn).to receive(:adapter)
507
+ connection_headers = {}
508
+ allow(mock_conn).to receive(:headers).and_return(connection_headers)
509
+
510
+ expect(mock_conn).to receive(:post) do |&block|
511
+ mock_req = double('Faraday::Request')
512
+ allow(mock_req).to receive(:body=)
513
+ block.call(mock_req) if block_given?
514
+ mock_response
515
+ end.and_return(mock_response)
516
+
517
+ client.checkout.payments_api.payments({})
518
+
519
+ expect(connection_headers['User-Agent']).to_not be_nil
520
+ expect(connection_headers['User-Agent']).to_not be_empty
521
+ expect(connection_headers['User-Agent']).to eq("#{Adyen::NAME}/#{Adyen::VERSION}")
522
+ end
523
+
524
+ it 'ensures User-Agent includes application_name when provided' do
525
+ client = Adyen::Client.new(api_key: 'api_key', env: :test, application_name: 'MyTestApp')
526
+ mock_response = Faraday::Response.new(status: 200, body: '{}')
527
+
528
+ mock_conn = instance_double(Faraday::Connection)
529
+ expect(Faraday).to receive(:new).and_yield(mock_conn).and_return(mock_conn)
530
+ allow(mock_conn).to receive(:adapter)
531
+ connection_headers = {}
532
+ allow(mock_conn).to receive(:headers).and_return(connection_headers)
533
+
534
+ expect(mock_conn).to receive(:post) do |&block|
535
+ mock_req = double('Faraday::Request')
536
+ allow(mock_req).to receive(:body=)
537
+ block.call(mock_req) if block_given?
538
+ mock_response
539
+ end.and_return(mock_response)
540
+
541
+ client.checkout.payments_api.payments({})
542
+
543
+ expect(connection_headers['User-Agent']).to_not be_nil
544
+ expect(connection_headers['User-Agent']).to_not be_empty
545
+ expect(connection_headers['User-Agent']).to eq("MyTestApp #{Adyen::NAME}/#{Adyen::VERSION}")
546
+ end
547
+
548
+ it 'ensures User-Agent includes application_name when set after initialization' do
549
+ client = Adyen::Client.new
550
+ client.api_key = 'api_key'
551
+ client.env = :test
552
+ client.application_name = 'MyTestAppAfterInit' # Set after initialization
553
+
554
+ mock_response = Faraday::Response.new(status: 200, body: '{}')
555
+
556
+ mock_conn = instance_double(Faraday::Connection)
557
+ expect(Faraday).to receive(:new).and_yield(mock_conn).and_return(mock_conn)
558
+ allow(mock_conn).to receive(:adapter)
559
+ connection_headers = {}
560
+ allow(mock_conn).to receive(:headers).and_return(connection_headers)
561
+
562
+ expect(mock_conn).to receive(:post) do |&block|
563
+ mock_req = double('Faraday::Request')
564
+ allow(mock_req).to receive(:body=)
565
+ block.call(mock_req) if block_given?
566
+ mock_response
567
+ end.and_return(mock_response)
568
+
569
+ client.checkout.payments_api.payments({})
570
+
571
+ expect(connection_headers['User-Agent']).to_not be_nil
572
+ expect(connection_headers['User-Agent']).to_not be_empty
573
+ expect(connection_headers['User-Agent']).to eq("MyTestAppAfterInit #{Adyen::NAME}/#{Adyen::VERSION}")
574
+ end
404
575
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Adyen::DataProtection, service: 'Data Protection Service' do
3
+ RSpec.describe Adyen::DataProtection, service: 'DataProtection' do
4
4
  # client instance to be used in dynamically generated tests
5
5
  client = create_client(:basic)
6
6
 
@@ -10,5 +10,5 @@ RSpec.describe Adyen::DataProtection, service: 'Data Protection Service' do
10
10
  %w[request_subject_erasure result SUCCESS]
11
11
  ]
12
12
 
13
- generate_tests(client, 'DataProtectionService', test_sets, client.data_protection.data_protection_api)
13
+ generate_tests(client, 'DataProtection', test_sets, client.data_protection.data_protection_api)
14
14
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe Adyen::Disputes, service: 'disputes service' do
3
+ RSpec.describe Adyen::Disputes, service: 'Disputes' do
4
4
  before(:all) do
5
5
  @shared_values = {
6
6
  client: create_client(:api_key),
@@ -11,9 +11,9 @@ RSpec.describe Adyen::Disputes, service: 'disputes service' do
11
11
  # methods / values to test for
12
12
  # format is defined in spec_helper
13
13
  it 'makes a retrieve_applicable_defense_reasons call' do
14
- request_body = JSON.parse(json_from_file('mocks/requests/DisputesService/retrieve_applicable_defense_reasons.json'))
14
+ request_body = JSON.parse(json_from_file('mocks/requests/Disputes/retrieve_applicable_defense_reasons.json'))
15
15
 
16
- response_body = json_from_file('mocks/responses/DisputesService/retrieve_applicable_defense_reasons.json')
16
+ response_body = json_from_file('mocks/responses/Disputes/retrieve_applicable_defense_reasons.json')
17
17
 
18
18
  url = @shared_values[:client].service_url(@shared_values[:service], 'retrieveApplicableDefenseReasons',
19
19
  @shared_values[:client].disputes.version)
data/spec/lem_spec.rb CHANGED
@@ -60,4 +60,79 @@ RSpec.describe Adyen::LegalEntityManagement, service: 'LegalEntityManagement' do
60
60
  expect(result.status)
61
61
  .to eq(200)
62
62
  end
63
+
64
+ it 'makes a legal_entities GET call' do
65
+ legal_entity_id = 'LE322JV223222D5F4K62J7465'
66
+ response_body = json_from_file('mocks/responses/LegalEntityManagement/get_legal_entity.json')
67
+
68
+ url = @shared_values[:client].service_url(@shared_values[:service], "legalEntities/#{legal_entity_id}",
69
+ @shared_values[:client].legal_entity_management.version)
70
+ WebMock.stub_request(:get, url)
71
+ .with(
72
+ headers: {
73
+ 'x-api-key' => @shared_values[:client].api_key
74
+ }
75
+ )
76
+ .to_return(
77
+ body: response_body
78
+ )
79
+
80
+ result = @shared_values[:client].legal_entity_management.legal_entities_api.get_legal_entity(legal_entity_id)
81
+ response_hash = result.response
82
+
83
+ expect(result.status)
84
+ .to eq(200)
85
+ expect(response_hash)
86
+ .to eq(JSON.parse(response_body))
87
+ expect(response_hash)
88
+ .to be_a Adyen::HashWithAccessors
89
+ expect(response_hash)
90
+ .to be_a_kind_of Hash
91
+ end
92
+
93
+ it 'raises an error when calling legal_entities GET call' do
94
+ invalid_legal_entity_id = 'NON_EXISTENT_ID'
95
+ error_response_body = { status: 404, errorCode: '100', message: 'Legal entity not found', errorType: 'validation' }.to_json
96
+
97
+ url = @shared_values[:client].service_url(@shared_values[:service], "legalEntities/#{invalid_legal_entity_id}",
98
+ @shared_values[:client].legal_entity_management.version)
99
+ WebMock.stub_request(:get, url)
100
+ .with(
101
+ headers: {
102
+ 'x-api-key' => @shared_values[:client].api_key
103
+ }
104
+ )
105
+ .to_return(
106
+ status: 404,
107
+ body: error_response_body
108
+ )
109
+
110
+ expect do
111
+ @shared_values[:client].legal_entity_management.legal_entities_api.get_legal_entity(invalid_legal_entity_id)
112
+ end.to raise_error(Adyen::NotFoundError) do |error|
113
+ expect(error.code).to eq(404)
114
+ expect(error.msg).to eq('Legal entity not found ErrorCode: 100')
115
+ end
116
+ end
117
+
118
+ it 'makes a LegaleEntity /requestPeriodicReview call' do
119
+ url = @shared_values[:client].service_url(@shared_values[:service], "legalEntities/LE123/requestPeriodicReview",
120
+ @shared_values[:client].legal_entity_management.version)
121
+ WebMock.stub_request(:post, url)
122
+ .with(
123
+ headers: {
124
+ 'x-api-key' => @shared_values[:client].api_key
125
+ }
126
+ )
127
+ .to_return(
128
+ body: '{}'
129
+ )
130
+
131
+ result = @shared_values[:client].legal_entity_management.legal_entities_api.request_periodic_review('LE123')
132
+ result.response
133
+
134
+ expect(result.status)
135
+ .to eq(200)
136
+ end
137
+
63
138
  end
@@ -0,0 +1,20 @@
1
+ {
2
+ "id": "CG00000000000000000000001",
3
+ "fundingBalanceAccountId": "BA00000000000000000000001",
4
+ "limits": [
5
+ {
6
+ "amount": {
7
+ "currency": "EUR",
8
+ "value": 100000
9
+ }
10
+ }
11
+ ],
12
+ "balances": [
13
+ {
14
+ "currency": "EUR",
15
+ "principal": 10000,
16
+ "fee": 1000,
17
+ "total": 11000
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "id": "DI00000000000000000000001",
3
+ "grantId": "GR00000000000000000000001",
4
+ "accountHolderId": "AH00000000000000000000001",
5
+ "balanceAccountId": "BA00000000000000000000001",
6
+ "amount": {
7
+ "currency": "EUR",
8
+ "value": 10000
9
+ },
10
+ "fee": {
11
+ "amount": {
12
+ "currency": "EUR",
13
+ "value": 1000
14
+ }
15
+ },
16
+ "balances": {
17
+ "currency": "EUR",
18
+ "principal": 10000,
19
+ "fee": 1000,
20
+ "total": 11000
21
+ },
22
+ "repayment": {
23
+ "basisPoints": 1000,
24
+ "updateDescription": "string"
25
+ }
26
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "disbursements": [
3
+ {
4
+ "id": "DI00000000000000000000001",
5
+ "grantId": "GR00000000000000000000001",
6
+ "accountHolderId": "AH00000000000000000000001",
7
+ "balanceAccountId": "BA00000000000000000000001",
8
+ "amount": {
9
+ "currency": "EUR",
10
+ "value": 10000
11
+ },
12
+ "fee": {
13
+ "amount": {
14
+ "currency": "EUR",
15
+ "value": 1000
16
+ }
17
+ },
18
+ "balances": {
19
+ "currency": "EUR",
20
+ "principal": 10000,
21
+ "fee": 1000,
22
+ "total": 11000
23
+ },
24
+ "repayment": {
25
+ "basisPoints": 1000,
26
+ "updateDescription": "string"
27
+ }
28
+ }
29
+ ]
30
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "id": "GO00000000000000000000001",
3
+ "accountHolderId": "AH00000000000000000000001",
4
+ "contractType": "cashAdvance",
5
+ "amount": {
6
+ "currency": "EUR",
7
+ "value": 10000
8
+ },
9
+ "fee": {
10
+ "amount": {
11
+ "currency": "EUR",
12
+ "value": 1000
13
+ },
14
+ "aprBasisPoints": 1200
15
+ },
16
+ "repayment": {
17
+ "basisPoints": 1000,
18
+ "term": {
19
+ "estimatedDays": 180,
20
+ "maximumDays": 365
21
+ },
22
+ "threshold": {
23
+ "amount": {
24
+ "currency": "EUR",
25
+ "value": 1000
26
+ }
27
+ }
28
+ },
29
+ "startsAt": "2024-01-01T00:00:00Z",
30
+ "expiresAt": "2024-01-31T23:59:59Z"
31
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "id": "GR00000000000000000000001",
3
+ "grantAccountId": "CG00000000000000000000001",
4
+ "grantOfferId": "GO00000000000000000000001",
5
+ "counterparty": {
6
+ "accountHolderId": "AH00000000000000000000001",
7
+ "balanceAccountId": "BA00000000000000000000001"
8
+ },
9
+ "amount": {
10
+ "currency": "EUR",
11
+ "value": 10000
12
+ },
13
+ "balances": {
14
+ "currency": "EUR",
15
+ "principal": 10000,
16
+ "fee": 1000,
17
+ "total": 11000
18
+ },
19
+ "status": {
20
+ "code": "Active"
21
+ }
22
+ }