intune/laravel-paystack
Composer 安装命令:
composer require intune/laravel-paystack
包简介
Utility API Layer for Paytstack Integration
README 文档
README
A Laravel package for seamless integration with the Paystack payment gateway. This package provides various functionalities, including customer management, transaction initialization, subscription handling, and more.
Features
- Create and manage customers on Paystack.
- Initialize transactions for purchases and subscriptions.
- Handle subscriptions: create, manage, enable, and disable.
- Validate account numbers and retrieve a list of banks.
- Initiate transfers and check balances.
Installation
You can install the package via Composer:
composer require intune/laravel-paystack
Configuration
After installation, publish the configuration file using the following command:
php artisan vendor:publish --provider="Intune/laravel-paystack\PaystackServiceProvider"
This will create a paystack.php file in your config directory, where you can set your Paystack API credentials:
return [ 'secret' => env('PAYSTACK_SECRET_KEY'), 'plan_code' => env('PAYSTACK_PLAN_CODE'), 'redirect_url' => env('PAYSTACK_REDIRECT_URL'), 'white_list' => env('PAYSTACK_WHITE_LIST'), ];
Make sure to add the following environment variables to your .env file:
PAYSTACK_SECRET_KEY=your_paystack_secret_key
PAYSTACK_PLAN_CODE=your_paystack_plan_code
PAYSTACK_REDIRECT_URL=your_redirect_url
PAYSTACK_WHITE_LIST=your_white_list
Usage
Creating a Customer
To create a new customer on Paystack:
use Intune\LaravelPaystack\Dtos\UserDto; use Intune\LaravelPaystack\PaystackService; $paystackService = app(PaystackService::class); $userDto = UserDto::create([ 'email' => 'user@example.com', 'first_name' => 'John', 'last_name' => 'Doe', 'phone_number' => '1234567890', // Optional ]); $customer = $paystackService->createCustomer($userDto);
Initializing a Transaction
To initialize a transaction:
$email = 'customer@example.com'; $amount = 1000; // Amount in kobo (1000 kobo = 10 NGN) $dto = TransactionInitPayloadDto::create([ 'email' => $email, 'amount' => $amount, // other transaction details ]); $transaction = $paystackService->initializePurchaseTransaction($dto);
Subscribing a Customer
To create a subscription for a customer:
$customer_id = 'customer_id_from_paystack'; $subscription = $paystackService->createSubscription($customer_id);
Managing a Subscription
To get a link for managing a subscription:
$subscription_id = 'subscription_id'; $manageLink = $paystackService->manageSubscription($subscription_id);
Validating a Webhook
To validate a Paystack webhook:
$payload = request()->getContent(); $signature = request()->header('x-paystack-signature'); if ($paystackService->isValidPaystackWebhook($payload, $signature)) { // Valid webhook }
Available Methods
createCustomer(UserDto $user): CustomerDtofetchCustomer(string $email): ?CustomerDtoinitializePurchaseTransaction(TransactionInitPayloadDto $data): TransactionInitializationDtoinitializeSubscriptionTransaction(string $email, int $amount): TransactionInitializationDtocreateSubscription(string $customer_id): SubscriptionDtomanageSubscription(string $subscription_id): stringfetchSubscription(string $subscription_id): ?SubscriptionDtoenableSubscription(string $subscription_id): booldisableSubscription(string $subscription_code): boolisValidPaystackWebhook($payload, $signature): boolfetchBanks(): ?CollectionvalidateAccountNumber(string $account_number, string $bank_code): boolcheckPTBalanceIsSufficient(int $amount): boolcreateTransferRecipient($name, $account_number, $bank_code): TransferRecipientDtoinitiateTransfer(string $amount, string $recipient_code, string $reference): TransferDto
License
This package is licensed under the MIT License. See the LICENSE file for more information.
intune/laravel-paystack 适用场景与选型建议
intune/laravel-paystack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 44 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 intune/laravel-paystack 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 intune/laravel-paystack 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-16