dapi-co/dapi-php

Dapi Client Library for PHP

1.3.0 2022-11-22 10:13 UTC

README

A PHP library that talks to the Dapi API.

Quickstart

Configure Project

First add the library module to your project using composer. Add the following in your composer.json

"require": {
    "dapi-co/dapi-php": "^1.3",
},

OR simply type this in your project folder.

composer require dapi-co/dapi-php

Configure Library

  1. Create a DapiClient with your App Secret.
// Assuming that Dapi library is already autoloaded. If not, manually include/require it here.
$dapiClient = new Dapi\DapiClient('APP_SECRET');
  1. Now you can use any of the functions of the products available on the client (data for example) instance to call Dapi with your appSecret.
$accessToken = 'ACCESS_TOKEN'; 
$userSecret = 'USER_SECRET'; 
$accounts = $dapiClient->data->getAccounts($accessToken, $userSecret);
echo PHP_EOL . 'Accounts' . PHP_EOL . PHP_EOL;
echo (json_encode($accounts, JSON_PRETTY_PRINT));
  1. Or, you can use the handleSDKRequests function of the client instance inside an endpoint in your server. Our code will basically update the request to add your app's appSecret to it, and forward the request to Dapi, then return the result.
<?php

// Assuming that Dapi library is already autoloaded. If not, manually include/require it here. 

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

// Initialize DapiClient with your appSecret here
$dapiClient = new Dapi\DapiClient('APP_SECRET');

$headers = getallheaders();
$body = json_decode(file_get_contents("php://input"), true);

// Make dapiClient automatically handle your SDK requests
if (!empty($body)) {
  echo json_encode($dapiClient->handleSDKRequests($body, $headers)); 
} else {
  http_response_code(400);
  echo "Bad Request: No data sent or wrong request";
}

DAPI API

A list of all options on Dapi's PHP Library that your backend can call to perform some operations.

  • Auth Product:

    auth->exchangeToken

  • Data Product:

    data->getIdentity

    data->getAccounts

    data->getAccountBalance

    data->getAccountTransactions

    data->getCards

    data->getCardBalance

    data->getCardTransactions

  • Payment Product:

    payment->getBeneficiaries

    payment->createBeneficiary

    payment->createTransfer

    payment->transferAutoFlow

  • Metadata Product:

    metadata->getAccounts

  • Operation Product: operation->getOperationStatus

Reference

BaseResponse

All the responses have the fields described here. Meaning all the responses described below in the document will have following fields besides the ones specific to each response.

Parameter Type Description
operationID string Unique ID generated to identify a specific operation.
success boolean Returns true if request is successful and false otherwise.
status string The status of the job.

done - Operation Completed.
failed - Operation Failed.
user_input_required - Pending User Input.
initialized - Operation In Progress.

For further explanation see Operation Statuses.
userInputs array Array of userInput objects, that are needed to complete this operation.

Specifies the type of further information required from the user before the job can be completed.

Note: It's only returned if operation status is user_input_required
type string Type of error encountered.

Note: It's only returned if operation status is failed
msg string Detailed description of the error.

Note: It's only returned if operation status is failed

userInput Object

Parameter Type Description
id string Type of input required.

You can read more about user input types on User Input Types.
query string Textual description of what is required from the user side.
index int Is used in case more than one user input is requested.
Will always be 0 If only one input is requested.
answer string User input that must be submitted. In the response it will always be empty.

Methods

auth->exchangeToken

Method is used to obtain user's permanent access token by exchanging it with access code received during the user authentication (user login).

Note:

You can read more about how to obtain a permanent token on Obtain an Access Token.

Method Description
function exchangeToken($accessCode, $connectionID)
Input Parameters
Parameter Type Description
accessCode
REQUIRED
string Unique code for a user’s successful login to Connect. Returned in the response of UserLogin.
connectionID
REQUIRED
string The connectionID from a user’s successful log in to Connect.
Response

In addition to the fields described in the BaseResponse, it has the following fields, which will only be returned if the status is done:

Parameter Type Description
AccessToken string A unique permanent token linked to the user.

data->getIdentity

Method is used to retrieve personal details about the user.

Method Description
function getIdentity($accessToken, $userSecret, $userInputs = [], $operationID = "")
Input Parameters
Parameter Type Description
accessToken
REQUIRED
string Access Token obtained using the ExchangeToken method.
userSecret
REQUIRED
string The userSecret from a user’s successful log in to Connect.
operationID
OPTIONAL
string The OperationID from a previous call's response.
Required only when resuming a previous call that responded with user_input_required status, to provided user inputs.
userInputs
OPTIONAL
array Array of UserInput object, that are needed to complete this operation.
Required only if a previous call responded with user_input_required status.

