jarnovanleeuwen/php-tikkie

该包已被废弃,不再维护。没有建议的替代包。

Tikkie API接口的实现。

v0.2.4 2019-11-15 07:31 UTC

This package is auto-updated.

Last update: 2020-12-28 13:00:34 UTC


README

Build Status

⚠️ Tikkie 已宣布,从 2021-01-01 开始将停止支持 Tikkie 支付请求 API(该库实现的 API),转而使用新的 Tikkie API。有关更多信息,包括路线图,请参阅 https://medium.com/abn-amro-developer/abn-amro-introduces-the-new-tikkie-api-87c8bb54720a

目前,我还没有计划更新这个库。这可能在将来改变,但在此期间欢迎提交 PR。

通过 Tikkie 轻松创建支付请求。

非官方的 Tikkie 支付请求 API 实现(已弃用,可用至 2021-01-01)。

安装

PHPTikkie 需要 PHP 7.1+

使用 Composer 将此包添加到您的项目中

composer require jarnovanleeuwen/php-tikkie

使用方法

初始化 PHPTikkie

use PHPTikkie\Environment;
use PHPTikkie\PHPTikkie;

$apiKey = "abc123";
$testMode = true;

$environment = new Environment($apiKey, $testMode);
$environment->loadPrivateKey('private_rsa.pem');

$tikkie = new PHPTikkie($environment);

创建平台

use PHPTikkie\Entities\Platform;

$platform = $tikkie->newPlatform([
    // Mandatory attributes
    'name' => 'YourPlatform',
    'phoneNumber' => '06123456789',
    'platformUsage' => Platform::USAGE_TYPE_MYSELF,

    // Optional attributes
    'email' => 'tikkie@yourcompany.com',
    'notificationUrl' => ''
])->save();

$platformToken = $platform->platformToken;

创建用户

$user = $tikkie->newUser($platformToken, [
    'name' => 'ExamplePlatform',
    'phoneNumber' => '06123456789',
    'iban' => 'NL00BANK123456789',
    'bankAccountLabel' => 'YourLabel'
])->save();

$userToken = $user->userToken;
$bankAccountToken = $user->bankAccounts[0]->bankAccountToken;

创建支付请求

$paymentRequest = $tikkie->newPaymentRequest($platformToken, $userToken, $bankAccountToken, [
    // Mandatory attributes
    'amountInCents' => '1250',
    'currency' => 'EUR',
    'description' => 'Thank you',
    'externalId' => 'Order 1234'
])->save();

$tikkieUrl = $paymentRequest->paymentRequestUrl;
$paymentRequestToken = $paymentRequest->paymentRequestToken;

获取支付请求

function paymentRequest(string $platformToken, string $userToken, string $paymentRequestToken): PaymentRequest

列出平台

function platforms(): Platform[]

列出用户

function users(string $platformToken): User[]

列出支付请求

function paymentRequests(string $platformToken, string $userToken, int $offset, int $limit, DateTimeInterface $fromDate = null, DateTimeInterface $toDate = null): PaymentRequest[]

处理支付

$paymentRequest = $tikkie->paymentRequest($platformToken, $userToken, $paymentRequestToken);

foreach ($paymentRequest->payments as $payment) {
    if ($payment->isPaid()) {
        // Payment successful
    }
}

异常处理

所有方法可能返回包含错误代码和描述的 PHPTikkieException

use PHPTikkie\Exceptions\PHPTikkieException;

try {
    var_dump($tikkie->platforms());
} catch (PHPTikkieException $exception) {
    print $exception->getMessage(); // [ERR_2005_002] The API Key is invalid for the requested resource | traceId: 6fda2ce8-225d-4ca2-920a-b687c7aeb2f3 | (see https://developer.abnamro.com/get-started#obtaining-an-api-key)
}