woocommerce/packages/js/api-core-tests/endpoints/shipping-methods.js

85 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-11-11 13:11:03 +00:00
/**
* Internal dependencies
*/
const {
getRequest,
postRequest,
putRequest,
deleteRequest,
} = require( '../utils/request' );
/**
* WooCommerce Shipping method endpoints.
*
* https://woocommerce.github.io/woocommerce-rest-api-docs/#shipping-methods
*/
const shippingMethodsApi = {
name: 'Shipping methods',
create: {
name: 'Include a shipping method to a shipping zone',
method: 'POST',
path: 'shipping/zones/<id>/methods',
responseCode: 200,
shippingMethod: async ( shippingZoneId, shippingMethod ) =>
postRequest(
`shipping/zones/${ shippingZoneId }/methods`,
shippingMethod
),
},
retrieve: {
name: 'Retrieve a shipping method from a shipping zone',
method: 'GET',
path: 'shipping/zones/<zone_id>/methods/<id>',
responseCode: 200,
shippingMethod: async ( shippingZoneId, shippingMethodInstanceId ) =>
getRequest(
`shipping/zones/${ shippingZoneId }/methods/${ shippingMethodInstanceId }`
),
},
listAll: {
name: 'List all shipping methods from a shipping zone',
method: 'GET',
path: 'shipping/zones/<id>/methods',
responseCode: 200,
shippingMethods: async ( shippingZoneId, params = {} ) =>
getRequest( `shipping/zones/${ shippingZoneId }/methods`, params ),
},
update: {
name: 'Update a shipping method of a shipping zone',
method: 'PUT',
path: 'shipping/zones/<zone_id>/methods/<id>',
responseCode: 200,
shippingMethod: async (
shippingZoneId,
shippingMethodInstanceId,
updatedShippingMethod
) =>
putRequest(
`shipping/zones/${ shippingZoneId }/methods/${ shippingMethodInstanceId }`,
updatedShippingMethod
),
},
delete: {
2021-12-02 18:41:21 +00:00
name: 'Delete a shipping method from a shipping zone',
2021-11-11 13:11:03 +00:00
method: 'DELETE',
path: 'shipping/zones/<zone_id>/methods/<id>>',
responseCode: 200,
payload: {
force: false,
},
shippingMethod: async (
shippingZoneId,
shippingMethodInstanceId,
deletePermanently
) =>
deleteRequest(
`shipping/zones/${ shippingZoneId }/methods/${ shippingMethodInstanceId }`,
deletePermanently
),
},
};
module.exports = {
shippingMethodsApi,
};