nikba/laravel-maib
Composer 安装命令:
composer require nikba/laravel-maib
包简介
Laravel 12 integration for the maib e-Commerce API — all payment types, token management, and webhook handling.
README 文档
README
A Laravel 12 package for the maib e-Commerce API — full coverage of all payment types, automatic token management, and HMAC-SHA256 callback webhook handling.
API documentation: https://docs.maibmerchants.md/e-commerce
Features
- Direct payment (one-step charge)
- Two-step payment (hold → capture or cancel)
- Recurring payments (register card + server-side execute)
- One-click payments (register card + redirect execute)
- Payment refund (partial or full)
- Payment information query
- Saved card deletion
- Callback webhook handling with HMAC-SHA256 signature validation
- Laravel Events dispatched on successful/failed callbacks
- Automatic Bearer token generation, caching, and refresh
- Full PHPUnit test suite
Requirements
| Version | |
|---|---|
| PHP | ^8.2 |
| Laravel | ^12.0 |
Installation
composer require nikba/laravel-maib
Publish the configuration
php artisan vendor:publish --tag=maib-config
Environment variables
Add the following to your .env file:
MAIB_PROJECT_ID=your-project-id MAIB_PROJECT_SECRET=your-project-secret MAIB_SIGNATURE_KEY=your-signature-key MAIB_ENV=sandbox MAIB_CALLBACK_ROUTE=/maib/callback
Credentials are available in maibmerchants.md under your project settings.
Configuration
After publishing, edit config/maib.php:
return [ 'project_id' => env('MAIB_PROJECT_ID'), 'project_secret' => env('MAIB_PROJECT_SECRET'), 'signature_key' => env('MAIB_SIGNATURE_KEY'), 'environment' => env('MAIB_ENV', 'production'), 'base_url' => 'https://api.maibmerchants.md/v1', 'callback_route' => env('MAIB_CALLBACK_ROUTE', '/maib/callback'), 'cache_driver' => env('MAIB_CACHE_DRIVER', null), 'cache_prefix' => 'maib_token', ];
Usage
Direct Payment
use Nikba\LaravelMaib\Facades\Maib; use Nikba\LaravelMaib\Dto\Requests\DirectPaymentRequest; use Nikba\LaravelMaib\Dto\PaymentItem; use Nikba\LaravelMaib\Enums\Currency; use Nikba\LaravelMaib\Enums\Language; $response = Maib::directPayment( new DirectPaymentRequest( amount: 99.99, currency: Currency::MDL, clientIp: $request->ip(), language: Language::RO, orderId: 'ORDER-001', description: 'Order #001', callbackUrl: route('maib.callback'), okUrl: route('payment.success'), failUrl: route('payment.fail'), items: [ new PaymentItem(id: '1', name: 'Product A', price: 99.99, quantity: 1), ], ) ); return redirect($response->payUrl);
Two-Step Payment (Hold → Capture)
use Nikba\LaravelMaib\Dto\Requests\CapturePaymentRequest; use Nikba\LaravelMaib\Dto\Requests\HoldPaymentRequest; // Step 1: Hold $hold = Maib::hold(new HoldPaymentRequest( amount: 99.99, currency: Currency::MDL, clientIp: $request->ip(), language: Language::RO, )); return redirect($hold->payUrl); // Step 2: Capture (after callback confirms hold) $capture = Maib::capture(new CapturePaymentRequest( payId: $payId, confirmAmount: 99.99, // optional — omit to capture full hold amount ));
Recurring Payments
use Nikba\LaravelMaib\Dto\Requests\ExecuteRecurringRequest; use Nikba\LaravelMaib\Dto\Requests\SaveCardRecurringRequest; // Registration (once per customer — redirect to 3DS checkout) $save = Maib::savecardRecurring(new SaveCardRecurringRequest( billerExpiry: '1228', clientIp: $request->ip(), currency: Currency::MDL, language: Language::RO, email: 'user@example.com', )); return redirect($save->payUrl); // Callback will return billerId — store it for the customer. // Server-side execution (no customer redirect) $response = Maib::executeRecurring(new ExecuteRecurringRequest( billerId: $user->maib_biller_id, amount: 29.99, currency: Currency::MDL, orderId: 'SUBSCRIPTION-' . now()->format('Y-m'), )); if ($response->status === \Nikba\LaravelMaib\Enums\TransactionStatus::OK) { // subscription renewed }
One-Click Payments
use Nikba\LaravelMaib\Dto\Requests\ExecuteOneclickRequest; use Nikba\LaravelMaib\Dto\Requests\SaveCardOneclickRequest; // Registration $save = Maib::savecardOneclick(new SaveCardOneclickRequest( billerExpiry: '1228', clientIp: $request->ip(), currency: Currency::MDL, language: Language::RO, email: 'user@example.com', )); return redirect($save->payUrl); // Execution (redirects customer to checkout for 3DS confirmation) $response = Maib::executeOneclick(new ExecuteOneclickRequest( billerId: $user->maib_biller_id, amount: 49.99, currency: Currency::MDL, clientIp: $request->ip(), language: Language::RO, )); return redirect($response->payUrl);
Refund
use Nikba\LaravelMaib\Dto\Requests\RefundRequest; $response = Maib::refund(new RefundRequest( payId: $payId, refundAmount: 30.00, // optional — omit to refund the full amount ));
Payment Info
$info = Maib::payInfo($payId); echo $info->status->value; // 'OK', 'FAILED', etc. echo $info->cardNumber;
Delete Saved Card
$response = Maib::deleteCard($billerId);
Handling Callbacks
The package automatically registers the callback route at MAIB_CALLBACK_ROUTE (default: /maib/callback). This route is excluded from CSRF middleware.
Register this URL in your maibmerchants.md project settings.
Allowed callback IPs (optional firewall rule): 91.250.245.70, 91.250.245.71, 91.250.245.142
Listening for Events
// In App\Providers\EventServiceProvider (or using #[AsEventListener]) use Nikba\LaravelMaib\Events\MaibPaymentFailed; use Nikba\LaravelMaib\Events\MaibPaymentReceived; Event::listen(MaibPaymentReceived::class, function (MaibPaymentReceived $event) { $payload = $event->payload; Order::where('maib_pay_id', $payload->payId) ->update([ 'status' => 'paid', 'rrn' => $payload->rrn, 'approval' => $payload->approval, 'card_number' => $payload->cardNumber, ]); }); Event::listen(MaibPaymentFailed::class, function (MaibPaymentFailed $event) { Order::where('maib_pay_id', $event->payload->payId) ->update(['status' => 'failed']); });
Important: Always return HTTP 200 from your listener logic — the package's callback handler already does this. maib retries the callback at increasing intervals (
10, 60, 300, 600, 3600, 43200, 86400seconds) if it does not receive a 200 response. Implement idempotency in your listeners.
Testing
composer test
Author
Nicolai Bargan
Nikba Creative Studio
office@nikba.com
License
The MIT License (MIT). See LICENSE for details.
nikba/laravel-maib 适用场景与选型建议
nikba/laravel-maib 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ecommerce」 「payment」 「gateway」 「laravel」 「recurring」 「maib」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nikba/laravel-maib 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nikba/laravel-maib 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nikba/laravel-maib 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Nevogate Payment Gateway SDK
Payyo Gateway for the Omnipay payment processing library
Dealing with payments through the Egyptian payment gateway PayMob
A PHP (and Laravel) package to interface with the Snipcart api.
Client library to send SMS using Comilio SMS Gateway API (https://www.comilio.it)
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-15