Skip to content

Commit 9ab3ed2

Browse files
authored
feat: Add functions for more API endpoints in ShopClient (#11)
1 parent f12c296 commit 9ab3ed2

File tree

1 file changed

+77
-17
lines changed

1 file changed

+77
-17
lines changed

src/ViURShopClient.js

+77-17
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ export class ViURShopClient {
122122
.then(req => req.json());
123123
}
124124

125-
// --- Basket ---------------------------------------------------------------
126-
basket_list() {
127-
return request(`${this.shop_api_url}/basket_list`).then(req => req.json());
128-
}
129-
130125
// --- Cart ---------------------------------------------------------------
131126

132127
/**
@@ -236,6 +231,26 @@ export class ViURShopClient {
236231
.then(req => req.json());
237232
}
238233

234+
/**
235+
* List the children of the basket (the cart stored in the session)
236+
*
237+
* @returns {Promise<Response>}
238+
*/
239+
basket_list() {
240+
return request(`${this.shop_api_url}/basket_list`)
241+
.then(req => req.json());
242+
}
243+
244+
/**
245+
* View the basket (the cart stored in the session) itself
246+
*
247+
* @returns {Promise<Response>}
248+
*/
249+
basket_view() {
250+
return request(`${this.shop_api_url}/basket_view`)
251+
.then(req => req.json());
252+
}
253+
239254
cart_structure() {
240255
return request(`${this.getStructure_url}/${this.shop_module}.cart`, {
241256
method: 'GET',
@@ -308,7 +323,24 @@ export class ViURShopClient {
308323

309324
// --- Order --------------------------------------------------------------
310325

311-
payment_providers_list({} = {}) {
326+
327+
/**
328+
* Get a list of payment providers.
329+
*
330+
* This API method returns a JSON response containing a object of
331+
* payment providers. The keys in the response represent provider
332+
* identifiers, and the values are objects describing the details of
333+
* each provider.
334+
*
335+
* @param {boolean} [onlyAvailable=true] -
336+
* If true, only payment providers that are currently available
337+
* will be included in the response. If false, all providers will
338+
* be listed regardless of availability.
339+
* @returns {Promise<Response>}
340+
*/
341+
payment_providers_list({
342+
only_available = true,
343+
} = {}) {
312344
return request(`${this.shop_url}/order/payment_providers_list`)
313345
.then(req => req.json());
314346
}
@@ -365,37 +397,65 @@ export class ViURShopClient {
365397
.then(req => req.json());
366398
}
367399

368-
order_checkout_start({
369-
order_key,
370-
} = {}) {
371-
return request(`${this.shop_url}/order/checkout_start`, {
372-
method: 'POST',
400+
/**
401+
* List the orders of the current user
402+
* @param {object} param Any key-value pairs for filtering or ordering
403+
* @returns {Promise<Response>}
404+
*/
405+
order_list(param = {}) {
406+
return request(`${this.shop_url}/api/order_list`, {
407+
method: 'GET',
408+
params,
409+
})
410+
.then(req => req.json());
411+
}
412+
413+
/**
414+
* View an order
415+
* @param {String} order_key Key of the order to view.
416+
* Use "SESSION" as key to view the order of the current session
417+
* @returns {Promise<Response>}
418+
*/
419+
order_view({
420+
order_key = 'SESSION',
421+
} = {}) {
422+
return request(`${this.shop_url}/api/order_view`, {
423+
method: 'GET',
373424
params: {order_key},
374425
})
375426
.then(req => req.json());
376427
}
377428

378-
order_checkout_order({
429+
/**
430+
* Start the checkout process
431+
* @param {String} key The key of the order
432+
* @returns {Promise<Response>}
433+
*/
434+
order_checkout_start({
379435
order_key,
380436
} = {}) {
381-
return request(`${this.shop_url}/order/checkout_order`, {
437+
return request(`${this.shop_url}/order/checkout_start`, {
382438
method: 'POST',
383439
params: {order_key},
384440
})
385441
.then(req => req.json());
386442
}
387443

388-
order_pp_get_settings({
389-
order_key,
390-
} = {}) {
444+
/**
445+
* The final order now step
446+
* @param {String} key The key of the order
447+
* @returns {Promise<Response>}
448+
*/
449+
order_checkout_order({
450+
order_key,
451+
} = {}) {
391452
return request(`${this.shop_url}/order/checkout_order`, {
392453
method: 'POST',
393454
params: {order_key},
394455
})
395456
.then(req => req.json());
396457
}
397458

398-
399459
// --- User ---------------------------------------------------------------
400460

401461
user_view({

0 commit comments

Comments
 (0)