adyen-ruby-api-library 4.0.2 → 5.0.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -1
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +7 -0
  6. data/.github/dependabot.yml +8 -0
  7. data/.gitignore +2 -0
  8. data/README.md +72 -110
  9. data/lib/adyen-ruby-api-library.rb +4 -12
  10. data/lib/adyen/client.rb +57 -24
  11. data/lib/adyen/services/bin_lookup.rb +18 -0
  12. data/lib/adyen/services/checkout.rb +88 -8
  13. data/lib/adyen/services/{checkout_utility.rb → data_protection.rb} +4 -3
  14. data/lib/adyen/services/dispute.rb +20 -0
  15. data/lib/adyen/services/marketpay.rb +26 -6
  16. data/lib/adyen/services/payments.rb +15 -5
  17. data/lib/adyen/services/payouts.rb +3 -2
  18. data/lib/adyen/services/postfmapi.rb +19 -0
  19. data/lib/adyen/services/recurring.rb +3 -2
  20. data/lib/adyen/services/service.rb +2 -2
  21. data/lib/adyen/version.rb +1 -1
  22. data/spec/account_spec.rb +3 -1
  23. data/spec/bin_lookup_spec.rb +15 -0
  24. data/spec/checkout_spec.rb +247 -5
  25. data/spec/data_protection_spec.rb +14 -0
  26. data/spec/dispute_spec.rb +17 -0
  27. data/spec/fund_spec.rb +2 -1
  28. data/spec/hop_spec.rb +14 -0
  29. data/spec/mocks/requests/Account/check_account_holder.json +5 -0
  30. data/spec/mocks/requests/Account/delete_payout_methods.json +6 -0
  31. data/spec/mocks/requests/BinLookup/get_3ds_availability.json +4 -0
  32. data/spec/mocks/requests/BinLookup/get_cost_estimate.json +8 -0
  33. data/spec/mocks/requests/Checkout/orders.json +6 -0
  34. data/spec/mocks/requests/Checkout/orders_cancel.json +7 -0
  35. data/spec/mocks/requests/Checkout/origin_keys.json +3 -0
  36. data/spec/mocks/requests/Checkout/payment_methods_balance.json +9 -0
  37. data/spec/mocks/requests/DataProtectionService/request_subject_erasure.json +5 -0
  38. data/spec/mocks/requests/DisputeService/defend_dispute.json +5 -0
  39. data/spec/mocks/requests/DisputeService/delete_dispute_defense_document.json +5 -0
  40. data/spec/mocks/requests/DisputeService/retrieve_applicable_defense_reasons.json +4 -0
  41. data/spec/mocks/requests/DisputeService/supply_defense_document.json +11 -0
  42. data/spec/mocks/requests/Fund/refund_funds_transfer.json +7 -0
  43. data/spec/mocks/requests/Hop/get_onboarding_url.json +4 -0
  44. data/spec/mocks/requests/Payment/donate.json +10 -0
  45. data/spec/mocks/requests/Payment/get_authentication_result.json +4 -0
  46. data/spec/mocks/requests/Payment/retrieve_3ds2_result.json +4 -0
  47. data/spec/mocks/requests/Payment/technical_cancel.json +4 -0
  48. data/spec/mocks/requests/Payment/void_pending_refund.json +4 -0
  49. data/spec/mocks/requests/Payout/payout.json +8 -0
  50. data/spec/mocks/requests/Recurring/schedule_account_updater.json +12 -0
  51. data/spec/mocks/requests/Terminal/assign_terminals.json +6 -0
  52. data/spec/mocks/requests/Terminal/find_terminal.json +3 -0
  53. data/spec/mocks/requests/Terminal/get_terminals_under_account.json +4 -0
  54. data/spec/mocks/responses/Account/check_account_holder.json +3 -0
  55. data/spec/mocks/responses/Account/delete_payout_methods.json +3 -0
  56. data/spec/mocks/responses/BinLookup/get_3ds_availability.json +8 -0
  57. data/spec/mocks/responses/BinLookup/get_cost_estimate.json +8 -0
  58. data/spec/mocks/responses/Checkout/get-payment-link.json +11 -0
  59. data/spec/mocks/responses/Checkout/orders.json +8 -0
  60. data/spec/mocks/responses/Checkout/orders_cancel.json +4 -0
  61. data/spec/mocks/responses/Checkout/origin_keys.json +5 -0
  62. data/spec/mocks/responses/Checkout/payment_methods_balance.json +3 -0
  63. data/spec/mocks/responses/Checkout/update-payment-link.json +11 -0
  64. data/spec/mocks/responses/DataProtectionService/request_subject_erasure.json +3 -0
  65. data/spec/mocks/responses/DisputeService/defend_dispute.json +5 -0
  66. data/spec/mocks/responses/DisputeService/delete_dispute_defense_document.json +5 -0
  67. data/spec/mocks/responses/DisputeService/retrieve_applicable_defense_reasons.json +28 -0
  68. data/spec/mocks/responses/DisputeService/supply_defense_document.json +5 -0
  69. data/spec/mocks/responses/Fund/refund_funds_transfer.json +5 -0
  70. data/spec/mocks/responses/Hop/get_onboarding_url.json +7 -0
  71. data/spec/mocks/responses/Payment/donate.json +4 -0
  72. data/spec/mocks/responses/Payment/get_authentication_result.json +5 -0
  73. data/spec/mocks/responses/Payment/retrieve_3ds2_result.json +5 -0
  74. data/spec/mocks/responses/Payment/technical_cancel.json +3 -0
  75. data/spec/mocks/responses/Payment/void_pending_refund.json +3 -0
  76. data/spec/mocks/responses/Payout/payout.json +3 -0
  77. data/spec/mocks/responses/Recurring/schedule_account_updater.json +4 -0
  78. data/spec/mocks/responses/Terminal/assign_terminals.json +5 -0
  79. data/spec/mocks/responses/Terminal/find_terminal.json +6 -0
  80. data/spec/mocks/responses/Terminal/get_terminals_under_account.json +11 -0
  81. data/spec/payments_spec.rb +6 -1
  82. data/spec/payouts_spec.rb +2 -1
  83. data/spec/postfmapi_spec.rb +16 -0
  84. data/spec/recurring_spec.rb +2 -1
  85. data/spec/service_spec.rb +2 -0
  86. data/spec/spec_helper.rb +18 -12
  87. metadata +69 -7
  88. data/spec/checkout_utility_spec.rb +0 -29
  89. data/spec/mocks/requests/CheckoutUtility/origin_keys.json +0 -7
  90. data/spec/mocks/responses/CheckoutUtility/origin_keys.json +0 -7
