PHP Client for the plaid.com API
This is a PHP port of the official python client library for the Plaid API
$ composer require 40katty04/plaid-api-php-client
The module supports only a select few Plaid API endpoints at the moment. For complete information about the Plaid.com API, head to the Plaid Documentation.
Exchange a public_token
from Plaid Link for a Plaid access token:
$clientId = '*****';
$secret = '*****';
$publicKey = '*****';
$publicToken = '<public_token from Plaid Link>';
// Available environments are 'sandbox', 'development', and 'production'
$client = new Client($clientId, $secret, $publicKey, 'sandbox');
$response = $client->item()->publicToken()->exchange($publicToken);
$accessToken = $response['access_token'];
$response = $client->transactions()->get($accessToken, '2018-01-01', '2018-01-31');
$transactions = $response['transactions'];
There are multiple steps to retrieving an Asset Report.
- Create the report
- Filter unwanted accounts out of report
- Retrieve the report as JSON or PDF
- Refresh a previously created or filtered report
- Remove a report
// an array of previously generated access_tokens
$accessTokens = ['<access_token(s) returned from exchange token call(s)>'];
$daysRequested = 180;
// all of these are optional
$options = [
'client_report_id' => '<user supplied id for reference',
'webhook' => 'https://your-application.io/webhook',
'user' => [
'client_user_id' => '<user supplied id>',
'first_name' => 'Testynthia',
'middle_name' => 'T.',
'last_name' => 'Tertestdez',
'ssn' => '123-45-6789',
'phone_number' => '555-555-1234',
'email' => '[email protected]'
]
];
$response = $this->client->assetReport()->create($accessTokens, $daysRequested, $options);
{
"asset_report_id": "<asset_report guid>",
"asset_report_token": "<assets-sandbox-guid>",
"request_id": "<request_id>"
}
$assetReportToken = '<returned in asset report creation call>';
$accountIdsToExclude = ['<credit_card_id>', '<401k_account_id>'];
$response = $this->client->assetReport()->filter($assetReportToken, $accountIdsToExclude);
{
"asset_report_id": "<asset_report guid>",
"asset_report_token": "<assets-sandbox-guid>",
"request_id": "<request_id>"
}
// retrieve the report in JSON format
$response = $this->client->assetReport()->get($accessReportToken);
// retrieve the report in PDF format
$response = $this->client->assetReport()->getPdf($accessReportToken);
file_put_contents('asset-report.pdf', $response);
The JSON results of an asset report can be reviewed in plaid's documentation.
The /asset_report/pdf/get endpoint returns binary PDF data, which can be saved into a local file.
// $daysRequested is optional and only needed if you want to override the value sent when report was created
// $options is optional, only required for overrides to previous values
$response = $this->client->assetReport()->refresh($assetReportToken, $daysRequested, $options);
{
"asset_report_id": "<asset_report guid>",
"asset_report_token": "<assets-sandbox-guid>",
"request_id": "<request_id>"
}
$response = $this->client->assetReport()->remove($assetReportToken);
{
"removed": true,
"request_id": "<request_id>"
}