项目作者: avadev

项目描述 :
Sales Tax API SDK for Javascript / Node and AvaTax REST
高级语言: JavaScript
项目地址: git://github.com/avadev/AvaTax-REST-V2-JS-SDK.git
创建时间: 2016-12-28T18:56:10Z
项目社区:https://github.com/avadev/AvaTax-REST-V2-JS-SDK

开源协议:Apache License 2.0

下载


AvaTax Rest V2 Node.js SDK

AvaTax v2 SDK for languages using node.js

Version
Build Status
Downloads
Try on RunKit

Installation

Install the package with:

  1. # using npm
  2. npm install avatax
  3. # using yarn
  4. yarn add avatax

Usage

Configuration

  1. // es5 import
  2. var Avatax = require('avatax');
  3. // es6/7 import
  4. // import Avatax from 'avatax';
  5. // resolve configuration, credentials and logOptions
  6. const config = {
  7. appName: 'your-app',
  8. appVersion: '1.0',
  9. environment: 'sandbox',
  10. machineName: 'your-machine-name',
  11. timeout: 5000, // optional, default 20 min
  12. logOptions: {
  13. logEnabled: true, // toggle logging on or off, by default its off.
  14. logLevel: 3, // logLevel that will be used, Options are LogLevel.Error (0), LogLevel.Warn (1), LogLevel.Info (2), LogLevel.Debug (3)
  15. logRequestAndResponseInfo: true, // Toggle logging of the request and response bodies on and off.
  16. logger: myCustomLogger // (OPTIONAL) Custom logger can be passed in that implements the BaseLogger interface (e.g. debug, info, warn, error, and log functions) Otherwise console.log/error etc will be used by default.
  17. },
  18. customHttpAgent: new https.Agent({keepAlive: true}), // (OPTIONAL) Define a custom https agent, import https from node to use this constructor. See https://node.readthedocs.io/en/latest/api/https/#https_class_https_agent for more information.
  19. enableStrictTypeConversion: true // Ensures that all responses returned by the API methods will be type-safe and match the Models explicitly, For Example, the enums will be returned as integer values instead of as Strings as previously were.
  20. };
  21. const creds = {
  22. username: '<your-username>',
  23. password: '<your-password>'
  24. };
  25. var client = new Avatax(config).withSecurity(creds);

Tax Calculation

  1. const taxDocument = {
  2. type: 'SalesInvoice',
  3. companyCode: 'abc123',
  4. date: '2017-04-12',
  5. customerCode: 'ABC',
  6. purchaseOrderNo: '2017-04-12-001',
  7. addresses: {
  8. SingleLocation: {
  9. line1: '123 Main Street',
  10. city: 'Irvine',
  11. region: 'CA',
  12. country: 'US',
  13. postalCode: '92615'
  14. }
  15. },
  16. lines: [
  17. {
  18. number: '1',
  19. quantity: 1,
  20. amount: 100,
  21. taxCode: 'PS081282',
  22. itemCode: 'Y0001',
  23. description: 'Yarn'
  24. }
  25. ],
  26. commit: true,
  27. currencyCode: 'USD',
  28. description: 'Yarn'
  29. }
  30. return client.createTransaction({ model: taxDocument })
  31. .then(result => {
  32. // response tax document
  33. console.log(result);
  34. });

Address Validation

  1. const address = {
  2. city: 'irvine',
  3. postalCode: '92615',
  4. region: 'ca',
  5. country: 'us'
  6. };
  7. return client.resolveAddress(address)
  8. .then(result => {
  9. // address validation result
  10. console.log(result);
  11. });

Release Notes

Please see the Github releases for in-depth release notes.

Typescript support

As of version 22.11.0, Typescript support is included in the SDK. Models and Enums included in addition to typing for all of the API methods and parameters. The team welcomes any feedback on this feature.

Models and Enums can be imported into Typescript projects as follows:

  1. import { AddressResolutionModel } from 'avatax/lib/models';
  2. import { AddressCategoryId } from 'avatax/lib/enums';

SDK Development

Adding integration test credentials

Running integration tests will hit the deployed lower environment

Test credentials are resolved in the following order:

  1. Environment variables

The following environment variables will get loaded as test credentials

  1. SANDBOX_USERNAME="your-username"
  2. SANDBOX_PASSWORD="your-password"
  1. Local credentials file

You can also add a local credentials file to the the path “/local_creds.json”. This file will be gitignored

  1. {
  2. "username": "your-username",
  3. "password": "your-password"
  4. }
  1. Static (mock) values

The mocked values are used for unit tests via ‘nock’.

The test credentials helper can be found here
https://github.com/avadev/AvaTax-REST-V2-JS-SDK/blob/master/test/helpers/load_creds.js

Publish tags upstream

  1. # assuming a tag of v17.5.2 and a remote of 'upstream'
  2. git push upstream v17.5.2