finTech/finTech-sdk-php

用于Fintecture API的PHP库。

2.5.2 2024-04-02 07:32 UTC

README

Latest Stable Version Total Downloads Monthly Downloads Latest Unstable Version License

Fintecture是一家提供通过银行转账进行支付解决方案的Fintech公司,可在fintecture.com上找到。

此库是Fintecture API的PHP客户端。

要求

  • PHP >= 7.2

快速安装

通过 Composer,使用我们的Packagist包 finTech/finTech-sdk-php

此命令将快速使用Guzzle HTTP客户端(v7)。

composer require fintecture/fintecture-sdk-php guzzlehttp/guzzle

Guzzle客户端将通过 php-http/discovery 包自动找到。如果您想指定一个自定义HTTP客户端,请参阅 高级使用 部分。

入门

简单用法如下

require_once('vendor/autoload.php');

$state = '<my-uniq-id-for-the-payment>'; // it's my transaction ID, I have to generate it myself, it will be sent back in the callback
$pisClient = new \Fintecture\PisClient([
    'appId' => 'app_id',
    'appSecret' => 'app_secret',
    'privateKey' => 'private_key', // could be a file path or the private key itself
    'environment' => 'sandbox' // or 'production'
]);

$pisToken = $pisClient->token->generate();
if (!$pisToken->error) {
    $pisClient->setAccessToken($pisToken); // set token of PIS client
} else {
    echo $pisToken->errorMsg;
}

$payload = [
    'meta' => [
        // Info of the buyer
        'psu_name' => 'M. John Doe',
        'psu_email' => 'john@doe.com',
        'psu_address' => [
            'street' => '5 Void Street',
            'zip' => '12345',
            'city' => 'Gotham',
            'country' => 'FR'
        ]
    ],
    'data' => [
        'type' => 'SEPA',
        'attributes' => [
            'amount' => '550.60',
            'currency' => 'EUR',
            'communication' => 'Commande N°15654'
        ]
    ]
];

$connect = $pisClient->connect->generate($payload, $state);
if (!$connect->error) {
    $pisClient->redirect($connect->meta->url);
} else {
    echo $connect->errorMsg;
}

客户端可用选项

  • 'appId' => 'app_id',
  • 'appSecret' => 'app_secret',
  • 'privateKey' => 'private_key', // 可以是文件路径或私钥本身
  • 'environment' => 'sandbox' // 或 'production'
  • 'shopName' => 'My super shop', // 不要忘记给你的客户端起一个好听的名字(即使它是可选的)

示例

一些示例(包括webhook处理)可在 examples 文件夹 中找到。

高级使用

我们通过与 HTTPlug 的帮助解耦任何HTTP消息客户端。社区提供的客户端列表在此: https://packagist.org.cn/providers/php-http/client-implementation

使用不同的HTTP客户端

composer require fintecture/fintecture-sdk-php symfony/http-client nyholm/psr7

要使用此HTTP客户端设置Fintecture客户端

use Fintecture\PisClient;
use Symfony\Component\HttpClient\Psr18Client;

$pisClient = new PisClient([$config], new Psr18Client());

可用方法

这些方法遵循我们的 API结构

认证

  • token
    • generate
    • refresh

AIS

  • account
    • get
  • accountHolder
    • get
  • authorize
    • generate
    • generateDecoupled
  • connect
    • generate
  • customer
    • delete
  • transaction
    • get

PIS

  • assessment
    • get
  • connect
    • generate
  • initiate
    • generate
  • payment
    • get
  • refund
    • generate
  • requestForPayout
    • generate
  • requestToPay
    • generate
  • settlement
    • get

资源

  • application
    • get
  • functionality
    • get
  • provider
    • get
  • testAccount
    • get

开发

要求

  • PHP
  • Git
  • Composer
  • Make
  • Xdebug(用于测试覆盖率)

为开发初始化项目

make init

PHPUnit(单元测试)

然后你可以运行测试

make test

要生成测试覆盖率报告,你可以运行此命令

make test-coverage

PHPStan(静态分析)

有10个级别(0-9)。级别在 phpstan.neon 中设置。

make analyse

PHP CS Fixer(编码规范)

make format

故障排除

遇到问题?请通过developer@fintecture.com联系我们。

许可协议

finTech PHP API客户端是一个开源软件,许可协议为MIT许可证