@@ -0,0 +1,18 @@
1
+ require_relative 'service'
2
+
3
+ module Adyen
4
+ class BinLookup < Service
5
+ attr_accessor :version
6
+ DEFAULT_VERSION = 50
7
+
8
+ def initialize(client, version = DEFAULT_VERSION)
9
+ service = 'BinLookup'
10
+ method_names = [
11
+ :get_3ds_availability,
12
+ :get_cost_estimate
13
+ ]
14
+
15
+ super(client, version, service, method_names)
16
+ end
17
+ end
18
+ end
@@ -1,18 +1,21 @@
1
- require_relative 'service'
1
+ require_relative "service"
2
2
 
3
3
  module Adyen
4
4
  class Checkout < Service
5
- DEFAULT_VERSION = 50
5
+ DEFAULT_VERSION = 67
6
6
 
7
7
  def initialize(client, version = DEFAULT_VERSION)
8
- service = 'Checkout'
8
+ service = "Checkout"
9
9
  method_names = [
10
- :payment_methods,
11
10
  :payment_session,
12
- :payment_links
11
+ :origin_keys,
13
12
  ]
14
13
 
15
- super(client, version, service, method_names)
14
+ with_application_info = [
15
+ :payment_session,
16
+ ]
17
+
18
+ super(client, version, service, method_names, with_application_info)
16
19
  end
17
20
 
18
21
  # This method can't be dynamically defined because
@@ -25,7 +28,40 @@ module Adyen
25
28
  when 0
26
29
  Adyen::CheckoutDetail.new(@client, @version)
27
30
  else
28
- action = 'payments'
31
+ action = "payments"
32
+ args[1] ||= {} # optional headers arg
33
+ @client.call_adyen_api(@service, action, args[0], args[1], @version, true)
34
+ end
35
+ end
36
+
37
+ def payment_links(*args)
38
+ case args.size
39
+ when 0
40
+ Adyen::CheckoutLink.new(@client, @version)
41
+ else
42
+ action = "paymentLinks"
43
+ args[1] ||= {} # optional headers arg
44
+ @client.call_adyen_api(@service, action, args[0], args[1], @version, true)
45
+ end
46
+ end
47
+
48
+ def payment_methods(*args)
49
+ case args.size
50
+ when 0
51
+ Adyen::CheckoutMethod.new(@client, @version)
52
+ else
53
+ action = "paymentMethods"
54
+ args[1] ||= {} # optional headers arg
55
+ @client.call_adyen_api(@service, action, args[0], args[1], @version)
56
+ end
57
+ end
58
+
59
+ def orders(*args)
60
+ case args.size
61
+ when 0
62
+ Adyen::CheckoutOrder.new(@client, @version)
63
+ else
64
+ action = "orders"
29
65
  args[1] ||= {} # optional headers arg
