getkevin/kevin-php

kevin. 平台的 PHP 客户端。

0.18.0 2023-04-20 07:47 UTC

README

实现 kevin. API 的 PHP 客户端。

先决条件

  • PHP 5.6 或更高版本

安装

Composer

  1. 使用 Composer 安装最新的 kevin. PHP 客户端存储库
composer require getkevin/kevin-php
  1. 使用 Composer 自动加载器,包含 kevin. PHP 客户端
require('vendor/autoload.php');

有关可用版本的详细信息可以在 Packagist 存储库中找到

https://packagist.org.cn/packages/getkevin/kevin-php

使用示例

参数名称和响应数据与 API 文档中定义的相匹配。

详细的 API 文档可以在此处找到 这里

初始化

use Kevin\Client;

$clientId = 'my-client-id';
$clientSecret = 'my-client-secret';
$options = ['error' => 'array', 'version' => '0.3', 'lang' => 'en'];

$kevinClient = new Client($clientId, $clientSecret, $options);

$clientId - 您的客户端 ID。您可以在 kevin. 平台控制台中获取。

$clientSecret - 您的客户端密钥。您可以在 kevin. 平台控制台中获取。

$options - 可选的选项数组。

  • error - 定义错误数据的返回类型。可能的值是:array - 错误时返回一个数组,exception - 错误时抛出异常,默认值是 exception

  • version - 选择要使用的 API 版本。默认值是 0.3。可能的值是 0.10.20.3

  • lang - 根据 ISO 639-1 标准定义的两位小写语言代码。设置框架页面的语言。

1. 身份验证

1.1 获取支持的国家

$response = $kevinClient->auth()->getCountries();

1.2 获取支持的银行

$attr = ['countryCode' => 'LT'];
$response = $kevinClient->auth()->getBanks($attr);

1.3 获取支持的银行

$bankId = 'SEB_LT_SAND';
$response = $kevinClient->auth()->getBank($bankId);

1.4 获取项目设置

$response = $kevinClient->auth()->getProjectSettings();

1.5 开始身份验证

$attr = [
    'redirectPreferred' => 'false',
    'scopes' => 'payments,accounts_basic',
    'Request-Id' => 'your-guid',
    'Redirect-URL' => 'https://redirect.kevin.eu/authorization.html'
];
$response = $kevinClient->auth()->authenticate($attr);

1.6 接收令牌

$attr = ['code' => 'your-auth-code'];
// ...or $attr = 'your-auth-code';
$response = $kevinClient->auth()->receiveToken($attr);

1.7 刷新令牌

$attr = ['refreshToken' => 'your-refresh-token'];
// ...or $attr = 'your-refresh-token';
$response = $kevinClient->auth()->refreshToken($attr);

1.8 接收令牌内容

$attr = ['Authorization' => 'your-bearer-token'];
// ...or $attr = 'your-bearer-token';
// ...or $attr = 'Bearer your-bearer-token';
$response = $kevinClient->auth()->receiveTokenContent($attr);

2. 支付

2.1 初始化银行支付

$attr = [
    'Redirect-URL' => 'https://redirect.kevin.eu/payment.html',
    'description' => 'Test',
    'currencyCode' => 'EUR',
    'amount' => '0.01',
    'bankPaymentMethod' => [
        'endToEndId' => '1',
        'creditorName' => 'John Smith',
        'creditorAccount' => [
            'iban' => 'LT0000000000000000'
        ],
    ],
];
$response = $kevinClient->payment()->initPayment($attr);

2.2 初始化卡支付

$attr = [
    'Redirect-URL' => 'https://redirect.kevin.eu/payment.html',
    'description' => 'Test',
    'currencyCode' => 'EUR',
    'amount' => '0.01',
    'bankPaymentMethod' => [
        'endToEndId' => '1',
        'creditorName' => 'John Smith',
        'creditorAccount' => [
            'iban' => 'LT0000000000000000',
        ],
    ],
    'cardPaymentMethod' => [],
    'paymentMethodPreferred' => 'card',
];
$response = $kevinClient->payment()->initPayment($attr);

2.3 初始化混合支付

