adyen-ruby-api-library 4.4.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -1
  3. data/README.md +73 -136
  4. data/lib/adyen-ruby-api-library.rb +0 -1
  5. data/lib/adyen/client.rb +28 -16
  6. data/lib/adyen/services/checkout.rb +80 -4
  7. data/lib/adyen/services/marketpay.rb +9 -7
  8. data/lib/adyen/services/payments.rb +5 -1
  9. data/lib/adyen/services/payouts.rb +3 -2
  10. data/lib/adyen/services/recurring.rb +3 -2
  11. data/lib/adyen/version.rb +1 -1
  12. data/spec/account_spec.rb +3 -1
  13. data/spec/checkout_spec.rb +247 -5
  14. data/spec/fund_spec.rb +2 -1
  15. data/spec/mocks/requests/Account/check_account_holder.json +5 -0
  16. data/spec/mocks/requests/Account/delete_payout_methods.json +6 -0
  17. data/spec/mocks/requests/Checkout/orders.json +6 -0
  18. data/spec/mocks/requests/Checkout/orders_cancel.json +7 -0
  19. data/spec/mocks/requests/Checkout/origin_keys.json +3 -0
  20. data/spec/mocks/requests/Checkout/payment_methods_balance.json +9 -0
  21. data/spec/mocks/requests/Fund/refund_funds_transfer.json +7 -0
  22. data/spec/mocks/requests/Payment/get_authentication_result.json +4 -0
  23. data/spec/mocks/requests/Payment/retrieve_3ds2_result.json +4 -0
  24. data/spec/mocks/requests/Payment/technical_cancel.json +4 -0
  25. data/spec/mocks/requests/Payment/void_pending_refund.json +4 -0
  26. data/spec/mocks/requests/Payout/payout.json +8 -0
  27. data/spec/mocks/requests/Recurring/schedule_account_updater.json +12 -0
  28. data/spec/mocks/responses/Account/check_account_holder.json +3 -0
  29. data/spec/mocks/responses/Account/delete_payout_methods.json +3 -0
  30. data/spec/mocks/responses/Checkout/get-payment-link.json +11 -0
  31. data/spec/mocks/responses/Checkout/orders.json +8 -0
  32. data/spec/mocks/responses/Checkout/orders_cancel.json +4 -0
  33. data/spec/mocks/responses/Checkout/origin_keys.json +5 -0
  34. data/spec/mocks/responses/Checkout/payment_methods_balance.json +3 -0
  35. data/spec/mocks/responses/Checkout/update-payment-link.json +11 -0
  36. data/spec/mocks/responses/Fund/refund_funds_transfer.json +5 -0
  37. data/spec/mocks/responses/Payment/get_authentication_result.json +5 -0
  38. data/spec/mocks/responses/Payment/retrieve_3ds2_result.json +5 -0
  39. data/spec/mocks/responses/Payment/technical_cancel.json +3 -0
  40. data/spec/mocks/responses/Payment/void_pending_refund.json +3 -0
  41. data/spec/mocks/responses/Payout/payout.json +3 -0
  42. data/spec/mocks/responses/Recurring/schedule_account_updater.json +4 -0
  43. data/spec/payments_spec.rb +5 -1
  44. data/spec/payouts_spec.rb +2 -1
  45. data/spec/recurring_spec.rb +2 -1
  46. data/spec/spec_helper.rb +0 -1
  47. metadata +32 -7
  48. data/lib/adyen/services/checkout_utility.rb +0 -16
  49. data/spec/checkout_utility_spec.rb +0 -29
  50. data/spec/mocks/requests/CheckoutUtility/origin_keys.json +0 -7
  51. data/spec/mocks/responses/CheckoutUtility/origin_keys.json +0 -7
@@ -29,7 +29,7 @@ module Adyen
29
29
 
30
30
  class Account < Service
31
31
  attr_accessor :version
32
- DEFAULT_VERSION = 4
32
+ DEFAULT_VERSION = 6
33
33
 
34
34
  def initialize(client, version = DEFAULT_VERSION)
35
35
  service = 'Account'
@@ -46,9 +46,10 @@ module Adyen
46
46
  :delete_shareholders,
47
47
  :close_account,
