PHP code example of paykrypt / paykrypt-php-sdk

1. Go to this page and download the library: Download paykrypt/paykrypt-php-sdk 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/ */

    

paykrypt / paykrypt-php-sdk example snippets


use PayKrypt\PayKryptClient;

$paykrypt = new PayKryptClient([
    'apiKey' => getenv('PAYKRYPT_API_KEY'),
    'baseUrl' => getenv('PAYKRYPT_BASE_URL') ?: 'https://api.paykrypt.io',
]);

$intent = $paykrypt->paymentIntents->create([
    'amount' => '100.00',
    'currency' => 'USD',
    'description' => 'Order #12345',
    'customerEmail' => '[email protected]',
    'allowedChains' => ['ethereum', 'tron'],
    'expiresInMinutes' => 60,
]);

// Redirect the customer to:
// https://gate.paykrypt.io/pay/{$intent['id']}

$paykrypt = new PayKryptClient([
    'apiKey' => 'pk_12345678_...',
    'baseUrl' => 'https://api.paykrypt.io',
    'timeout' => 30_000,
    'retries' => 3,
    'retryDelayMs' => 250,
]);

if (!$paykrypt->isTestMode()) {
    throw new RuntimeException('Refusing to run the integration suite against a live key');
}

$intent = $paykrypt->paymentIntents->create(
    ['amount' => '100.00', 'currency' => 'USD'],
    ['idempotencyKey' => 'order:12345'],
);

$paykrypt->paymentIntents->retrieve('pi_...');
$paykrypt->paymentIntents->list(['page' => 1, 'limit' => 20]);
$paykrypt->paymentIntents->cancel('pi_...');

$paykrypt->payouts->create([
    'amount' => '95',
    'currency' => 'USDT',
    'destinationAddress' => 'TXYZ...',
    'chainId' => 'tron',
]);
$paykrypt->payouts->stats();

$paykrypt->refunds->create([
    'paymentIntentId' => '00000000-0000-0000-0000-000000000000',
    'amount' => '50.00',
    'reason' => 'Customer requested refund',
]);

$paykrypt->webhooks->register([
    'url' => 'https://example.com/webhooks/paykrypt',
    'events' => ['payment.confirmed.v1'],
]);

// What was actually sent to your endpoints, what they answered, and which attempt it was.
$paykrypt->webhooks->deliveries(['limit' => 20, 'paymentIntentId' => 'pi_...']);

$paykrypt->addressBook->create([
    'label' => 'Treasury wallet',
    'address' => 'TXYZ...',
    'chainId' => 'tron',
]);

$paykrypt->conversions->preview([
    'fromAssetId' => 1,
    'toAssetId' => 2,
    'amount' => 10,
]);

$paykrypt->currencies->list();
$paykrypt->assets->list();
$paykrypt->assets->listByChain('tron');
$paykrypt->pricing->rates(['currency' => 'USD', 'symbols' => ['BTC', 'ETH', 'USDT']]);

$paykrypt = new PayKryptClient(['apiKey' => getenv('PAYKRYPT_TEST_KEY')]);

if (!$paykrypt->isTestMode()) {
    throw new RuntimeException('Refusing to run tests against a live key');
}

$intent = $paykrypt->paymentIntents->create(['amount' => '25.00', 'currency' => 'USD']);

$paykrypt->test->pay($intent['id'], [
    'scenario' => 'confirm',
    'chainId' => 'tron',
    'assetSymbol' => 'USDT',
]);

$paykrypt->test->expire($intent['id']);

// A sandbox payout waits in `pending` exactly as a real one does. Drive the outcome:
$paykrypt->test->completePayout($payout['id'], ['outcome' => 'confirmed']);
$paykrypt->test->completeRefund($refund['id'], [
    'outcome' => 'rejected',
    'reason' => 'Insufficient hot wallet balance',
]);

use PayKrypt\Webhook;
use PayKrypt\WebhookVerificationException;

$rawBody = file_get_contents('php://input');
$headers = getallheaders() ?: [];

try {
    $event = Webhook::constructEvent(
        $rawBody,
        $headers,
        getenv('PAYKRYPT_WEBHOOK_SECRET')
    );

    if ($event['type'] === 'payment.confirmed.v1') {
        // Fulfill the order.
    }
} catch (WebhookVerificationException $exception) {
    http_response_code(400);
    echo 'Invalid webhook signature';
    return;
}

use PayKrypt\PayKryptApiException;

try {
    $paykrypt->paymentIntents->retrieve('pi_missing');
} catch (PayKryptApiException $exception) {
    error_log($exception->getStatusCode() . ' ' . $exception->getErrorCode() . ' ' . $exception->getMessage());
}
txt
<millisecond_timestamp>.<raw_body>