tohidplus/mellat
Composer 安装命令:
composer require tohidplus/mellat
包简介
A Laravel package for connecting to (Iran) Mellat bank gateway.
README 文档
README
Laravel package for Mellat bank
This package is built for connecting Iranian websites to Mellat bank gateway.
Installation
- Run the command below
composer require tohidplus/mellat
- Add the following code to end of the providers array in config/app.php file.
'providers' => [ Tohidplus\Mellat\MellatServiceProvider::class, ];
- Add the following code to end of the aliases array in config/app.php file.
'aliases' => [ 'Mellat' => Tohidplus\Mellat\Facades\Mellat::class, ];
- Run the command below
php artisan vendor:publish --provider=Tohidplus\Mellat\MellatServiceProvider
- Migrate the database
php artisan migrate
- Now you can see a new config file named mellat.php is added to config directory. So open the file...
<?php return [ 'terminalId' => 'your-temrinalId', 'username' => 'your-username', 'password' => 'your-password', 'callBackUrl' => 'http://yourwebsite.com/verifyPayment', 'convertToRial' => true ];
Fill the array elements
Notice: you can leave callBackUrl here blanked and initialize it dynamically by using setCallBackUrl method as we will explain
- Now you have to exclude callBackUrl from verifyCsrfToken middleware. Open the file app/Http/Middleware/VerifyCsrfToken.php and add the callbackUrl to except array.
protected $except = [ '/verifyPayment' ];
mellat.blade.php file
While redirecting user to the bank you will see a simple page with no design which is located inside the resources/views/vendor/mellat directory. So you can open this file and design it as you wish.
Methods
setCallBackUrl
if you haven't set callBackUrl in mellat.php config file you must set it using this method before redirecting user .
Parameters:
- callBackUrl (required)
set
Before redirecting user to the gateway you have to initialize the fields using this method otherwise you will get an exception.
Parameters:
- amount (Required - if the value of convertToRial in mellat.php file is true you must pass the value in Toman otherwise pass it in Rial.)
- orderId (Optional)
- payerId (Optional)
- additionalData (Optional)
redirect
after initializing the fields you can redirect user to the bank by using this method.
Parameters:
- It only accepts one parameter as a callback funtion and if there is an error while redirection the callback function will be triggered with error message as a parameter.
verify
This method indicates if transaction was successful or not.
Parameters:
- success is a callback function which will be triggered if the transaction was successful and accepts an instance of Tohidplus\Mellat\Models\MellatLog as a parameter.
- error is a callback function which will be triggered if the transaction was unsuccessful and accepts an instance of Tohidplus\Mellat\Models\MellatLog as a parameter.
Full example
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Tohidplus\Mellat\Facades\Mellat; class PaymentController extends Controller { public function redirectUserToBank() { //Mellat::setCallBackUrl(url('/verifyPayment')); Mellat::set(100); return Mellat::redirect(function($message){ // Do something if there was a problem while redirection //dd($message); }); } public function verifyPayment(Request $request) { return Mellat::verify( function ($log){ // The transaction is successfull //dd($log); },function ($log){ // The trasnsaction is unsuccessful //dd($log); }); } }
Transaction Logs
Simply all events are saved in mellat_logs table which is associated with Tohidplus\Mellat\Models\MellatLog model .
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Tohidplus\Mellat\Models\MellatLog; class MellatLogController extends Controller { public function index() { $successfulTransactions = MellatLog::successful()->get(); $unsuccessfulTransactions = MellatLog::unsuccessful()->get(); $pendingTransactions = MellatLog::pending()->get(); } }
tohidplus/mellat 适用场景与选型建议
tohidplus/mellat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 203 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tohidplus/mellat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tohidplus/mellat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 203
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-27