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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e483ea1b71301634db57072423fd8cea1483b160eec7c1ba85fcf62ccbac0414
4
- data.tar.gz: fa6dd93d1fe95ccf9ce3e9cc4a9956e523e6f25a20ae49fb2529e560c1aec14a
3
+ metadata.gz: 02ec361baadfa4a0b114ff3f4b162f737775e22ed23b40d79e76fb0dfda3d7e2
4
+ data.tar.gz: cbffe8658ad929e8e7a7eb210013a43dbf2c58094b46e3c753c4e07ba41f4b43
5
5
  SHA512:
6
- metadata.gz: 50f51f247bb68817b56ef596ad2b435280fedb1dc06806665a5e48b4c1cfb67fda4c1060f882929c0c40c8b225635cc19d36d6f90be4ae1e0e7149dc8f8638bd
7
- data.tar.gz: 15273291ffb0122fab7050dc1263028c6a38d6634519c744057d1b3756b62461c028de7982d5c36adfb04e50f25a7d121541d1ef496a91c3c63bd67ee75c7829
6
+ metadata.gz: aa6e2f3474c3d4178fd25076994ccb76b034c8976f47f6da749bdda656b2dbc15c18757f2f7339777a15fd67f18c1d0b0b6f31436a5430a84283d6b39f69387d
7
+ data.tar.gz: 1b13bf85208f2820b7d4bc033a267b1db8dc727c00b64bd2357cc16e1e34398a70c63bb05b8d7559e3bd7b4b6a03307025a7c5d87c59dc71404a460a758b7cd9
data/.github/CODEOWNERS CHANGED
@@ -1 +1 @@
1
- * @crrood @hbkwong @KadoBOT @Aleffio @rikterbeek
1
+ * @crrood @Aleffio @wboereboom @cyattilakiss
data/README.md CHANGED
@@ -1,55 +1,69 @@
1
1
  # Adyen API Library for Ruby
2
2
 
3
- The Adyen API Library for Ruby lets you easily work with Adyen's API.
3
+
4
+ This is the officially supported Ruby library for using Adyen's APIs.
4
5
 
5
6
  ## Integration
7
+ The library supports all APIs under the following services:
6
8
 
