2021-08-23 17:39:03 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-05-05 03:02:50 +00:00
|
|
|
const {
|
|
|
|
getRequest,
|
|
|
|
postRequest,
|
|
|
|
putRequest,
|
|
|
|
deleteRequest,
|
|
|
|
} = require( '../utils/request' );
|
|
|
|
const { coupon, shared } = require( '../data' );
|
2021-08-23 17:39:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2022-05-05 03:02:50 +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,
|
2022-05-05 03:02:50 +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-10-19 07:09:48 +00:00
|
|
|
coupons: async ( queryString ) => getRequest( 'coupons', queryString ),
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
|
|
|
update: {
|
|
|
|
name: 'Update a coupon',
|
|
|
|
method: 'PUT',
|
|
|
|
path: 'coupons/<id>',
|
|
|
|
responseCode: 200,
|
|
|
|
payload: coupon,
|
2022-05-05 03:02:50 +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: {
|
2022-05-05 03:02:50 +00:00
|
|
|
force: false,
|
2021-08-23 17:39:03 +00:00
|
|
|
},
|
2022-05-05 03:02:50 +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 ),
|
2022-05-05 03:02:50 +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
|
|
|
|
2022-05-05 03:02:50 +00:00
|
|
|
module.exports = { couponsApi };
|