You can read more about user inputs specification on Specify User Input
userInput Object
Parameter Type Description
Id string Type of input required.

You can read more about user input types on User Input Types.
Index int Is used in case more than one user input is requested.
Will always be 0 If only one input is requested.
Answer string User input that must be submitted.
Response

In addition to the fields described in the BaseResponse, it has the following fields, which will only be returned if the status is done:

Parameter Type Description
identity array An object (associative array) containing the identity data of the user.

data->getAccounts

Method is used to retrieve list of all the bank accounts registered on the user. The list will contain all types of bank accounts.

Method Description
function getAccounts($accessToken, $userSecret, $userInputs = [], $operationID = "")
Input Parameters
Parameter Type Description
accessToken
REQUIRED
string Access Token obtained using the ExchangeToken method.
userSecret
REQUIRED
string The userSecret from a user’s successful log in to Connect.
operationID
OPTIONAL
string The OperationID from a previous call's response.
Required only when resuming a previous call that responded with user_input_required status, to provided user inputs.
userInputs
OPTIONAL
array Array of UserInput object, that are needed to complete this operation.
Required only if a previous call responded with user_input_required status.

You can read more about user inputs specification on Specify User Input
userInput Object
Parameter Type Description
id string Type of input required.

You can read more about user input types on User Input Types.
index int Is used in case more than one user input is requested.
Will always be 0 If only one input is requested.
answer string User input that must be submitted.
Response

In addition to the fields described in the BaseResponse, it has the following fields, which will only be returned if the status is done:

Parameter Type Description
Accounts array An array containing the accounts data of the user.

data->getBalance

Method is used to retrieve balance on specific bank account of the user.

Method Description
function getBalance($accessToken, $userSecret, $accountID, $userInputs = [], $operationID = "")
Input Parameters
Parameter Type Description
accountID
REQUIRED
string The bank account ID which its balance is requested.
Retrieved from one of the accounts returned from the GetAccounts method.
accessToken
REQUIRED
string Access Token obtained using the ExchangeToken method.
userSecret
REQUIRED
string The userSecret from a user’s successful log in to Connect.
operationID
OPTIONAL
string The OperationID from a previous call's response.
Required only when resuming a previous call that responded with user_input_required status, to provided user inputs.
userInputs
OPTIONAL
array Array of UserInput object, that are needed to complete this operation.
Required only if a previous call responded with user_input_required status.

You can read more about user inputs specification on Specify User Input
userInput Object
Parameter Type Description
id string Type of input required.

You can read more about user input types on User Input Types.
index int Is used in case more than one user input is requested.
Will always be 0 If only one input is requested.
answer string User input that must be submitted.
Response

In addition to the fields described in the BaseResponse, it has the following fields, which will only be valid if the status is done:

Parameter Type Description
Balance Balance An object (associative array) containing the account's balance information.

data->getTransactions

Method is used to retrieve transactions that user has performed over a specific period of time from their bank account. The transaction list is unfiltered, meaning the response will contain all the transactions performed by the user (not just the transactions performed using your app).

Date range of the transactions that can be retrieved varies for each bank. The range supported by the users bank is shown in the response parameter transactionRange of Get Accounts Metadata endpoint.

Method Description
function getTransactions($accessToken, $userSecret, $accountID, $fromDate, $toDate, $userInputs = [], $operationID = "")
Input Parameters
Parameter Type Description
accountID
REQUIRED
string The bank account ID which its transactions are requested.
Retrieved from one of the accounts returned from the getAccounts method.
fromDate
REQUIRED
string The start date of the transactions wanted.
It should be in this format: YYYY-MM-DD
toDate
REQUIRED
string The end date of the transactions wanted.
It should be in this format: YYYY-MM-DD
accessToken
REQUIRED
string Access Token obtained using the ExchangeToken method.
userSecret
REQUIRED
string The userSecret from a user’s successful log in to Connect.
operationID
OPTIONAL
string The OperationID from a previous call's response.
Required only when resuming a previous call that responded with user_input_required status, to provided user inputs.
userInputs
OPTIONAL
array Array of UserInput object, that are needed to complete this operation.
Required only if a previous call responded with user_input_required status.

You can read more about user inputs specification on Specify User Input
userInput Object
Parameter Type Description
id string Type of input required.

You can read more about user input types on User Input Types.
index int Is used in case more than one user input is requested.
Will always be 0 If only one input is requested.
answer string User input that must be submitted.
Response