48
48
  :close_account_holder,
49
- :get_tier_configuration,
50
49
  :suspend_account_holder,
51
- :un_suspend_account_holder
50
+ :un_suspend_account_holder,
51
+ :delete_payout_methods,
52
+ :check_account_holder
52
53
  ]
53
54
 
54
55
  super(client, version, service, method_names)
@@ -57,7 +58,7 @@ module Adyen
57
58
 
58
59
  class Fund < Service
59
60
  attr_accessor :version
60
- DEFAULT_VERSION = 3
61
+ DEFAULT_VERSION = 6
61
62
 
62
63
  def initialize(client, version = DEFAULT_VERSION)
63
64
  service = 'Fund'
@@ -67,7 +68,8 @@ module Adyen
67
68
  :account_holder_transaction_list,
68
69
  :refund_not_paid_out_transfers,
69
70
  :setup_beneficiary,
70
- :transfer_funds
71
+ :transfer_funds,
72
+ :refund_funds_transfer
71
73
  ]
72
74
 
73
75
  super(client, version, service, method_names)
@@ -76,7 +78,7 @@ module Adyen
76
78
 
77
79
  class Notification < Service
78
80
  attr_accessor :version
79
- DEFAULT_VERSION = 5
81
+ DEFAULT_VERSION = 6
80
82
 
81
83
  def initialize(client, version = DEFAULT_VERSION)
82
84
  service = 'Notification'
@@ -95,7 +97,7 @@ module Adyen
95
97
 
96
98
  class Hop < Service
97
99
  attr_accessor :version
98
- DEFAULT_VERSION = 1
100
+ DEFAULT_VERSION = 6
99
101
 
100
102
  def initialize(client, version = DEFAULT_VERSION)
101
103
  service = 'Hop'
@@ -3,7 +3,7 @@ require_relative "service"
3
3
  module Adyen
4
4
  class Payments < Service
5
5
  attr_accessor :version
6
- DEFAULT_VERSION = 50
6
+ DEFAULT_VERSION = 64
7
7
 
8
8
  def initialize(client, version = DEFAULT_VERSION)
9
9
  service = "Payment"
@@ -17,6 +17,10 @@ module Adyen
17
17
  :cancel_or_refund,
18
18
  :adjust_authorisation,
19
19
  :donate,
20
+ :get_authentication_result,
21
+ :technical_cancel,
22
+ :void_pending_refund,
23
+ :retrieve_3ds2_result
20
24
  ]
21
25
  with_application_info = [
22
26
  :authorise,
@@ -3,7 +3,7 @@ require_relative 'service'
3
3
  module Adyen
4
4
  class Payouts < Service
5
5
  attr_accessor :version
6
- DEFAULT_VERSION = 30
6
+ DEFAULT_VERSION = 64
7
7
 
8
8
  def initialize(client, version = DEFAULT_VERSION)
9
9
  service = 'Payout'
@@ -12,7 +12,8 @@ module Adyen
12
12
  :store_detail_and_submit_third_party,
13
13
  :submit_third_party,
14
14
  :confirm_third_party,
15
- :decline_third_party
15
+ :decline_third_party,
16
+ :payout
16
17
  ]
17
18
 
18
19
  super(client, version, service, method_names)
@@ -3,14 +3,15 @@ require_relative 'service'
3
3
  module Adyen
4
4
  class Recurring < Service
5
5
  attr_accessor :version
6
- DEFAULT_VERSION = 30
6
+ DEFAULT_VERSION = 49
7
7
 
8
8
  def initialize(client, version = DEFAULT_VERSION)
9
9
  service = 'Recurring'
10
10
  method_names = [
11
11
  :list_recurring_details,
12
12
  :disable,
13
- :store_token
13
+ :store_token,
14
+ :schedule_account_updater
14
15
  ]
15
16
 
16
17
  super(client, version, service, method_names)
data/lib/adyen/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Adyen
2
2
  NAME = "adyen-ruby-api-library"
3
- VERSION = "4.4.0".freeze
3
+ VERSION = "5.0.0".freeze
4
4
  end
