cynobit/crediborg-client

用于调用CrediBorg API的PHP库

0.1.0 2020-07-22 21:43 UTC

This package is auto-updated.

Last update: 2024-09-23 17:02:35 UTC


README

build Coverage Status Packagist Downloads

crediborg-php-client

CrediBorg服务的PHP客户端。

CrediBorg是一种信用警报处理技术,它可以监听您的邮箱中的信用交易邮件(警报),从中提取相关信息,并在客户生成的发票中进行匹配,同时通过web hooks将相关详细信息通知您的服务器。

这是一个基于PHP的客户端库,用于使用服务(CrediBorg)API。

前往查看完整的REST API文档。

安装

CrediBorg PHP客户端SDK可在Packagist上找到,名称为cynobit/crediborg-client

$ composer require cynobit/crediborg-client:dev-master

用法

创建发票

$amount = 75000;

$secret = ".....";
$token = "...";

$invoice = new CrediBorg\Invoice($amount);

$invoice->setCode('AHYT645623')
    ->setEmail('example@example.com');
    ->setCustomer([
        'first_name'  => 'John',
        'middle_name' => 'Alfred',
        'last_name'   => 'Doe'
    ])
    ->setMetaData([
        // Possible cart items or anything you want.
        'items' => [
            [
                'name'       => 'Raspberry Pi'
                'qty'        => 2,
                'unit_price' => 25000
            ],
            [
                'name'       => 'ESP32 Module'
                'qty'        => 20,
                'unit_price' => 2000
            ]
        ]
    ]);
$crediborg = new CrediBorg\CrediBorg($secret, $token);

$crediborg->createInvoice($invoice);

echo $invoice->getCode(); // Invoice Code

在配置的WebHook上处理事件负载

$secret = ".....";
$token = "...";

$crediborg = new CrediBorg\CrediBorg($secret, $token);

$event = $crediborg->getEventPayload();

foreach ($event->getMatchedInvoices() as $invoice) {
    echo $invoice->code . PHP_EOL;
    foreach ($invoice->getMatchedTransactions() as $transaction) {
        echo $transaction->narration . PHP_EOL;
        echo $transaction->type . PHP_EOL;
        echo $transaction->amount . PHP_EOL;
    }
}