iamolayemi/laravel-paystack
Composer 安装命令:
composer require iamolayemi/laravel-paystack
包简介
A laravel package for working with paystack api
README 文档
README
A comprehensive Laravel package for seamless integration with the Paystack payment gateway. This package provides an expressive and convenient way to interact with the Paystack API within your Laravel application.
✨ Features
- 🚀 Fluent API Interface - Clean and intuitive method chaining
- 🛡️ Comprehensive Error Handling - Custom exception classes for different error types
- 🔒 Security First - Built-in validation and security checks
- 📊 Full API Coverage - Support for all Paystack API endpoints
- 🧪 Extensive Testing - High test coverage with mock support
- 📚 Excellent Documentation - Comprehensive guides and examples
- 🔧 Developer Friendly - Easy setup and configuration
- ⚡ Performance Optimized - Efficient HTTP client with retry logic
- 🌍 Multi-Currency Support - NGN, GHS, USD, and more
- 🔄 Webhook Support - Built-in webhook handling and verification
📋 Requirements
- PHP: ^8.1|^8.2|^8.3
- Laravel: ^9.0|^10.0|^11.0
- Composer: ^2.0
🚀 Installation
You can install the package via Composer:
composer require iamolayemi/laravel-paystack
The package will automatically register itself if you're using Laravel's auto-discovery feature.
⚙️ Configuration
Environment Variables
Add your Paystack credentials to your .env file:
PAYSTACK_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxx PAYSTACK_PUBLIC_KEY=pk_test_xxxxxxxxxxxxxxxxxxxxx PAYSTACK_CALLBACK_URL=https://yourdomain.com/paystack/callback PAYSTACK_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxxxxxxxxxx
Publishing Configuration (Optional)
php artisan vendor:publish --provider="Iamolayemi\Paystack\PaystackServiceProvider"
📖 Quick Start
Basic Usage
use Iamolayemi\Paystack\Facades\Paystack; // Initialize a payment $paymentData = [ 'amount' => 500000, // 5000 NGN in kobo 'email' => 'customer@example.com', 'reference' => 'PAY_' . uniqid(), 'callback_url' => 'https://yourdomain.com/payment/callback', ]; $response = Paystack::transaction() ->initialize($paymentData) ->response(); if ($response['status']) { $authorizationUrl = $response['data']['authorization_url']; // Redirect user to $authorizationUrl }
Using Helper Function
// Using the helper function $response = paystack()->transaction() ->initialize($paymentData) ->response();
Getting Specific Data
// Get only the authorization URL $authorizationUrl = Paystack::transaction() ->initialize($paymentData) ->response('data.authorization_url'); // Or use the dedicated method $authorizationUrl = Paystack::transaction() ->initialize($paymentData) ->authorizationURL();
Verifying Transactions
// Verify a transaction $reference = 'PAY_xxxxxxxxx'; $verification = Paystack::transaction() ->verify($reference) ->response(); if ($verification['status'] && $verification['data']['status'] === 'success') { // Payment was successful $amount = $verification['data']['amount']; $customerEmail = $verification['data']['customer']['email']; }
🔧 Available Endpoints
The package provides access to all Paystack API endpoints:
Transactions
Paystack::transaction()->initialize($data); Paystack::transaction()->verify($reference); Paystack::transaction()->list($params); Paystack::transaction()->fetch($id);
Customers
Paystack::customer()->create($data); Paystack::customer()->list($params); Paystack::customer()->fetch($emailOrCode); Paystack::customer()->update($code, $data);
Transfers
Paystack::transfer()->initiate($data); Paystack::transfer()->finalize($data); Paystack::transfer()->list($params); Paystack::transfer()->fetch($code);
Plans & Subscriptions
Paystack::plan()->create($data); Paystack::plan()->list($params); Paystack::subscription()->create($data); Paystack::subscription()->list($params);
And Many More...
- Banks: List banks, resolve account numbers
- Countries: List countries and states
- Invoices: Create and manage invoices
- Products: Product management
- Refunds: Process refunds
- Settlements: Settlement management
- Splits: Split payment configuration
- Sub-accounts: Sub-account management
🛡️ Error Handling
The package provides comprehensive error handling with custom exception classes:
use Iamolayemi\Paystack\Exceptions\PaystackApiException; use Iamolayemi\Paystack\Exceptions\PaystackValidationException; use Iamolayemi\Paystack\Exceptions\PaystackConnectionException; try { $response = Paystack::transaction()->initialize($data)->response(); } catch (PaystackValidationException $e) { // Handle validation errors $errors = $e->getErrors(); } catch (PaystackApiException $e) { // Handle API errors $message = $e->getMessage(); $endpoint = $e->getEndpoint(); } catch (PaystackConnectionException $e) { // Handle connection errors $url = $e->getUrl(); }
🧪 Testing
Running Tests
# Run all tests composer test # Run with coverage composer test-coverage # Run specific test vendor/bin/phpunit --filter=TransactionTest
Mock Testing
use Illuminate\Support\Facades\Http; Http::fake([ 'api.paystack.co/transaction/initialize' => Http::response([ 'status' => true, 'message' => 'Authorization URL created', 'data' => [ 'authorization_url' => 'https://checkout.paystack.com/0x234567', 'reference' => 'TEST_REF_123', ], ], 200), ]);
📚 Documentation
For detailed documentation, visit https://laravel-paystack.netlify.app
Additional Resources
🔧 Development
Prerequisites
- PHP: ^8.1|^8.2|^8.3
- Composer: ^2.0
- Node.js: ^16.0 (for documentation)
Quick Setup
# Clone the repository git clone https://github.com/iamolayemi/laravel-paystack.git cd laravel-paystack # Install dependencies composer install # Run all checks to ensure everything is working make ci
Available Commands
The project uses a comprehensive Makefile for development tasks:
# Show all available commands make help # Install dependencies make install # Development workflow make dev-setup # Complete development setup make dev-install # Install development dependencies
Testing Commands
# Run all tests make test # Run tests with coverage report make test-coverage # Run specific test file vendor/bin/phpunit tests/Unit/TransactionEndpointTest.php # Run tests with specific filter vendor/bin/phpunit --filter=testTransactionInitialization
Code Quality Commands
# Run static analysis with PHPStan make analyse # Fix code style issues automatically make fix # Check code style without fixing make fix-dry-run # Run all code quality checks make check
Security & Validation
# Check for security vulnerabilities make security-check # Validate composer.json make validate
CI/CD Commands
# Run complete CI pipeline (test + analyse + style + security) make ci # Run all checks (test + analyse + style) make check
Maintenance Commands
# Clean build artifacts make clean # Update dependencies make update # Update only composer.lock make update-lock # Build the package for production make build
Documentation Commands
# Generate documentation make docs # Build documentation (if using docs package) cd docs && npm install && npm run build
Docker Commands (Optional)
# Build Docker image make docker-build # Run tests in Docker make docker-test # Run shell in Docker container make docker-shell
Release Commands
# Release patch version (1.0.0 -> 1.0.1) make release-patch # Release minor version (1.0.0 -> 1.1.0) make release-minor # Release major version (1.0.0 -> 2.0.0) make release-major
Development Workflow
- Setup:
make dev-setup - Make changes: Edit code
- Test:
make test - Check quality:
make analyse - Fix style:
make fix - Full validation:
make ci - Commit:
git commit -m "Your message" - Push:
git push
Code Quality Standards
The project enforces high code quality standards:
- PHPStan Level 8: Strict static analysis
- Laravel Pint: PSR-12 coding standards
- PHPUnit: 100% test coverage target
- Security Checker: Vulnerability scanning
Testing Strategy
# Run all tests make test # Run with coverage (generates HTML report) make test-coverage # Run specific test suite vendor/bin/phpunit --testsuite=Unit vendor/bin/phpunit --testsuite=Feature # Run tests with verbose output vendor/bin/phpunit --verbose # Run tests with stop on failure vendor/bin/phpunit --stop-on-failure
Static Analysis
# Run PHPStan analysis make analyse # Run with specific level vendor/bin/phpstan analyse --level=8 # Generate baseline (for ignoring existing errors) vendor/bin/phpstan analyse --generate-baseline
Code Style
# Fix all code style issues make fix # Check what would be fixed make fix-dry-run # Fix specific file vendor/bin/pint src/Endpoints/Transaction.php
Troubleshooting
# If tests fail, try cleaning and reinstalling make clean composer install make test # If PHPStan fails, check configuration vendor/bin/phpstan analyse --debug # If style check fails, auto-fix make fix
IDE Setup
For the best development experience:
- PHPStorm/IntelliJ: Enable PHPStan integration
- VS Code: Install PHP extensions
- EditorConfig: Project includes
.editorconfig - PHP CS Fixer: Configuration in
.php-cs-fixer.php
Pre-commit Hooks
Consider setting up pre-commit hooks:
# Create pre-commit hook cat > .git/hooks/pre-commit << 'EOF' #!/bin/sh make ci EOF chmod +x .git/hooks/pre-commit
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
- Fork the repository
- Clone your fork
- Install dependencies:
composer install - Run tests:
make test - Make your changes
- Ensure all tests pass:
make ci - Submit a pull request
🐛 Bug Reports
If you discover any bugs, please create an issue on GitHub.
🔒 Security
If you discover any security-related issues, please email olatayo.olayemi.peter@gmail.com instead of using the issue tracker.
📄 License
The MIT License (MIT). Please see License File for more information.
🙏 Credits
- Olayemi Olatayo - Original author
- All Contributors - Community contributors
- Paystack - Payment gateway provider
🔗 Links
📊 Statistics
iamolayemi/laravel-paystack 适用场景与选型建议
iamolayemi/laravel-paystack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 650 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「paystack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iamolayemi/laravel-paystack 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iamolayemi/laravel-paystack 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iamolayemi/laravel-paystack 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Implementation of Paystack API
A simple interface to Paystack's subscription billing services. It takes the pain of implementing subscription management off you.
A Laravel Package for Paystack
A Laravel Package for Paystack
Alfabank REST API integration
A Laravel Package for Paystack
统计信息
- 总下载量: 650
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-16