transferzero/transferzero-php-sdk

TransferZero Client Library for PHP


README

This is the PHP client library for use with the TransferZero API. To use the API please register and obtain valid API keys on the TransferZero developer portal.

For more information, please visit:

This PHP package is automatically generated by the OpenAPI Generator project:

  • API version: 1.0
  • Package version: 1.36.4

Requirements

PHP 7.1 and later

Installation & Usage

Composer

To install via Composer, run:

composer require transferzero/transferzero-php-sdk

Then run composer install

New to Composer? Learn more at Composer's Getting Started page

Manual Installation

Download the files and include autoload.php:

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

Getting Started

Please follow the installation procedure and then run the following:

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

Authentication

Set the API Key and Secret on the Configuration object for authentication:

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

Example

$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();
    }
}

?>

You can find more examples in the examples directory on the features required by the Onboarding documentation

Webhooks

To parse webhooks you can use the following snippet:

$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());
}

Documentation for API Endpoints

All URIs are relative to https://api-sandbox.transferzero.com/v1

Documentation For Models