TomorrowIdeas / plaid-sdk-php

PHP bindings for the Plaid API
MIT License
111 stars 42 forks source link

Plaid SDK

Latest Stable Version Build Status Code Coverage License

Plaid PHP SDK supporting:

Official Plaid API docs

For full description of request and response payloads and properties, please see the official Plaid API docs.

Requirements

Installation

composer require tomorrow-ideas/plaid-sdk-php

Configuration

Instantiate the Plaid client class with your credentials.

$client = new \TomorrowIdeas\Plaid\Plaid("your-client-id", "your-secret", "environment");

Environments

The Plaid client by default uses the production Plaid API hostname for all API calls. You can change the environment by using the setEnvironment method.

Possible environments:

Options

Many methods allow the passing of options to the Plaid endpoint. These options should be an associative array of key/value pairs. The exact options supported are dependent on the endpoint being called. Please refer to the official Plaid documentation for more information.

$options = [
    "foo" => "bar",
    "baz" => "bat"
];

Example

use TomorrowIdeas\Plaid\Plaid;

require __DIR__ . "/vendor/autoload.php";

$plaid = new Plaid(
    \getenv("PLAID_CLIENT_ID"),
    \getenv("PLAID_CLIENT_SECRET"),
    \getenv("PLAID_ENVIRONMENT")
);

$item = $plaid->items->get("itm_1234");

Resources

For a full description of the response payload, please see the official Plaid API docs.

Accounts

Resource: accounts

Reference: https://plaid.com/docs/#accounts

Methods:

Example:

$accounts = $plaid->accounts->list($access_token);

Auth

Resource: auth

Reference: https://plaid.com/docs/#auth

Methods:

Example:

$auth = $plaid->auth->get($access_token);

Bank Transfers (U.S. only)

Resource: bank_transfers

Reference: https://plaid.com/docs/bank-transfers/

Methods:

create(
    string $access_token,
    string $idempotency_key,
    string $type,
    string $account_id,
    string $network,
    string $amount,
    string $currency_code,
    AccountHolder $account_holder,
    string $description,
    string $ach_class = null,
    string $custom_tag = null,
    array $metadata = [],
    string $origination_account_id = null): object

Example:

$transfers = $plaid->bank_transfers->list();

Categories

Resource: categories

Reference: https://plaid.com/docs/api/products/#categoriesget

Methods:

Example:

$categories = $plaid->categories->list();

Institutions

Resource: institutions

Reference: https://plaid.com/docs/api/institutions/

Methods:

Example:

$institutions = $plaid->institutions->list(20, 0);

Investments

Resource: investments

Reference: https://plaid.com/docs/api/products/#investments

Methods:

Example:

$holdings = $plaid->investments->listHoldings($access_token);

Tokens

Resource: tokens

Reference: https://plaid.com/docs/api/tokens/

Methods:

create(string $client_name,
    string $language,
    array $country_codes,
    User $user,
    array $products = [],
    ?string $webhook = null,
    ?string $link_customization_name = null,
    ?AccountFilters $account_filters = null,
    ?string $access_token = null,
    ?string $redirect_url = null,
    ?string $android_package_name = null,
    ?string $payment_id = null): object

get(string $link_token): object

Example:

$token = $plaid->tokens->create($client_name, $language, ["US","CA"], $user_id);

Liabilities

Resource: liabilities

Reference: https://plaid.com/docs/api/products/#liabilities

Methods:

Example:

$liabilities = $plaid->liabilities->list($access_token);

Items

Resource: items

Reference: https://plaid.com/docs/api/items/

Methods:

$item = $plaid->items->get($access_token);

Webhooks

Resource: webhooks

Reference: https://plaid.com/docs/api/webhooks/

Methods:

Example:

$verification_key = $plaid->webhooks->getVerificationKey($key_id);

Transactions

Resource: transactions

Reference: https://plaid.com/docs/api/products/#transactions

Methods:

Example:

$transactions = $plaid->transactions->list($access_token, $start_date, $end_date);

Reports

Resource: reports

Reference: https://plaid.com/docs/assets/

Methods:

Payment Initiation (UK only)

Resource: payments

Reference: https://plaid.com/docs/#payment-initiation

Methods:

Example:

$plaid->payments->createRecipient($name, $iban, $address);

Processors

Resource: processors

Reference: https://plaid.com/docs/api/processors

Methods:

Sandbox

Resource: sandbox

Reference: https://plaid.com/docs/api/sandbox/

Methods:

Example:

$response = $plaid->sandbox->fireWebhook($access_token);

Entities

User

The TomorrowIdeas\Plaid\Entities\User entity is used to represent your end user when creating a new link token.

Example:

$token_user = new User(
    string $id,
    ?string $name = null,
    ?string $phone_number = null,
    ?string $phone_number_verified_time = null,
    ?string $email_address = null,
    ?string $ssn = null,
    ?string $date_of_birth = null
)

RecipientAddress

The TomorrowIdeas\Plaid\Entities\RecipientAddress entity is used to represent an address object for the recipient of a payment request.

Example:

$address = new TomorrowIdeas\Plaid\Entities\RecipientAddress("123 Elm St.", "Apt 1", "Anytown", "ABC 123", "GB");

PaymentSchedule

Example:

The TomorrowIdeas\Plaid\Entities\PaymnentSchedule entity is used when creating a new payment that will be a recurring charge. See createPayment method for more information.

$payment_schedule = new TomorrowIdeas\Plaid\Entities\PaymnentSchedule(
    PaymentSchedule::INTERVAL_MONTHLY,
    15,
    new DateTime("2020-10-01")
);

Errors

All unsuccessfull (non 2xx) responses will throw a PlaidRequestException. The full response object is available via the getResponse() method.