Skip to content

Commit 5f5233c

Browse files
Merge pull request #137 from Adyen/develop
Release 7.0.0
2 parents 0899324 + 18eed31 commit 5f5233c

File tree

125 files changed

+5733
-576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+5733
-576
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ design.txt
1515
.DS_Store
1616

1717
.idea
18+
main.rb
19+
build/
20+
openapi-generator-cli-6.0.1.jar

Makefile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
generator:=ruby
2+
openapi-generator-version:=6.4.0
3+
openapi-generator-url:=https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/$(openapi-generator-version)/openapi-generator-cli-$(openapi-generator-version).jar
4+
openapi-generator-jar:=build/openapi-generator-cli.jar
5+
openapi-generator-cli:=java -jar build/openapi-generator-cli.jar
6+
output:=build/out
7+
8+
services:=balancePlatform checkout legalEntityManagement management payout platformsAccount platformsFund platformsHostedOnboardingPage platformsNotificationConfiguration transfers
9+
singleFileServices:=balanceControlService binLookup dataProtection recurring storedValue posTerminalManagement payment
10+
11+
binLookup: spec=BinLookupService-v54
12+
checkout: spec=CheckoutService-v70
13+
dataProtection: spec=DataProtectionService-v1
14+
storedValue: spec=StoredValueService-v46
15+
posTerminalManagement: spec=TfmAPIService-v1
16+
payment: spec=PaymentService-v68
17+
recurring: spec=RecurringService-v68
18+
payout: spec=PayoutService-v68
19+
management: spec=ManagementService-v1
20+
legalEntityManagement: spec=LegalEntityService-v3
21+
balancePlatform: spec=BalancePlatformService-v2
22+
platformsAccount: spec=AccountService-v6
23+
platformsFund: spec=FundService-v6
24+
platformsNotificationConfiguration: spec=NotificationConfigurationService-v6
25+
platformsHostedOnboardingPage: spec=HopService-v6
26+
transfers: spec=TransferService-v3
27+
balanceControlService: spec=BalanceControlService-v1
28+
29+
allServices: $(services) $(singleFileServices)
30+
31+
$(services): build/spec $(openapi-generator-jar)
32+
wget $(openapi-generator-url) -O build/openapi-generator-cli.jar
33+
rm -rf $(output)
34+
$(openapi-generator-cli) generate \
35+
-i build/spec/json/$(spec).json \
36+
-g $(generator) \
37+
-c ./templates/config.yaml \
38+
-o $(output) \
39+
--global-property apis,apiTests=false,apiDocs=false,supportingFiles=api-single.rb\
40+
--additional-properties serviceName=$@\
41+
--skip-validate-spec
42+
rm -f $(output)/lib/openapi_client/api/*-small.rb
43+
mkdir -p lib/adyen/services/$@
44+
mv $(output)/lib/openapi_client/api/*.rb lib/adyen/services/$@
45+
mv $(output)/api/api-single.rb lib/adyen/services/$@.rb
46+
rm -rf $(output)
47+
48+
$(singleFileServices): build/spec
49+
wget $(openapi-generator-url) -O build/openapi-generator-cli.jar
50+
cat <<< "$$(jq 'del(.paths[][].tags)' build/spec/json/$(spec).json)" > build/spec/json/$(spec).json
51+
rm -rf $(output)
52+
$(openapi-generator-cli) generate \
53+
-i build/spec/json/$(spec).json \
54+
-g $(generator) \
55+
-c ./templates/config.yaml \
56+
-o $(output) \
57+
--global-property apis,apiTests=false,apiDocs=false\
58+
--additional-properties serviceName=$@\
59+
--skip-validate-spec
60+
mv $(output)/lib/openapi_client/api/default_api-small.rb lib/adyen/services/$@.rb
61+
rm -rf $(output)
62+
63+
templates: $(openapi-generator-jar)
64+
$(openapi-generator-cli) author template -g $(generator) -o build/templates
65+
66+
# Download the generator
67+
$(openapi-generator-jar):
68+
wget --quiet -o /dev/null $(openapi-generator-url) -O $(openapi-generator-jar)
69+
70+
build/spec:
71+
git clone https://github.com/Adyen/adyen-openapi.git build/spec
72+
perl -i -pe's/"openapi" : "3.[0-9].[0-9]"/"openapi" : "3.0.0"/' build/spec/json/*.json

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1+
![Ruby](https://user-images.githubusercontent.com/93914435/236416787-3da4dd32-0a7d-43f7-9aa4-8d77697c85f9.png)
12
# Adyen API Library for Ruby
23

3-
44
This is the officially supported Ruby library for using Adyen's APIs.
55

6-
## Integration
7-
The library supports all APIs under the following services:
8-
9-
* [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v68/overview): Our latest integration for accepting online payments. Current supported version: **v68**
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**
21-
6+
## Supported APIs
7+
8+
This library supports the following:
9+
10+
| API name | API version | Description | API object |
11+
|----------|:-----------:|-------------|------------|
12+
| [BIN lookup API](https://docs.adyen.com/api-explorer/#/BinLookup/v52/overview) | v54 | The BIN Lookup API provides endpoints for retrieving information based on a given BIN. | [BinLookup](lib/adyen/services/binLookup.rb) |
13+
| [Checkout API](https://docs.adyen.com/api-explorer/#/CheckoutService/v69/overview) | v70 | Our latest integration for accepting online payments. | [CheckoutAPI](lib/adyen/services/checkout.rb) |
14+
| [Configuration API](https://docs.adyen.com/api-explorer/#/balanceplatform/v2/overview) | v2 | The Configuration API enables you to create a platform where you can onboard your users as account holders and create balance accounts, cards, and business accounts. | [BalancePlatform](lib/adyen/services/balancePlatform.rb) |
15+
| [DataProtection API](https://docs.adyen.com/development-resources/data-protection-api) | v1 | Adyen Data Protection API provides a way for you to process [Subject Erasure Requests](https://gdpr-info.eu/art-17-gdpr/) as mandated in GDPR. Use our API to submit a request to delete shopper's data, including payment details and other related information (for example, delivery address or shopper email) | [DataProtection](lib/adyen/services/dataProtection.rb) |
16+
| [Legal Entity Management API](https://docs.adyen.com/api-explorer/#/legalentity/v3/overview) | v3 | Manage legal entities that contain information required for verification. | [LegalEntityManagement](lib/adyen/services/legalEntityManagement.rb) |
17+
| [Management API](https://docs.adyen.com/api-explorer/#/ManagementService/v1/overview) | v1 | Configure and manage your Adyen company and merchant accounts, stores, and payment terminals. | [Management](lib/adyen/services/management.rb) |
18+
| [Payments API](https://docs.adyen.com/api-explorer/#/Payment/v68/overview) | v68 | Our classic integration for online payments. | [Classic Integration API](lib/adyen/services/payment.rb) |
19+
| [Payouts API](https://docs.adyen.com/api-explorer/#/Payout/v68/overview) | v68 | Endpoints for sending funds to your customers. | [Payout](lib/adyen/services/payout.rb) |
20+
| [POS Terminal Management API](https://docs.adyen.com/api-explorer/#/postfmapi/v1/overview) | v1 | Endpoints for managing your point-of-sale payment terminals. | [TerminalManagement](lib/adyen/services/posTerminalManagement.rb) |
21+
| [Recurring API](https://docs.adyen.com/api-explorer/#/Recurring/v68/overview) | v68 | Endpoints for managing saved payment details. | [Recurring](lib/adyen/services/recurring.rb) |
22+
| [Stored Value API](https://docs.adyen.com/payment-methods/gift-cards/stored-value-api) | v46 | Manage both online and point-of-sale gift cards and other stored-value cards. | [StoredValue](lib/adyen/services/storedValue.rb) |
23+
| [Transfers API](https://docs.adyen.com/api-explorer/transfers/3/overview) | v3 | The Transfers API provides endpoints that can be used to get information about all your transactions, move funds within your balance platform or send funds from your balance platform to a transfer instrument. | [Transfers](lib/adyen/services/transfers.rb) |
2224

2325
For more information, refer to our [documentation](https://docs.adyen.com/) or the [API Explorer](https://docs.adyen.com/api-explorer/).
2426

@@ -64,7 +66,7 @@ adyen.api_key = 'AF5XXXXXXXXXXXXXXXXXXXX'
6466

6567
- Make a Payment
6668
~~~~ruby
67-
response = adyen.checkout.payments({
69+
response = adyen.checkout.payments_api.payments({
6870
:amount => {
6971
:currency => "EUR",
7072
:value => 1000

lib/adyen-ruby-api-library.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
require_relative "adyen/client"
33
require_relative "adyen/errors"
44
require_relative "adyen/services/checkout"
5-
require_relative "adyen/services/payments"
6-
require_relative "adyen/services/payouts"
5+
require_relative "adyen/services/payment"
6+
require_relative "adyen/services/payout"
77
require_relative "adyen/services/recurring"
88
require_relative "adyen/services/marketpay"
9-
require_relative "adyen/services/postfmapi"
9+
require_relative "adyen/services/posTerminalManagement"
1010
require_relative "adyen/services/service"
11-
require_relative "adyen/services/data_protection"
11+
require_relative "adyen/services/dataProtection"
1212
require_relative "adyen/services/dispute"
13-
require_relative "adyen/services/bin_lookup"
13+
require_relative "adyen/services/binLookup"
1414
require_relative "adyen/hash_with_accessors"
1515
require_relative "adyen/utils/hmac_validator"
16+
require_relative "adyen/services/legalEntityManagement"
17+
require_relative "adyen/services/balancePlatform"
18+
require_relative "adyen/services/transfers"
19+
require_relative "adyen/services/management"
20+
require_relative "adyen/services/storedValue"
21+
require_relative "adyen/services/balanceControlService"

lib/adyen/client.rb

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,43 @@ def live_url_prefix=(value)
3535

3636
# base URL for API given service and @env
3737
def service_url_base(service)
38-
raise ArgumentError, "Please set Client.live_url_prefix to the portion of your merchant-specific URL prior to '-[service]-live.adyenpayments.com'" if @live_url_prefix.nil? and @env == :live
3938
if @env == :mock
4039
@mock_service_url_base
4140
else
4241
case service
4342
when "Checkout"
44-
url = "https://checkout-#{@env}.adyen.com/checkout"
43+
url = "https://checkout-#{@env}.adyen.com"
4544
supports_live_url_prefix = true
4645
when "Account", "Fund", "Notification", "Hop"
47-
url = "https://cal-#{@env}.adyen.com/cal/services"
46+
url = "https://cal-#{@env}.adyen.com/cal/services/#{service}"
4847
supports_live_url_prefix = false
49-
when "Recurring", "Payment", "Payout", "BinLookup"
50-
url = "https://pal-#{@env}.adyen.com/pal/servlet"
48+
when "Recurring", "Payment", "Payout", "BinLookup", "StoredValue", "BalanceControlService"
49+
url = "https://pal-#{@env}.adyen.com/pal/servlet/#{service}"
5150
supports_live_url_prefix = true
52-
when "Terminal"
51+
when "PosTerminalManagement"
5352
url = "https://postfmapi-#{@env}.adyen.com/postfmapi/terminal"
5453
supports_live_url_prefix = false
5554
when "DataProtectionService", "DisputeService"
56-
url = "https://ca-#{@env}.adyen.com/ca/services"
55+
url = "https://ca-#{@env}.adyen.com/ca/services/#{service}"
56+
supports_live_url_prefix = false
57+
when "LegalEntityManagement"
58+
url = "https://kyc-#{@env}.adyen.com/lem"
59+
supports_live_url_prefix = false
60+
when "BalancePlatform"
61+
url = "https://balanceplatform-api-#{@env}.adyen.com/bcl"
62+
supports_live_url_prefix = false
63+
when "Transfers"
64+
url = "https://balanceplatform-api-#{@env}.adyen.com/btl"
65+
supports_live_url_prefix = false
66+
when "Management"
67+
url = "https://management-#{@env}.adyen.com"
5768
supports_live_url_prefix = false
5869
else
5970
raise ArgumentError, "Invalid service specified"
6071
end
61-
72+
73+
raise ArgumentError, "Please set Client.live_url_prefix to the portion of your merchant-specific URL prior to '-[service]-live.adyenpayments.com'" \
74+
if @live_url_prefix.nil? and @env == :live and supports_live_url_prefix
6275
if @env == :live && supports_live_url_prefix
6376
url.insert(8, "#{@live_url_prefix}-")
6477
url["adyen.com"] = "adyenpayments.com"
@@ -70,11 +83,7 @@ def service_url_base(service)
7083

7184
# construct full URL from service and endpoint
7285
def service_url(service, action, version)
73-
if service == "Checkout" || service == "Terminal"
74-
"#{service_url_base(service)}/v#{version}/#{action}"
75-
else
76-
"#{service_url_base(service)}/#{service}/v#{version}/#{action}"
77-
end
86+
"#{service_url_base(service)}/v#{version}/#{action}"
7887
end
7988

8089
# send request to adyen API
@@ -121,17 +130,17 @@ def call_adyen_api(service, action, request_data, headers, version, with_applica
121130
headers.map do |key, value|
122131
faraday.headers[key] = value
123132
end
133+
134+
# add library headers
135+
faraday.headers["adyen-library-name"] = Adyen::NAME
136+
faraday.headers["adyen-library-version"] = Adyen::VERSION
124137
end
125138
# if json string convert to hash
126139
# needed to add applicationInfo
127140
if request_data.is_a?(String)
128141
request_data = JSON.parse(request_data)
129142
end
130143

131-
# add application only on checkout service
132-
if with_application_info
133-
add_application_info(request_data)
134-
end
135144

136145
# convert to json
137146
request_data = request_data.to_json
@@ -160,7 +169,7 @@ def call_adyen_api(service, action, request_data, headers, version, with_applica
160169
raise connection_error, "Connection to #{url} failed"
161170
end
162171
end
163-
else
172+
if action.fetch(:method) == 'post'
164173
# post request to Adyen
165174
begin
166175
response = conn.post do |req|
@@ -169,8 +178,16 @@ def call_adyen_api(service, action, request_data, headers, version, with_applica
169178
rescue Faraday::ConnectionFailed => connection_error
170179
raise connection_error, "Connection to #{url} failed"
171180
end
181+
end
182+
else
183+
begin
184+
response = conn.post do |req|
185+
req.body = request_data
186+
end # handle client errors
187+
rescue Faraday::ConnectionFailed => connection_error
188+
raise connection_error, "Connection to #{url} failed"
189+
end
172190
end
173-
174191
# check for API errors
175192
case response.status
176193
when 401
@@ -189,31 +206,18 @@ def call_adyen_api(service, action, request_data, headers, version, with_applica
189206
formatted_response
190207
end
191208

192-
# add application_info for analytics
193-
def add_application_info(request_data)
194-
adyenLibrary = {
195-
:name => Adyen::NAME,
196-
:version => Adyen::VERSION.to_s,
197-
}
198-
199-
if request_data[:applicationInfo].nil?
200-
request_data[:applicationInfo] = {}
201-
end
202-
203-
request_data[:applicationInfo][:adyenLibrary] = adyenLibrary
204-
end
205209

206210
# services
207211
def checkout
208212
@checkout ||= Adyen::Checkout.new(self)
209213
end
210214

211-
def payments
212-
@payments ||= Adyen::Payments.new(self)
215+
def payment
216+
@payment ||= Adyen::Payment.new(self)
213217
end
214218

215-
def payouts
216-
@payouts ||= Adyen::Payouts.new(self)
219+
def payout
220+
@payout ||= Adyen::Payout.new(self)
217221
end
218222

219223
def recurring
@@ -224,8 +228,8 @@ def marketpay
224228
@marketpay ||= Adyen::Marketpay::Marketpay.new(self)
225229
end
226230

227-
def postfmapi
228-
@postfmapi ||= Adyen::PosTerminalManagement.new(self)
231+
def pos_terminal_management
232+
@pos_terminal_management ||= Adyen::PosTerminalManagement.new(self)
229233
end
230234

231235
def data_protection
@@ -239,5 +243,29 @@ def dispute
239243
def bin_lookup
240244
@bin_lookup ||= Adyen::BinLookup.new(self)
241245
end
246+
247+
def legal_entity_management
248+
@legal_entity_management ||= Adyen::LegalEntityManagement.new(self)
249+
end
250+
251+
def balance_platform
252+
@balance_platform ||= Adyen::BalancePlatform.new(self)
253+
end
254+
255+
def transfers
256+
@transfers ||= Adyen::Transfers.new(self)
257+
end
258+
259+
def management
260+
@management ||= Adyen::Management.new(self)
261+
end
262+
263+
def stored_value
264+
@stored_value ||=Adyen::StoredValue.new(self)
265+
end
266+
267+
def balance_control_service
268+
@balance_control_service ||=Adyen::BalanceControlService.new(self)
269+
end
242270
end
243271
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require_relative './service'
2+
module Adyen
3+
4+
5+
class BalanceControlService < Service
6+
attr_accessor :service, :version
7+
DEFAULT_VERSION = 1
8+
9+
def initialize(client, version = DEFAULT_VERSION)
10+
@service = "BalanceControlService"
11+
@client = client
12+
@version = version
13+
end
14+
15+
def balance_transfer(request, headers: {} )
16+
"""
17+
Start a balance transfer
18+
"""
19+
endpoint = "/balanceTransfer".gsub(/{.+?}/, '%s')
20+
endpoint = endpoint.gsub(/^\//, "")
21+
endpoint = endpoint % []
22+
23+
action = { method: "post", url: endpoint}
24+
@client.call_adyen_api(@service, action, request, headers, @version)
25+
end
26+
27+
end
28+
end

0 commit comments

Comments
 (0)