nexagon/flow-php

Nexagon Flow API库,适用于PHP

1.2.6 2020-11-24 07:30 UTC

This package is auto-updated.

Last update: 2024-09-24 15:38:58 UTC


README

Flow PHP库为PHP编写的应用程序提供了对Nexagon Flow API资源的便捷访问。

要求

PHP 7.2及以后版本

Composer

您可以使用Composer安装flow-php。运行以下命令

composer require nexagon/flow-php

要使用库,请使用Composer的自动加载器

require_once('vendor/autoload.php');

手动安装

如果您不想使用Composer,可以从该仓库下载代码。然后,为了使用库,只需包含init.php文件。

require_once('/path/to/flow-php/init.php');

依赖项

该SDK使用以下依赖项。

  • guzzlehttp/guzzle
  • json

如果您使用的是Composer,所有内容都应该可以正常工作。否则,请确保以下扩展可用。

入门

库的简单使用

$flow = new Flow\FlowClient("api-key-goes-here");
[$customer,] = $flow->customers->create([
    "name" => "Test customer",
    "email" => "some@email.test",
    "reference_identifier" => "some reference",
    "locations" => [
        "name" => "Headquarters",
        "phone" => "004588888888",
        "address_line_1" => "Test street 2",
        "postal_code" => "8000",        
        "city" => "Aarhus",
        "country" => "DK",
    ], 
]);

[$order,] = $flow->orders->create([
    "customer_group" => $customer->id,
]);
echo $order;

更改API端点

如果您正在测试或在一个预发布环境中工作,可能需要更改API端点。

$flow = new Flow\FlowClient("api-key-goes-here", "https://:8000/");
// or
$flow->setApiEndpoint("http://sometest-endpoint.test");

请记住在末尾添加一个斜杠/。否则,请求可能会失败。

上传文件和添加多个文件版本

每次您需要将文件添加到flow中时,必须首先创建并上传它,然后任何资源才能使用它。以下是如何将文件上传到flow的参考。

$flow = new Flow\FlowClient("api-key-goes-here");
$stream = fopen("path/to/file.png", "r");
$mimetype = mime_content_type("path/to/file.png");
[$file,] = $flow->files->createAndUpload($stream, "file.png", $mimetype);

// Consume the file on order lines or other resources
$order_line_data = [
    "files" => [$file->id],
    ... // Any other required order line data - see documentation
];
[$order,] = $flow->orders->create([
    "order_lines" => [$order_line_data]
]);

如果需要更新文件,必须添加一个新版本

$flow = new Flow\FlowClient("api-key-goes-here");
$stream = ...;
$name = ...;
$mimetype = ...;
[$file, ] = $flow->files->addFileVersion($stream, $name, $mimetype);

// You have access to all version
foreach ($file->versions as &$version) {
    if ($version->latest) {
        print_r("Im the latest version ($version->last_modified)! Download me here: $version->url");
    }
}

文档

请参阅Nexagon Flow文档

访问请求

您可以直接访问Gruzzle\Request

$flow = new Flow\FlowClient("api-key-goes-here");
[$order, $request] = $flow->orders->retrieve(1);

echo $request->getStatusCode();

请注意,所有状态码大于等于300的请求都会失败并抛出FlowException

许可证

MIT许可证

版权(c)2020 Nexagon IVS

特此授予任何获得本软件及其相关文档副本(以下简称“软件”)的人免费使用软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许有权获得软件的人使用本软件,前提是遵守以下条件

上述版权声明和本许可声明应包含在软件的副本或主要部分中。

本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论是因合同、侵权或其他原因而引起的,无论该索赔、损害或其他责任是否与软件或其使用或其它交易有关。