In addition to the fields described in the BaseResponse, it has the following fields, which will only be valid if the status is done:

Parameter Type Description
Transactions array Array containing the transactional data for the specified account within the specified period.

payment->getBeneficiaries

Method is used to retrieve list of all the beneficiaries already added for a user within a financial institution.

Method Description
function getBeneficiaries($accessToken, $userSecret, $userInputs = [], $operationID = "")
Input Parameters
Parameter Type Description
accessToken
REQUIRED
string Access Token obtained using the ExchangeToken method.
userSecret
REQUIRED
string The userSecret from a user’s successful log in to Connect.
operationID
OPTIONAL
string The OperationID from a previous call's response.
Required only when resuming a previous call that responded with user_input_required status, to provided user inputs.
userInputs
OPTIONAL
array Array of UserInput object, that are needed to complete this operation.
Required only if a previous call responded with user_input_required status.

You can read more about user inputs specification on Specify User Input
userInput Object
Parameter Type Description
id string Type of input required.

You can read more about user input types on User Input Types.
index int Is used in case more than one user input is requested.
Will always be 0 If only one input is requested.
answer string User input that must be submitted.
Response

In addition to the fields described in the BaseResponse, it has the following fields, which will only be returned if the status is done:

Parameter Type Description
Beneficiaries array An array containing the beneficiary information.

payment->createBeneficiary

Method is used to retrieve list of all the beneficiaries already added for a user within a financial institution.

Method Description
function createBeneficiary($accessToken, $userSecret, $beneficiaryData, $userInputs = [], $operationID = "")
Input Parameters
Parameter Type Description
beneficiaryData
REQUIRED
array An object (associative array) that contains info about the beneficiary that should be added.
accessToken
REQUIRED
string Access Token obtained using the ExchangeToken method.
userSecret
REQUIRED
string The userSecret from a user’s successful log in to Connect.
operationID
OPTIONAL
string The OperationID from a previous call's response.
Required only when resuming a previous call that responded with user_input_required status, to provided user inputs.
userInputs
OPTIONAL
array Array of UserInput object, that are needed to complete this operation.
Required only if a previous call responded with user_input_required status.

You can read more about user inputs specification on Specify User Input
userInput Object
Parameter Type Description
id string Type of input required.

You can read more about user input types on User Input Types.
index int Is used in case more than one user input is requested.
Will always be 0 If only one input is requested.
answer string User input that must be submitted.
beneficiaryData object
Parameter Type Description
name
REQUIRED
string Name of the beneficiary.
accountNumber
REQUIRED
string Account number of the beneficiary.
iban
REQUIRED
string Beneficiary's IBAN number.
swiftCode
REQUIRED
string Beneficiary's financial institution's SWIFT code.
type
REQUIRED
string Type of beneficiary.
For further explanation see Beneficiary Types.
address
REQUIRED
array An object (associative arry) containing the address information of the beneficiary.
country
REQUIRED
string Name of the country in all uppercase letters.
branchAddress
REQUIRED
string Address of the financial institution’s specific branch.
branchName
REQUIRED
string Name of the financial institution’s specific branch.
phoneNumber
OPTIONAL
string Beneficiary's phone number.
routingNumber
OPTIONAL
string Beneficiary's Routing number, needed only for US banks accounts.
Address Object
Parameter Type Description
line1
REQUIRED
string Street name and number. Note: value should not contain any commas or special characters.
line2
REQUIRED
string City name. Note: value should not contain any commas or special characters.
line3
REQUIRED
string Country name. Note: value should not contain any commas or special characters.
Response

Method returns only the fields defined in the BaseResponse.

payment->createTransfer

Method is used to initiate a new payment from one account to another account.

Important

We suggest you use TransferAutoflow method instead to initiate a payment. TransferAutoFlow abstracts all the validations and processing logic, required to initiate a transaction using CreateTransfer method.

You can read about TransferAutoFlow further in the document.

Method Description
function createTransfer($accessToken, $userSecret, $transferData, $userInputs = [], $operationID = "")
Input Parameters
Parameter Type Description
transferData
REQUIRED
array An object (associative array) that contains info about the transfer that should be initiated.
accessToken
REQUIRED
string Access Token obtained using the ExchangeToken method.
userSecret
REQUIRED
string The userSecret from a user’s successful log in to Connect.
operationID
OPTIONAL
string The OperationID from a previous call's response.
Required only when resuming a previous call that responded with user_input_required status, to provided user inputs.
userInputs
OPTIONAL
array Array of UserInput object, that are needed to complete this operation.
Required only if a previous call responded with user_input_required status.

