cray/laravel-sdk
最新稳定版本:v1.0.0
Composer 安装命令:
composer require cray/laravel-sdk
包简介
Cray Laravel SDK for Card and MoMo payments
README 文档
README
- Package name:
cray/laravel-sdk - Installation:
composer require cray/laravel-sdk - Supported Frameworks: Laravel 8, 9, 10, 11 (PHP 8.1+)
- Auto-Discovery: Enabled by default
- Manual Registration (Lumen or Custom): Add
Cray\\LaravelSDK\\CrayServiceProviderto providers and aliasCraytoCray\\LaravelSDK\\Facades\\Cray.
Environment Configuration
Publish config:
php artisan vendor:publish --provider="Cray\\LaravelSDK\\CrayServiceProvider" --tag="config"
Add to .env:
CRAY_PUBLIC_KEY=your_public_key
CRAY_SECRET_KEY=your_secret_key
CRAY_TIMEOUT=30
Environment switching (automatic):
- Uses
APP_ENVto select base URL and environment. - When
APP_ENVisproduction/prod/live→ base URLhttps://pay.connectramp.com, envproduction. - Otherwise (e.g.,
staging,sandbox,local,testing) → base URLhttps://dev-gateman.v3.connectramp.com, envsandbox. − No need to setCRAY_BASE_URLorCRAY_ENV— they are derived. You may still overrideCRAY_BASE_URLif required.
SDK Usage Examples
Card Payment Flow
Initiate a Card Transaction
use Cray\LaravelSDK\Facades\Cray; use Illuminate\Support\Str; $transaction = Cray::card()->initiate([ 'reference' => (string) Str::uuid(), 'amount' => '100.00', 'currency' => 'USD', 'narration' => 'Payment for Order #12345', 'card_data' => [ 'pan' => '5399832641760090', 'cvv' => '146', 'expiryMonth' => '05', 'expiryYear' => '50', ], 'callback_url' => route('cray.callback'), 'customer_information' => [ 'email' => 'customer@example.com', 'firstName' => 'John', 'lastName' => 'Doe', 'mobilePhone' => '+15551234567', ], ]);
Charge the Transaction
if ($transaction['status'] ?? false) { $txId = $transaction['data']['transaction_id'] ?? null; if ($txId) { $charge = Cray::card()->charge($txId); } }
Query a Transaction
$status = Cray::card()->query('87c89286-afbc-4776-adfd-665c9927b2db');
Refund a Transaction
$refund = Cray::refund()->refund('87c89286-afbc-4776-adfd-665c9927b2db', 50.00);
Query Refund Status
$refundStatus = Cray::refund()->queryRefund('87c89286-afbc-4776-adfd-665c9927b2db');
MoMo Payment Flow
Initiate a MoMo Transaction
use Cray\LaravelSDK\Facades\Cray; use Illuminate\Support\Str; $momo = Cray::momo()->initiate([ 'customer_reference' => (string) Str::uuid(), 'amount' => '200', 'currency' => 'GHS', 'phone_no' => '233801234567', 'payment_provider' => 'MTN', 'firstname' => 'John', 'lastname' => 'Doe', ]);
Query MoMo Transaction
$requery = Cray::momo()->query('ad75b9bb-2501-4761-8980-42b525e21c37');
Key Features
- Unified SDK for Card and MoMo APIs
- Supports refunding and querying across both transaction types
- Sandbox and production environment toggling
- Standardized response structure and built-in error handling
- Logging, retries, and correlation IDs included
CI/CD and Versioning
- CI Matrix: PHP 8.1–8.3, Laravel 8–11
- Unit Tests: PHPUnit/Larastan static analysis
- Versioning: Semantic Versioning (v1.0.0)
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-10