fetchdocs/fetchdocs-api-php

fetchdocs API的PHP封装库

1.0.0 2019-04-02 10:29 UTC

This package is auto-updated.

Last update: 2024-09-25 03:20:05 UTC


README

##概述
fetchdocs.io - Fetch API 可用于文档获取的API集成以及UI Plug&Play集成。
所有API访问都受到API密钥的限制。通过提交联系表单在 https://www.fetchdocs.io 请求访问权限。

##Fetchdocs PHP SDK客户端
Fetch PHP SDK客户端使您能够与fetchdocs API交互,您可以点击以下 链接 查看API文档

##安装

  1. 运行 composer require fetchdocs/fetchdocs-api-php
  2. require_once '/path/to/your-project/vendor/autoload.php'; 添加到您的索引文件中

示例

####1. 获取文档

require '../vendor/autoload.php';

//Client using stage server
$clientStage = \Fetchdocs\SDKClient\Client::make('Your API KEY', 'Your Hash Key', true);

//Create Environment
$environment = $clientStage->createEnvironment([
    'name' => 'Environment Name',
    'default_environment' => true,
    'push_notification_url' => 'Your Push Notification Url',
    'push_input_request_url' => 'Your Push Input Request Url'
]);

//Create a customer
$customer = $clientStage->createCustomer([
    'environment_prim_uid' => $environment->prim_uid
]);


//Supplier
$supplier = getSupplierByName($clientStage, 'Test Portal');

//Create Customer Supplier
$customerSupplier = $clientStage->createCustomerSupplier([
    'customer_prim_uid' => $customer->prim_uid,
    'supplier_prim_uid' => $supplier->prim_uid,
    'active' => true,
    'username' => 'Customer Supplier Username',
    'password' => 'PASSWORD'
], 'Your Encryption Key');

//Push document to document queue
$doc = $clientStage->testQueueDocument([
    'prim_uid' => $customer->prim_uid,
    'customer_supplier_uid' => $customerSupplier->customer_supplier_prim_uid
]);

//Get Documents
$documents = $clientStage->getDocumentsQueue([
    'environment_prim_uid' => $environment->prim_uid
]);

while ($documents->count <= 0) {
    $documents = $clientStage->getDocumentsQueue([
        'environment_prim_uid' => $environment->data->prim_uid
    ]);
}

//Get document
$document = $clientStage->getDocument([
    'prim_uid' => $documents->documents[0]->prim_uid,
    'customer_secret' => $customer->customer_secret
]);

##SDK API

  • 请查看以下 链接 了解更多关于请求参数和预期响应的API文档
  • 请注意,每个客户端方法都返回一个映射API响应的 STD Object
$client = \Fetchdocs\SDKClient\Client::make('Your API Key', 'Your Hash Key');

#####1. 使用生产服务器

$client = \Fetchdocs\SDKClient\Client::make('Your Stage API Key', 'Your Stage Hash Key', true);

#####2. 使用测试服务器

$client->environments();
[
    {
        "prim_uid": "10361",
        "name": "Default",
        "push_document_url": "",
        "push_notification_url": "https://push.domain.tld/notifications/",
        "push_input_request_url": "https://push.domain.tld/input_request/",
        "ui_redirect_url": "",
        "default_environment": true
    },
    {
        "prim_uid": "10362",
        "name": "Env",
        "push_document_url": "",
        "push_notification_url": "https://push.domain.tld/notifications/",
        "push_input_request_url": "https://push.domain.tld/input_request/",
        "ui_redirect_url": "",
        "default_environment": false
    }
]

#####3. 列出环境

$client->timezones();
[
    "Africa/Abidjan",
    "Africa/Accra"
]

#####4. 列出时区

$client->dateFormats();
[
    "d.m.Y",
    "m/d/Y",
    "d/m/Y"
]

#####5. 日期格式

$client->createEnvironment([
    'name' => 'Environment Name',
    'default_environment' => true,
    'push_notification_url' => 'https://push.domain.tld/notifications/',
    'push_input_request_url' => 'https://push.domain.tld/input_request/'
]);
{
    "prim_uid": 10432
}

#####6. 创建环境

$client->updateEnvironment([
    'prim_uid' => $environment->prim_uid,
    'name' => 'New Name'
])
{
    "success": true
}

#####7. 更新环境

$client->deleteEnvironment([
   'prim_uid' => $environment->prim_uid,
])
{
    "success": true
}

#####8. 删除环境

$client->listCustomerAccounts([
    'environment_prim_uid' => 10361
])
[
    {
        "prim_uid": 1, 
        "language": "en",
        "timezone": "Europe/Berlin",
        "date_format": "m/d/Y",
        "environment": 144 
    }
]

#####9. 列出客户账户

$client->createCustomer([
   'environment_prim_uid' => $environment->prim_uid
]);
{
    "prim_uid": 6684,
    "customer_secret": "b3cjpcy8",
    "access_token": "o1zhz0yzrbx3i5v65j20a751rrg6tyji"
}

#####10. 创建客户

$client->updateCustomer([
   'prim_uid' => '10500',
   'customer_secret' => 'Customer Secret',
   'language' => 'de'
])
{
    "success": true
}

#####11. 更新客户

$client->deleteCustomer([
   'prim_uid' => '10500',
   'customer_secret' => 'Customer Secret',
])
{
    "success": true
}

#####12. 删除客户