data/spec/account_spec.rb CHANGED
@@ -20,7 +20,9 @@ RSpec.describe Adyen::Payments, service: "marketpay account service" do
20
20
  ["upload_document", "pspReference", "9914762681460244"],
21
21
  ["get_uploaded_documents", "pspReference", "9914694369860322"],
22
22
  ["delete_bank_accounts", "pspReference", "9914694372670551"],
23
- ["delete_shareholders", "pspReference", "9914694372990637"]
23
+ ["delete_shareholders", "pspReference", "9914694372990637"],
24
+ ["delete_payout_methods", "pspReference", "9914694372990637"],
25
+ ["check_account_holder", "pspReference", "9914694372990637"],
24
26
  ]
25
27
 
26
28
  generate_tests(client, "Account", test_sets, client.marketpay.account)
@@ -13,9 +13,79 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
13
13
 
14
14
  # must be created manually because every field in the response is an array
15
15
  it "makes a payment_methods call" do
16
- parsed_body = create_test(@shared_values[:client], @shared_values[:service], "payment_methods", @shared_values[:client].checkout)
17
- expect(parsed_body["paymentMethods"].class).
18
- to be Array
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: {
25
+ "x-api-key" => @shared_values[:client].api_key
26
+ }
27
+ ).
28
+ to_return(
29
+ body: response_body
30
+ )
31
+
32
+ result = @shared_values[:client].checkout.payment_methods(request_body)
33
+ response_hash = result.response
34
+
35
+ expect(result.status).
36
+ to eq(200)
37
+ expect(response_hash).
38
+ to eq(JSON.parse(response_body))
39
+ expect(response_hash).
40
+ to be_a Adyen::HashWithAccessors
41
+ expect(response_hash).
42
+ to be_a_kind_of Hash
43
+ end
44
+
45
+ it "makes a paymentMethods/balance call" do
46
+ request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment_methods_balance.json"))
47
+ request_body[:applicationInfo] = {}
48
+ request_body[:applicationInfo][:adyenPaymentSource] = {
49
+ :name => "adyen-test",
50
+ :version => "1.0.0",
51
+ }
52
+
53
+ @shared_values[:client].add_application_info(request_body)
54
+
55
+ response_body = json_from_file("mocks/responses/Checkout/payment_methods_balance.json")
56
+
57
+ url = @shared_values[:client].service_url(@shared_values[:service], "paymentMethods/balance", @shared_values[:client].checkout.version)
58
+ WebMock.stub_request(:post, url).
59
+ with(
60
+ body: request_body,
61
+ headers: {
62
+ "x-api-key" => @shared_values[:client].api_key
63
+ }
64
+ ).
65
+ to_return(
66
+ body: response_body
67
+ )
68
+
69
+ result = @shared_values[:client].checkout.payment_methods.balance(request_body)
70
+ # result.response is already a Ruby hash (rather than an unparsed JSON string)
71
+ response_hash = result.response
72
+
73
+ expect(request_body[:applicationInfo][:adyenLibrary][:name]).
74
+ to eq(Adyen::NAME)
75
+ expect(request_body[:applicationInfo][:adyenLibrary][:version]).
76
+ to eq(Adyen::VERSION)
77
+ expect(request_body[:applicationInfo][:adyenPaymentSource][:name]).
78
+ to eq("adyen-test")
79
+ expect(result.status).
80
+ to eq(200)
81
+ expect(response_hash).
82
+ to eq(JSON.parse(response_body))
83
+ expect(response_hash).
84
+ to be_a Adyen::HashWithAccessors
85
+ expect(response_hash).
86
+ to be_a_kind_of Hash
87
+ expect(response_hash["balance"]).
88
+ to eq("100")
19
89
  end
20
90
 
21
91
  # must be created manually due to payments/details format
@@ -102,6 +172,178 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
102
172
  expect(response_hash.resultCode).
103
173
  to eq("Authorised")
104
174
  end