30
66
  @client.call_adyen_api(@service, action, args[0], args[1], @version)
31
67
  end
@@ -34,7 +70,7 @@ module Adyen
34
70
 
35
71
  class CheckoutDetail < Service
36
72
  def initialize(client, version = DEFAULT_VERSION)
37
- @service = 'Checkout'
73
+ @service = "Checkout"
38
74
  @client = client
39
75
  @version = version
40
76
  end
@@ -49,4 +85,48 @@ module Adyen
49
85
  @client.call_adyen_api(@service, action, request, headers, @version)
50
86
  end
51
87
  end
88
+
89
+ class CheckoutLink < Service
90
+ def initialize(client, version = DEFAULT_VERSION)
91
+ @service = "Checkout"
92
+ @client = client
93
+ @version = version
94
+ end
95
+
96
+ def get(linkId, headers = {})
97
+ action = { method: 'get', url: "paymentLinks/" + linkId }
98
+ @client.call_adyen_api(@service, action, {}, headers, @version, true)
99
+ end
100
+
101
+ def update(linkId, request, headers = {})
102
+ action = { method: 'patch', url: "paymentLinks/" + linkId }
103
+ @client.call_adyen_api(@service, action, request, headers, @version, false)
104
+ end
105
+ end
106
+
107
+ class CheckoutMethod < Service
108
+ def initialize(client, version = DEFAULT_VERSION)
109
+ @service = "Checkout"
110
+ @client = client
111
+ @version = version
112
+ end
113
+
114
+ def balance(request, headers = {})
115
+ action = "paymentMethods/balance"
116
+ @client.call_adyen_api(@service, action, request, headers, @version, true)
117
+ end
118
+ end
119
+
120
+ class CheckoutOrder < Service
121
+ def initialize(client, version = DEFAULT_VERSION)
122
+ @service = "Checkout"
123
+ @client = client
124
+ @version = version
125
+ end
126
+
127
+ def cancel(request, headers = {})
128
+ action = "orders/cancel"
129
+ @client.call_adyen_api(@service, action, request, headers, @version)
130
+ end
131
+ end
52
132
  end
@@ -1,13 +1,14 @@
1
1
  require_relative 'service'
2
2
 
3
3
  module Adyen
4
- class CheckoutUtility < Service
4
+ class DataProtection < Service
5
+ attr_accessor :version
5
6
  DEFAULT_VERSION = 1
6
7
 
7
8
  def initialize(client, version = DEFAULT_VERSION)
8
- service = 'Checkout'
9
+ service = 'DataProtectionService'
9
10
  method_names = [
10
- :origin_keys
11
+ :request_subject_erasure
11
12
  ]
12
13
 
13
14
  super(client, version, service, method_names)
@@ -0,0 +1,20 @@
1
+ require_relative 'service'
2
+
3
+ module Adyen
4
+ class Dispute < Service
5
+ attr_accessor :version
6
+ DEFAULT_VERSION = 30
7
+
8
+ def initialize(client, version = DEFAULT_VERSION)
9
+ service = 'DisputeService'
10
+ method_names = [
11
+ :retrieve_applicable_defense_reasons,
12
+ :supply_defense_document,
13
+ :delete_dispute_defense_document,
14
+ :defend_dispute,
15
+ ]
16
+
17
+ super(client, version, service, method_names)
18
+ end
19
+ end
20
+ end
@@ -21,11 +21,15 @@ module Adyen
21
21
  def notification
22
22
  @notification ||= Adyen::Marketpay::Notification.new(@client)
23
23
  end
24
+
25
+ def hop
26
+ @hop ||= Adyen::Marketpay::Hop.new(@client)
27
+ end
24
28
  end
25
29
 
26
30
  class Account < Service
27
31
  attr_accessor :version
28
- DEFAULT_VERSION = 4
32
+ DEFAULT_VERSION = 6
29
33
 
30
34
  def initialize(client, version = DEFAULT_VERSION)
31
35
  service = 'Account'
@@ -42,9 +46,10 @@ module Adyen
42
46
  :delete_shareholders,
43
47
  :close_account,
44
48
  :close_account_holder,
45
- :get_tier_configuration,
46
49
  :suspend_account_holder,
47
- :un_suspend_account_holder
50
+ :un_suspend_account_holder,
51
+ :delete_payout_methods,
52
+ :check_account_holder
48
53
  ]
49
54
 
50
55
  super(client, version, service, method_names)
@@ -53,7 +58,7 @@ module Adyen
53
58
 