$attr = [
    'Redirect-URL' => 'https://redirect.kevin.eu/payment.html',
    'description' => 'Test',
    'currencyCode' => 'EUR',
    'amount' => '0.01',
    'bankPaymentMethod' => [
        'endToEndId' => '1',
        'creditorName' => 'John Smith',
        'creditorAccount' => [
            'iban' => 'LT0000000000000000'
        ],
    ],
    'cardPaymentMethod' => [],
];
$response = $kevinClient->payment()->initPayment($attr);

2.4 获取支付

$paymentId = 'your-payment-id';
$response = $kevinClient->payment()->getPayment($paymentId);

2.5 获取支付状态

$paymentId = 'your-payment-id';
$response = $kevinClient->payment()->getPaymentStatus($paymentId);

2.6 初始化支付退款

$paymentId = 'your-payment-id';
$attr = [
    'amount' => '1.00',
    'Webhook-URL' => 'https://yourapp.com/notify'
];
$response = $kevinClient->payment()->initiatePaymentRefund($paymentId, $attr);

2.7 获取支付退款

$paymentId = 'your-payment-id';
$response = $kevinClient->payment()->getPaymentRefunds($paymentId);

3. 账户

3.1 获取账户

$accessToken = 'your-bearer-token';
$attr = [
    'Authorization' => $accessToken,
    'PSU-IP-Address' => 'your-ip-address',
    'PSU-User-Agent' => 'your-user-agent',
    'PSU-IP-Port' => 'your-ip-port',
    'PSU-Http-Method' => 'GET',
    'PSU-Device-ID' => 'your-device-id'
];
$response = $kevinClient->account()->getAccountList($attr);

3.2 获取账户详情

$accountId = 'your-account-id';
$accessToken = 'your-bearer-token';
$attr = [
    'Authorization' => $accessToken,
    'PSU-IP-Address' => 'your-ip-address',
    'PSU-User-Agent' => 'your-user-agent',
    'PSU-IP-Port' => 'your-ip-port',
    'PSU-Http-Method' => 'GET',
    'PSU-Device-ID' => 'your-device-id'
];
$response = $kevinClient->account()->getAccountDetails($accountId, $attr);

3.3 获取账户交易

$accountId = 'your-account-id';
$accessToken = 'your-bearer-token';
$attr = [
    'Authorization' => $accessToken,
    'PSU-IP-Address' => 'your-ip-address',
    'PSU-User-Agent' => 'your-user-agent',
    'PSU-IP-Port' => 'your-ip-port',
    'PSU-Http-Method' => 'GET',
    'PSU-Device-ID' => 'your-device-id',
    'dateFrom' => '2021-09-01',
    'dateTo' => '2021-09-15'
];
$response = $kevinClient->account()->getAccountTransactions($accountId, $attr);

3.4 获取账户余额

$accountId = 'your-account-id';
$accessToken = 'your-bearer-token';
$attr = [
    'Authorization' => $accessToken,
    'PSU-IP-Address' => 'your-ip-address',
    'PSU-User-Agent' => 'your-user-agent',
    'PSU-IP-Port' => 'your-ip-port',
    'PSU-Http-Method' => 'GET',
    'PSU-Device-ID' => 'your-device-id'
];
$response = $kevinClient->account()->getAccountBalance($accountId, $attr);

4. 安全性

4.1 验证签名

我们建议忽略超过 5 分钟的签名。

use Kevin\SecurityManager;

$endpointSecret = 'your-endpoint-secret';
$webhookUrl = 'your-webhook-url';

// Timestamp is provided in milliseconds
$timestampTimeout = 300000;

$requestBody = file_get_contents("php://input");
$headers = getallheaders();

$isValid = SecurityManager::verifySignature($endpointSecret, $requestBody, $headers, $webhookUrl, $timestampTimeout);

贡献

在做出任何代码更改之前,请确保运行 composer install 以安装开发需求。

我们使用 PHP CS Fixer GitHub action 对每个提交和拉取请求进行代码风格检查。在提交更改之前,请确保运行 composer fix-style 以确保您的代码符合我们的风格标准。代码风格检查失败的拉取请求将不会获得批准。

警告:我们使用有风险的规则,请确保检查破坏性风格修复。

可以通过运行 composer check-style 命令查看样式错误和违反的规则日志。

支持

电子邮件:help@kevin.eu

许可证