承接 codejutsu1/laravel-paystack-transfer 相关项目开发

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

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

codejutsu1/laravel-paystack-transfer

Composer 安装命令:

composer require codejutsu1/laravel-paystack-transfer

包简介

An Elegant laravel package to make single and bulk transfers using paystack.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status License Total Downloads

A Laravel package to make single and bulk transfers with Paystack.

Installation

PHP 8.2+ and Composer are required.

Compatible with Laravel 9, 10, 11.

  • Install the package via composer:

    composer require codejutsu1/laravel-paystack-transfer
  • Optional you can publish the config file via this command:

    php artisan paystack-transfer:install

    A configuration file named paystack-transfer.php will be placed in the config folder of your laravel application:

    <?php
    
    // config for Codejutsu1/LaravelPaystackTransfer
    return [
        /**
         * Public Key From Paystack Dashboard
         *
         */
        'public_key' => env('PAYSTACK_PUBLIC_KEY'),
    
        /**
         * Secret Key From Paystack Dashboard
         *
         */
        'secret_key' => getenv('PAYSTACK_SECRET_KEY'),
    
    ];

Usage

Open your .env file and add your public and secret API keys.

PAYSTACK_PUBLIC_KEY=
PAYSTACK_SECRET_KEY=

Table of Contents

Payment Flow

  1. To make a transfer, either single or in bulk using this package, you need to provide an array of four parameters:
    • amount - Amount to be sent.
    • reference (Transfer Reference) - A unique identifier which will be used to track your transactions. This package provides a helper function, generateTransferReference(), which returns a UUID you can use as a unique reference.
    • recipient (Transfer Recipient) - A transfer recipient is a beneficiary that you can send money to. To create a transfer recipient, you need to collect their details first.
    • reason - Reason for the transfer.
    • currency - (Optional) NGN by default but you can specify your currency.
<?php

$transfers = [
    "amount": "37800",
    "reference": "your-unique-reference", 
    "recipient": "RCP_t0ya41mp35flk40", 
    "reason": "Holiday Flexing" 
];
  1. Each request returns a response as an object containing:
    • status (boolean)
    • message (string)
    • data (array)
    • meta (array)

Transfer Recipient

Create Single Transfer Recipient

To create a single transfer recipient:

<?php 

$data = [
    "type" => "nuban", //Recipient type, either nuban, ghipps, mobile_money or bass
    "name" => "Daniel Dunu", //Recipient name
    "account_number" => "01000000010", // Recipient Account Number
    "bank_code" => "058", // Recipient bank code
    "currency" => "NGN", // Recipient Currency
];

try{
    $response = PaystackTransfer::createTransferRecipient($data);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code Logic
}

Important

Store the recipient_code in your database alongside the recipient. For more information, visit Paystack Create Transfer Recipient.

Create Bulk Transfer Recipient

You can create multiple transfer recipient no matter the number of batches. To create multiple transfer recipient:

<?php 

$data = [
    [
        "type" => "nuban", //Recipient type, either nuban, ghipps, mobile_money or bass
        "name" => "Daniel Dunu", //Recipient name
        "account_number" => "01000000010", // Recipient Account Number
        "bank_code" => "058", // Recipient bank code
        "currency" => "NGN", // Recipient Currency
    ],
    [
        "type" => "ghipps", //Recipient type, either nuban, ghipps, mobile_money or bass
        "name" => "John Doe", //Recipient name
        "account_number" => "02000000020", // Recipient Account Number
        "bank_code" => "018", // Recipient bank code
        "currency" => "NGN", // Recipient Currency
    ],
];

try{
    $response = PaystackTransfer::bulkTransferRecipient($data);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code Logic
}

Note

For more information, visit Paystack Bulk Create Transfer Recipient

List Transfer Recipients

To list all transfer recipients:

<?php

try{
    $response = PaystackTransfer::listTransferRecipients();
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Eg of code logic
    $transferRecipients = collect($response->data);

    return $transferRecipients;
}

You can also provide query parameters as an array:

<?php

