partfire/onfido

Onfido PHP 库的 composer 包版本。

1.0 2016-11-09 06:35 UTC

This package is not auto-updated.

Last update: 2024-09-23 12:16:50 UTC


README

这是 Onfido REST API 的 PHP API 客户端。

我们尽可能保持此库与 原始库 一致,因此可以使用文档中所述的方式。

为了运行测试,您必须更新 AbstractTest 文件以包含您的 api 令牌。测试数据较差,因为它们依赖于您的 Onfido 账户中的数据(例如客户 ID)。

这些是 Onfido 提供的原始单元测试。

安装

您可以从源代码获取 onfido-php

$ git clone https://github.com/onfido/php-onfido.git

或您可以通过 composer 安装

$ composer require partfire/onfido

用法

最初,您需要导入 autoload.php 文件,初始化 Config 并设置 Token

require_once('autoload.php');

\Onfido\Config::init()->set_token('YOUR TOKEN');

申请人

申请人 端点支持两种操作 - create()get()

创建申请人

$applicant = new \Onfido\Applicant();
$applicant->first_name = 'John';
$applicant->last_name = 'Smith';
$applicant->email = 'email@server.com';

$address1 = new \Onfido\Address();
$address1->postcode = 'abc';
$address1->town = 'London';
$address1->country = 'GBR';

$applicant->addresses = Array($address1);

$response = $applicant->create();

检索申请人

APPLICANT_ID 是您要检索的申请人的 ID。

$applicant = (new \Onfido\Applicant())->get(APPLICANT_ID);

列出申请人

->paginate(2, 5) 表示获取第 2 页,每页有 5 个申请人,任一项可为 null 以忽略

\Onfido\Config::init()->set_token('YOUR TOKEN')->paginate(2, 5);

$applicants = (new \Onfido\Applicant())->get();

文件

文件 端点支持一种操作 - upload_for()

上传文件

$document = new \Onfido\Document();

$document->file_name = 'file.jpg';
$document->file_path = '/path/to/file.jpg';
$document->file_type = 'image/jpg';
$document->type = 'passport';
$document->side = 'front';

$response = $document->upload_for(APPLICANT_ID);

检查

检查 端点支持两种操作 - create_for()get()

创建检查

$check = new \Onfido\Check();
$check->type = 'standard';

$report1 = new \Onfido\CheckReport();
$report1->name = 'identity';

$check->reports = Array(
    $report1
);
$response = $check->create_for(APPLICANT_ID);

检索检查

$check = (new \Onfido\Check())->get(APPLICANT_ID, CHECK_ID);

列出检查

\Onfido\Config::init()->set_token('YOUR TOKEN')->paginate(null, 5);

$checks = (new \Onfido\Check())->get(APPLICANT_ID);

报告

报告 端点支持一种操作 - get()

检索报告

$report = (new \Onfido\Report())->get(CHECK_ID, REPORT_ID);

列出报告

$report = (new \Onfido\Report())->get(CHECK_ID);

地址选择器

您可以使用 Onfido 的 地址选择器,例如

$address = new \Onfido\AddressPicker();
$address->postcode = 'SW4 6EH';
$addresses = $address->pick();

运行测试

您需要安装最新版本的 phpunit。然后

phpunit Applicants.php

将运行与申请人端点操作相关的测试,并以可读的方式显示结果。您可以运行其他测试,如:检查、文件和报告。