PHP code example of tokenpay-platform / sdk-php

1. Go to this page and download the library: Download tokenpay-platform/sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tokenpay-platform / sdk-php example snippets



TokenPay\SDK\TokenPay;

$tokenpay = new TokenPay(getenv('TOKENPAY_API_KEY'));

// Create a payment (currency, amount in the smallest unit, optional metadata).
$payment = $tokenpay->payments->create([
    'currency' => 'AUD',
    'amount'   => 12500,          // A$125.00
    'metadata' => ['order_id' => 'WC-1234'],
]);

echo $payment['id'];              // pay_...
echo $payment['checkout_url'];    // https://merchant.tokenpayment.io/pay/...

$tokenpay->payments->get($payment['id']);

$tokenpay->payments->list([
    'status'    => 'matched',
    'from_date' => '2026-04-01T00:00:00Z',
    'limit'     => 50,
    'offset'    => 0,
]);

// Cancel a payment that is still in `created` or `matching` state.
$tokenpay->payments->cancel($payment['id']);

use TokenPay\SDK\TokenPay;

$tokenpay = new TokenPay(getenv('TOKENPAY_API_KEY'));

$isValid = $tokenpay->webhooks->verify(
    secret:    getenv('TOKENPAY_WEBHOOK_SECRET'),
    method:    $_SERVER['REQUEST_METHOD'],         // "POST"
    path:      $_SERVER['REQUEST_URI'],            // "/webhooks/merchant"
    timestamp: $_SERVER['HTTP_X_TOKENPAY_TIMESTAMP'],
    payload:   file_get_contents('php://input'),
    signature: $_SERVER['HTTP_X_TOKENPAY_SIGNATURE'],
);

if (!$isValid) {
    http_response_code(401);
    exit;
}

$tokenpay = new TokenPay('tk_test_...', [
    'baseUrl'    => 'https://api.tokenpayment.io',   // default
    'timeout'    => 30,                              // seconds, Guzzle compat
    'maxRetries' => 3,                               // 5xx + network errors only
    'userAgent'  => 'tokenpay-sdk-php/0.1.0',        // default
]);
bash
composer 
bash
git tag -a v0.1.0-php -m "sdks/php v0.1.0 — initial Packagist release"
git push origin v0.1.0-php
# Packagist webhook fires within ~60s.
# Verify: https://packagist.org/packages/tokenpay-platform/sdk-php