Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/adyen-ruby-api-library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
require_relative 'adyen/services/openBanking'
require_relative 'adyen/services/sessionAuthentication'
require_relative 'adyen/services/balanceControl'
require_relative 'adyen/services/capital'

7 changes: 7 additions & 0 deletions lib/adyen/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def service_url_base(service)
when 'Transfers'
url = "https://balanceplatform-api-#{@env}.adyen.com/btl"
supports_live_url_prefix = false
when 'Capital'
url = "https://balanceplatform-api-#{@env}.adyen.com/capital"
supports_live_url_prefix = false
when 'Management'
url = "https://management-#{@env}.adyen.com"
supports_live_url_prefix = false
Expand Down Expand Up @@ -331,6 +334,10 @@ def balance_control
@balance_control ||= Adyen::BalanceControl.new(self)
end

def capital
@capital ||= Adyen::Capital.new(self)
end


private

Expand Down
186 changes: 186 additions & 0 deletions spec/capital_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
require 'spec_helper'
require 'json'

RSpec.describe Adyen::Capital do
let(:client) { create_client(:api_key) }
let(:service) { 'Capital' }
let(:version) { client.capital.version }

describe 'GrantAccountsApi' do
it 'gets grant account information' do
response_body = json_from_file('mocks/responses/Capital/get-grant-account-success.json')
grant_account_id = 'CG00000000000000000000001'

url = client.service_url(service, "grantAccounts/#{grant_account_id}", version)

WebMock.stub_request(:get, url)
.with(headers: { 'x-api-key' => client.api_key })
.to_return(body: response_body)

result = client.capital.grant_accounts_api.get_grant_account_information(grant_account_id)

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
expect(result.response).to be_a(Adyen::HashWithAccessors)
expect(result.response).to be_a(Hash)
end
end

describe 'GrantOffersApi' do
it 'gets all grant offers with query params' do
response_body = json_from_file('mocks/responses/Capital/grant-offers-success.json')
account_holder_id = 'AH00000000000000000000001'

url = client.service_url(service, 'grantOffers', version)

WebMock.stub_request(:get, url)
.with(
query: { 'accountHolderId' => account_holder_id },
headers: { 'x-api-key' => client.api_key }
)
.to_return(body: response_body)

result = client.capital.grant_offers_api.get_all_grant_offers(query_params: { 'accountHolderId' => account_holder_id })

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
end

it 'gets all grant offers without query params' do
response_body = json_from_file('mocks/responses/Capital/grant-offers-success.json')

url = client.service_url(service, 'grantOffers', version)

WebMock.stub_request(:get, url)
.with(headers: { 'x-api-key' => client.api_key })
.to_return(body: response_body)

result = client.capital.grant_offers_api.get_all_grant_offers

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
end

it 'gets a specific grant offer' do
response_body = json_from_file('mocks/responses/Capital/get-grant-offer-success.json')
id = 'GO00000000000000000000001'

url = client.service_url(service, "grantOffers/#{id}", version)

WebMock.stub_request(:get, url)
.with(headers: { 'x-api-key' => client.api_key })
.to_return(body: response_body)

result = client.capital.grant_offers_api.get_grant_offer(id)

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
end
end

describe 'GrantsApi' do
it 'gets a specific grant' do
response_body = json_from_file('mocks/responses/Capital/get-grant-success.json')
id = 'GR00000000000000000000001'

url = client.service_url(service, "grants/#{id}", version)

WebMock.stub_request(:get, url)
.with(headers: { 'x-api-key' => client.api_key })
.to_return(body: response_body)

result = client.capital.grants_api.get_grant(id)

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
end

it 'gets all grants' do
response_body = json_from_file('mocks/responses/Capital/grants-success.json')

url = client.service_url(service, 'grants', version)

WebMock.stub_request(:get, url)
.with(headers: { 'x-api-key' => client.api_key })
.to_return(body: response_body)

result = client.capital.grants_api.get_all_grants

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
end

it 'requests a grant' do
request_payload = { "grantAccountId" => "GR00000000000000000000001" }
response_body = json_from_file('mocks/responses/Capital/request-grant.json')

url = client.service_url(service, 'grants', version)

WebMock.stub_request(:post, url)
.with(
body: request_payload,
headers: { 'x-api-key' => client.api_key }
)
.to_return(body: response_body)

result = client.capital.grants_api.request_grant(request_payload)

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
end

it 'gets a grant disbursement' do
response_body = json_from_file('mocks/responses/Capital/get-grant-disbursement-success.json')
grant_id = 'GR00000000000000000000001'
disbursement_id = 'DI00000000000000000000001'

url = client.service_url(service, "grants/#{grant_id}/disbursements/#{disbursement_id}", version)

WebMock.stub_request(:get, url)
.with(headers: { 'x-api-key' => client.api_key })
.to_return(body: response_body)

result = client.capital.grants_api.get_grant_disbursement(grant_id, disbursement_id)

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
end

