midoelhawy/laravel-payfort
Composer 安装命令:
composer require midoelhawy/laravel-payfort
包简介
Laravel-payfort is a simple package to process payments throught Payfort payment gateway.
README 文档
README
Laravel Payfort provides a simple and rich way to perform and handle operations for
Payfort (MEA based online payment gateway) check here to read more Payfort.
This package supports a set of Payfort operations as listed below, other operations are open for future work and
contribution.
- AUTHORIZATION/PURCHASE
- CAPTURE
- TOKENIZATION
- SDK_TOKEN
- CHECK_STATUS
- REFUND
You have to read the Payfort documentation very well before proceeding in using any package, the package author
will not write about Payfort operations, what and how to use.
Install
You can install Laravel Payfort package to your laravel project via composer command:
$ composer require midoelhawy/laravel-payfort
Configuration
For Laravel > 7.0
After installing the Laravel Payfort library, register the LaravelPayfort\Providers\PayfortServiceProvider
in your config/app.php configuration file:
'providers' => [ // Other service providers... LaravelPayfort\Providers\PayfortServiceProvider::class, ],
Also, add the Payfort facade to the aliases array in your app configuration file:
'Payfort' => LaravelPayfort\Facades\Payfort::class
After that, run the following command to publish the configurations file:
$ php artisan vendor:publish --provider "LaravelPayfort\Providers\PayfortServiceProvider"
This will create a new config file named payfort.php in config folder. Then you have to add the following
constants in the .env file, you can find most of these values in your Payfort account.
PAYFORT_USE_SANDBOX=true #Defines wether to activate the payfort sandbox env or not.
PAYFORT_USE_TEST_ENV=true #Define Test env mode for development
PAYFORT_MERCHANT_IDENTIFIER=51e316554 # The payfort merchant account identifier
PAYFORT_ACCESS_CODE=XwMv28sHSAkSaB71uGON # The payfort account access code
PAYFORT_SHA_TYPE=sha256 # The payfort account sha type. sha256/sha512
PAYFORT_SHA_REQUEST_PHRASE=58obfoddsfg.. # The payfort account sha request phrase
PAYFORT_SHA_RESPONSE_PHRASE=86md5f56s.. # The payfort account sha response phrase
PAYFORT_CURRENCY=SAR # The default currency for you app. Currency ISO code 3.
PAYFORT_LANGUAGE=EN # The system default langauge for response messages
PAYFORT_RETURN_URL=/payfort/response # The url to return after submitting payfort forms.
Basic Usage
Once all configuration steps are done, you are ready to use payfort operations in your app. Here is some examples on how to use this package:
Authorization/Purchase request (Redirection)
To display payfort authorization or purchase page, in your controller's method add the following code snippet:
return Payfort::redirection()->displayRedirectionPage([ 'command' => 'AUTHORIZATION', # AUTHORIZATION/PURCHASE according to your operation. 'merchant_reference' => 'ORDR.'.rand(10000,100000), 'amount' => 3501.35, 'currency' => 'SAR', 'customer_email' => 'example@example.com', 'payment_option' => 'VISA', //Mada and others types "language"=>'ar', 'return_url'=>"https://expm.com/response" ]);
⚠ Note
Mada payment method works only as PURCHASE (not as AUTHORIZATION).
Other optional parameters that can be passed to displayRedirectionPage method as follows:
- token_name
- sadad_olp
- eci
- order_description
- customer_ip
- customer_name
- merchant_extra
- merchant_extra1
- merchant_extra2
- merchant_extra3
Payfort page will be displayed and once user submits the payment form, the return url defined in the environment
configurations will be called.
See Payfort documentation for more info.
Tokenization request
To display payfort tokenization page, in your controller's method add the following code snippet:
return Payfort::redirection()->displayTokenizationPage([ 'merchant_reference' => 'ORDR.34562134', # You reference id for this operation (Order id for example). ]);
Payfort page will be displayed and once user submits the payment form, the return url defined in the config file
will be called.
Capture Payment
To Capture after callback AUTHORIZATION, in your controller's method add the following code snippet:
$checkpayfort->captureOperationByFortId( [ "fort_id"=>$payfort_return["fort_id"], "merchant_reference"=>$payfort_return["merchant_reference"], "amount"=>3501.35,//your amount to capture (max : the authraized amount) "currency"=>"SAR", ] );
See Payfort documentation for more info.
Handling Payfort Authorization/Purchase response
Handling callback (return)
In your handling controller that handle the return url, you can simply use the PayfortResponse trait as follows:
use LaravelPayfort\Traits\PayfortResponse as PayfortResponse;
class PayfortOrdersController extends Controller{
use PayfortResponse;
public function processReturn(Request $request){
$payfort_return = $this->handlePayfortCallback($request);
$checkpayfort =new PayfortAPI(config('payfort'));
$checkStatus = $checkpayfort->checkOrderStatusByFortId($payfort_return["fort_id"]);
if($checkStatus->isSuccess()){
return $checkStatus->getResponse();//return payfort json array
}
if($payfort_return["command"] == "AUTHORIZATION"){
$captureAuthorizaPymnt = $checkpayfort->captureOperationByFortId(
[
"fort_id"=>$payfort_return["fort_id"],
"merchant_reference"=>$payfort_return["merchant_reference"],
"amount"=>3501.35,//your amount to capture (max : the authraized amount)
"currency"=>"SAR",
]
);
if($captureAuthorizaPymnt->isSuccess()){
//success payment
}
//....
}
}
}
See Payfort documentation for more info.
Handling Direct Transaction Feedback
Same as handling payfort response except that you have to call handlePayfortFeedback instead of handlePayfortCallback
Contribution
Want to improve this package or found a bug ?. Open an issue or do this contribution by yourself and get this honor.
Simply, fork => do you work => make pull request.
Write clear comments and description ;-).
License
Laravel Payfort is open-sourced software licensed under the MIT license
laravel-payfort
This Library implemented on :
midoelhawy/laravel-payfort 适用场景与选型建议
midoelhawy/laravel-payfort 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 180 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payfort」 「laravel payfort」 「amazon payment」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 midoelhawy/laravel-payfort 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 midoelhawy/laravel-payfort 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 midoelhawy/laravel-payfort 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
A simple Laravel 5/6/7/8 service provider for including the AWS SDK for PHP.
NinjaImg PHP SDK.
Alfabank REST API integration
Amazon Advertising API Client Library
统计信息
- 总下载量: 180
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-10