goosfraba/kontomatik-sdk

1.0.0 2023-05-24 12:38 UTC

This package is auto-updated.

Last update: 2024-08-25 10:43:09 UTC


README

本仓库提供了 Kontomatik 的 PHP SDK。

安装

通过 composer

composer require goosfraba/kontomatik-sdk

使用方法

ApiFactory

为了创建特定的 API,首先需要 ApiFactory 实例。

<?php
use Goosfraba\Kontomatik\Common\ApiFactory;

$apiFactory = new ApiFactory(
    $logger = null // optionally, provide the logger to catch the raw responses from the API, it needs to work with level "Debug"
);

导入Api

获取 ImportingApi 实例

<?php
use Goosfraba\Kontomatik\Common\Dsn;

$importingApi = $apiFactory->importingApi(
    Dsn::parse(
        "kontomatik://your-api-key@prod" // or "kontomatik://your-api-key@test"
    );
);

支持的方法

  • defaultImport
  • getCommand
  • getData
  • removeData
  • signOut

LendingApi

获取 ImportingApi 实例

<?php
use Goosfraba\Kontomatik\Common\Dsn;

$api = $apiFactory->lendingApi(
    Dsn::parse(
        "kontomatik://your-api-key@prod" // or "kontomatik://your-api-key@test"
    );
);

支持的方法

  • getScores

导入数据用例/评分

use Goosfraba\Kontomatik\Importing\Session;

$commandReply = $importingApi->defaultImport(
    new Session("known-id", "known-signature"),
    date_create_immutable("now - 6 months") // import data for last 6 months
);

$commandId = $commandReply->getCommand()->getId();
$ownerExternalId = $commandReply->getOwnerExternalId();

do {
    /** @var \Goosfraba\Kontomatik\Importing\CommandReply $commandReply */
    $commandReply = $importingApi->getCommand($commandId));
} while(!$commandReply->getCommand()->isFinished() && sleep(5) === 0);

if ($commandReply->isSuccessful()) {
    $ownerScoreReply = $lendingApi->getScore($ownerExternalId);
}

贡献

欢迎添加不受支持端点或修复发现的错误。