You can read more about user inputs specification on Specify User Input
userInput Object
Parameter Type Description
id string Type of input required.

You can read more about user input types on User Input Types.
index int Is used in case more than one user input is requested.
Will always be 0 If only one input is requested.
answer string User input that must be submitted.
transferData Object
Parameter Type Description
senderID
REQUIRED
string The id of the account which the money should be sent from.
Retrieved from one of the accounts array returned from the getAccounts method.
amount
REQUIRED
float64 The amount of money which should be sent.
receiverID
OPTIONAL
string The id of the beneficiary which the money should be sent to.
Retrieved from one of the beneficiaries array returned from the getBeneficiaries method.
Needed only when creating a transfer from a bank that requires the receiver to be already registered as a beneficiary to perform a transaction.
name
OPTIONAL
string The name of receiver.
Needed only when creating a transfer from a bank that handles the creation of beneficiaries on its own, internally, and doesn't require the receiver to be already registered as a beneficiary to perform a transaction.
accountNumber
OPTIONAL
string The Account Number of the receiver's account.
Needed only when creating a transfer from a bank that handles the creation of beneficiaries on its own, internally, and doesn't require the receiver to be already registered as a beneficiary to perform a transaction.
iban
OPTIONAL
string The IBAN of the receiver's account.
Needed only when creating a transfer from a bank that handles the creation of beneficiaries on its own, internally, and doesn't require the receiver to be already registered as a beneficiary to perform a transaction.
Response

In addition to the fields described in the BaseResponse, it has the following fields, which will only be returned if the status is done:

Parameter Type Description
reference string Transaction reference string returned by the bank.

payment->transferAutoflow

Method is used to initiate a new payment from one account to another account, without having to care nor handle any special cases or scenarios.

Method Description
function transferAutoflow($accessToken, $userSecret, $transferAutoFlowData, $userInputs = [], $operationID = "")
Input Parameters
Parameter Type Description
transferAutoflowData
REQUIRED
array An object (associative array) that contains info about the transfer that should be initiated, and any other details that's used to automate the operation.
accessToken
REQUIRED
string Access Token obtained using the ExchangeToken method.
userSecret
REQUIRED
string The userSecret from a user’s successful log in to Connect.
operationID
OPTIONAL
string The OperationID from a previous call's response.
Required only when resuming a previous call that responded with user_input_required status, to provided user inputs.
userInputs
OPTIONAL
array Array of UserInput object, that are needed to complete this operation.
Required only if a previous call responded with user_input_required status.

You can read more about user inputs specification on Specify User Input
userInput Object
Parameter Type Description
id string Type of input required.

You can read more about user input types on User Input Types.
index int Is used in case more than one user input is requested.
Will always be 0 If only one input is requested.
answer string User input that must be submitted.
transferAutoflowData Object
Parameter Type Description
senderID
REQUIRED
string The id of the account which the money should be sent from.
Retrieved from one of the accounts array returned from the getAccounts method.
amount
REQUIRED
float The amount of money which should be sent.
beneficiary
REQUIRED
array An object (associative) that holds the info about the beneficiary which the money should be sent to.
bankID
REQUIRED
string The bankID of the user which is initiating this transfer.
beneficiary object
Parameter Type Description
name
REQUIRED
string Name of the beneficiary.
accountNumber
REQUIRED
string Account number of the beneficiary.
iban
REQUIRED
string Beneficiary's IBAN number.
swiftCode
REQUIRED
string Beneficiary's financial institution's SWIFT code.
type
REQUIRED
string Type of beneficiary.
For further explanation see Beneficiary Types.
address
REQUIRED
array An object (associative arry) containing the address information of the beneficiary.
country
REQUIRED
string Name of the country in all uppercase letters.
branchAddress
REQUIRED
string Address of the financial institution’s specific branch.
branchName
REQUIRED
string Name of the financial institution’s specific branch.
phoneNumber
OPTIONAL
string Beneficiary's phone number.
routingNumber
OPTIONAL
string Beneficiary's Routing number, needed only for US banks accounts.
address Object
Parameter Type Description
line1
REQUIRED
string Street name and number. Note: value should not contain any commas or special characters.
line2
REQUIRED
string City name. Note: value should not contain any commas or special characters.
line3
REQUIRED
string Country name. Note: value should not contain any commas or special characters.
Response

In addition to the fields described in the BaseResponse, it has the following fields, which will only be returned if the status is done:

Parameter Type Description
reference string Transaction reference string returned by the bank.