2021-11-15 14:30:34 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
const {
|
|
|
|
getRequest,
|
|
|
|
postRequest,
|
|
|
|
putRequest,
|
|
|
|
deleteRequest,
|
|
|
|
} = require( '../utils/request' );
|
2021-12-02 13:52:25 +00:00
|
|
|
const { getTaxRateExamples, shared } = require( '../data' );
|
2021-11-15 14:30:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce Tax Rates endpoints.
|
|
|
|
*
|
|
|
|
* https://woocommerce.github.io/woocommerce-rest-api-docs/#tax-rates
|
|
|
|
*/
|
|
|
|
const taxRatesApi = {
|
|
|
|
name: 'Tax Rates',
|
|
|
|
create: {
|
|
|
|
name: 'Create a tax rate',
|
|
|
|
method: 'POST',
|
|
|
|
path: 'taxes',
|
|
|
|
responseCode: 201,
|
2021-12-02 13:52:25 +00:00
|
|
|
payload: getTaxRateExamples(),
|
2021-11-15 14:30:34 +00:00
|
|
|
taxRate: async ( taxRate ) => postRequest( 'taxes', taxRate ),
|
|
|
|
},
|
|
|
|
retrieve: {
|
|
|
|
name: 'Retrieve a tax rate',
|
|
|
|
method: 'GET',
|
|
|
|
path: 'taxes/<id>',
|
|
|
|
responseCode: 200,
|
2022-10-12 02:05:01 +00:00
|
|
|
// eslint-disable-next-line no-undef
|
2021-11-15 14:30:34 +00:00
|
|
|
taxRate: async ( taxRateId ) => taxes( `coupons/${ taxRateId }` ),
|
|
|
|
},
|
|
|
|
listAll: {
|
|
|
|
name: 'List all tax rates',
|
|
|
|
method: 'GET',
|
|
|
|
path: 'taxes',
|
|
|
|
responseCode: 200,
|
|
|
|
taxRates: async ( queryString = {} ) =>
|
|
|
|
getRequest( 'taxes', queryString ),
|
|
|
|
},
|
|
|
|
update: {
|
|
|
|
name: 'Update a tax rate',
|
|
|
|
method: 'PUT',
|
|
|
|
path: 'taxes/<id>',
|
|
|
|
responseCode: 200,
|
2021-12-02 13:52:25 +00:00
|
|
|
payload: getTaxRateExamples(),
|
2021-11-15 14:30:34 +00:00
|
|
|
taxRate: async ( taxRateId, taxRateDetails ) =>
|
|
|
|
putRequest( `taxes/${ taxRateId }`, taxRateDetails ),
|
|
|
|
},
|
|
|
|
delete: {
|
|
|
|
name: 'Delete a tax rate',
|
|
|
|
method: 'DELETE',
|
|
|
|
path: 'taxes/<id>',
|
|
|
|
responseCode: 200,
|
|
|
|
payload: {
|
|
|
|
force: false,
|
|
|
|
},
|
|
|
|
taxRate: async ( taxRateId, deletePermanently ) =>
|
|
|
|
deleteRequest( `taxes/${ taxRateId }`, deletePermanently ),
|
|
|
|
},
|
|
|
|
batch: {
|
|
|
|
name: 'Batch update tax rates',
|
|
|
|
method: 'POST',
|
|
|
|
path: 'taxes/batch',
|
|
|
|
responseCode: 200,
|
2021-12-02 13:52:25 +00:00
|
|
|
payload: shared.getBatchPayloadExample( getTaxRateExamples() ),
|
2021-11-15 14:30:34 +00:00
|
|
|
taxRates: async ( batchUpdatePayload ) =>
|
|
|
|
postRequest( `taxes/batch`, batchUpdatePayload ),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = { taxRatesApi };
|