wshurafa / laravel-payfort
laravel-payfort是一个简单的包,用于通过Payfort支付网关处理支付。
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.2
- illuminate/support: ^8.50|^9.0
- nesbot/carbon: ^2.0
Requires (Dev)
- fabpot/goutte: ^4.0
- phpunit/phpunit: ^9.3
This package is not auto-updated.
Last update: 2024-09-29 01:13:07 UTC
README
Laravel Payfort
提供了一种简单而丰富的方式来执行和处理Payfort(基于中东和非洲的在线支付网关)的操作。查看更多Payfort信息。
本包支持以下列出的Payfort操作,其他操作将留待未来工作和贡献。
- 授权/购买
- 令牌化
- SDK_TOKEN
- 检查状态
在开始使用任何包之前,您必须非常仔细地阅读Payfort文档,包作者不会编写关于Payfort操作的内容,包括如何使用。
安装
您可以通过composer安装此包
composer require wshurafa/laravel-payfort
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider "LaravelPayfort\Providers\PayfortServiceProvider"
以下是要发布的文件的内容,它将在config/payfort.php
中发布
return [ /** * Defines wether to activate the Payfort sandbox enviroment or not. */ 'sandbox' => env('PAYFORT_USE_SANDBOX', false), /** * The Payfort merchant account identifier. */ 'merchant_identifier' => env('PAYFORT_MERCHANT_IDENTIFIER'), /** * The Payfort account access code. */ 'access_code' => env('PAYFORT_ACCESS_CODE'), /** * The Payfort account sha type (sha256/sha512). */ 'sha_type' => env('PAYFORT_SHA_TYPE', 'sha256'), /** * The Payfort account sha request phrase. */ 'sha_request_phrase' => env('PAYFORT_SHA_REQUEST_PHRASE'), /** * The Payfort account sha response phrase. */ 'sha_response_phrase' => env('PAYFORT_SHA_RESPONSE_PHRASE'), /** * The default currency for you app. Currency ISO code 3. */ 'currency' => env('PAYFORT_CURRENCY', 'USD'), /** * The URL to return after submitting Payfort forms. */ 'return_url' => env('PAYFORT_RETURN_URL', '/') ];
然后您必须在.env
文件中添加以下常量
PAYFORT_USE_SANDBOX=true # Defines wether to activate the payfort sandbox enviroment or not. PAYFORT_MERCHANT_IDENTIFIER=s2b3rj1vrjrhc1x # The payfort merchant account identifier PAYFORT_ACCESS_CODE=s31bpM1ebfNnwqo # The payfort account access code PAYFORT_SHA_TYPE=sha256 # The payfort account sha type. sha256/sha512 PAYFORT_SHA_REQUEST_PHRASE=keljhgiergh # The payfort account sha request phrase PAYFORT_SHA_RESPONSE_PHRASE=lkejgoegj # The payfort account sha response phrase PAYFORT_CURRENCY=USD # The default currency for you app. Currency ISO code 3. PAYFORT_RETURN_URL=/payfort/handle # The url to return after submitting payfort forms.
您可以在Payfort账户中找到这些值的大部分
使用方法
完成所有配置步骤后,您就可以在应用程序中使用Payfort操作了。以下是如何使用此包的一些示例
授权/购买请求(重定向)
要显示payfort授权或购买页面,在控制器的方法中添加以下代码片段
return Payfort::redirection()->displayRedirectionPage([ 'command' => 'AUTHORIZATION', # AUTHORIZATION/PURCHASE according to your operation. 'merchant_reference' => 'ORDR.34562134', # You reference id for this operation (Order id for example). 'amount' => 100, # The operation amount. 'currency' => 'QAR', # Optional if you need to use another currenct than set in config. 'customer_email' => 'example@example.com' # Customer email. ]);
以下是可以传递给displayRedirectionPage
方法的其他可选参数
token_name
payment_option
sadad_olp
eci
订单描述
客户IP
客户姓名
商户额外信息
商户额外信息1
商户额外信息2
商户额外信息3
将显示Payfort页面,用户提交支付表单后,将调用环境配置中定义的返回URL。
有关更多信息,请参阅Payfort
文档。
令牌化请求
要显示payfort令牌化页面,在控制器的方法中添加以下代码片段
return Payfort::redirection()->displayTokenizationPage([ 'merchant_reference' => 'ORDR.34562134', # You reference id for this operation (Order id for example). ]);
将显示Payfort页面,用户提交支付表单后,将调用配置文件中定义的返回URL。
有关更多信息,请参阅Payfort
文档。
处理Payfort授权/购买响应
处理回调(返回)
在处理返回URL的处理控制器中,您可以使用以下方式简单使用PayfortResponse
特质
use LaravelPayfort\Traits\PayfortResponse as PayfortResponse;
class PayfortOrdersController extends Controller{
use PayfortResponse;
public function processReturn(Request $request){
$payfort_return = $this->handlePayfortCallback($request);
# Here you can process the response and make your decision.
# The response structure is as described in payfort documentation
}
}
有关更多信息,请参阅Payfort
文档。
处理直接交易反馈
与处理Payfort响应相同,但您必须调用handlePayfortFeedback
而不是handlePayfortCallback
本地化
重定向页面可以通过简单地使用您应用程序lang
目录中的语言json文件进行翻译。
例如,ar.json
文件
{
...
"Payment redirect page": "صفحة إعادة توجيه الدفع",
"Click here to proceed to payment if you are not automatically redirected": "انقر هنا لمتابعة الدفع إذا لم تتم إعادة توجيهك تلقائيًا",
...
}
贡献
想要改进这个包或发现了一个错误?打开一个问题或自己进行此贡献并获得这份荣誉。
简单来说,fork => 做你的工作 => 提交拉取请求。
写清晰的注释和描述 ;-).
许可证
Laravel Payfort
是开源软件,许可协议为MIT许可证