adyen-ruby-api-library 8.0.1 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codeql.yml +3 -3
- data/VERSION +1 -1
- data/lib/adyen/services/checkout/donations_api.rb +20 -0
- data/lib/adyen/services/checkout/payments_api.rb +0 -9
- data/lib/adyen/services/checkout.rb +5 -0
- data/lib/adyen/services/transfers/transfers_api.rb +3 -3
- data/lib/adyen/utils/hmac_validator.rb +12 -20
- data/lib/adyen/version.rb +1 -1
- data/spec/utils/hmac_validator_spec.rb +15 -15
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8b08de6a807cdb9b167fbcceda1c0faee1877a74019598143937c601fdb8761
|
4
|
+
data.tar.gz: 06b6bf8881d4f769691782f6bdae19ce6141b1f6d921178e0d0b10b332739e3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c49ff13c0d95d1e2cc9a0efca40aad05a5ea1cfaca2b582069fdff3aab7d91c963e8ceeaa8162f1aa3fff3b2078b93ba59a3bac1fbbf8a74793544ac8e7ca622
|
7
|
+
data.tar.gz: ef19a8c76e01f6b34c8976c472ec336e3cc30e90a8decd480daea4f7517867b1307a4a0bf169e115ddd6ec483ebe6aff1d6e9449419042bbf9d9114d6e0a8b2b
|
@@ -27,15 +27,15 @@ jobs:
|
|
27
27
|
uses: actions/checkout@v4
|
28
28
|
|
29
29
|
- name: Initialize CodeQL
|
30
|
-
uses: github/codeql-action/init@
|
30
|
+
uses: github/codeql-action/init@v3
|
31
31
|
with:
|
32
32
|
languages: ${{ matrix.language }}
|
33
33
|
queries: +security-and-quality
|
34
34
|
|
35
35
|
- name: Autobuild
|
36
|
-
uses: github/codeql-action/autobuild@
|
36
|
+
uses: github/codeql-action/autobuild@v3
|
37
37
|
|
38
38
|
- name: Perform CodeQL Analysis
|
39
|
-
uses: github/codeql-action/analyze@
|
39
|
+
uses: github/codeql-action/analyze@v3
|
40
40
|
with:
|
41
41
|
category: "/language:${{ matrix.language }}"
|
data/VERSION
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
9.0.0
|
2
2
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../service'
|
2
|
+
module Adyen
|
3
|
+
class DonationsApi < Service
|
4
|
+
attr_accessor :service, :version
|
5
|
+
|
6
|
+
def initialize(client, version = DEFAULT_VERSION)
|
7
|
+
super(client, version, 'Checkout')
|
8
|
+
end
|
9
|
+
|
10
|
+
def donations(request, headers: {})
|
11
|
+
endpoint = '/donations'.gsub(/{.+?}/, '%s')
|
12
|
+
endpoint = endpoint.gsub(%r{^/}, '')
|
13
|
+
endpoint = format(endpoint)
|
14
|
+
|
15
|
+
action = { method: 'post', url: endpoint }
|
16
|
+
@client.call_adyen_api(@service, action, request, headers, @version)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -16,15 +16,6 @@ module Adyen
|
|
16
16
|
@client.call_adyen_api(@service, action, request, headers, @version)
|
17
17
|
end
|
18
18
|
|
19
|
-
def donations(request, headers: {})
|
20
|
-
endpoint = '/donations'.gsub(/{.+?}/, '%s')
|
21
|
-
endpoint = endpoint.gsub(%r{^/}, '')
|
22
|
-
endpoint = format(endpoint)
|
23
|
-
|
24
|
-
action = { method: 'post', url: endpoint }
|
25
|
-
@client.call_adyen_api(@service, action, request, headers, @version)
|
26
|
-
end
|
27
|
-
|
28
19
|
def get_result_of_payment_session(session_id, headers: {}, query_params: {})
|
29
20
|
endpoint = '/sessions/{sessionId}'.gsub(/{.+?}/, '%s')
|
30
21
|
endpoint = endpoint.gsub(%r{^/}, '')
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative 'checkout/classic_checkout_sdk_api'
|
2
|
+
require_relative 'checkout/donations_api'
|
2
3
|
require_relative 'checkout/modifications_api'
|
3
4
|
require_relative 'checkout/orders_api'
|
4
5
|
require_relative 'checkout/payment_links_api'
|
@@ -21,6 +22,10 @@ module Adyen
|
|
21
22
|
@classic_checkout_sdk_api ||= Adyen::ClassicCheckoutSDKApi.new(@client, @version)
|
22
23
|
end
|
23
24
|
|
25
|
+
def donations_api
|
26
|
+
@donations_api ||= Adyen::DonationsApi.new(@client, @version)
|
27
|
+
end
|
28
|
+
|
24
29
|
def modifications_api
|
25
30
|
@modifications_api ||= Adyen::ModificationsApi.new(@client, @version)
|
26
31
|
end
|
@@ -7,10 +7,10 @@ module Adyen
|
|
7
7
|
super(client, version, 'Transfers')
|
8
8
|
end
|
9
9
|
|
10
|
-
def return_transfer(request,
|
11
|
-
endpoint = '/transfers/{
|
10
|
+
def return_transfer(request, transfer_id, headers: {})
|
11
|
+
endpoint = '/transfers/{transferId}/returns'.gsub(/{.+?}/, '%s')
|
12
12
|
endpoint = endpoint.gsub(%r{^/}, '')
|
13
|
-
endpoint = format(endpoint,
|
13
|
+
endpoint = format(endpoint, transfer_id)
|
14
14
|
|
15
15
|
action = { method: 'post', url: endpoint }
|
16
16
|
@client.call_adyen_api(@service, action, request, headers, @version)
|
@@ -15,7 +15,8 @@ module Adyen
|
|
15
15
|
|
16
16
|
def valid_webhook_hmac?(webhook_request_item, hmac_key)
|
17
17
|
expected_sign = calculate_webhook_hmac(webhook_request_item, hmac_key)
|
18
|
-
merchant_sign =
|
18
|
+
merchant_sign =
|
19
|
+
webhook_request_item.dig('additionalData', 'hmacSignature')
|
19
20
|
|
20
21
|
expected_sign == merchant_sign
|
21
22
|
end
|
@@ -29,29 +30,20 @@ module Adyen
|
|
29
30
|
def calculate_webhook_hmac(webhook_request_item, hmac_key)
|
30
31
|
data = data_to_sign(webhook_request_item)
|
31
32
|
|
32
|
-
Base64.strict_encode64(
|
33
|
+
Base64.strict_encode64(
|
34
|
+
OpenSSL::HMAC.digest(HMAC_ALGORITHM, [hmac_key].pack('H*'), data)
|
35
|
+
)
|
33
36
|
end
|
34
37
|
|
38
|
+
# TODO: Deprecate instead of aliasing
|
39
|
+
alias valid_notification_hmac? valid_webhook_hmac?
|
40
|
+
alias calculate_notification_hmac calculate_webhook_hmac
|
35
41
|
|
36
42
|
def data_to_sign(webhook_request_item)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def fetch(hash, keys)
|
44
|
-
value = hash
|
45
|
-
keys.to_s.split('.').each do |key|
|
46
|
-
value = if key.to_i.to_s == key
|
47
|
-
value[key.to_i]
|
48
|
-
else
|
49
|
-
value[key].nil? ? value[key.to_sym] : value[key]
|
50
|
-
end
|
51
|
-
break if value.nil?
|
52
|
-
end
|
53
|
-
|
54
|
-
value
|
43
|
+
WEBHOOK_VALIDATION_KEYS
|
44
|
+
.map { webhook_request_item.dig(*_1.split('.')).to_s }
|
45
|
+
.compact
|
46
|
+
.join(DATA_SEPARATOR)
|
55
47
|
end
|
56
48
|
end
|
57
49
|
end
|
data/lib/adyen/version.rb
CHANGED
@@ -6,19 +6,19 @@ RSpec.describe Adyen::Utils::HmacValidator do
|
|
6
6
|
let(:expected_sign) { 'coqCmt/IZ4E3CzPvMY8zTjQVL5hYJUiBRg8UU+iCWo0=' }
|
7
7
|
let(:webhook_request_item) do
|
8
8
|
{
|
9
|
-
additionalData
|
10
|
-
hmacSignature
|
9
|
+
'additionalData' => {
|
10
|
+
'hmacSignature' => expected_sign
|
11
11
|
},
|
12
|
-
amount
|
13
|
-
value
|
14
|
-
currency
|
12
|
+
'amount' => {
|
13
|
+
'value' => 1130,
|
14
|
+
'currency' => 'EUR'
|
15
15
|
},
|
16
|
-
pspReference
|
17
|
-
eventCode
|
18
|
-
merchantAccountCode
|
19
|
-
merchantReference
|
20
|
-
paymentMethod
|
21
|
-
success
|
16
|
+
'pspReference' => '7914073381342284',
|
17
|
+
'eventCode' => 'AUTHORISATION',
|
18
|
+
'merchantAccountCode' => 'TestMerchant',
|
19
|
+
'merchantReference' => 'TestPayment-1407325143704',
|
20
|
+
'paymentMethod' => 'visa',
|
21
|
+
'success' => 'true'
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
@@ -44,22 +44,22 @@ RSpec.describe Adyen::Utils::HmacValidator do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should validate backslashes correctly' do
|
47
|
-
webhook = JSON.parse(json_from_file(
|
47
|
+
webhook = JSON.parse(json_from_file('mocks/responses/Webhooks/backslash_webhook.json'))
|
48
48
|
expect(validator.valid_webhook_hmac?(webhook, '74F490DD33F7327BAECC88B2947C011FC02D014A473AAA33A8EC93E4DC069174')).to be true
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'should validate colons correctly' do
|
52
|
-
webhook = JSON.parse(json_from_file(
|
52
|
+
webhook = JSON.parse(json_from_file('mocks/responses/Webhooks/colon_webhook.json'))
|
53
53
|
expect(validator.valid_webhook_hmac?(webhook, '74F490DD33F7327BAECC88B2947C011FC02D014A473AAA33A8EC93E4DC069174')).to be true
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should validate forward slashes correctly' do
|
57
|
-
webhook = JSON.parse(json_from_file(
|
57
|
+
webhook = JSON.parse(json_from_file('mocks/responses/Webhooks/forwardslash_webhook.json'))
|
58
58
|
expect(validator.valid_webhook_hmac?(webhook, '74F490DD33F7327BAECC88B2947C011FC02D014A473AAA33A8EC93E4DC069174')).to be true
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should validate mix of slashes and colon correctly' do
|
62
|
-
webhook = JSON.parse(json_from_file(
|
62
|
+
webhook = JSON.parse(json_from_file('mocks/responses/Webhooks/mixed_webhook.json'))
|
63
63
|
expect(validator.valid_webhook_hmac?(webhook, '74F490DD33F7327BAECC88B2947C011FC02D014A473AAA33A8EC93E4DC069174')).to be true
|
64
64
|
end
|
65
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adyen-ruby-api-library
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 9.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/adyen/services/binLookup.rb
|
137
137
|
- lib/adyen/services/checkout.rb
|
138
138
|
- lib/adyen/services/checkout/classic_checkout_sdk_api.rb
|
139
|
+
- lib/adyen/services/checkout/donations_api.rb
|
139
140
|
- lib/adyen/services/checkout/modifications_api.rb
|
140
141
|
- lib/adyen/services/checkout/orders_api.rb
|
141
142
|
- lib/adyen/services/checkout/payment_links_api.rb
|
@@ -442,7 +443,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
442
443
|
- !ruby/object:Gem::Version
|
443
444
|
version: '0'
|
444
445
|
requirements: []
|
445
|
-
rubygems_version: 3.
|
446
|
+
rubygems_version: 3.5.3
|
446
447
|
signing_key:
|
447
448
|
specification_version: 4
|
448
449
|
summary: Official Adyen Ruby API Library
|