175
+
176
+ # must be created manually due to paymentsLinks format
177
+ it "makes a paymentLinks call" do
178
+ request_body = JSON.parse(json_from_file("mocks/requests/Checkout/payment_links.json"))
179
+ request_body[:applicationInfo] = {}
180
+ request_body[:applicationInfo][:adyenPaymentSource] = {
181
+ :name => "adyen-test",
182
+ :version => "1.0.0",
183
+ }
184
+
185
+ @shared_values[:client].add_application_info(request_body)
186
+
187
+ response_body = json_from_file("mocks/responses/Checkout/payment_links.json")
188
+
189
+ url = @shared_values[:client].service_url(@shared_values[:service], "paymentLinks", @shared_values[:client].checkout.version)
190
+ WebMock.stub_request(:post, url).
191
+ with(
192
+ body: request_body,
193
+ headers: {
194
+ "x-api-key" => @shared_values[:client].api_key
195
+ }
196
+ ).
197
+ to_return(
198
+ body: response_body
199
+ )
200
+
201
+ result = @shared_values[:client].checkout.payment_links(request_body)
202
+ response_hash = result.response
203
+
204
+ expect(result.status).
205
+ to eq(200)
206
+ expect(response_hash).
207
+ to eq(JSON.parse(response_body))
208
+ expect(response_hash).
209
+ to be_a Adyen::HashWithAccessors
210
+ expect(response_hash).
211
+ to be_a_kind_of Hash
212
+ end
213
+
214
+ # must be created manually due to paymentsLinks/{linkId} format
215
+ it "makes a get paymentLinks/{linkId} call" do
216
+ response_body = json_from_file("mocks/responses/Checkout/get-payment-link.json")
217
+
218
+ url = @shared_values[:client].service_url(@shared_values[:service], "paymentLinks/1", @shared_values[:client].checkout.version)
219
+ WebMock.stub_request(:get, url).
220
+ with(
221
+ headers: {
222
+ "x-api-key" => @shared_values[:client].api_key
223
+ }
224
+ ).
225
+ to_return(
226
+ body: response_body
227
+ )
228
+
229
+ result = @shared_values[:client].checkout.payment_links.get("1")
230
+ response_hash = result.response
231
+
232
+ expect(result.status).
233
+ to eq(200)
234
+ expect(response_hash).
235
+ to eq(JSON.parse(response_body))
236
+ expect(response_hash).
237
+ to be_a Adyen::HashWithAccessors
238
+ expect(response_hash).
239
+ to be_a_kind_of Hash
240
+ expect(response_hash["status"]).
241
+ to eq("active")
242
+ expect(response_hash.id).
243
+ to eq("MockId")
244
+ end
245
+
246
+ # must be created manually due to paymentsLinks/{linkId} format
247
+ it "makes a patch paymentLinks/{linkId} call" do
248
+ request_body = {
249
+ :status => "expired",
250
+ }
251
+
252
+ @shared_values[:client].add_application_info(request_body)
253
+ response_body = json_from_file("mocks/responses/Checkout/update-payment-link.json")
254
+
255
+ url = @shared_values[:client].service_url(@shared_values[:service], "paymentLinks/1", @shared_values[:client].checkout.version)
256
+ WebMock.stub_request(:patch, url).
257
+ with(
258
+ body: request_body,
259
+ headers: {
260
+ "x-api-key" => @shared_values[:client].api_key
261
+ }
262
+ ).
263
+ to_return(
264
+ body: response_body
265
+ )
266
+
267
+ result = @shared_values[:client].checkout.payment_links.update("1", request_body)
268
+ response_hash = result.response
269
+
270
+ expect(result.status).
271
+ to eq(200)
272
+ expect(response_hash).
273
+ to eq(JSON.parse(response_body))
274
+ expect(response_hash).
275
+ to be_a Adyen::HashWithAccessors
276
+ expect(response_hash).
277
+ to be_a_kind_of Hash
278
+ expect(response_hash["status"]).
279
+ to eq("expired")
280
+ expect(response_hash.id).
281
+ to eq("MockId")
282
+ end
283
+
284
+ it "makes an orders call" do
285
+ request_body = JSON.parse(json_from_file("mocks/requests/Checkout/orders.json"))
286
+
287
+ response_body = json_from_file("mocks/responses/Checkout/orders.json")
288
+
289
+ url = @shared_values[:client].service_url(@shared_values[:service], "orders", @shared_values[:client].checkout.version)
290
+ WebMock.stub_request(:post, url).
291
+ with(
292
+ body: request_body,
293
+ headers: {
294
+ "x-api-key" => @shared_values[:client].api_key
295
+ }
296
+ ).
297
+ to_return(
298
+ body: response_body
299
+ )
300
+
301
+ result = @shared_values[:client].checkout.orders(request_body)
302
+ response_hash = result.response
303
+
304
+ expect(result.status).
305
+ to eq(200)
306
+ expect(response_hash).
307
+ to eq(JSON.parse(response_body))
308
+ expect(response_hash).
309
+ to be_a Adyen::HashWithAccessors
310
+ expect(response_hash).
311
+ to be_a_kind_of Hash
312
+ expect(response_hash["remainingAmount"]["value"]).
313
+ to eq(100)
314
+ end
315
+
316
+ it "makes an orders/cancel call" do
317
+ request_body = JSON.parse(json_from_file("mocks/requests/Checkout/orders_cancel.json"))
318
+
319
+ response_body = json_from_file("mocks/responses/Checkout/orders_cancel.json")
320
+
321
+ url = @shared_values[:client].service_url(@shared_values[:service], "orders/cancel", @shared_values[:client].checkout.version)
322
+ WebMock.stub_request(:post, url).
323
+ with(
324
+ body: request_body,
325
+ headers: {
326
+ "x-api-key" => @shared_values[:client].api_key
327
+ }
328
+ ).
329
+ to_return(
330
+ body: response_body
331
+ )
332
+
333
+ result = @shared_values[:client].checkout.orders.cancel(request_body)
334
+ response_hash = result.response
335
+
336
+ expect(result.status).
337
+ to eq(200)
338
+ expect(response_hash).
339
+ to eq(JSON.parse(response_body))
340
+ expect(response_hash).
341
+ to be_a Adyen::HashWithAccessors
342
+ expect(response_hash).
343
+ to be_a_kind_of Hash
344
+ expect(response_hash["resultCode"]).
345
+ to eq("cancelled")
346
+ end
105
347
 