7
- The Library supports all APIs under the following services:
9
+ * [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v67/overview): Our latest integration for accepting online payments. Current supported version: **v67**
10
+ * [Payments API](https://docs.adyen.com/api-explorer/#/Payment/v64/overview): Our classic integration for online payments. Current supported version: **v64**
11
+ * [Recurring API](https://docs.adyen.com/api-explorer/#/Recurring/v49/overview): Endpoints for managing saved payment details. Current supported version: **v49**
12
+ * [Payouts API](https://docs.adyen.com/api-explorer/#/Payout/v64/overview): Endpoints for sending funds to your customers. Current supported version: **v64**
13
+ * [Platforms APIs](https://docs.adyen.com/platforms/api): Set of APIs when using Adyen for Platforms.
14
+ * [Account API](https://docs.adyen.com/api-explorer/#/Account/v6/overview) Current supported version: **v6**
15
+ * [Fund API](https://docs.adyen.com/api-explorer/#/Fund/v6/overview) Current supported version: **v6**
16
+ * [Notification Configuration API](https://docs.adyen.com/api-explorer/#/NotificationConfigurationService/v6/overview) Current supported version: **v6**
17
+ * [POS Terminal Management API](https://docs.adyen.com/api-explorer/#/postfmapi/v1/overview): Current supported version: **v1**
18
+ * [Adyen BinLookup API](https://docs.adyen.com/api-explorer/#/BinLookup/v50/overview): Current supported version: **v50**
19
+ * [Data Protection API](https://docs.adyen.com/development-resources/data-protection-api): Current supported version: **v1**
20
+ * [Disputes API](https://docs.adyen.com/risk-management/disputes-api): Current supported version: **v50**
8
21
 
9
- * checkout
10
- * checkout utility
11
- * payments
12
- * modifications
13
- * payouts
14
- * recurring
15
- * marketpay
16
- * postfmapi
17
- * data_protection
18
- * dispute
19
- * bin_lookup
20
22
 
21
- ## Requirements
23
+ For more information, refer to our [documentation](https://docs.adyen.com/) or the [API Explorer](https://docs.adyen.com/api-explorer/).
22
24
 
23
- Built for Ruby >= 2.1
25
+ ## Prerequisites
26
+ - [Adyen test account](https://docs.adyen.com/get-started-with-adyen)
27
+ - [API key](https://docs.adyen.com/development-resources/api-credentials#generate-api-key). For testing, your API credential needs to have the [API PCI Payments role](https://docs.adyen.com/development-resources/api-credentials#roles).
28
+ - Ruby >= 2.1
24
29
 
25
30
  ## Installation
26
31
 
27
- The sole dependency is faraday for http communication - run `bundle install` to install faraday if you don't already have it
32
+ The sole dependency is faraday for HTTP communication. Run the following command to install faraday if you don't already have it:
33
+
34
+ ~~~~bash
35
+ bundle install
36
+ ~~~~
28
37
 
29
- To validate functionality of client, use `bundle install --with development` and `rspec` to run mock API tests.
38
+ To validate functionality of client and run mock API tests use
30
39
 
40
+ ~~~~bash
41
+ bundle install --with development
42
+ ~~~~
43
+ and
44
+ ~~~~bash
45
+ rspec
46
+ ~~~~
31
47
  ## Documentation
32
48
 
33
49
  Follow the rest of our guides from the [documentation](https://adyen.github.io/adyen-ruby-api-library/) on how to use this library.
34
50
 
35
- ## Usage
51
+ ## Using the library
36
52
 
37
- ### Create a client to connect to the Adyen API
38
- ```ruby
39
- require 'adyen-ruby-api-library'
53
+ ### General use with API key
40
54
 
55
+ ~~~~bash
56
+ require 'adyen-ruby-api-library'
57
+ ~~~~
58
+ ~~~~ruby
41
59
  adyen = Adyen::Client.new
42
60
 
43
- # for API-key based implementations
44
61
  adyen.api_key = 'AF5XXXXXXXXXXXXXXXXXXXX'
45
62
 
46
- # for basic-auth based implementations
47
- adyen.ws_user = 'ws@Company.Adyen'
48
- adyen.ws_password = 'super_secure_password123'
49
- ```
63
+ ~~~~
50
64
 
51
- ### Make a Payment
52
- ```ruby
65
+ - Make a Payment
66
+ ~~~~ruby
53
67
  response = adyen.checkout.payments({
54
68
  :amount => {
55
69
  :currency => "EUR",
@@ -58,122 +72,45 @@ response = adyen.checkout.payments({
58
72
  :reference => "Your order number",
59
73
  :paymentMethod => {
60
74
  :type => "scheme",
61
- :encryptedCardNumber => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
62
- :encryptedExpiryMonth => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
63
- :encryptedExpiryYear => "adyenjs_0_1_18$MT6ppy0FAMVMLH...",
64
- :encryptedSecurityCode => "adyenjs_0_1_18$MT6ppy0FAMVMLH..."
75
+ :encryptedCardNumber => "test_4111111111111111",
76
+ :encryptedExpiryMonth => "test_03",
77
+ :encryptedExpiryYear => "test_2030",
78
+ :encryptedSecurityCode => "test_737"
65
79
  },
66
80
  :returnUrl => "https://your-company.com/checkout/",
67
81
  :merchantAccount => "YourMerchantAccount"
68
82
  })
69
- ```
70
-
71
- ### Change API Version
72
- ```ruby
73
- adyen.checkout.version = 50
74
- ```
75
-
76
- ## List of supported methods
77
-
78
- **checkout:**
79
- - payment_session
80
- - payments.result
81
- - payment_methods
82
- - payments
83
- - payments.details
84
- - payment_links
85
-
86
- **checkout utility:**
87
- - origin_keys
88
-
89
- **payments:**
90
- - authorise
91
- - authorise3d
92
-
93
- **modifications:**
94
- - capture
95
- - cancel
96
- - refund
97
- - cancel_or_refund
98
- - adjust_authorisation
99
- - donate
100
-
101
- **payouts:**
102
- - confirm_third_party
103
- - decline_third_party
104
- - store_detail
105
- - submit_third_party
106
- - store_detail_and_submit_third_party
107
-
108
- **recurring:**
109
- - list_recurring_details
110
- - disable
111
- - store_token
112
-
113
- **marketpay.account:**
114
- - create_account_holder
115
- - get_account_holder
116
- - update_account_holder
117
- - update_account_holder_state
118
- - suspend_account_holder
119
- - un_suspend_account_holder
120
- - close_account_holder
121
- - create_account
122
- - update_account
123
- - close_account
124
- - upload_document
125
- - get_uploaded_documents
126
- - delete_bank_accounts
127
- - delete_shareholders
128
-
129
- **marketpay.fund:**
130
- - account_holder_balance
131
- - account_holder_transaction_list
132
- - payout_account_holder
133
- - transfer_funds
134
- - setup_beneficiary
135
- - refund_not_paid_out_transfers
136
-
137
- **marketpay.notification:**
138
- - create_notification_configuration
139
- - get_notification_configuration
140
- - get_notification_configuration_list
141
- - test_notification_configuration
142
- - update_notification_configuration
143
- - delete_notification_configurations
144
-
145
- **marketpay.hop:**
146
- - get_onboarding_url
147
-
148
- **postfmapi:**
149
- - assign_terminals
150
- - find_terminal
151
- - get_terminals_under_account
152
-
153
- **data_protection:**
154
- - request_subject_erasure
155
-
156
- **dispute:**
157
- - retrieve_applicable_defense_reasons
158
- - supply_defense_document
159
- - delete_dispute_defense_document
160
- - defend_dispute
161
-
162
- **bin_lookup:**
163
- - get_3ds_availability
164
- - get_cost_estimate
83
+ ~~~~
165
84
 
166
- ## Support
167
- If you have a feature request, or spotted a bug or a technical problem, create a GitHub issue. For other questions, contact our [support team](https://support.adyen.com/hc/en-us/requests/new?ticket_form_id=360000705420).
85
+ - Change API Version
86
+ ~~~~ruby
87
+ adyen.checkout.version = 67
88
+ ~~~~
89
+
90
+ ### Example integration
91
+
92
+ For a closer look at how our Ruby library works, clone our [example integration](https://github.com/adyen-examples/adyen-rails-online-payments). This includes commented code, highlighting key features and concepts, and examples of API calls that can be made using the library.
93
+
94
+ ### Running the tests
95
+ To run the tests use :
96
+ ~~~~bash
97
+ bundle install --with development
98
+ ~~~~
168
99
 
169
100
  ## Contributing
170
- We strongly encourage you to join us in contributing to this repository so everyone can benefit from:
171
- * New features and functionality
172
- * Resolved bug fixes and issues
173
- * Any general improvements
174
101
 
175
- Read our [**contribution guidelines**](CONTRIBUTING.md) to find out how.
102
+ We encourage you to contribute to this repository, so everyone can benefit from new features, bug fixes, and any other improvements.
103
+ Have a look at our [contributing guidelines](https://github.com/Adyen/adyen-ruby-api-library/blob/develop/CONTRIBUTING.md) to find out how to raise a pull request.
104
+
105
+ ## Support
106
+ If you have a feature request, or spotted a bug or a technical problem, [create an issue here](https://github.com/Adyen/adyen-ruby-api-library/issues/new/choose).
107
+
108
+ For other questions, [contact our Support Team](https://www.adyen.help/hc/en-us/requests/new?ticket_form_id=360000705420).
176
109
 
177
110
  ## Licence
111
+ This repository is available under the [MIT license](https://github.com/Adyen/adyen-ruby-api-library/blob/master/LICENSE).
178
112
 
179
- MIT license. For more information, see the LICENSE file.
113
+ ## See also
114
+ * [Example integration](https://github.com/adyen-examples/adyen-rails-online-payments)
115
+ * [Adyen docs](https://docs.adyen.com/)
116
+ * [API Explorer](https://docs.adyen.com/api-explorer/)
@@ -2,7 +2,6 @@ require_relative "adyen/version"
2
2
  require_relative "adyen/client"
3
3
  require_relative "adyen/errors"
4
4
  require_relative "adyen/services/checkout"
5
- require_relative "adyen/services/checkout_utility"
6
5
  require_relative "adyen/services/payments"
7
6
  require_relative "adyen/services/payouts"
8
7
  require_relative "adyen/services/recurring"
data/lib/adyen/client.rb CHANGED
@@ -42,9 +42,6 @@ module Adyen
42
42
  when "Checkout"
43
43
  url = "https://checkout-#{@env}.adyen.com/checkout"
44
44
  supports_live_url_prefix = true
45
- when "CheckoutUtility"
46
- url = "https://checkout-#{@env}.adyen.com/checkout"
47
- supports_live_url_prefix = true
48
45
  when "Account", "Fund", "Notification", "Hop"
49
46
  url = "https://cal-#{@env}.adyen.com/cal/services"
50
47
  supports_live_url_prefix = false
@@ -72,7 +69,7 @@ module Adyen
72
69
 
73
70
  # construct full URL from service and endpoint
74
71
  def service_url(service, action, version)
75
- if service == "Checkout" || service == "CheckoutUtility" || service == "Terminal"
72
+ if service == "Checkout" || service == "Terminal"
76
73
  "#{service_url_base(service)}/v#{version}/#{action}"
77
74
  else
78
75
  "#{service_url_base(service)}/#{service}/v#{version}/#{action}"
@@ -82,7 +79,7 @@ module Adyen
82
79
  # send request to adyen API
83
80
  def call_adyen_api(service, action, request_data, headers, version, with_application_info = false)
84
81
  # get URL for requested endpoint
85
- url = service_url(service, action, version)
82
+ url = service_url(service, action.is_a?(String) ? action : action.fetch(:url), version)
86
83
 
87
84
  # make sure right authentication has been provided
88
85
  # will use api_key if present, otherwise ws_user and ws_password
@@ -132,13 +129,32 @@ module Adyen
132
129
  # convert to json
133
130
  request_data = request_data.to_json
134
131
 
135
- # post request to Adyen
136
- begin
137
- response = conn.post do |req|
138
- req.body = request_data
139
- end # handle client errors
140
- rescue Faraday::ConnectionFailed => connection_error
141
- raise connection_error, "Connection to #{url} failed"
132
+ if action.is_a?(::Hash)
133
+ if action.fetch(:method) == "get"
134
+ begin
135
+ response = conn.get
136
+ rescue Faraday::ConnectionFailed => connection_error
137
+ raise connection_error, "Connection to #{url} failed"
138
+ end
139
+ end
140
+ if action.fetch(:method) == "patch"
141
+ begin
142
+ response = conn.patch do |req|
143
+ req.body = request_data
144
+ end
145
+ rescue Faraday::ConnectionFailed => connection_error
146
+ raise connection_error, "Connection to #{url} failed"
147
+ end
148
+ end
149
+ else
150
+ # post request to Adyen
151
+ begin
152
+ response = conn.post do |req|
153
+ req.body = request_data
154
+ end # handle client errors
155
+ rescue Faraday::ConnectionFailed => connection_error
156
+ raise connection_error, "Connection to #{url} failed"
157
+ end
142
158
  end
143
159
 
144
160
  # check for API errors
@@ -173,10 +189,6 @@ module Adyen
173
189
  @checkout ||= Adyen::Checkout.new(self)
174
190
  end
175
191
 
176
- def checkout_utility
177
- @checkout_utility ||= Adyen::CheckoutUtility.new(self)
178
- end
179
-
180
192
  def payments
181
193
  @payments ||= Adyen::Payments.new(self)
182
194
  end
@@ -2,18 +2,17 @@ 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
8
  service = "Checkout"
9
9
  method_names = [
10
- :payment_methods,
11
10
  :payment_session,
12
- :payment_links,
11
+ :origin_keys,
13
12
  ]
13
+
14
14
  with_application_info = [
15
15
  :payment_session,
16
- :payment_links,
17
16
  ]
18
17
 
19
18
  super(client, version, service, method_names, with_application_info)
@@ -34,6 +33,39 @@ module Adyen
34
33
  @client.call_adyen_api(@service, action, args[0], args[1], @version, true)
35
34
  end
36
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"
65
+ args[1] ||= {} # optional headers arg
66
+ @client.call_adyen_api(@service, action, args[0], args[1], @version)
67
+ end
68
+ end
37
69
  end
38
70
 
39
71
  class CheckoutDetail < Service
@@ -53,4 +85,48 @@ module Adyen
53
85
  @client.call_adyen_api(@service, action, request, headers, @version)
54
86
  end
55
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
56
132
  end