acoriss/payment-gateway
最新稳定版本:v0.1.4
Composer 安装命令:
composer require acoriss/payment-gateway
包简介
PHP SDK for Acoriss Payment Gateway
README 文档
README
A PHP SDK for interacting with the Acoriss Payment Gateway API. Mirrors the functionality of the existing Node.js SDK: creating payment sessions and retrieving payments.
Installation
Require via Composer (after publishing to Packagist or using VCS repo):
composer require acoriss/payment-gateway
For local development inside this monorepo:
cd sdks/php
composer install
Quick Start
use Acoriss\PaymentGateway\Client; $client = new Client([ 'apiKey' => 'your-api-key', 'apiSecret' => 'your-api-secret', // enables automatic HMAC-SHA256 signing // 'environment' => 'live', // default is 'sandbox' ]); $session = $client->createSession([ 'amount' => 5000, 'currency' => 'USD', 'customer' => [ 'email' => 'john@example.com', 'name' => 'John Doe' ], 'description' => 'Order #1234', 'serviceId' => 'service_123' // Optional: specify a service ]); echo $session['checkoutUrl']; $payment = $client->getPayment($session['id']); print_r($payment);
Configuration Options
| Key | Type | Description |
|---|---|---|
| apiKey | string | Required API key |
| apiSecret | string | Optional secret for HMAC signing |
| environment | `sandbox | live` |
| baseUrl | string | Overrides environment base URL |
| signer | SignerInterface |
Custom signing strategy |
| timeout | float | Timeout in seconds (default 15) |
| logger | LoggerInterface |
PSR-3 logger for debugging (default: NullLogger) |
| verify | bool|string | SSL certificate verification (default: true) |
Features
Signing
createSessionsigns the raw JSON request body.getPaymentsigns only the payment ID string.- Provide either
apiSecret, a customSignerInterface, or passsignatureOverrideper call.
Webhook Verification
Verify webhook signatures to ensure authenticity:
$payload = file_get_contents('php://input'); $signature = $_SERVER['HTTP_X_SIGNATURE'] ?? ''; if ($client->verifyWebhookSignature($payload, $signature)) { $data = json_decode($payload, true); // Process webhook } else { http_response_code(401); echo 'Invalid signature'; }
PSR-3 Logging
Add a PSR-3 compatible logger for debugging:
use Monolog\Logger; use Monolog\Handler\StreamHandler; $logger = new Logger('payment-gateway'); $logger->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG)); $client = new Client([ 'apiKey' => 'your-api-key', 'apiSecret' => 'your-api-secret', 'logger' => $logger, ]);
Logs include:
- Debug: Client initialization, request details
- Info: Successful operations
- Error: Failures and exceptions
Error Handling
All API/network errors throw Acoriss\PaymentGateway\Exceptions\APIException exposing:
try { $client->createSession($payload); } catch (\Acoriss\PaymentGateway\Exceptions\APIException $e) { echo $e->getMessage(); var_dump($e->getStatus(), $e->getData(), $e->getHeaders()); }
Development
Running Tests
composer install
composer test
Static Analysis
Run PHPStan for type safety:
composer analyse
Code Style
Format code with PHP-CS-Fixer:
# Fix code style composer format # Check without fixing composer format-check
Versioning & Compatibility
SDK targets PHP >= 8.1 and Guzzle 7.x.
License
MIT
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-15