ayman-elmalah / laravel-myfatoorah
My fatoorah API 包装器
v1.0.7
2023-01-22 21:34 UTC
Requires
- php: ^7.4|^8.0
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ^6.0|^7.0
- illuminate/http: ^6.0|^7.0|^8.0|^9.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0
This package is not auto-updated.
Last update: 2024-09-30 05:12:22 UTC
README
laravel myfatoorah 是一个由 Ayman Elmalah 编写的 PHP 包,使用 Laravel 处理 Myfatoorah 功能,使其 API 更加容易使用。
特性
- 创建发票
- 返回支付
- 检查支付是否成功
- 动态更改令牌
- 退款发票
安装指南
Composer 安装
composer require ayman-elmalah/laravel-myfatoorah
该包与 laravel ^6.0|^7.0|^8.0|^9.0 兼容,因此您无需为包设置提供者或别名,我们使用 Laravel 自动发现
配置
要发布配置,运行
php artisan vendor:publish --provider="AymanElmalah\MyFatoorah\MyFatoorahServiceProvider"
并修改配置文件 /config/myfatoorah.php
中的您的信息。
从 Myfatoorah 获取您的凭证
- 前往 My fatoorah
- 您将获得访问令牌
- 前往您的 .env 文件并粘贴您的凭证,使其如下所示
- MYFATOORAH_MODE 选项 ["test", "live", "live-sa"]
MYFATOORAH_MODE=test
MYFATOORAH_TOKEN=token
或者您可以使用 setAccessToken($token?)->setMode($mode?)
添加它
您现在可以使用此包了
测试卡片页面
您可以从 DOCS 获取测试卡片
使用示例
创建支付页面
Route::get('payment', [\App\Http\Controllers\MyFatoorahController::class, 'index']);
Route::get('payment/callback', [\App\Http\Controllers\MyFatoorahController::class, 'callback']);
Route::get('payment/error', [\App\Http\Controllers\MyFatoorahController::class, 'error']);
在控制器中,您可以从支付页面获取数据,请参阅 DOCS
use AymanElmalah\MyFatoorah\Facades\MyFatoorah;
public function index() {
$data = [
'CustomerName' => 'New user',
'NotificationOption' => 'all',
'MobileCountryCode' => '+966',
'CustomerMobile' => '0000000000',
'DisplayCurrencyIso' => 'SAR',
'CustomerEmail' => 'test@test.test',
'InvoiceValue' => '100',
'Language' => 'en',
'CallBackUrl' => 'https://yourdomain.test/callback',
'ErrorUrl' => 'https://yourdomain.test/error',
];
// If you want to set the credentials and the mode manually.
// $myfatoorah = MyFatoorah::setAccessToken($token)->setMode('test')->createInvoice($data);
// And this one if you need to access token from config
$myfatoorah = MyFatoorah::createInvoice($data);
// when you got a response from myFatoorah API, you can redirect the user to the myfatoorah portal
return response()->json($myfatoorah);
}
获取回调以检查支付是否成功
public function callback(Request $request) {
$myfatoorah = MyFatoorah::payment($request->paymentId);
// It will check that payment is success or not
// return response()->json($myfatoorah->isSuccess());
// It will return payment response with all data
return response()->json($myfatoorah->get());
}
错误页面
public function error(Request $request) {
// Show error actions
return response()->json(['status' => 'fail']);
}
退款支付
Route::get('reund', [\App\Http\Controllers\MyFatoorahController::class, 'refund']);
在控制器中,您可以从支付页面获取数据,请参阅 DOCS
use AymanElmalah\MyFatoorah\Facades\MyFatoorah;
public function refund() {
$data = [
'KeyType' => 'invoiceid', // can be invoiceId or PaymentId
'Key' => '94272', // key value like payment reference id, you can got it from the $request->paymentId in callback function
'RefundChargeOnCustomer' => false,
'ServiceChargeOnCustomer' => false,
'Amount' => 210,
'Comment' => 'Refund',
'AmountDeductedFromSupplier' => 0
];
// If you want to set the credentials and the mode manually.
// $myfatoorah = MyFatoorah::setAccessToken($token)->setMode('test')->refundInvoice($data);
// And this one if you need to access token from config
$myfatoorah = MyFatoorah::refundInvoice($data);
// You can check the output
return response()->json($myfatoorah);
}
作者
- Ayman Elmalah - 初始工作 - ayman-elmalah
请参阅参与此项目的 贡献者 列表。
许可
本项目采用 MIT 许可协议 - 请参阅 LICENSE.md 文件以获取详细信息
致谢
- 如果您有任何问题、问题或 PR,请随时联系我。