2021-08-23 17:39:03 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
const { getRequest, postRequest, putRequest, deleteRequest } = require('../utils/request');
|
2021-09-08 01:02:58 +00:00
|
|
|
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-09-07 22:20:44 +00:00
|
|
|
order: async ( orderId ) => getRequest( `orders/${orderId}` ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
listAll: {
|
|
|
|
name: 'List all orders',
|
|
|
|
method: 'GET',
|
|
|
|
path: 'orders',
|
|
|
|
responseCode: 200,
|
2021-09-22 20:15:40 +00:00
|
|
|
orders: async () => getRequest( 'orders' ),
|
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-09-07 22:20:44 +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: {
|
|
|
|
force: false
|
|
|
|
},
|
2021-09-07 22:20:44 +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-09-07 22:20:44 +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
|
|
|
};
|