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/views | |
parent | 3925b2674aa06b9824e75c584dce493d515b52e2 (diff) | |
download | mevn-ecommerce-ea671474106d6416fb4d90da05c34d916b6ca5a2.tar.gz mevn-ecommerce-ea671474106d6416fb4d90da05c34d916b6ca5a2.zip |
Move transaction requests to Vuex.
Diffstat (limited to 'client/src/views')
-rw-r--r-- | client/src/views/Checkout.vue | 20 |
1 files changed, 7 insertions, 13 deletions
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 @@ </template> <script> -import axios from 'axios'; - export default { name: 'Checkout', mounted() { @@ -49,22 +47,18 @@ export default { this.$store.commit('removeFromCart', id); }, paypalLoaded() { - const checkoutRequest = {items: this.$store.getters.getCart}; + const dispatch = this.$store.dispatch; window.paypal.Buttons({ async createOrder() { - 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; + return await dispatch('createOrder'); }, async onApprove(data) { - await axios - .post(`${process.env.VUE_APP_ROOT_API}/transaction/capture`, {orderId: data.orderID}) - .then(() => console.log('Paid successfully!')) - .catch(err => console.error(err)); + const success = await dispatch('captureOrder', data.orderID); + if (success === true) + console.log('Successfully paid!'); + else + console.log('Capturing order failed!'); }, onError(err) { console.error(err); |