pacexyz/payfort-laravel

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

dev-master 2017-09-27 10:51 UTC

This package is not auto-updated.

Last update: 2024-09-18 23:16:33 UTC


README

Software License

Laravel Payfort提供了一种简单而丰富的操作方式,用于执行和处理Payfort(基于中东和非洲的在线支付网关)的操作。请在此处查看更多信息 Payfort
此包支持以下Payfort操作,其他操作将在未来的工作中开放以供贡献。

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

在继续使用任何包之前,您必须非常仔细地阅读Payfort文档,包作者不会编写有关Payfort操作、如何使用的信息。

安装

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

$ composer require pacexyz/payfort-laravel

配置

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

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

    PayfortLaravel\Providers\PayfortServiceProvider::class,
],

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

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

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

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

这将在config文件夹中创建一个名为payfort.php的新配置文件。然后您必须在.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 PayfortLaravel\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请求。

写清楚注释和描述 ;-).

许可证

Laravel Payfort 是一个开源软件,遵循 MIT 许可协议