diff options
author | Mateja <mail@matejamaric.com> | 2021-07-27 14:34:41 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2021-07-27 14:34:41 +0200 |
commit | ea671474106d6416fb4d90da05c34d916b6ca5a2 (patch) | |
tree | 0250c86df52194ce9f66e705bca180146e3daa42 /client/src/store | |
parent | 3925b2674aa06b9824e75c584dce493d515b52e2 (diff) | |
download | mevn-ecommerce-ea671474106d6416fb4d90da05c34d916b6ca5a2.tar.gz mevn-ecommerce-ea671474106d6416fb4d90da05c34d916b6ca5a2.zip |
Move transaction requests to Vuex.
Diffstat (limited to 'client/src/store')
-rw-r--r-- | client/src/store/index.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/client/src/store/index.js b/client/src/store/index.js index 519347d..a2d3f9f 100644 --- a/client/src/store/index.js +++ b/client/src/store/index.js @@ -77,6 +77,22 @@ export default createStore({ await axios.get(`${process.env.VUE_APP_ROOT_API}/products/${productId}`) .then(response => context.commit('setCurrentProduct', response.data)) .catch(error => console.error(error)); + }, + async createOrder(context) { + const checkoutRequest = {items: context.state.cart}; + + const orderId = await axios + .post(`${process.env.VUE_APP_ROOT_API}/transaction/setup`, checkoutRequest) + .then(response => response.data.orderId) + .catch(err => console.error(err)); + + return orderId; + }, + async captureOrder(context, orderId) { + return await axios + .post(`${process.env.VUE_APP_ROOT_API}/transaction/capture`, {orderId}) + .then(() => true) + .catch(err => console.error(err)); } }, modules: { |