chainbook/paystack
Composer 安装命令:
composer require chainbook/paystack
包简介
A Laravel package for seamless Paystack payment integration — initialize transactions, verify payments, manage customers, plans and subscriptions.
README 文档
README
A clean, simple Laravel package for Paystack payment integration. Supports transactions, customers, plans, subscriptions and webhook verification — with zero configuration beyond your API keys.
Requirements
- PHP ^8.1
- Laravel ^10 | ^11 | ^12
Installation
composer require chainbook/paystack
Laravel's auto-discovery will register the service provider and Paystack facade automatically.
Publish the config file (optional)
php artisan vendor:publish --provider="Chainbook\Paystack\PaystackServiceProvider" --tag="paystack-config"
Add your keys to .env
PAYSTACK_PUBLIC_KEY=pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx PAYSTACK_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Usage
Transactions
use Chainbook\Paystack\Facades\Paystack; // Initialize a transaction $response = Paystack::initializeTransaction([ 'email' => 'customer@example.com', 'amount' => 500000, // Amount in kobo/pesewas (= 5000 NGN/GHS) 'reference' => uniqid('ref_'), 'callback_url' => 'https://yourapp.com/payment/callback', ]); // $response['data']['authorization_url'] — redirect the user here // Verify a transaction $verification = Paystack::verifyTransaction('ref_abc123'); if ($verification['data']['status'] === 'success') { // Payment confirmed } // List transactions $transactions = Paystack::listTransactions(['perPage' => 20, 'page' => 1]); // Fetch a specific transaction $transaction = Paystack::fetchTransaction(123456789); // Charge a returning customer using saved authorization $charge = Paystack::chargeAuthorization([ 'authorization_code' => 'AUTH_xxxxxxxx', 'email' => 'customer@example.com', 'amount' => 500000, ]);
Customers
// Create a customer $customer = Paystack::createCustomer([ 'email' => 'customer@example.com', 'first_name' => 'Jane', 'last_name' => 'Doe', 'phone' => '+2348012345678', ]); // Fetch a customer (by ID or customer code) $customer = Paystack::fetchCustomer('CUS_xxxxxxxx'); // Update a customer Paystack::updateCustomer('CUS_xxxxxxxx', ['first_name' => 'Janet']); // List customers $customers = Paystack::listCustomers(['perPage' => 50]);
Plans & Subscriptions
// Create a plan $plan = Paystack::createPlan([ 'name' => 'Monthly Premium', 'interval' => 'monthly', 'amount' => 500000, ]); // List plans / fetch / subscribe $plans = Paystack::listPlans(); $plan = Paystack::fetchPlan('PLN_xxxxxxxx'); $subscription = Paystack::createSubscription([ 'customer' => 'CUS_xxxxxxxx', 'plan' => 'PLN_xxxxxxxx', 'start_date' => now()->addDay()->toIso8601String(), ]); $subscriptions = Paystack::listSubscriptions();
Webhook Verification
// routes/web.php Route::post('/webhooks/paystack', function (Illuminate\Http\Request $request) { $signature = $request->header('X-Paystack-Signature'); $computed = hash_hmac('sha512', $request->getContent(), config('paystack.secret_key')); if ($signature !== $computed) { abort(400, 'Invalid signature'); } $event = $request->json()->all(); match ($event['event'] ?? null) { 'charge.success' => /* handle payment */ null, 'transfer.success' => /* handle transfer */ null, default => null, }; return response('OK', 200); })->withoutMiddleware([\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class]);
Get the Public Key (for frontend/JavaScript use)
$publicKey = Paystack::getPublicKey();
Configuration
After publishing, edit config/paystack.php:
return [ 'public_key' => env('PAYSTACK_PUBLIC_KEY'), 'secret_key' => env('PAYSTACK_SECRET_KEY'), 'base_url' => env('PAYSTACK_BASE_URL', 'https://api.paystack.co'), 'webhook_secret' => env('PAYSTACK_WEBHOOK_SECRET'), ];
Testing
composer test
License
The MIT License (MIT). See LICENSE for more information.
chainbook/paystack 适用场景与选型建议
chainbook/paystack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 107 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「laravel」 「africa」 「Nigeria」 「paystack」 「Ghana」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chainbook/paystack 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chainbook/paystack 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chainbook/paystack 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Validation rules and an Eloquent Model attribute cast to value object encapsulating a South African government-issued personal identification number, for Laravel.
Feature-based billing for Laravel with African payment provider support (M-Pesa, Paystack, Flutterwave, Pesapal). Plans, feature gating, usage metering, subscriptions, and invoicing.
Modern Laravel package for Flutterwave v4 API integration
Alfabank REST API integration
Laravel package for Beem API integration - SMS, Airtime, OTP, Payment Checkout, Collections, Contacts, Moja, and International SMS services
PayDunya Magento Payment Gateway
统计信息
- 总下载量: 107
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-09