udevrandom / avataxclient

Avalara AvaTax 套件的企业税务计算和处理服务的客户端库。使用 REST v2 API。更新以使用 Guzzle 7 以实现 Laravel 兼容性。


README

此 GitHub 仓库是 Avalara 顶级税务服务 AvaTax 的 PHP SDK。它使用 AvaTax REST v2 API,这是一个完整的 REST 实现,提供对 AvaTax 所有功能的单一客户端。有关 AvaTax REST v2 的更多信息,请访问 Avalara 开发者网络 或查看 在线 Swagger 文档

构建状态

Packagist

Packagist

Travis-CI

Travis

安装 PHP SDK

AvaTax PHP SDK 可作为 Composer 包使用。

要从 Composer 使用 AvaTax PHP SDK

  • composer.json 文件添加到您的项目中,并将其链接到 AvaTax
{
    "require": {
        "avalara/avataxclient": "*"
    }
}
  • 运行 composer install 以下载最新版本。

使用 PHP SDK

PHP SDK 使用流畅的接口来定义连接到 AvaTax 以及执行 API 调用来计算交易的税额。以下是一个连接到 API 的示例。

<?php

// Include the AvaTaxClient library
require __DIR__ . '/vendor/autoload.php';
use Avalara\AvaTaxClient;

// Create a new client
$client = new Avalara\AvaTaxClient('phpTestApp', '1.0', 'localhost', 'sandbox');
$client->withSecurity('myUsername', 'myPassword');

// If I am debugging, I can call 'Ping' to see if I am connected to the server
$p = $client->ping();
echo('<h2>Ping</h2>');
echo('<pre>' . json_encode($p, JSON_PRETTY_PRINT) . '</pre>');
if ($p->authenticated == true) {
    echo '<p>Authenticated!</p>';
}

// Create a simple transaction for $100 using the fluent transaction builder
$tb = new Avalara\TransactionBuilder($client, "DEFAULT", Avalara\DocumentType::C_SALESINVOICE, 'ABC');
$t = $tb->withAddress('SingleLocation', '123 Main Street', null, null, 'Irvine', 'CA', '92615', 'US')
    ->withLine(100.0, 1, null, "P0000000")
    ->create();
echo('<h2>Transaction #1</h2>');
echo('<pre>' . json_encode($t, JSON_PRETTY_PRINT) . '</pre>');

// Now, let's create a more complex transaction!
$tb = new Avalara\TransactionBuilder($client, "DEFAULT", Avalara\DocumentType::C_SALESINVOICE, 'ABC');
$t = $tb->withAddress('ShipFrom', '123 Main Street', null, null, 'Irvine', 'CA', '92615', 'US')
    ->withAddress('ShipTo', '100 Ravine Lane', null, null, 'Bainbridge Island', 'WA', '98110', 'US')
    ->withLine(100.0, 1, null, "P0000000")
    ->withLine(1234.56, 1, null, "P0000000")
    ->withExemptLine(50.0, null, "NT")
    ->withLine(2000.0, 1, null, "P0000000")
    ->withLineAddress(Avalara\TransactionAddressType::C_SHIPFROM, "123 Main Street", null, null, "Irvine", "CA", "92615", "US")
    ->withLineAddress(Avalara\TransactionAddressType::C_SHIPTO, "1500 Broadway", null, null, "New York", "NY", "10019", "US")
    ->withLine(50.0, 1, null, "FR010000")
    ->create();
echo('<h2>Transaction #2</h2>');
echo('<pre>' . json_encode($t, JSON_PRETTY_PRINT) . '</pre>');

?>