54
59
  class Fund < Service
55
60
  attr_accessor :version
56
- DEFAULT_VERSION = 3
61
+ DEFAULT_VERSION = 6
57
62
 
58
63
  def initialize(client, version = DEFAULT_VERSION)
59
64
  service = 'Fund'
@@ -63,7 +68,8 @@ module Adyen
63
68
  :account_holder_transaction_list,
64
69
  :refund_not_paid_out_transfers,
65
70
  :setup_beneficiary,
66
- :transfer_funds
71
+ :transfer_funds,
72
+ :refund_funds_transfer
67
73
  ]
68
74
 
69
75
  super(client, version, service, method_names)
@@ -72,7 +78,7 @@ module Adyen
72
78
 
73
79
  class Notification < Service
74
80
  attr_accessor :version
75
- DEFAULT_VERSION = 5
81
+ DEFAULT_VERSION = 6
76
82
 
77
83
  def initialize(client, version = DEFAULT_VERSION)
78
84
  service = 'Notification'
@@ -88,5 +94,19 @@ module Adyen
88
94
  super(client, version, service, method_names)
89
95
  end
90
96
  end
97
+
98
+ class Hop < Service
99
+ attr_accessor :version
100
+ DEFAULT_VERSION = 6
101
+
102
+ def initialize(client, version = DEFAULT_VERSION)
103
+ service = 'Hop'
104
+ method_names = [
105
+ :get_onboarding_url
106
+ ]
107
+
108
+ super(client, version, service, method_names)
109
+ end
110
+ end
91
111
  end
92
112
  end
@@ -1,12 +1,12 @@
1
- require_relative 'service'
1
+ require_relative "service"
2
2
 
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
- service = 'Payment'
9
+ service = "Payment"
10
10
  method_names = [
11
11
  :authorise,
12
12
  :authorise3d,
@@ -15,10 +15,20 @@ module Adyen
15
15
  :cancel,
16
16
  :refund,
17
17
  :cancel_or_refund,
18
- :adjust_authorisation
18
+ :adjust_authorisation,
19
+ :donate,
20
+ :get_authentication_result,
21
+ :technical_cancel,
22
+ :void_pending_refund,
23
+ :retrieve_3ds2_result
24
+ ]
25
+ with_application_info = [
26
+ :authorise,
27
+ :authorise3d,
28
+ :authorise3ds2,
19
29
  ]
20
30
 
21
- super(client, version, service, method_names)
31
+ super(client, version, service, method_names, with_application_info)
22
32
  end
23
33
  end
24
34
  end
@@ -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)
@@ -0,0 +1,19 @@
1
+ require_relative 'service'
2
+
3
+ module Adyen
4
+ class PosTerminalManagement < Service
5
+ attr_accessor :version
6
+ DEFAULT_VERSION = 1
7
+
8
+ def initialize(client, version = DEFAULT_VERSION)
9
+ service = 'Terminal'
10
+ method_names = [
11
+ :assign_terminals,
12
+ :find_terminal,
13
+ :get_terminals_under_account
14
+ ]
15
+
16
+ super(client, version, service, method_names)
17
+ end
18
+ end
19
+ end
@@ -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)
@@ -11,7 +11,7 @@ module Adyen
11
11
  method_name.to_s.gsub(/_./) { |x| x[1].upcase }
12
12
  end
13
13
 
14
- def initialize(client, version, service, method_names)
14
+ def initialize(client, version, service, method_names, with_application_info = [])
15
15
  @client = client
16
16
  @version = version
17
17
  @service = service
@@ -20,7 +20,7 @@ module Adyen
20
20
  method_names.each do |method_name|
21
21
  define_singleton_method method_name do |request, headers = {}|
22
22
  action = self.class.action_for_method_name(method_name)
23
- @client.call_adyen_api(@service, action, request, headers, @version)
23
+ @client.call_adyen_api(@service, action, request, headers, @version, with_application_info.include?(method_name))
24
24
  end
25
25
  end
26
26
  end
data/lib/adyen/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Adyen
2
2
  NAME = "adyen-ruby-api-library"
3
- VERSION = "4.0.2".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)
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Adyen::BinLookup, service: "BIN lookup service" do
4
+ # client instance to be used in dynamically generated tests
5
+ client = create_client(:basic)
6
+
7
+ # methods / values to test for
8
+ # format is defined in spec_helper
9
+ test_sets = [
10
+ ["get_3ds_availability", "threeDS2supported", false],
11
+ ["get_cost_estimate", "resultCode", "Success"]
12
+ ]
13
+
14
+ generate_tests(client, "BinLookup", test_sets, client.bin_lookup)
15
+ end
@@ -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)