$client->deactivateCustomer([
   'prim_uid' => '10500',
   'customer_secret' => 'Customer Secret',
])
{
    "success": true
}

#####12. 禁用客户

$client->activateCustomer([
   'prim_uid' => '10500',
   'customer_secret' => 'Customer Secret',
])
{
    "success": true
}

#####12. 启用客户

$client->->getCustomerAccountOverview([
 'prim_uid' => '10500',
])
{
    "customer_data": {
        "prim_uid": 1, 
        "language": "en", 
        "timezone": "Europe/Berlin", 
        "date_format": "m/d/Y" 
    },
    "customer_suppliers": [
        { 
            "prim_uid": 307,
            "name": "1&1.de"
        }
    ]
}

#####13. 获取客户账户概览

$client->getCustomerSession([
   'prim_uid' => $customer->prim_uid,
   'customer_secret' => $customer->customer_secret
])
{
    "prim_uid": 6690,
    "access_token": "Access Token"
}

#####14. 获取客户会话

$client->destroyCustomerSession([
    'access_token => "Access Token"
])
{
    "success": true
}

#####15. 销毁客户会话

$client->->listSuppliers()
[
    {
        "prim_uid": 2568,
        "name": "1&1 - Versatel (Business-Kunden)",
        "created": "2018-02-12 12:52:38",
        "supplier_login_url": "https://online-rechnung.versatel.de/tb/telcobill.faces",
        "supplier_logo_url": "https://portal-ui-images.s3.eu-central-1.amazonaws.com/logo/120x120/25206.jpg",
        "document_type": "invoice",
        "quick_feedback_supported": false
    }
]

#####16. 列出供应商

$client->createCustomerSupplier([
    'customer_prim_uid' => 10050,
    'supplier_prim_uid' => 2568,
    'active' => true,
    'username' => 'CustomerSupplier',
    'password' => 'PASSWORD'
], 'Encryption-Key');
{
    "success": true,
    "customer_supplier_prim_uid": 13
}

#####17. 创建客户供应商

{
    "success": true,
    "quick_feedback_started": true,
    "feedback_process_uid": 12
}

如果将quick_feedback参数设置为true

$client->deleteCustomerSupplier([
    'prim_uid' => '15000'
])
{
    "success": true
}

#####18. 删除客户供应商

$client->listCustomerSuppliers([
    'prim_uid' => '10500' //customer uid
])
[
    {
        "prim_uid": 2355,
        "supplier_name": "1&1.de",
        "supplier_prim_uid": 307,
        "supplier_logo": "",
        "supplier_logo_url": "", 
        "active": true,
        "input_request_prim_uid": 585, 
        "download_start_date": "2013-07-18", 
        "last_started": "2013-07-18 08:17:13", 
        "next_planned_run": "2013-07-18 10:00:00", 
        "last_status_key": "PENDING", 
        "username": "admin", 
        "document_type": "invoice" 
    }
]

#####19. 列出客户供应商

$client->updateCustomerSupplier([
    'customer_prim_uid' => 10050,
    'supplier_prim_uid' => 2568,
    'active' => true,
    'username' => 'CustomerSupplier',
    'password' => 'PASSWORD'
], 'Encryption-Key');
{
    "success": true
}

#####20. 更新客户供应商

$client->getSuppliersFields([
    'prim_uid' => '2568'
])
[
    {
        "field_key": "USERNAME",
        "label": "Username",
        "help_text": "Here can be any string that can be shown as a help text for the field",
        "mandatory": true,
        "type": "text",
        "dependency": ""
    }, 
    {
        "field_key": "PASSWORD",
        "label": "Password",
        "help_text": "Here can be any string that can be shown as a help text for the field",
        "mandatory": true,
        "type": "password",
        "dependency": "USERNAME" 
    }, 
    {
        "field_key": "LANG",
        "label": "Language",
        "help_text": "",
        "mandatory": false,
        "type": "dropdown",
        "dependency": "",
        "options": "{\"de_de\":\"Deutsch\",\"en_us\":\"English\"}"
    }
]

#####21. 获取供应商字段

$client->getDocumentQueue([
    'environment_prim_uid' => '15'
]);
{
    "count": 100,
    "total": 2345,
    "documents": [
        {
            "prim_uid": 173, 
            "customer_prim_uid": 1, 
            "customer_supplier_prim_uid": 13, 
            "supplier_prim_uid": 307, 
            "filename": "receipt-1708171523.pdf",
            "file_size": 136.75, // File size is always in KB
            "file_content_checksum": "", // md5 hash of file content (raw content, not base64 encoded content)
            "document_type": "invoice" // currently "invoice" and "bank_statement" are supported
        }
    ]
}

#####22. 获取文档队列

$client->getDocument([
   'prim_uid' => '102',
   'customer_secret' => 'Customer Secret'
]);
{
    "prim_uid": 102,
    "customer_prim_uid": 1, 
    "customer_supplier_prim_uid": 13, 
    "supplier_prim_uid": 307, 
    "filename": "receipt-1708171523.pdf",
    "file_size": "136.75", 
    "file_content_checksum": "", 
    "file_content": "", 
    "document_type": "invoice" 
}

#####23. 获取文档

$client->removeDocumentFromQueue([
    'prim_uid' => $document->prim_uid,
    'customer_secret' => $customer->customer_secret
]);
{
    "success": true
}