106
348
  # create client for automated tests
107
349
  client = create_client(:api_key)
@@ -110,8 +352,8 @@ RSpec.describe Adyen::Checkout, service: "checkout" do
110
352
  # format is defined in spec_helper
111
353
  test_sets = [
112
354
  ["payment_session", "publicKeyToken", "8115054323780109"],
113
- ["payment_links", "url", "https://checkoutshopper-test.adyen.com"],
114
- ["payments", "resultCode", "Authorised"]
355
+ ["payments", "resultCode", "Authorised"],
356
+ ["origin_keys", "originKeys", { "https://adyen.com" => "mocked_origin_key" }]
115
357
  ]
116
358
 
117
359
  generate_tests(client, "Checkout", test_sets, client.checkout)
data/spec/fund_spec.rb CHANGED
@@ -12,7 +12,8 @@ RSpec.describe Adyen::Payments, service: "marketpay fund service" do
12
12
  ["account_holder_transaction_list", "pspReference", "9914721175530029"],
13
13
  ["refund_not_paid_out_transfers", "pspReference", "9915090894215323"],
14
14
  ["setup_beneficiary", "pspReference", "9914860354282596"],
15
- ["transfer_funds", "pspReference", "9915090893984580"]
15
+ ["transfer_funds", "pspReference", "9915090893984580"],
16
+ ["refund_funds_transfer", "pspReference", "9915090893984580"]
16
17
  ]
17
18
 
18
19
  generate_tests(client, "Fund", test_sets, client.marketpay.fund)
@@ -0,0 +1,5 @@
1
+ {
2
+ "accountHolderCode": "CODE_OF_ACCOUNT_HOLDER",
3
+ "accountStateType": "Payout",
4
+ "tier": "2"
5
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "accountHolderCode": "CODE_OF_ACCOUNT_HOLDER",
3
+ "payoutMethodCodes": [
4
+ "mock_code"
5
+ ]
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "amount": {
3
+ "currency":"USD",
4
+ "value": "1000"
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "merchantAccount": "MERCHANT_ACCOUNT",
3
+ "order": {
4
+ "orderData": "mocked_order_data",
5
+ "pspReference": "mocked_psp_ref"
6
+ }
7
+ }