UNPKG

@ringmybelle/taxjar

Version:
162 lines (161 loc) 4.22 kB
"use strict"; const request_1 = require("./util/request"); const TaxjarTypes = require("./util/types"); class Taxjar { constructor(config) { let apiUrl = Taxjar.DEFAULT_API_URL + '/' + Taxjar.API_VERSION + '/'; if (!config || !config['apiKey']) { throw new Error('Please provide a TaxJar API key'); } if (config && config['apiUrl']) { apiUrl = config['apiUrl'] + '/' + Taxjar.API_VERSION + '/'; } this.config = { apiUrl: apiUrl, apiKey: config['apiKey'], headers: config['headers'] }; this.request = (0, request_1.default)(this.config); } getApiConfig(index) { return this.config[index]; } setApiConfig(index, value) { if (index === 'apiUrl') { value += '/' + Taxjar.API_VERSION + '/'; } this.config[index] = value; this.request = (0, request_1.default)(this.config); } categories() { return this.request.get({ url: 'categories' }); } taxForOrder(params) { return this.request.post({ url: 'taxes', params }); } listOrders(params) { return this.request.get({ url: 'transactions/orders', params }); } showOrder(transactionId, params) { return this.request.get({ url: 'transactions/orders/' + transactionId, params }); } createOrder(params) { return this.request.post({ url: 'transactions/orders', params }); } updateOrder(params) { return this.request.put({ url: 'transactions/orders/' + params.transaction_id, params }); } deleteOrder(transactionId, params) { return this.request.delete({ url: 'transactions/orders/' + transactionId, params }); } listRefunds(params) { return this.request.get({ url: 'transactions/refunds', params }); } showRefund(transactionId, params) { return this.request.get({ url: 'transactions/refunds/' + transactionId, params }); } createRefund(params) { return this.request.post({ url: 'transactions/refunds', params }); } updateRefund(params) { return this.request.put({ url: 'transactions/refunds/' + params.transaction_id, params }); } deleteRefund(transactionId, params) { return this.request.delete({ url: 'transactions/refunds/' + transactionId, params }); } listCustomers() { return this.request.get({ url: 'customers' }); } showCustomer(customerId) { return this.request.get({ url: 'customers/' + customerId }); } createCustomer(params) { return this.request.post({ url: 'customers', params }); } updateCustomer(params) { return this.request.put({ url: 'customers/' + params.customer_id, params }); } deleteCustomer(customerId) { return this.request.delete({ url: 'customers/' + customerId }); } ratesForLocation(zip, params) { return this.request.get({ url: 'rates/' + zip, params }); } nexusRegions() { return this.request.get({ url: 'nexus/regions' }); } validateAddress(params) { return this.request.post({ url: 'addresses/validate', params }); } validate(params) { return this.request.get({ url: 'validation', params }); } summaryRates() { return this.request.get({ url: 'summary_rates' }); } } Taxjar.DEFAULT_API_URL = 'https://api.taxjar.com'; Taxjar.SANDBOX_API_URL = 'https://api.sandbox.taxjar.com'; Taxjar.API_VERSION = 'v2'; Taxjar.Error = TaxjarTypes.TaxjarError; module.exports = Taxjar;