rizwansaleem70 / laravel-payfort
Payfort支付网关与Laravel集成。在您的Laravel应用程序中添加Amazon支付服务(PayFort)。
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.2
- illuminate/support: ^10.0
- nesbot/carbon: ^2.0
This package is auto-updated.
Last update: 2024-09-22 16:01:36 UTC
README
Laravel Payfort
提供了一种简单而丰富的方式来执行和处理 Payfort
(中东地区在线支付网关)的操作。查看更多信息 Payfort。
此包支持以下 Payfort
操作,其他操作将留待未来工作和贡献。
- 授权/购买
- 令牌化
- SDK_TOKEN
- 检查状态
在继续使用任何包之前,您必须仔细阅读 Payfort
文档,包作者不会编写有关 Payfort
操作的内容,以及如何使用。
安装
您可以通过 composer 安装此包
composer require rizwansaleem70/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": "انقر هنا لمتابعة الدفع إذا لم تتم إعادة توجيهك تلقائيًا",
...
}
贡献
想要改进此包或发现了一个错误?请打开一个问题或自己进行此贡献并赢得这份荣誉。
简单地,分支 => 进行你的工作 => 提交拉取请求。
编写清晰的注释和描述 ;-).
许可证
laravel payfort
是开源软件,遵循MIT 许可协议