2021-08-23 17:39:03 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
const { getRequest, postRequest, putRequest, deleteRequest } = require('../utils/request');
|
|
|
|
const { coupon, shared } = require('../data');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce Coupon endpoints.
|
|
|
|
*
|
|
|
|
* https://woocommerce.github.io/woocommerce-rest-api-docs/#coupons
|
|
|
|
*/
|
|
|
|
const couponsApi = {
|
|
|
|
name: 'Coupons',
|
|
|
|
create: {
|
|
|
|
name: 'Create a coupon',
|
|
|
|
method: 'POST',
|
|
|
|
path: 'coupons',
|
|
|
|
responseCode: 201,
|
|
|
|
payload: coupon,
|
2021-09-07 22:20:44 +00:00
|
|
|
coupon: async ( couponDetails ) => postRequest( 'coupons', couponDetails ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
retrieve: {
|
|
|
|
name: 'Retrieve a coupon',
|
|
|
|
method: 'GET',
|
|
|
|
path: 'coupons/<id>',
|
|
|
|
responseCode: 200,
|
2021-09-07 22:20:44 +00:00
|
|
|
coupon: async ( couponId ) => getRequest( `coupons/${couponId}` ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
listAll: {
|
|
|
|
name: 'List all coupons',
|
|
|
|
method: 'GET',
|
|
|
|
path: 'coupons',
|
|
|
|
responseCode: 200,
|
2021-09-22 20:15:40 +00:00
|
|
|
coupons: async () => getRequest( 'coupons' ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
update: {
|
|
|
|
name: 'Update a coupon',
|
|
|
|
method: 'PUT',
|
|
|
|
path: 'coupons/<id>',
|
|
|
|
responseCode: 200,
|
|
|
|
payload: coupon,
|
2021-09-07 22:20:44 +00:00
|
|
|
coupon: async ( couponId, couponDetails ) => putRequest( `coupons/${couponId}`, couponDetails ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
delete: {
|
|
|
|
name: 'Delete a coupon',
|
|
|
|
method: 'DELETE',
|
|
|
|
path: 'coupons/<id>',
|
|
|
|
responseCode: 200,
|
|
|
|
payload: {
|
|
|
|
force: false
|
|
|
|
},
|
2021-09-07 22:20:44 +00:00
|
|
|
coupon: async ( couponId, deletePermanently ) => deleteRequest( `coupons/${couponId}`, deletePermanently ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
batch: {
|
|
|
|
name: 'Batch update coupons',
|
|
|
|
method: 'POST',
|
|
|
|
path: 'coupons/batch',
|
|
|
|
responseCode: 200,
|
|
|
|
payload: shared.getBatchPayloadExample( coupon ),
|
2021-09-07 22:20:44 +00:00
|
|
|
coupons: async ( batchUpdatePayload ) => postRequest( `coupons/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
|
|
|
|
2021-09-07 22:20:44 +00:00
|
|
|
module.exports = { couponsApi };
|