mattiabasone/pagonline

PagOnline API 库,支持 Laravel 集成

v3.0.0 2024-07-04 21:05 UTC

This package is auto-updated.

Last update: 2024-09-04 21:28:53 UTC


README

此库可与 PagOnline 支付网关一起使用,并且可以轻松集成到 Laravel 中。

使用此包,我试图改进 PagOnline 支付网关提供的糟糕的 IGFS CG PHP 库。

PHP Version Latest Stable Version Total Downloads Build Status Coverage Status Scrutinizer Code Quality

基本用法

示例脚本位于 tests/demo 目录中,示例初始化请求

<?php 

require __DIR__.'/vendor/autoload.php';

$init = new \PagOnline\Init\IgfsCgInit();
$init->serverURL = "https://payment-gateway-example.com/IGFS_CG_SERVICES/services";
$init->tid = "MY-TID-CODE";
$init->kSig = '1234567890987654321';
$init->shopID = 'my-transaction-id';
$init->shopUserRef = "email@example.org";
$init->trType = "AUTH";
$init->currencyCode = "EUR";
$init->amount = 500; // Amount without comma (500 = 5,00)
$init->langID = "IT";
$init->notifyURL = "http://my-domain.tld/verify.php";
$init->errorURL = "http://my-domain.tld/error.php";
$init->addInfo1 = 'myFirstAddintionalInfo';

// if you need to edit http client parameters...
$init->setRequestTimeout(10); // Seconds
$init->setConnectTimeout(5); // Seconds
$init->setHttpProxy('tcp://some.proxy'); // Proxy server for requests
$init->setHttpAuthUser('username'); // HTTP Basic Auth username
$init->setHttpAuthPass('password'); // HTTP Basic Auth password

if (!$init->execute()) {
    // Something went wrong
} else {
    // Redirect user to payment gateway
    header("location: ".$init->redirectURL);
}

Laravel 中使用

使用 Laravel 5.5+,PagOnline 服务提供者在启动时自动加载。它会加载配置文件和可用于创建 IgfsCg 类实例的 Factory Facade。

使用 Laravel 自动发现功能,您无需执行此操作,但是您可以使用 artisan 命令 vendor:publish
为旧版本的 Laravel 复制 pagonline.php 配置文件

php artisan vendor:publish --provider="PagOnline\Laravel\PagOnlineServiceProvider"

您还需要注册 PagOnline 服务提供者(PagOnline\Laravel\PagOnlineServiceProvider)。

使用 Facade

use IgfsCg;
use PagOnline\Actions;

[...]

class MyController 
{
    public function mySuperMethod()
    {
        $igfsCgInit = IgfsCg::make(Actions::IGFS_CG_INIT);
        // Do something
    }
}

`.env` 文件配置

在您的 .env 文件中设置以下环境变量

  • PAGONLINE_SERVER_URL 支付网关服务器 URL(默认:null
  • PAGONLINE_REQUEST_TIMEOUT 完成请求的最大超时时间(秒)(默认:15
  • PAGONLINE_CONNECT_TIMEOUT 连接到服务器的最大超时时间(秒)(默认:5
  • PAGONLINE_TERMINAL_ID 支付网关提供的标识符(默认:null
  • PAGONLINE_SIGNATURE_KEY 支付网关提供的签名密钥(默认:null
  • PAGONLINE_CURRENCY_CODE 货币代码(默认:EUR
  • PAGONLINE_LANGUAGE_ID 语言代码(默认:IT

待办事项

  • 单元测试

贡献

如果您想为此项目做出贡献,请使用 php-cs-fixer 将您的代码格式化为 PSR 标准,并遵循此仓库中提供的 .php_cs.dist 配置文件中指定的规则。谢谢!