bitpesa/bitpesa-php-sdk

TransferZero 客户端库,适用于PHP


README

这是用于与TransferZero API一起使用的PHP客户端库。要使用API,请注册并在TransferZero开发者门户上获取有效的API密钥。

更多信息,请访问

此PHP包由OpenAPI Generator项目自动生成

  • API版本:1.0
  • 包版本:1.36.4

要求

PHP 7.1及更高版本

安装与使用

Composer

要通过Composer安装,请运行

composer require transferzero/transferzero-php-sdk

然后运行 composer install

是Composer新手?在Composer入门页面了解更多

手动安装

下载文件并包含 autoload.php

require_once('/path/to/TransferZeroSdk/vendor/autoload.php');

入门

请遵循安装程序,然后运行以下操作

<?php
require_once(__DIR__ . '/vendor/autoload.php');

身份验证

在配置对象上设置API密钥和密钥,以进行身份验证

TransferZero\Configuration::getDefaultConfiguration()
  ->setHost("https://api-sandbox.transferzero.com/v1")
  ->setApiKey("<key>")
  ->setApiSecret("<secret>");

示例

$apiInstance = new TransferZero\Api\APILogsApi();
$api_log_id = 'api_log_id_example'; // string | ID of the API log to retrieve  Example: `/v1/api_logs/00485ce9-532b-45e7-8518-7e5582242407`

try {
    $result = $apiInstance->getApiLog($api_log_id);
    print_r($result);
} catch (Exception $e) {
    if ($e->isValidationError()) {
        $response = $e->getResponseObject();
        echo "Validation error(s) occurred when calling the endpoint";
        print_r($response);
    } else {
        echo "An exception occurred when calling APILogsApi#getApiLog";
        echo $e->getMessage();
    }
}

?>

您可以在入职文档中的examples目录中找到更多示例

Webhooks

要解析webhooks,可以使用以下片段

$webhook_content = "{ (...) }"; // The string received through the webhook callback url
$webhook_headers = [
    "Authorization-Nonce" => "<authorization-nonce>",
    "Authorization-Key" => "<authorization-key>",
    "Authorization-Signature" => "<authorization-signature>"
]; // The headers from the webook callback url
$webhook_url = "<url>"; // The url of the webhook callback

$webhooksApi = new TransferZero\Api\WebhooksApi();
if (!$webhooksApi->validateWebhookRequest($webhook_url, $webhook_content, $webhook_headers)) {
    echo "Webhook request validation failed";
    return false;
}

$webhook = $webhooksApi->parseResponseString($webhook_content, 'Webhook');

if (strpos($webhook->getEvent(), 'transaction') === 0) {
    $transactionWebhook = $webhooksApi->parseResponseString($webhook_content, 'TransactionWebhook');
    print_r($transactionWebhook->getObject()->__toString());
} elseif (strpos($webhook->getEvent(), 'recipient') === 0) {
    $recipientWebhook = $webhooksApi->parseResponseString($webhook_content, 'RecipientWebhook');
    print_r($recipientWebhook->getObject()->__toString());
} elseif (strpos($webhook->getEvent(), 'payout_method') === 0) {
    $payoutMethodWebhook = $webhooksApi->parseResponseString($webhook_content, 'PayoutMethodWebhook');
    print_r($payoutMethodWebhook->getObject()->__toString());
} elseif (strpos($webhook->getEvent(), 'sender') === 0) {
    $senderWebhook = $webhooksApi->parseResponseString($webhook_content, 'SenderWebhook');
    print_r($senderWebhook->getObject()->__toString());
} elseif (strpos($webhook->getEvent(), 'document') === 0) {
    $documentWebhook = $webhooksApi->parseResponseString($webhook_content, 'DocumentWebhook');
    print_r($documentWebhook->getObject()->__toString());
}

API端点文档

所有URI均相对于https://api-sandbox.transferzero.com/v1

模型文档