paykrypt/paykrypt-php-sdk
Composer 安装命令:
composer require paykrypt/paykrypt-php-sdk
包简介
Official PHP SDK for the PayKrypt crypto payment gateway API.
README 文档
README
Official PHP SDK for the PayKrypt crypto payment gateway API.
Installation
composer require paykrypt/paykrypt-php-sdk composer require guzzlehttp/guzzle
The SDK is framework-agnostic and uses PSR-18 HTTP clients. If no PSR-18 client can be auto-discovered, install one such as guzzlehttp/guzzle or symfony/http-client.
Requires PHP 8.1 or newer.
Quick Start
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' => 'customer@example.com', 'allowedChains' => ['ethereum', 'tron'], 'expiresInMinutes' => 60, ]); // Redirect the customer to: // https://gate.paykrypt.io/pay/{$intent['id']}
Configuration
$paykrypt = new PayKryptClient([ 'apiKey' => 'pk_12345678_...', 'baseUrl' => 'https://api.paykrypt.io', 'timeout' => 30_000, 'retries' => 3, 'retryDelayMs' => 250, ]);
All merchant API calls use:
Authorization: Bearer pk_<prefix>_<secret>
Sandbox and live environments are selected by baseUrl.
Idempotency
PayKrypt requires an Idempotency-Key on value-creating POST endpoints. The SDK generates one automatically for:
paymentIntents->create()payouts->create()payouts->createWithVerification()refunds->create()refunds->createWithVerification()conversions->convert()
Pass your own stable key when retrying the same app-level action:
$intent = $paykrypt->paymentIntents->create( ['amount' => '100.00', 'currency' => 'USD'], ['idempotencyKey' => 'order:12345'], );
Resources
$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'], ]); $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']]);
Responses are returned as associative arrays to stay compatible with PayKrypt's evolving API response shapes.
Webhook Verification
PayKrypt signs webhook deliveries with X-PayKrypt-Signature and X-PayKrypt-Timestamp.
Use the secret returned from webhooks->register(...) as PAYKRYPT_WEBHOOK_SECRET.
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; }
The signature payload is:
<millisecond_timestamp>.<raw_body>
The SDK also accepts the older documented aliases Paykrypt-Signature and Paykrypt-Timestamp.
Error Handling
use PayKrypt\PayKryptApiException; try { $paykrypt->paymentIntents->retrieve('pi_missing'); } catch (PayKryptApiException $exception) { error_log($exception->getStatusCode() . ' ' . $exception->getErrorCode() . ' ' . $exception->getMessage()); }
Development
composer validate --strict
composer install
composer lint
composer analyse
composer test
Publishing To Packagist
- Push
maintohttps://github.com/PayKrypt/paykrypt-php-sdk. - Submit the public repository URL to Packagist once under
paykrypt/paykrypt-php-sdk. - Enable Packagist auto-updates through the GitHub app, or configure a GitHub webhook manually:
payload URL
https://packagist.org/api/github?username=PACKAGIST_USERNAME, content typeapplication/json, secret set to your Packagist API token, and push events only. - Tag releases with semantic version tags such as
v1.0.0; Composer reads package versions from VCS tags, so do not add aversionfield tocomposer.json. - Create a GitHub Release from the tag and verify Packagist indexed the new version.
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-14