tomorrow-ideas/plaid-sdk-php

Plaid API的PHP实现,作为SDK。

1.0.9 2022-07-07 18:57 UTC

This package is auto-updated.

Last update: 2024-08-26 22:57:22 UTC


README

Latest Stable Version Build Status Code Coverage License

Plaid PHP SDK支持

  • 链接令牌
  • 身份验证
  • 条目
  • 账户
  • 机构
  • Webhooks
  • 身份
  • 收入
  • 资产
  • 余额
  • 负债
  • 投资
  • 支付发起(仅限英国)
  • 处理器(包括Stripe & Dwolla)
  • 银行转账(仅限美国)
  • 沙盒

官方Plaid API文档

有关请求和响应负载以及属性的完整描述,请参阅官方Plaid API文档

要求

  • PHP 7.3+ | PHP 8.0+
  • ext-curl
  • ext-json

安装

composer require tomorrow-ideas/plaid-sdk-php

配置

使用您的凭证实例化Plaid客户端类。

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

环境

Plaid客户端默认使用生产环境Plaid API主机名进行所有API调用。您可以使用setEnvironment方法更改环境。

可能的环境

  • 生产
  • 开发
  • 沙盒

选项

许多方法允许向Plaid端点传递选项。这些选项应该是键值对的关联数组。支持的确切选项取决于被调用的端点。有关更多信息,请参阅官方Plaid文档。

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

示例

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");

资源

有关响应负载的完整描述,请参阅官方Plaid API文档

账户

资源: accounts

参考: https://plaid.com/docs/#accounts

方法

  • list(string $access_token, array $options = []): object
  • getBalance(string $access_token, array $options = []): object
  • getIdentity(string $access_token): object

示例

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

身份验证

资源:auth

参考:https://plaid.com/docs/#auth

方法

  • get(string $access_token, array $options = []): object

示例

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

银行转账(仅限美国)

资源:bank_transfers

参考:https://plaid.com/docs/bank-transfers/

方法

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
  • cancel(string $bank_transfer_id): object
  • get(string $bank_transfer_id): object
  • list( ?DateTime $start_date = null, ?DateTime $end_date = null, ?int $count = null, ?int $offset = null, ?string $direction = null, ?string $origination_account_id = null): object
  • getEventList( ?DateTime $start_date = null, ?DateTime $end_date = null, ?string $bank_transfer_id = null, ?string $account_id = null, ?string $bank_transfer_type = null, array $event_type = [], ?int $count = null, ?int $offset = null, ?string $direction = null, ?string $origination_account_id = null): object
  • syncEvents(string $after_id, ?int $count = null): object
  • migrateAccount(string $account_number, string $routing_number, string $account_type): object
  • getOriginationAccountBalance(string $origination_account_id = null): object

示例

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

分类

资源:categories

参考:https://plaid.com/docs/api/products/#categoriesget

方法

  • list(): object

示例

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

机构

资源:institutions

参考:https://plaid.com/docs/api/institutions/

方法

  • get(string $institution_id, array $country_codes, array $options = []): object
  • list(int $count, int $offset, array $country_codes, array $options = []): object
  • find(string $query, array $country_codes, array $products = [], array $options = []): object

示例

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

投资

资源:investments

参考: https://plaid.com/docs/api/products/#investments

方法

  • listHoldings(string $access_token, array $options = []): object
  • listTransactions(string $access_token, DateTime $start_date, DateTime $end_date, array $options = []): object

示例

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

令牌

资源: tokens

参考: https://plaid.com/docs/api/tokens/

方法

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

示例

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

负债

资源: liabilities

参考: https://plaid.com/docs/api/products/#liabilities

方法

  • list(string $access_token, array $options = []): object

示例

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

条目

资源: items

参考: https://plaid.com/docs/api/items/

方法

  • get(string $access_token): object
  • remove(string $access_token): object
  • getIncome(string $access_token): object
  • createPublicToken(string $access_token): object
  • exchangeToken(string $public_token): object
  • rotateAccessToken(string $access_token): object
$item = $plaid->items->get($access_token);

Webhooks

资源: webhooks

参考: https://plaid.com/docs/api/webhooks/

方法

  • getVerificationKey(string $key_id): object
  • update(string $access_token, string $webhook): object

示例

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

交易

资源: transactions

参考: https://plaid.com/docs/api/products/#transactions

方法

  • list(string $access_token, DateTime $start_date, DateTime $end_date, array $options = []): object
  • refresh(string $access_token): object
  • sync(string $access_token, ?string $cursor = null, ?int $count = null, array $options = []): object
  • recurring(string $access_token, array $account_ids, array $options = []): object

示例

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

报告

资源: reports

参考: https://plaid.com/docs/assets/

方法

  • createAssetReport(array $access_tokens, int $days_requested, array $options = []): object
  • refreshAssetReport(string $asset_report_token, int $days_requested, array $options = []): object
  • filterAssetReport(string $asset_report_token, array $exclude_accounts): object
  • getAssetReport(string $asset_report_token, bool $include_insights = false): object
  • getAssetReportPdf(string $asset_report_token): ResponseInterface 注意:因为此端点在响应体中返回PDF内容,此方法返回PSR-7 ResponseInterface的实例。您可以利用Response对象将PDF流回请求客户端并访问响应头
  • removeAssetReport(string $asset_report_token): object
  • createAssetReportAuditCopy(string $asset_report_token, string $auditor_id): object
  • removeAssetReportAuditCopy(string $audit_copy_token): object

支付发起(仅限英国)

资源: payments

参考: https://plaid.com/docs/#payment-initiation

方法

  • createRecipient(string $name, string $iban, RecipientAddress $address): object
  • getRecipient(string $recipient_id): object
  • listRecipients(): object
  • create(string $recipient_id, string $reference, float $amount, string $currency, PaymentSchedule $payment_schedule = null): object
  • createToken(string $payment_id): object
  • get(string $payment_id): object
  • list(array $options = []): object

示例

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

处理器

资源: processors

参考: https://plaid.com/docs/api/processors

方法

  • createToken(string $access_token, string $account_id, string $processor): object
  • getAuth(string $processor_token): object
  • getBalance(string $processor_token): object
  • getIdentity(string $processor_token): object
  • createStripeToken(string $access_token, string $account_id): object [?]
  • createDwollaToken(string $access_token, string $account_id): object [?]

沙盒

资源: sandbox

参考: https://plaid.com/docs/api/sandbox/

方法

  • createPublicToken(string $institution_id, array $initial_products, array $options = []): object
  • resetLogin(string $access_token): object
  • setVerificationStatus(string $access_token, string $account_id, string $verification_status): object
  • fireWebhook(string $access_token, string $webhook_code = "DEFAULT_UPDATE"): object
  • simulateBankTransfer(string $bank_transfer_id, string $event_type, ?string $ach_return_code = null, ?string $failure_description = null): object

示例

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

实体

用户

TomorrowIdeas\Plaid\Entities\User 实体用于在创建新的链接令牌时表示您的最终用户。

示例

$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
)

收款地址

TomorrowIdeas\Plaid\Entities\RecipientAddress 实体用于表示付款请求收款人的地址对象。

示例

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

支付计划

示例

在创建将作为定期费用的新支付时使用 TomorrowIdeas\Plaid\Entities\PaymnentSchedule 实体。有关更多信息,请参阅 createPayment 方法。

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

错误

所有不成功的(非 2xx)响应都将抛出 PlaidRequestException。完整的响应对象可通过 getResponse() 方法获取。