承接 chainbook/paystack 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chainbook/paystack

最新稳定版本:v1.0.0

Composer 安装命令:

composer require chainbook/paystack

包简介

A Laravel package for seamless Paystack payment integration — initialize transactions, verify payments, manage customers, plans and subscriptions.

README 文档

README

Latest Version on Packagist Total Downloads License

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.

统计信息

  • 总下载量: 101
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固