$queryParameters = [
    "perPage" => 30, //Integer(optional), Records per page.
    "page" => 2, //Integer(optional), exact page to retrieve.
    "from" => "2016-09-24T00:00:05.000Z", //dateTime(optional), Timestamp to start listing transfer recipient.
    "to" => "2016-09-24T00:00:05.000Z", //dateTime(optional), Timestamp to stop listing transfer recipient
];

try{
    $response = PaystackTransfer::listTransferRecipients($queryParameters);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

return $response;

Note

For more information, visit Paystack List Transfer Recipients.

Fetch a Transfer Recipient

To fetch a transfer recipient, you need to provide the id or recipient code of the recipient:

<?php

try{
    $response = PaystackTransfer::fetchTransferRecipient("RCP_2x5j67tnnw1t98k");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code logic here
}

Note

For more information, visit Paystack Fetch Transfer Recipient.

Update a Transfer Recipient

To update a transfer recipient details, you need to provide the id or recipient code of the recipient alongside the details to be updated (name and/or email):

<?php

$data = [
    'email' => 'danieldunu001@gmail.com'
];

try{
    $response = transfer()->updateTransferRecipient("RCP_2x5j67tnnw1t98k", $data);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code logic here
}

Note

For more information, visit Paystack Update Transfer Recipient.

Delete a Transfer Recipient

To delete a transfer recipient, you need to provide the id or recipient code of the recipient:

<?php

try{
    $response = transfer()->deleteTransferRecipient("RCP_2x5j67tnnw1t98k");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    // Your code logic here
}

Note

For more information, visit Paystack Delete Transfer Recipient.

Banks

Get Banks API

To get lists of banks in Nigeria:

<?php

try{
    $response = transfer()->getBanks();
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    $banks = collect($response->data); // To a collection.

    // Your logic
}

You can also provide query parameters as an array:

<?php 

$queryParameters = [
    "country" => "ghana", //String(Optional), nigeria or ghana, default is nigeria
    "perPage" => 50,  //Integer(optional), Records per page.
    //Other query parameters in the documentation.
];

try{
    $response = transfer()->getBanks($queryParameters);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

return $response;

Note

For more information, visit Paystack List Banks API.

Get Bank Code

To get a bank code, you need to provide the bank name from the get bank API:

<?php 

try{
    $code = transfer()->getBankCode("United Bank For Africa");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

return $code;

Verify Account Number

To confirm the account belongs to the right customer, you need to provide the account number and the bank code of the customer as both strings:

<?php

try{
    $response = PaystackTransfer::verifyAccountNumber(accountNumber:"2134288420", bankCode:"022");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}

Note

For more information, visit Paystack Resolve Account.

Transfers

Single Transfers

To make a single transfers, you need these provide four parameters as an array:

  • reason
  • amount
  • reference
  • recipient

The currency is NGN by default. You can override the default currency by adding it to the array. For the source, we took care of that by merging the array with a value of balance.

<?php

$parameters = [
	"reason": "Savings",
	"amount": 300000, //NGN3000, converted to kobo. 
	"reference": "your-unique-reference",
	"recipient": "RCP_1a25w1h3n0xctjg"
];
try{
    $response = PaystackTransfer::singleTransfer($parameters);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your code logic
}

Note

For more information, visit Paystack Single Transfers.

Finalize a Transfer

After making a single transfer with OTP enabled, you will have to finalized your transfer by providing the OTP and the transfer code as both strings:

<?php

try{
    $response = transfer()->finalizeTransfer(transfer_code:"TRF_vsyqdmlzble3uii", otp: "930322");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}

Note

For more information, visit Paystack Finalize Transfers.

Bulk Transfers

To send money to multiple recipients, you need to make request in batches. A batch is an array of arrays containing the transfer parameters. A batch should not contain more than 100 arrays.

<?php

$transfers = [
    [
        "amount"=> 20000,
        "reference"=> "588YtfftReF355894J",
        "reason"=> "Why not?",
        "recipient"=> "RCP_2tn9clt23s7qr28",    
    ],
    [
        "amount"=> 30000,
        "reference"=> "YunoTReF35e0r4J",
        "reason"=> "Because I can",
        "recipient"=> "RCP_1a25w1h3n0xctjg",    
    ],
    [
        "amount"=> 40000,
        "reference"=> generateTransferReference(),
        "reason"=> "Go buy your mama a house",
        "recipient"=> "RCP_aps2aibr69caua7",
    ]
];

try{
    $response = PaystackTransfer::bulkTransfer($transfers);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}

If the batch should contain more than 100 arrays, it should be broken down into batches, each containing 100 arrays and each batch should be sent every 5 seconds.

But you don't have to worry about that, just pass the batch (even if its contains more than 100 arrays) as a parameter in the batchTransfer method. This package will proceed to break it down into batches, each containing not more than 100 arrays and will make a request every 5 seconds.

Note

It will return an array of response instead of an object for each request being made.

<?php

$transfers = [
    [
        "amount"=> 20000,
        "reference"=> "588YtfftReF355894J",
        "reason"=> "Why not?",
        "recipient"=> "RCP_2tn9clt23s7qr28",    
    ],
    [
        "amount"=> 30000,
        "reference"=> "YunoTReF35e0r4J",
        "reason"=> "Because I can",
        "recipient"=> "RCP_1a25w1h3n0xctjg",    
    ],
    [
        "amount"=> 40000,
        "reference"=> generateTransferReference(),
        "reason"=> "Go buy your mama a house",
        "recipient"=> "RCP_aps2aibr69caua7",
    ],
    //.... > 97 more arrays
];

try{
    $response = PaystackTransfer::batchTransfer($transfers);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}

Note

You need to set up webhooks to keep track of your transfers. For more information, visit Paystack Bulk Transfers.

List Transfers

Paystack gives you the option to get the list of all your transfers:

<?php

try{
    $response = PaystackTransfer::listTransfers();
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}

You can also provide query parameters as an array:

$queryParameters = [
    "perPage" => 30, //Integer(optional), Records per page.
    "page" => 2, //Integer(optional), exact page to retrieve.
    "customer" => "12121", //String(optional), filter by id.
    "from" => "2016-09-24T00:00:05.000Z", //dateTime(optional), Timestamp to start listing transfer recipient.
    "to" => "2016-09-24T00:00:05.000Z", //dateTime(optional), Timestamp to stop listing transfer recipient
];

try{
    $response = PaystackTransfer::listTransfers($queryParameters);
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

return $response;

Note

For more information, visit Paystack List Transfers.

Fetch a Transfer

Get details of a transfer. You need to provide transfer id.

<?php

try{
    $response = PaystackTransfer::fetchTransfer("14938");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your logic
}

Note

For more information, visit Paystack Fetch Transfers.

Verify a Transfer

Verify the status of a transfer. You need to provide transfer reference.

try{
    $response = PaystackTransfer::verifyTransfer("your_reference");
}catch(\Exception $e){
    return redirect()->back()->withMessage($e->getMessage());
}

if($response->status){
    //Your code logic
} 

Note

For more information, visit Paystack Verify Transfers.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Feel free to submit Issues (for bugs or suggestions) and Pull Requests(to the dev branch).

Security Vulnerabilities

If you discover a security vulnerability within this package, please send an email to Daniel Dunu at danieldunu001@gmail.com. All security vulnerabilities will be promptly addressed..

TODO

  • Write test for integrating third party APIs.
  • If your business is a registered business, test the transfer feature with your test API Keys and give feedbacks.

Credits

License

The MIT License (MIT). Please see License File for more information.

codejutsu1/laravel-paystack-transfer 适用场景与选型建议

codejutsu1/laravel-paystack-transfer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 04 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「Bank API」 「Daniel Dunu」 「laravel-paystack-transfer」 「single and bulk transfers」 「paystack transfer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 codejutsu1/laravel-paystack-transfer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codejutsu1/laravel-paystack-transfer 我们能提供哪些服务?
定制开发 / 二次开发

基于 codejutsu1/laravel-paystack-transfer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-10