Skip to content
Open
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
21 changes: 21 additions & 0 deletions lib/investec_open_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require "faraday_middleware"
require "investec_open_api/models/account"
require "investec_open_api/models/transaction"
require "investec_open_api/models/transfer"

class InvestecOpenApi::Client
INVESTEC_API_URL="https://openapi.investec.com/"
Expand All @@ -24,6 +25,26 @@ def transactions(account_id)
end
end

def transfer(account_id, to_account_id, amount, my_reference, their_reference)
response = connection.post(
"za/pb/v1/accounts/#{account_id}/transfermultiple",
{
transferList: [
{
beneficiaryAccountId: to_account_id,
amount: amount,
myReference: my_reference,
theirReference: their_reference
}
]
}
)

response.body["data"]["TransferResponses"].map do |transfer_raw|
InvestecOpenApi::Models::Transfer.from_api(transfer_raw)
end
end

private

def get_oauth_token
Expand Down
38 changes: 38 additions & 0 deletions lib/investec_open_api/models/transfer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module InvestecOpenApi::Models
class Transfer < Base
attribute :payment_reference_number
attribute :payment_date
attribute :status
attribute :beneficiary_name
attribute :beneficiary_account_id
attribute :authorisation_required

def self.from_api(params = {})
if params['PaymentReferenceNumber'].present?
params['payment_reference_number'] = params['PaymentReferenceNumber']
end

if params['PaymentDate'].present?
params['payment_date'] = params['PaymentDate']
end

if params['Status'].present?
params['status'] = params['Status']
end

if params['BeneficiaryName'].present?
params['beneficiary_name'] = params['BeneficiaryName']
end

if params['BeneficiaryAccountId'].present?
params['beneficiary_account_id'] = params['BeneficiaryAccountId']
end

if params['AuthorisationRequired'].present?
params['authorisation_required'] = params['AuthorisationRequired']
end

super
end
end
end
48 changes: 48 additions & 0 deletions spec/lib/investec_open_api/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,52 @@
expect(transactions.first).to be_an_instance_of(InvestecOpenApi::Models::Transaction)
end
end

describe "#transfer" do
before do
stub_request(:post, "#{api_url}za/pb/v1/accounts/12345/transfermultiple")
.with(
body: {
transferList: [
{
beneficiaryAccountId: '6789',
amount: 10,
myReference: 'Library Transfer',
theirReference: 'Library Transfer'
}
]
},
headers: {
"Accept" => "application/json",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Authorization" => "Bearer 123",
"User-Agent" => "Faraday v1.10.3"
}
)
.to_return(
body: {
data: {
"TransferResponses": [
{
"PaymentReferenceNumber": "UBP0111111111",
"PaymentDate": "10/05/2023",
"Status": "- No authorisation necessary <BR>- Payment/Transfer effective date 10/05/2023",
"BeneficiaryName": "API transfer",
"BeneficiaryAccountId": "6789",
"AuthorisationRequired": false
}
]
}
}.to_json
)

client.authenticate!
end

it "returns transfer details based on the transfer as InvestecOpenApi::Models::Transfer instances" do
transferResponses = client.transfer('12345', '6789', 10, 'Library Transfer', 'Library Transfer')

expect(transferResponses.first).to be_an_instance_of(InvestecOpenApi::Models::Transfer)
end
end
end