sagapay/sdk-php
Composer 安装命令:
composer require sagapay/sdk-php
包简介
SagaPay - The world's first free, non-custodial blockchain payment gateway SDK for PHP
README 文档
README
SagaPay (https://sagapay.net) is the world's first free, non-custodial blockchain payment gateway service provider, enabling businesses to seamlessly integrate cryptocurrency payments without holding customer funds. With enterprise-grade security and zero transaction fees, SagaPay empowers merchants to accept crypto payments across multiple blockchains while maintaining full control of their digital assets.
Installation
Install the SagaPay PHP SDK via Composer:
composer require sagapay/sdk-php
Quick Start
<?php // Initialize the SagaPay client require_once 'vendor/autoload.php'; use SagaPay\SDK\Client; $client = new Client('your-api-key', 'your-api-secret'); // Create a deposit address try { $deposit = $client->createDeposit([ 'networkType' => 'BEP20', 'contractAddress' => '0', // Use '0' for native coins 'amount' => '1.5', 'ipnUrl' => 'https://yourwebsite.com/webhook.php', 'udf' => 'order-123', 'type' => 'TEMPORARY' ]); echo "Deposit address created: " . $deposit['address']; } catch (\SagaPay\SDK\Exception $e) { echo "Error: " . $e->getMessage(); }
Features
- Deposit address generation
- Withdrawal processing
- Transaction status checking
- Wallet balance fetching
- Multi-chain support (ERC20, BEP20, TRC20, POLYGON, SOLANA)
- Webhook notifications (IPN)
- Custom UDF field support
- Zero transaction fees
- Non-custodial architecture
API Reference
Create Deposit
$deposit = $client->createDeposit([ 'networkType' => 'BEP20', // Required: ERC20, BEP20, TRC20, POLYGON, SOLANA 'contractAddress' => '0', // Required: Contract address or '0' for native coins 'amount' => '1.5', // Required: Expected deposit amount 'ipnUrl' => 'https://example.com/webhook.php', // Required: URL for notifications 'udf' => 'order-123', // Optional: User-defined field 'type' => 'TEMPORARY' // Optional: TEMPORARY or PERMANENT ]);
Create Withdrawal
$withdrawal = $client->createWithdrawal([ 'networkType' => 'ERC20', // Required: ERC20, BEP20, TRC20, POLYGON, SOLANA 'contractAddress' => '0xdAC17F...', // Required: Contract address or '0' for native coins 'address' => '0x742d35C...', // Required: Destination wallet address 'amount' => '10.5', // Required: Withdrawal amount 'ipnUrl' => 'https://example.com/webhook.php', // Required: URL for notifications 'udf' => 'withdrawal-456' // Optional: User-defined field ]);
Check Transaction Status
$status = $client->checkTransactionStatus('0x742d35C...', 'deposit');
Fetch Wallet Balance
$balance = $client->fetchWalletBalance( '0x742d35C...', // Address 'ERC20', // Network type '0xdAC17F...' // Contract address (use '0' for native currency) );
Handling Webhooks (IPN)
SagaPay sends webhook notifications to your specified ipnUrl when transaction statuses change. Use the WebhookHandler to process these notifications:
<?php // webhook.php require_once 'vendor/autoload.php'; use SagaPay\SDK\Client; use SagaPay\SDK\WebhookHandler; $client = new Client('your-api-key', 'your-api-secret'); $webhookHandler = new WebhookHandler($client); try { // Process and validate the webhook $webhookData = $webhookHandler->processWebhook(getallheaders(), file_get_contents('php://input')); // Handle the validated webhook data $transactionId = $webhookData['id']; $type = $webhookData['type']; // 'deposit' or 'withdrawal' $status = $webhookData['status']; // 'PENDING', 'PROCESSING', 'COMPLETED', 'FAILED', 'CANCELLED' $address = $webhookData['address']; $amount = $webhookData['amount']; $udf = $webhookData['udf'] ?? null; // Your custom reference field // Update your database or trigger actions based on status if ($status === 'COMPLETED') { // Process successful payment // e.g., updateOrderStatus($udf, 'paid'); } // Send success response $webhookHandler->sendSuccessResponse(); } catch (\SagaPay\SDK\Exception $e) { // Log the error and send error response error_log("Webhook error: " . $e->getMessage()); $webhookHandler->sendErrorResponse($e->getMessage(), $e->getCode()); }
Webhook Payload Format
When SagaPay sends a webhook to your endpoint, it will include the following payload:
{
"id": "transaction-uuid",
"type": "deposit|withdrawal",
"status": "PENDING|PROCESSING|COMPLETED|FAILED|CANCELLED",
"address": "0x123abc...",
"networkType": "ERC20|BEP20|TRC20|POLYGON|SOLANA",
"amount": "10.5",
"udf": "your-optional-user-defined-field",
"txHash": "0xabc123...",
"timestamp": "2025-03-16T14:30:00Z"
}
Error Handling
All methods in the SagaPay SDK can throw a SagaPay\SDK\Exception. This exception contains:
- Message: Error description
- Code: Error code
- HTTP code: HTTP status code (when applicable)
try { $client->createDeposit($params); } catch (\SagaPay\SDK\Exception $e) { echo "Error: " . $e->getMessage() . "\n"; echo "Code: " . $e->getCode() . "\n"; echo "HTTP Status: " . $e->getHttpCode() . "\n"; }
License
This SDK is released under the MIT License.
Support
For questions or support, please contact support@sagapay.net or visit https://sagapay.net.
sagapay/sdk-php 适用场景与选型建议
sagapay/sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「payment」 「sdk」 「blockchain」 「cryptocurrency」 「sagapay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sagapay/sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sagapay/sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sagapay/sdk-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
TrinkPOS Sanal POS (Virtual POS) API client for PHP
ABsurge PHP SDK for feature flags and A/B testing
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-16