From ea671474106d6416fb4d90da05c34d916b6ca5a2 Mon Sep 17 00:00:00 2001 From: Mateja Date: Tue, 27 Jul 2021 14:34:41 +0200 Subject: Move transaction requests to Vuex. --- client/src/store/index.js | 16 ++++++++++++++++ client/src/views/Checkout.vue | 20 +++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) (limited to 'client/src') 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: { diff --git a/client/src/views/Checkout.vue b/client/src/views/Checkout.vue index a62f83c..a009b94 100644 --- a/client/src/views/Checkout.vue +++ b/client/src/views/Checkout.vue @@ -23,8 +23,6 @@