avalara/avalara_sdk

API 用于评估交易是否符合针对直接面向消费者饮料酒精运输的规定。此 API 目前处于测试阶段。

24.2.29 2024-03-21 23:35 UTC

This package is not auto-updated.

Last update: 2024-09-21 01:01:35 UTC


README

API 用于评估交易是否符合针对直接面向消费者饮料酒精运输的规定。

此 API 目前处于测试阶段。

安装与使用

要求

PHP 7.3 及以上。应该也兼容 PHP 8.0,但尚未测试。

Composer

要通过 Composer 安装绑定,请将以下内容添加到 composer.json

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
    }
  ],
  "require": {
    "GIT_USER_ID/GIT_REPO_ID": "*@dev"
  }
}

然后运行 composer install

手动安装

下载文件并包含 autoload.php

<?php
require_once('/path/to/OpenAPIClient-php/vendor/autoload.php');

入门

请遵循 安装过程,然后运行以下命令

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure HTTP OAUTH2 Access Token and other config options
$config = new \Avalara\SDK\Configuration();
$config->setBearerToken('YOUR_JWT_ACCESS_TOKEN');
$config->setAppName('YOUR_APP_NAME');
$config->setEnvironment('sandbox');
$config->setMachineName('YOUR_MACHINE_NAME');
$config->setAppVersion('YOUR_APP_VERSION');

$client = new \Avalara\SDK\ApiClient($config);

$apiInstance = new Avalara\\SDK\Api\AddressesApi($client);

$x_avalara_client = 'Swagger UI; 22.7.0; Custom; 1.0'; // string | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) .
$body = new \Avalara\\SDK\Model\\Avatax\AddressValidationInfo(); // \Avalara\\SDK\Model\\Avatax\AddressValidationInfo | The address to resolve

try {
    $result = $apiInstance->resolveAddressPost($x_avalara_client, $body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AddressesApi->resolveAddressPost: ', $e->getMessage(), PHP_EOL;
}

授权文档

API 定义的认证方案:

OAuth 客户端凭证

  • 类型: OAuth
  • 流程: client_credentials
  • 作用域:
    • avatax_api: avatax_api 作用域。
<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure HTTP OAUTH2 Client Credentials Flow and other config options
$config = new \Avalara\SDK\Configuration();
$config->setClientId('YOUR_CLIENT_ID');
$config->setClientSecret('YOUR_CLIENT_SECRET');
$config->setAppName('YOUR_APP_NAME');
$config->setEnvironment('sandbox');
$config->setMachineName('YOUR_MACHINE_NAME');
$config->setAppVersion('YOUR_APP_VERSION');

$client = new \Avalara\SDK\ApiClient($config);

$apiInstance = new Avalara\\SDK\Api\AddressesApi($client);

$x_avalara_client = 'Swagger UI; 22.7.0; Custom; 1.0'; // string | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) .
$body = new \Avalara\\SDK\Model\\Avatax\AddressValidationInfo(); // \Avalara\\SDK\Model\\Avatax\AddressValidationInfo | The address to resolve

try {
    $result = $apiInstance->resolveAddressPost($x_avalara_client, $body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AddressesApi->resolveAddressPost: ', $e->getMessage(), PHP_EOL;
}

OAuth 设备码

  • 类型: OAuth
  • 流程: device_code
  • 作用域:
    • avatax_api: avatax_api 作用域。
<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure HTTP OAUTH2 Device Code Flow and other config options
$config = new \Avalara\SDK\Configuration();
$config->setClientId('YOUR_CLIENT_ID');
$config->setAppName('YOUR_APP_NAME');
$config->setEnvironment('sandbox');
$config->setMachineName('YOUR_MACHINE_NAME');
$config->setAppVersion('YOUR_APP_VERSION');

// Fetch Device Code 
$result = \Avalara\SDK\Auth\OAuthHelper::initiateDeviceAuthorizationFlow('avatax_api', $config);
// User Interaction needs to happen here - some polling logic is needed to wait for offline user to authenticate to verification_uri through browser
$tokenResult = \Avalara\SDK\Auth\OAuthHelper::getAccessTokenForDeviceFlow($result->deviceCode, $config);
// Once user authenticates, tokenResult will contain Bearer token.
$config->setBearerToken($tokenResult->accessToken);

$client = new \Avalara\SDK\ApiClient($config);

$apiInstance = new Avalara\\SDK\Api\AddressesApi($client);

$x_avalara_client = 'Swagger UI; 22.7.0; Custom; 1.0'; // string | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) .
$body = new \Avalara\\SDK\Model\\Avatax\AddressValidationInfo(); // \Avalara\\SDK\Model\\Avatax\AddressValidationInfo | The address to resolve

try {
    $result = $apiInstance->resolveAddressPost($x_avalara_client, $body);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling AddressesApi->resolveAddressPost: ', $e->getMessage(), PHP_EOL;
}

测试

要运行测试,请使用

composer install
vendor/bin/phpunit

日志记录

SDK 支持所有 PSR-3 兼容 的日志记录器。

用法

声明您想要的任何 PSR-3 日志记录器,并通过配置对象传递。以下示例使用 Monolog

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$config = new \Avalara\SDK\Configuration();
// Configure logger
$logger = new Logger('AddressLogger');
$logger->pushHandler(new StreamHandler(__DIR__ . '/../../app.log', Logger::DEBUG));
// Setup log options , first parameter is logRequestAndResponseBody, which can be true|false. Second parameter is the PSR-3 compatible logger.
$logOptions = new \Avalara\SDK\Utils\LogOptions(true, $logger);
$config->setLogOptions($logOptions);
$client =  new \Avalara\SDK\ApiClient($config);

关于此包

此 PHP 包是由 OpenAPI Generator 项目自动生成的

  • API 版本: v2
    • 包版本: 2.5.0
  • 构建包: org.openapitools.codegen.languages.PhpClientCodegen

API 端点文档

EInvoicing V1 API 文档

模型文档

EInvoicing V1 模型文档