mamounothman/laravel-payfort

Laravel-payfort是一个简单的包,用于通过Payfort支付网关处理支付。

1.0.1 2020-11-17 08:32 UTC

This package is not auto-updated.

Last update: 2024-10-03 01:32:38 UTC


README

Software License

Laravel Payfort提供了一种简单且丰富的方式,用于执行和处理Payfort(基于中东和非洲的在线支付网关)的操作。点击这里了解更多关于Payfort的信息。
此包支持以下列出的Payfort操作集,其他操作将留待未来工作和贡献。

  • 授权/购买
  • 令牌化
  • SDK_TOKEN
  • 检查状态

在继续使用任何包之前,您必须仔细阅读Payfort文档,包作者不会编写关于Payfort操作、如何使用的内容。

安装

您可以通过composer命令将Laravel Payfort包安装到laravel项目中

$ composer require wshurafa/laravel-payfort

配置

对于Laravel < 5.5(包自动发现:对于laravel 5.5+,跳过以下两个步骤)

安装Laravel Payfort库后,在您的config/app.php配置文件中注册LaravelPayfort\Providers\PayfortServiceProvider

'providers' => [
    // Other service providers...

    LaravelPayfort\Providers\PayfortServiceProvider::class,
],

此外,将Payfort外观添加到您的app配置文件中的aliases数组中

'Payfort' => LaravelPayfort\Facades\Payfort::class

然后,运行以下命令以发布配置文件

$ php artisan vendor:publish --provider "LaravelPayfort\Providers\PayfortServiceProvider"

这将创建一个名为payfort.php的新配置文件在config文件夹中。然后您必须在.env文件中添加以下常量,您可以在您的Payfort账户中找到这些值的大部分。

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授权或购买页面,在您的控制器方法中添加以下代码片段

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

贡献

想要改进这个包或发现了错误?打开一个问题,或者自己进行贡献,并获得这份荣誉。

简单来说,fork => 你工作 => 提交pull request。

编写清晰的注释和描述 ;-).

许可证

Laravel Payfort 是开源软件,根据 MIT 许可证 授权。