定制 bhekor/laravel-monnify 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

bhekor/laravel-monnify

Composer 安装命令:

composer require bhekor/laravel-monnify

包简介

A laravel package to seamlessly integrate monnify api within your laravel application

README 文档

README

Build Status Latest Version on Packagist Latest Stable Version Total Downloads License Quality Score

A laravel package to seamlessly integrate monnify api within your laravel application

What is Monnify

Monnify is a leading payment technology that powers seamless transactions for businesses through omnichannel platforms

Create a Monnify Account Sign Up.

Look up Monnify API Documentation API Documentation.

Installation

You can install the package via composer:

composer require bhekor/laravel-monnify

Publish Monnify configuration file, migrations as well as set default details in .env file:

php artisan monnify:init

Laravel Monnify Webhook Event (RESERVED ACCOUNT SHOULD USE THIS)

To handle Monnify Webhook event-based notifications, the Laravel Monnify already include all required webhook endpoints Log on to your Monnify Dashboard Setting, under Developer menu, select Webhook URLs and set the respective webhook URL as follows:

  • Transaction completion https://your_domain/laravel-monnify/webhook/transaction-completion
  • Refund completion https://your_domain/laravel-monnify/webhook/refund-completion
  • Disbursement https://your_domain/laravel-monnify/webhook/disbursement
  • Settlement https://your_domain/laravel-monnify/webhook/settlement

NOTE: Make sure you replace your_domain with your server url e.g. example.com

LEGACY Webhook

To handle Monnify LEGACY Webhook notification the Laravel Monnify already include the webhook endpoint https://your_domain/laravel-monnify/webhook, replace your_domain with your server url e.g. example.com

  • Log on to your Monnify Dashboard Setting, select API Keys & Webhooks and set your webhook to https://your_domain/laravel-monnify/webhook
Setup Listener

Next, create an Event Listener by running the command below within your project directory;

php artisan make:listener MonnifyNotificationListener -e NewWebHookCallReceived

The NewWebHookCallReceived has two properties:

  • WebHookCall webHookCall => This is an unguarded Model with property dump from the webhook call $event->webHookCall->transactionReference gives you the transactionReference from the webhook call, learn more about Transaction Completion Webhook properties on Monnify API Docs Here
  • bool isValidTransactionHash => This does the transaction hash calculation for you ahead of time, if you prefer doing it yourself; Monnify::Transactions()->calculateHash($event->webHookCall->paymentReference, $event->webHookCall->amountPaid, $event->webHookCall->paidOn, $event->webHookCall->transactionReference); Laravel Monnify Webhook Event

Please see MonnifyLegacyNotificationListener.example.txt for LEGACY sample implementation of the MonnifyNotificationListener. Please see MonnifyNotificationListener.example.txt for LEGACY sample implementation of the MonnifyNotificationListener.



Note

To ensure your listener works correctly, you have to register the event within in your App\Providers\EventServiceProvider manually if auto discovery isn't turned on

Manually Registering Events

Typically, events should be registered via the EventServiceProvider $listen array; however, you may also register class or closure based event listeners manually in the boot method of your EventServiceProvider: Learn More about manually registering events

use Bhekor\LaravelMonnify\Events\NewWebHookCallReceived;
use App\Listeners\MonnifyNotificationListener;

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
//    ... Other Event Registeration
    NewWebHookCallReceived::class => [
        MonnifyNotificationListener::class,
//    ... Other Listener you wish to also receive the WebHook call event
    ],
];

or

Turn On Event Discovery

Event discovery is disabled by default, but you can enable it by overriding the shouldDiscoverEvents method of your application's EventServiceProvider: Learn More about Event Discovery

/**
 * Determine if events and listeners should be automatically discovered.
 *
 * @return bool
 */
public function shouldDiscoverEvents()
{
    return true;
}

Usage

To use the monnify package you must import the Monnify Facades with the import statement below; Other Classes import is based on your specific usage and would be highlighted in their corresponding sections. You'll also need to import the MonnifyFailedRequestException and handle the exception as all failed request will throw this exception the with the corresponding monnify message and code Learn More

    //...
    use Bhekor\LaravelMonnify\Facades\Monnify;
    use Bhekor\LaravelMonnify\Exceptions\MonnifyFailedRequestException;
//...

Important Notice!!!

Migrating from Previous Version of Laravel Monnify

