tamkeen-tech/laravel-payfort
Composer 安装命令:
composer require tamkeen-tech/laravel-payfort
包简介
laravel Payfort package
README 文档
README
Helps you integrate Payfort into your application. currently it supports Custom merchant page integration refer to this link to understand more, also this package support using multiple merchant accounts.
Currently this package supports the below operation list:
- AUTHORIZATION/PURCHASE
- TOKENIZATION
- CAPTURE
- REFUND
- INSTALLMENTS
- VOID
- CHECK_STATUS
- APPLE_PAY
Please make sure to read and understand payfort documentation.
Currently it supports only Laravel 9.
Installation
You need to run this command
composer require tamkeen-tech/laravel-payfort
To publish the configurations please run this command
php artisan vendor:publish --tag payfort-config
This will generate a config/payfort.php with the default configurations
return [ 'gateway_host' => env('PAYFORT_GATEWAY_HOST', 'https://checkout.payfort.com/'), 'gateway_sandbox_host' => env('PAYFORT_GATEWAY_SAND_BOX_HOST', 'https://sbcheckout.payfort.com/'), 'merchants' => [ 'default' => [ 'merchant_identifier' => env('PAYFORT_MERCHANT_IDENTIFIER', null), 'access_code' => env('PAYFORT_ACESS_CODE', null), 'SHA_request_phrase' => env('PAYFORT_SHAR_REQUEST_PHARSE', null), 'SHA_response_phrase' => env('PAYFORT_SHAR_RESPONSE_PHRASE', null), ], ], 'sandbox_mode' => env('PAYFORT_SANDBOX_MODE', true), 'SHA_type' => env('PAYFORT_SHA_TYPE', 'sha256'), 'language' => env('PAYFORT_LANGUAGE', 'en'), ];
Then you can update your .env file to have the correct credentials:
PAYFORT_SANDBOX_MODE=true # Defines wether to activate the payfort sandbox enviroment or not. PAYFORT_MERCHANT_IDENTIFIER=test # The payfort merchant account identifier PAYFORT_ACCESS_CODE=test # The payfort account access code PAYFORT_SHA_TYPE=sha256 # The payfort account sha type. sha256/sha512 PAYFORT_SHA_REQUEST_PHRASE=test # The payfort account sha request phrase PAYFORT_SHA_RESPONSE_PHRASE=test # The payfort account sha response phrase
Usage
Once you identified your credentials and configurations, your are ready to use payfort operations.
Tokenization request:
To display tokenization page, in your controller method you can add the following
Payfort::tokenization( 1000, # Bill amount 'redirect_url', # the recirect to url after tokenization true # either to return form html or not (optional) );
Authorization/Purchase:
To send a purchase or authorization command, in your controller on the return of the tokenization request from payfort add this code
$response = Payfort::purchase( [], # Request body coming from the tokenization 100, # Bill amount 'test@test.ts', # User email 'redirect_url', # The return back url after purchase [] # installment data (optional) );
$response = Payfort::authorize( [], # Request body coming from the tokenization 100, # Bill amount 'test@test.ts', # User email 'redirect_url' # The return back url after purchase );
To handle the 3Ds redirection, you can use this code snippet:
if ($response->should3DsRedirect()) { return redirect()->away($response->get3DsUri()); }
Where $response is the response coming from the purchase or the authorization.
if the transaction is done successfully you can get the transaction fort id by using this:
$response->getResponseFortId();
or the used payment method by this:
$response->getResponsePaymentMethod()
Process response
To process the response coming from payfort and to make sure it's valid you can use the following code snippet:
Payfort::processResponse( [] # the response array );
it will throw exception \TamkeenTech\Payfort\Exceptions\PaymentFailed, if the response is not valid.
if the transaction is done successfully you can get the transaction fort id by using this:
$response->getResponseFortId();
or the used payment method by this:
$response->getResponsePaymentMethod()
Capture
Used only after authorization, to send a capture command use code below:
Payfort::capture( 'fort_id', # fort id for the payment transaction 100.0 # bill amount );
Void
Used only after authorization, to send a void command use code below:
Payfort::void( 'fort_id' # fort id for the payment transaction );
Refund
Used only after purchase, to send a refund command use the code below:
Payfort::refund( 'fort_id', # fort id for the payment transaction 1000 # amount to be reunded must not exceed the bill amount );
Merchant extra
Payfort support sending extra fields to the request and they will be returned back to you on the response, so to add merchant extras to any command, you do the following:
Payfort::setMerchantExtra('test')->tokenization( 1000, # Bill amount 'redirect_url', # the recirect to url after tokenization true # either to return form html or not (optional) );
you can use this method setMerchantExtra before any command you want, and you have max 5 extras to add.
Apple pay
To use apple pay services all you need to do is to do the following
Payfort::applePay( [], # fort params (please make sure to match the fort params mentioned below) 1000, # bill amount 'test@test.ts', # User email 'PURCHASE', # command to be sent to apple pay either PURCHASE or AUTHORIZE );
One important note, that you need to match the following fort params struture
[
"paymentData" => [
"data" => "apple_data",
"header" => [
'ephemeralPublicKey' => 'apple_ephemeralPublicKey',
'publicKeyHash' => 'apple_publicKeyHash',
'transactionId' => 'apple_transactionId',
],
"signature" => "signature",
],
"paymentMethod" => [
'displayName' => 'apple_displayName',
'network' => 'apple_network',
'type' => 'apple_type',
],
]
Logging
To log your requests with payfort you can listen to this event \TamkeenTech\Payfort\Events\PayfortMessageLog it will contain the data sent and the resposne
This is an example on how it can be used:
$log = app(PayfortLog::class); $log->contract_id = data_get($event->request, 'merchant_extra', data_get($event->response, 'merchant_extra', null)); if (isset($event->response['card_number'])) { $last_four_digits = substr($event->response['card_number'], -4); $log->card_number = '************'.$last_four_digits; } if (isset($event->response['amount'])) { $log->amount = floatval($event->response['amount'] / 100); } if (isset($event->response['response_message'])) { $log->response_message = data_get($event->response, 'response_message'); } if (isset($event->response['merchant_reference'])) { $log->merchant_reference = $event->response['merchant_reference']; } if (isset($event->request['merchant_reference'])) { $log->merchant_reference = $event->request['merchant_reference']; } $log->fort_id = data_get($event->response, 'fort_id'); $log->payment_option = data_get($event->response, 'payment_option'); $log->command = data_get($event->response, 'command', data_get($event->response, 'service_command')); $log->response_code = data_get($event->response, 'response_code'); $log->request = $event->request ? json_encode($event->request) : ""; $log->response = json_encode($event->response); $log->save();
License
The MIT License (MIT). Please see License File for more information.
tamkeen-tech/laravel-payfort 适用场景与选型建议
tamkeen-tech/laravel-payfort 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.46k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「payfort」 「laravel payfort」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tamkeen-tech/laravel-payfort 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tamkeen-tech/laravel-payfort 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tamkeen-tech/laravel-payfort 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel-payfort is a simple package to process payments throught Payfort payment gateway.
Laravel-payfort is a simple package to process payments throught Payfort payment gateway.
Larafort is a simple package to process payments throught PAYFORT Online Payment Gateway. (Using wshurafa/laravel-payfort)
PayFort integration with Magento 2
Payfort Start makes accepting online payments in the Middle East a piece of cake
统计信息
- 总下载量: 3.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-20