matscode/paystack-laravel-sdk
Composer 安装命令:
composer require matscode/paystack-laravel-sdk
包简介
A Laravel package for seamless Paystack integration, built on top of matscode/paystack-php-sdk.
README 文档
README
A modern, maintainable, and extensible Paystack integration for Laravel, built on top of the matscode/paystack-php-sdk. Feel free to reference the main SDK to see other available api method/property
Features
- Clean, service-based Paystack API integration
- Laravel service provider and facade
- Global
paystack()helper for convenient access - Uses matscode/paystack-php-sdk under the hood
- Configurable via
config/paystack.php - Well-documented
Requirements
- PHP 8.0+
- Laravel 9.0+
- matscode/paystack-php-sdk (installed automatically)
Installation
Install via Composer:
composer require matscode/paystack-laravel-sdk
Configuration
Optionally, publish the config file:
php artisan vendor:publish --provider="Matscode\\PaystackLaravel\\PaystackServiceProvider" --tag="config"
Set your Paystack secret key in your .env file:
PAYSTACK_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxxxxx
Usage
You can use the Paystack SDK in Laravel via:
- The
PaystackFacade (recommended) - Dependency Injection (
Matscode\Paystack\Paystack) - The
paystack()helper (just likerequest()orauth())
Note:
Access Style Facade ( Paystack)DI ( app(...))Helper ( paystack())Method call ✅ Yes ✅ Yes ✅ Yes Property access ❌ No ✅ Yes ✅ Yes
- For the Facade, you must use static method calls for resources, such as
Paystack::transaction(). Property access likePaystack::transactionwill not work.- For DI and the helper, both method calls (
->transaction()) and property access (->transaction) are supported.- Always use the method call syntax for maximum compatibility.
Transaction Resource
Initialize Transaction
Initializes a new transaction and returns an authorization URL for the customer to complete payment. The response contains the transaction reference and other details.
// Using the Facade Paystack::transaction()->initialize([ 'email' => 'customer@email.com', 'amount' => 500000, // amount in kobo 'callback_url' => 'https://yourapp.com/paystack/transaction/verify', ]); // Using the helper paystack()->transaction->initialize([ 'email' => 'customer@email.com', 'amount' => 500000, // amount in kobo 'callback_url' => 'https://yourapp.com/paystack/transaction/verify', ]);
List Transactions
Retrieves a list of all transactions carried out on your Paystack account. Returns an array of transaction objects.
// Using the Facade Paystack::transaction()->list(); // Using the helper paystack()->transaction->list();
Verify Transaction
Verifies the status of a transaction using its reference. Returns the transaction details if found.
// Using the Facade $verification = Paystack::transaction()->verify($reference); // Using the helper $verification = paystack()->transaction->verify($reference);
Check if Transaction is Successful
Checks if a transaction was successful using its reference. Returns true if successful, otherwise false.
// Using the Facade $isSuccessful = Paystack::transaction()->isSuccessful($reference); // returns true/false // Using the helper $isSuccessful = paystack()->transaction->isSuccessful($reference);
Example: Initializing a Transaction with the Paystack Facade (Laravel)
You can use the Paystack facade with method chaining to initialize a transaction and get the payment authorization URL:
use Paystack; // Make sure the facade is properly registered // ... inside your controller or service $response = Paystack::transaction() ->setCallbackUrl('https://yourapp.com/paystack/verify') ->setEmail('customer@email.com') ->setAmount(75000) // amount in Naira ->initialize(); $authorizationUrl = $response->data->authorization_url; // Using the helper $response = paystack()->transaction ->setCallbackUrl('https://yourapp.com/paystack/verify') ->setEmail('customer@email.com') ->setAmount(75000) ->initialize(); $authorizationUrl = $response->data->authorization_url;
setCallbackUrl()sets the URL Paystack will redirect to after payment.setEmail()sets the customer's email.setAmount()sets the amount (in Naira, not kobo, when using this method).initialize()sends the request to Paystack and returns the response.- The authorization URL for redirecting the user is in
$response->data->authorization_url.
If you want to use the array method (amount in kobo):
// Using the Facade $response = Paystack::transaction()->initialize([ 'email' => 'customer@email.com', 'amount' => 500000, // amount in kobo 'callback_url' => 'https://yourapp.com/paystack/verify', ]); $authorizationUrl = $response['data']['authorization_url']; // Using the helper $response = paystack()->transaction->initialize([ 'email' => 'customer@email.com', 'amount' => 500000, // amount in kobo 'callback_url' => 'https://yourapp.com/paystack/verify', ]); $authorizationUrl = $response['data']['authorization_url'];
Bank Resource
List Banks
Retrieves a list of all supported banks for your Paystack account. Useful for populating bank selection dropdowns in forms.
// Using the Facade Paystack::bank()->list(); // Using the helper paystack()->bank->list();
Resolve Account Information
Resolves and validates a Nigerian bank account number and bank code. Returns the account name and other details if valid.
// Using the Facade $account = Paystack::bank()->resolve($bankCode, $accountNumber); // Using the helper $account = paystack()->bank->resolve($bankCode, $accountNumber);
Note: More resources (Customers, Plans, Subscription, Transfers, etc.) may be added as the SDK evolves. For the latest, see the PHP SDK documentation.
License
This library is licensed under the GNU General Public License v3.0 (GPL-3.0). See the LICENSE file for the full license text.
matscode/paystack-laravel-sdk 适用场景与选型建议
matscode/paystack-laravel-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 69 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「payment」 「sdk」 「stripe」 「laravel」 「processor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 matscode/paystack-laravel-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 matscode/paystack-laravel-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 matscode/paystack-laravel-sdk 相关的其它包
同方向 / 同关键字的高下载量 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
统计信息
- 总下载量: 69
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-22