This new changes reflect my concern for modular code base, I'm certain you should not have any issues migrating and refactoring your codebase, but if you do, kindly contact me or use the issues tab, and I will make sure your concerns are all attended to. The Monnify class has been broken down grouping all actions into five(5) classes, Banks, CustomerReservedAccounts, Disbursements, SubAccounts, and Transactions see example usage below:

    //...
    use Bhekor\LaravelMonnify\Facades\Monnify;
    //...

    $responseBody = Monnify::Transactions()->initializeTransaction(float $amount, string $customerName, string $customerEmail, string $paymentReference, string $paymentDescription, string $redirectUrl, MonnifyPaymentMethods $monnifyPaymentMethods, MonnifyIncomeSplitConfig $incomeSplitConfig = null, string $currencyCode = null);
    $responseBody = Monnify::Transactions()->getAllTransactions(array $queryParams);
    $responseBody = Monnify::Transactions()->calculateHash(string $paymentReference, $amountPaid, string $paidOn, string $transactionReference);
    $responseBody = Monnify::Transactions()->getTransactionStatus(string $transactions);
    $responseBody = Monnify::Transactions()->payWithBankTransfer(string $transactionReference, string $bankCode);

Before

    //...
    use Bhekor\LaravelMonnify\Facades\Monnify;
    use Bhekor\LaravelMonnify\Classes\MonnifyPaymentMethod;
    use Bhekor\LaravelMonnify\Classes\MonnifyPaymentMethods;
    //...
    
    Monnify::initializeTransaction(
                        15000, "Customer Name", "customer@example.com", "transaction_ref", "Transaction Description",
                        "https://youdomain.com/afterpaymentendpoint", new MonnifyPaymentMethods(MonnifyPaymentMethod::CARD(), MonnifyPaymentMethod::ACCOUNT_TRANSFER()));

Now

    //...
    use Bhekor\LaravelMonnify\Facades\Monnify;
    use Bhekor\LaravelMonnify\Classes\MonnifyPaymentMethod;
    use Bhekor\LaravelMonnify\Classes\MonnifyPaymentMethods;
    //...

    Monnify::Transactions()->initializeTransaction(
                        15000, "Customer Name", "customer@example.com", "transaction_ref", "Transaction Description",
                        "https://youdomain.com/afterpaymentendpoint", new MonnifyPaymentMethods(MonnifyPaymentMethod::CARD(), MonnifyPaymentMethod::ACCOUNT_TRANSFER()));

Similar implementation applies to other sections (i.e. Banks, CustomerReservedAccounts, Disbursements, and SubAccounts)

    //...
    use Bhekor\LaravelMonnify\Facades\Monnify;
    //...
    $responseBody = Monnify::Banks()->getBanks();
    $responseBody = Monnify::Banks()->getBanksWithUSSDShortCode();
    $responseBody = Monnify::Banks()->validateBankAccount(MonnifyBankAccount $bankAccount);

    $responseBody = Monnify::Disbursements()->initiateTransferSingle(float $amount, string $reference, string $narration, MonnifyBankAccount $bankAccount, string $currencyCode = null);
    $responseBody = Monnify::Disbursements()->initiateTransferSingleWithMonnifyTransaction(MonnifyTransaction $monnifyTransaction);
    $responseBody = Monnify::Disbursements()->initiateTransferBulk(string $title, string $batchReference, string $narration, MonnifyOnFailureValidate $onFailureValidate, int $notificationInterval, MonnifyTransactionList $transactionList);
    $responseBody = Monnify::Disbursements()->authorizeTransfer2FA(string $authorizationCode, string $reference, string $path);


    $responseBody = Monnify::SubAccounts()->createSubAccount(string $bankCode, string $accountNumber, string $email, string $currencyCode = null, string $splitPercentage = null);
    $responseBody = Monnify::SubAccounts()->createSubAccounts(array $accounts);
    $responseBody = Monnify::SubAccounts()->getSubAccounts();
    $responseBody = Monnify::SubAccounts()->deleteSubAccount(string $subAccountCode);

    
    $responseBody = Monnify::ReservedAccounts()->getAllTransactions(array $queryParams);
    $responseBody = Monnify::ReservedAccounts()->reserveAccount(string $accountReference, string $accountName, string $customerEmail, string $customerName = null, string $customerBvn = null, string $currencyCode = null, bool $restrictPaymentSource = false, MonnifyAllowedPaymentSources $allowedPaymentSources = null, MonnifyIncomeSplitConfig $incomeSplitConfig = null);
    $responseBody = Monnify::ReservedAccounts()->getAccountDetails(string $accountReference);
    $responseBody = Monnify::ReservedAccounts()->updateSplitConfig(string $accountReference, MonnifyIncomeSplitConfig $incomeSplitConfig);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Bugs & Issues

If you notice any bug or issues with this package kindly create and issues here ISSUES

Security

If you discover any security related issues, please email adeoluibidapo@gmail.com instead of using the issue tracker.

Credits

License

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

bhekor/laravel-monnify 适用场景与选型建议

bhekor/laravel-monnify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.69k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-27