fire / business-api-sdk
Fire Business API的PHP封装
Requires
- php: >=5.3.0
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- robthree/twofactorauth: >=1.6
This package is not auto-updated.
Last update: 2024-09-28 18:58:48 UTC
README
用于访问Fire Business API的PHP库
安装
您可以通过下载最新的版本或使用composer安装fire-business-api-php
composer require fire/business-api-sdk
要运行示例,编辑文件sample/config.inc.php.sample
并将其重命名为sample/config.inc.php
。
文档
Fire Business API的文档可在fire.com/docs找到。请结合使用API文档和SDK文档。
先决条件
- PHP >= 5.3
- PHP JSON扩展
- PHP MBString扩展
- PHP cURL扩展
获取帮助
如果您需要安装或使用库的帮助,请通过support@fire.com联系Fire Support。
如果您在库中发现了错误或希望添加新功能,请在此存储库中打开问题或拉取请求!
身份验证
如果设置会话时出现问题,将抛出RestException
。检查$e->getCode()
和$e->getMessage()
以获取更多详细信息。
<?php // Set up the PHP Client and log in - keep your login credentials out of the code and out of Github!! $client = new Fire\Business\Client(); $client->initialise($config);
要使用除实时API之外的不同端点,请按照以下方式将其传递给$client
构造函数:
<?php $client = new Fire\Business\Client("https://api.fire.com/something");
Fire账户和收款人
有关返回的对象的详细信息,请参阅fire.com/docs。
<?php # Get lists of Fire Account and Payees print_r ($client->accounts->read()); print_r ($client->payees->read());
单个账户/收款人的详细信息
有关返回的对象的详细信息,请参阅fire.com/docs。
<?php # Get details of individual accounts/payees and the transactions for them. print_r ($client->account(2150)->read()); print_r ($client->payee(15996)->read());
账户或收款人的交易列表
有关返回的对象的详细信息,请参阅fire.com/docs。
<?php # Get details of individual accounts/payees and the transactions for them. print_r ($client->account(2150)->transactions()); print_r ($client->payee(15996)->transactions());
默认情况下,此操作返回10笔交易。使用$options
数组按以下方式分页:
<?php # Get items 10-35 of a list of transactions print_r ($client->account(2150)->transactions(array("offset"=>10, "limit"=>25)));
两个Fire账户之间的内部交易(同一货币)
fire.com API允许企业在其账户之间自动进行支付。
过程如下
- 创建新批次
- 将转账添加到批次中
- 提交批次以进行处理。
转账以最多100项的批次执行。内部转账无需批准。
如果转账存在问题,将抛出RestException
。检查$e->getCode()
和$e->getMessage()
以获取更多详细信息。
<?php # Perform an internal transfer between two of your Fire accounts try { $batch = $client->batches->create(array( "type" => "INTERNAL_TRANSFER", "currency" => "EUR", "batchName" => "January 2018 Payroll", "jobNumber" => "2018-01-PR", "callbackUrl" => "https://myserver.com/callback" )); $batchId = $batch["batchUuid"]; # retrieve batch details print_r ($client->batch($batchId)->read()); # Add an internal transfer $transaction = $client->batch($batchId)->addInternalTransfer(array( "icanFrom" => "2150", "icanTo" => "5532", "amount" => "100", "ref" => "Testing PHP Library" )); print_r($transaction); # List trasnfers in the batch $internalTransfers = $client->batch($batchId)->internalTransfers->read(); print_r ($internalTransfers); # remove a transfer if required. print_r ($client->batch($batchId)->internalTransfer($internalTransfers["items"][0]["batchItemUuid"])->delete()); # Submit the batch - this executes the transfers immediately. $client->batch($batchId)->submit(); } catch (Exception $e) { print_r ($e->getCode() . ': ' . $e->getMessage() . "\n"); }
向收款人进行银行转账
fire.com API允许企业在英国和欧洲自动向第三方支付。
出于安全考虑,API只能设置支付。支付批次必须由授权用户通过firework移动应用批准。
过程如下
- 创建新批次
- 将支付添加到批次中
- 提交批次以进行批准。
一旦提交批次,授权用户将收到firework移动应用的提醒。他们可以查看批次内容,然后批准或拒绝。如果批准,则处理批次。
有两种处理银行转账的方式 - 通过收款人ID(模式1)或通过收款人账户详情(模式2)。
如果转账存在问题,将抛出RestException
。检查$e->getCode()
和$e->getMessage()
以获取更多详细信息。
<?php # Perform a bank transfer to a payee try { // Bank Transfers - create a batch, add/remove transfers, submit $batch = $client->batches->create(array( "type" => "BANK_TRANSFER", "currency" => "EUR", "batchName" => "March 2019 Payroll", "jobNumber" => "2019-03-PR", "callbackUrl" => "https://myserver.com/callback" )); $batchId = $batch["batchUuid"]; print_r ($client->batch($batchId)->read()); $transaction = $client->batch($batchId)->addBankTransfer(array( "icanFrom" => "2150", "payeeId" => "1304", "payeeType" => "PAYEE_ID", "amount" => "500", "myRef" => "PHP Library Test", "yourRef" => "PHP Library Test" )); print_r($transaction); # Add a bank transfer using account details instead: $transaction = $client->batch($batchId)->addBankTransfer(array( "icanFrom" => "2001", "payeeType" => "ACCOUNT_DETAILS", "destIban" => "IE00AIBK93123412341234", "destAccountHolderName" => "John Smith", "amount" => "500" "myRef" => "Payment to John Smith for Consultancy in Dec.", "yourRef" => "ACME LTD - INV 23434" )); $bankTransfers = $client->batch($batchId)->bankTransfers->read(); print_r ($bankTransfers); print_r ($client->batch($batchId)->bankTransfer($bankTransfers["items"][0]["batchItemUuid"])->delete()); # Submit the batch. This triggers a notification to be sent to the Firework for Business mobile app for approval. # Transfers will not be processed until the batch is approved. $client->batch($batchId)->submit(); # If required, the batch can be cancelled up until it is approved. $client->batch($batchId)->cancel(); } catch (Exception $e) { print_r ($e->getCode() . ': ' . $e->getMessage() . "\n"); }
解码webhook
<?php // you can either pull in the library using Fire/Starter if you've copied the library to your standard library location. //include_once("Fire/Starter.php"); // Or using the Composer dependency manager require "vendor/autoload.php"; // Receive a webhook from your business account $keyId = "XXXXXX"; // The Key ID associated with your webhook $secret = "YYYYYY"; // The Secret associated with your webhook $handler = new Fire\Business\Webhook\Handler($keyId, $secret); // $events is an array of Fire\Business\Model\Transactions $events = $handler->parse($raw_post_data); print $events[0];
发送测试webhook
您可以使用samples/中的示例脚本将webhook发送到您的服务器。
php testwebhook.php --ref="INV 23798" --amount=1249 --endpoint=https://2i7yqo19qv39.runscope.net/
选项如下
Usage: php testwebhook.php --endpoint=https://example.com [options]
--ref=<reference> - the reference to use on the webhook lodgement
--amount=<amount> - the amount (in pence/cent) to use on the lodgement
--currency=<EUR|GBP> - the currency of the lodgement
--fromAccountNum=<accountnum> - the account number this lodgement is from
--fromNsc=<nsc> - the sortcode this lodgement is from
--fromBIC=<bic> - the bic this lodgement is from
--fromIBAN=<iban> - the IBAN this lodgement is from
--toAccountNum=<accountnum> - the fire account number this lodgement is for
--toIBAN=<iban> - the fire IBAN this lodgement is for