2021-08-23 17:39:03 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-11-16 17:03:53 +00:00
|
|
|
const {
|
|
|
|
getRequest,
|
|
|
|
postRequest,
|
|
|
|
putRequest,
|
|
|
|
deleteRequest,
|
|
|
|
} = require( '../utils/request' );
|
|
|
|
const { getOrderExample, shared } = require( '../data' );
|
2021-08-23 17:39:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce Orders endpoints.
|
|
|
|
*
|
|
|
|
* https://woocommerce.github.io/woocommerce-rest-api-docs/#orders
|
|
|
|
*/
|
|
|
|
const ordersApi = {
|
|
|
|
name: 'Orders',
|
|
|
|
create: {
|
|
|
|
name: 'Create an order',
|
|
|
|
method: 'POST',
|
|
|
|
path: 'orders',
|
|
|
|
responseCode: 201,
|
2021-09-08 01:02:58 +00:00
|
|
|
payload: getOrderExample(),
|
2021-09-07 22:20:44 +00:00
|
|
|
order: async ( orderDetails ) => postRequest( 'orders', orderDetails ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
retrieve: {
|
|
|
|
name: 'Retrieve an order',
|
|
|
|
method: 'GET',
|
|
|
|
path: 'orders/<id>',
|
|
|
|
responseCode: 200,
|
2021-11-16 17:03:53 +00:00
|
|
|
order: async ( orderId, ordersQuery = {} ) =>
|
|
|
|
getRequest( `orders/${ orderId }`, ordersQuery ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
listAll: {
|
|
|
|
name: 'List all orders',
|
|
|
|
method: 'GET',
|
|
|
|
path: 'orders',
|
|
|
|
responseCode: 200,
|
2021-11-16 17:03:53 +00:00
|
|
|
orders: async ( ordersQuery = {} ) =>
|
|
|
|
getRequest( 'orders', ordersQuery ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
update: {
|
|
|
|
name: 'Update an order',
|
|
|
|
method: 'PUT',
|
|
|
|
path: 'orders/<id>',
|
|
|
|
responseCode: 200,
|
2021-09-08 01:02:58 +00:00
|
|
|
payload: getOrderExample(),
|
2021-11-16 17:03:53 +00:00
|
|
|
order: async ( orderId, orderDetails ) =>
|
|
|
|
putRequest( `orders/${ orderId }`, orderDetails ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
delete: {
|
|
|
|
name: 'Delete an order',
|
|
|
|
method: 'DELETE',
|
|
|
|
path: 'orders/<id>',
|
|
|
|
responseCode: 200,
|
|
|
|
payload: {
|
2021-11-16 17:03:53 +00:00
|
|
|
force: false,
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
2021-11-16 17:03:53 +00:00
|
|
|
order: async ( orderId, deletePermanently ) =>
|
|
|
|
deleteRequest( `orders/${ orderId }`, deletePermanently ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
batch: {
|
|
|
|
name: 'Batch update orders',
|
|
|
|
method: 'POST',
|
|
|
|
path: 'orders/batch',
|
|
|
|
responseCode: 200,
|
2021-09-08 01:02:58 +00:00
|
|
|
payload: shared.getBatchPayloadExample( getOrderExample() ),
|
2021-11-16 17:03:53 +00:00
|
|
|
orders: async ( batchUpdatePayload ) =>
|
|
|
|
postRequest( `orders/batch`, batchUpdatePayload ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
2021-09-07 22:20:44 +00:00
|
|
|
};
|
|
|
|
|
2021-08-23 17:39:03 +00:00
|
|
|
module.exports = {
|
|
|
|
ordersApi,
|
2021-09-07 22:20:44 +00:00
|
|
|
};
|