This integration hooks into a customer's Plaid account for validating and retrieving asset accounts and balances
All calls require the following customer credentials
{
"client_id": string,
"secret": string
}
Method | URI | Headers |
---|---|---|
GET | /api/v1/integrations/plaid/accounts |
{"Authorization": "Bearer {access_token}"} |
{
//...credentials,
"data" : {
"public_token": "{public_token}"
}
}
public_token | generated after a user completes the Plaid frontend |
{
"data": [
{
"id": "zLyyZv9dAWI3xwvlMG75ckNQpM48zjuovbmXb",
"type": "account",
"attributes": {
"name": "Plaid Checking",
"official_name": "Plaid Gold Standard 0% Interest Checking",
"mask": "0000",
"subtype": "checking",
"type": "depository",
"balances": {
"available": 100,
"current": 110,
"iso_currency_code": "USD",
"limit": null,
"unofficial_currency_code": null
}
}
},
{
"id": "BXeenJ9zvBU3yNJ8LXdbcKryRo74AEFwKojxb",
"type": "account",
"attributes": {
"name": "Plaid Saving",
"official_name": "Plaid Silver Standard 0.1% Interest Saving",
"mask": "1111",
"subtype": "checking",
"type": "depository",
"balances": {
"available": 200,
"current": 210,
"iso_currency_code": "USD",
"limit": 2000,
"unofficial_currency_code": null
}
}
}
]
}
app.html
<form method="POST" action="/complete-application">
<div>
<label>Name</label>
<input type="text" name="name"/>
</div>
<div>
<div id="loader" style="display: none;">LOADING...</div>
<div id="bankAccountSelectContainer"></div>
<button type="button" onclick="javascript:linkBankAccount();">Link Your Bank Account</button>
</div>
<button type="submit">Submit</button>
</form>
...
<!-- note, using jquery for posting but could easily be replaced with axios or xhr -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
<script>
var plaidHandler = Plaid.create({
clientName: 'LHP',
countryCodes: ['US'],
env: 'sandbox',
key: 'plaid_public_key',
product: ['transactions'],
language: 'en',
onSuccess: function(public_token, metadata) {
document.getElementById('#loader').style.display = 'block';
$.post('/application-ajax.php', {
public_token: public_token,
}, function(data){
//A quick messy way to display each account for the user to select which should be added. Change this to fit your application
var accountSelectHtml = '<table class="table table-bordered">';
for(var i=0;i<data.accounts.length;i++){
var account = data.accounts[i];
var accountSelectHtmlItem = '<tr>';
accountSelectHtmlItem += '<td><input type="checkbox" name="account['+account.id+'][enabled]" value="true" /><input type="hidden" name="account['+account.id+'][available]" value="'+account.balances.available+'" /><input type="hidden" name="account['+account.id+'][name]" value="'+account.name+'" /><input type="hidden" name="account['+account.id+'][currency]" value="'+account.balances.currency+'" /></td>';
accountSelectHtmlItem += '<td>'+account.name+'</td>';
accountSelectHtmlItem += '<td>'+account.balances.available+' ['+account.balances.currency+']</td>';
accountSelectHtmlItem += '</tr>';
accountSelectHtml += accountSelectHtmlItem;
}
accountSelectHtml += '</table>';
document.getElementById('bankAccountSelectContainer').innerHTML = document.getElementById('bankAccountSelectContainer').innerHTML+accountSelectHtml;
document.getElementById('#loader').style.display = 'none';
});
}
});
function linkBankAccount(){
plaidHandler.open();
}
</script>
application-ajax.php
...
$response = IntegrationClient::request('GET','plaid/accounts',[
'credential' => $credentialId,
'data' => ['public_token'=>$request->get('public_token')]
]);
return $response;