it 'gets all grant disbursements' do
response_body = json_from_file('mocks/responses/Capital/get-grant-disbursements-success.json')
grant_id = 'GR00000000000000000000001'

url = client.service_url(service, "grants/#{grant_id}/disbursements", version)

WebMock.stub_request(:get, url)
.with(headers: { 'x-api-key' => client.api_key })
.to_return(body: response_body)

result = client.capital.grants_api.get_all_grant_disbursements(grant_id)

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
end

it 'updates a grant disbursement' do
response_body = json_from_file('mocks/responses/Capital/update-grant-disbursement-success.json')
grant_id = 'GR00000000000000000000001'
disbursement_id = 'DI00000000000000000000001'
request_payload = {}

url = client.service_url(service, "grants/#{grant_id}/disbursements/#{disbursement_id}", version)

WebMock.stub_request(:patch, url)
.with(
body: request_payload,
headers: { 'x-api-key' => client.api_key }
)
.to_return(body: response_body)

result = client.capital.grants_api.update_grant_disbursement(request_payload, grant_id, disbursement_id)

expect(result.status).to eq(200)
expect(result.response).to eq(JSON.parse(response_body))
end
end
end
20 changes: 20 additions & 0 deletions spec/mocks/responses/Capital/get-grant-account-success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"id": "CG00000000000000000000001",
"fundingBalanceAccountId": "BA00000000000000000000001",
"limits": [
{
"amount": {
"currency": "EUR",
"value": 100000
}
}
],
"balances": [
{
"currency": "EUR",
"principal": 10000,
"fee": 1000,
"total": 11000
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": "DI00000000000000000000001",
"grantId": "GR00000000000000000000001",
"accountHolderId": "AH00000000000000000000001",
"balanceAccountId": "BA00000000000000000000001",
"amount": {
"currency": "EUR",
"value": 10000
},
"fee": {
"amount": {
"currency": "EUR",
"value": 1000
}
},
"balances": {
"currency": "EUR",
"principal": 10000,
"fee": 1000,
"total": 11000
},
"repayment": {
"basisPoints": 1000,
"updateDescription": "string"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"disbursements": [
{
"id": "DI00000000000000000000001",
"grantId": "GR00000000000000000000001",
"accountHolderId": "AH00000000000000000000001",
"balanceAccountId": "BA00000000000000000000001",
"amount": {
"currency": "EUR",
"value": 10000
},
"fee": {
"amount": {
"currency": "EUR",
"value": 1000
}
},
"balances": {
"currency": "EUR",
"principal": 10000,
"fee": 1000,
"total": 11000
},
"repayment": {
"basisPoints": 1000,
"updateDescription": "string"
}
}
]
}
31 changes: 31 additions & 0 deletions spec/mocks/responses/Capital/get-grant-offer-success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "GO00000000000000000000001",
"accountHolderId": "AH00000000000000000000001",
"contractType": "cashAdvance",
"amount": {
"currency": "EUR",
"value": 10000
},
"fee": {
"amount": {
"currency": "EUR",
"value": 1000
},
"aprBasisPoints": 1200
},
"repayment": {
"basisPoints": 1000,
"term": {
"estimatedDays": 180,
"maximumDays": 365
},
"threshold": {
"amount": {
"currency": "EUR",
"value": 1000
}
}
},
"startsAt": "2024-01-01T00:00:00Z",
"expiresAt": "2024-01-31T23:59:59Z"
}
22 changes: 22 additions & 0 deletions spec/mocks/responses/Capital/get-grant-success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"id": "GR00000000000000000000001",
"grantAccountId": "CG00000000000000000000001",
"grantOfferId": "GO00000000000000000000001",
"counterparty": {
"accountHolderId": "AH00000000000000000000001",
"balanceAccountId": "BA00000000000000000000001"
},
"amount": {
"currency": "EUR",
"value": 10000
},
"balances": {
"currency": "EUR",
"principal": 10000,
"fee": 1000,
"total": 11000
},
"status": {
"code": "Active"
}
}
19 changes: 19 additions & 0 deletions spec/mocks/responses/Capital/grant-offers-success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"grantOffers": [
{
"id": "GO00000000000000000000001",
"amount": {
"currency": "EUR",
"value": 10000
},
"fee": {
"currency": "EUR",
"value": 100
},
"repayment": {
"currency": "EUR",
"value": 10100
}
}
]
}
26 changes: 26 additions & 0 deletions spec/mocks/responses/Capital/grants-success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"grants": [
{
"id": "GR00000000000000000000001",
"grantAccountId": "CG00000000000000000000001",
"grantOfferId": "GO00000000000000000000001",
"counterparty": {
"accountHolderId": "AH00000000000000000000001",
"balanceAccountId": "BA00000000000000000000001"
},
"amount": {
"currency": "EUR",
"value": 10000
},
"balances": {
"currency": "EUR",
"principal": 10000,
"fee": 1000,
"total": 11000
},
"status": {
"code": "Active"
}
}
]
}
Loading