sepay/sepay-pg
Composer 安装命令:
composer require sepay/sepay-pg
包简介
Official PHP SDK for SePay Payment Gateway — simple integration for payments, bank transfers, VietQR.
README 文档
README
Translations: English | Tiếng Việt
Official PHP SDK for SePay Payment Gateway. Easy integration for payments, bank transfers, VietQR.
Installation
You can install the SDK by running the following command:
composer require sepay/sepay-pg
Requirements
- PHP 7.4 or higher
- ext-json
- ext-curl
- Guzzle HTTP client
Quick Start
<?php require_once 'vendor/autoload.php'; use SePay\SePayClient; use SePay\Builders\CheckoutBuilder; // Initialize client $sepay = new SePayClient( 'SP-TEST-XXXXXXX', 'spsk_live_xxxxxxxxxxxo99PoE7RsBpss3EFH5nV', SePayClient::ENVIRONMENT_SANDBOX // or ENVIRONMENT_PRODUCTION ); // Create checkout $checkoutData = CheckoutBuilder::make() ->currency('VND') ->orderAmount(100000) // 100,000 VND ->operation('PURCHASE') ->orderDescription('Test payment') ->orderInvoiceNumber('INV_001') ->successUrl('https://yoursite.com/success') ->build(); // Display checkout form for payment echo $sepay->checkout()->generateFormHtml($checkoutData); // Or manually create form fields with signature $formFields = $sepay->checkout()->generateFormFields($checkoutData); echo "Checkout form created with signature: " . $formFields['signature'];
Examples
Run the examples to see how everything works:
# Overview php examples/basic-usage.php # Specific examples php examples/01-checkout-basic.php # Basic payments php examples/02-orders-management.php # Orders management php examples/03-payment-methods.php # Payment methods
Core Concepts
Client Initialization
use SePay\SePayClient; $sepay = new SePayClient( $merchantId, $secretKey, $environment, // 'sandbox' or 'production' $config // Optional configuration array ); // Enable debug mode $sepay->enableDebugMode(); // Configure retry behavior $sepay ->setRetryAttempts(3) ->setRetryDelay(1000); // milliseconds
API Resources
Checkout
Generate secure form fields for payment processing. This is how you start payments with SePay.
// Simple checkout using CheckoutBuilder $checkoutData = CheckoutBuilder::make() ->currency('VND') ->orderAmount(100000) // 100,000 VND ->operation('PURCHASE') ->orderDescription('Payment for order #123') ->orderInvoiceNumber('INV_123') ->customerId('customer_001') ->successUrl('https://yoursite.com/success') ->errorUrl('https://yoursite.com/error') ->cancelUrl('https://yoursite.com/cancel') ->build(); // Generate form fields with signature $formFields = $sepay->checkout()->generateFormFields($checkoutData); // Alternative: Pass array directly $checkoutArray = [ 'currency' => 'VND', 'order_amount' => 100000, 'operation' => 'PURCHASE', 'order_description' => 'Payment for order #123', 'order_invoice_number' => 'INV_123', 'customer_id' => 'customer_001', 'success_url' => 'https://yoursite.com/success', 'error_url' => 'https://yoursite.com/error', 'cancel_url' => 'https://yoursite.com/cancel', ]; $formFields = $sepay->checkout()->generateFormFields($checkoutArray);
Payment Methods
// Card payment $cardCheckout = CheckoutBuilder::make() ->paymentMethod('CARD') // ... ->build(); // Bank transfer payment $bankCheckout = CheckoutBuilder::make() ->paymentMethod('BANK_TRANSFER') // ... ->build(); // Show all payment methods $allMethodsCheckout = CheckoutBuilder::make() // ->paymentMethod('...') // ... ->build();
Orders
// Retrieve order by invoice number $order = $sepay->orders()->retrieve('ORDER_INVOICE_NUMBER'); // List orders with filters $orders = $sepay->orders()->list([ 'per_page' => 10, 'order_status' => 'CAPTURED', 'from_created_at' => '2024-01-01', 'to_created_at' => '2024-12-31', ]); // Void transaction (cancel payment) $result = $sepay->orders()->voidTransaction('ORDER_INVOICE_NUMBER');
Note: Orders are created when customers complete checkout, not directly through the API.
Error Handling
The SDK has different exception types for different errors:
use SePay\Exceptions\AuthenticationException; use SePay\Exceptions\ValidationException; use SePay\Exceptions\NotFoundException; use SePay\Exceptions\RateLimitException; use SePay\Exceptions\ServerException; try { $order = $sepay->orders()->retrieve('ORDER_INVOICE_NUMBER'); } catch (AuthenticationException $e) { // Invalid credentials or signature echo "Authentication failed: " . $e->getMessage(); } catch (ValidationException $e) { // Invalid request data echo "Validation error: " . $e->getMessage(); // Get field-specific errors if ($e->hasFieldError('amount')) { $errors = $e->getFieldErrors('amount'); echo "Amount errors: " . implode(', ', $errors); } } catch (NotFoundException $e) { // Resource not found echo "Not found: " . $e->getMessage(); } catch (RateLimitException $e) { // Rate limit exceeded echo "Rate limited. Retry after: " . $e->getRetryAfter() . " seconds"; } catch (ServerException $e) { // Server error (5xx) echo "Server error: " . $e->getMessage(); }
Configuration
$merchantId = 'SP-LIVE-XXXXXXX'; $secretKey = 'spsk_live_xxxxxxxxxxxo99PoE7RsBpss3EFH5nV'; $config = [ 'timeout' => 60, // Request timeout in seconds 'retry_attempts' => 5, // Number of retry attempts 'retry_delay' => 2000, // Delay between retries in milliseconds 'debug' => true, // Enable debug logging 'user_agent' => 'MyApp/1.0 SePay-PHP-SDK/1.0.0', 'logger' => $customLogger, // PSR-3 compatible logger ]; $sepay = new SePayClient($merchantId, $secretKey, $environment, $config);
Testing
Run the test suite:
# Run all tests composer test # Run tests with coverage composer test-coverage # Run static analysis composer phpstan # Fix code style composer cs-fix
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
This SDK is licensed under the MIT License. See LICENSE for details.
Support
- Email: info@sepay.vn
- Documentation: https://developer.sepay.vn
- Issues: https://github.com/sepayvn/sepay-pg-php/issues
Changelog
See CHANGELOG.md for version history and changes.
sepay/sepay-pg 适用场景与选型建议
sepay/sepay-pg 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.6k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「gateway」 「vietnam」 「vietqr」 「SePay」 「bank-transfer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sepay/sepay-pg 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sepay/sepay-pg 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sepay/sepay-pg 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Payyo Gateway for the Omnipay payment processing library
Vietnamese language pack.
Client library to send SMS using Comilio SMS Gateway API (https://www.comilio.it)
Vietnam language pack for Flarum. Updated by GaNuongLaChanh
A Laravel 5 Github Gist Clone from Larask Team.
统计信息
- 总下载量: 1.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-20