%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/takeaseat.eco-n-tech.co.uk/store/account/
Upload File :
Create Path :
Current File : //home/forge/takeaseat.eco-n-tech.co.uk/store/account/billing.js

export const state = () => ({
  setupIntent: {},
  defaultPaymentMethod: {},
  paymentMethods: []
})

export const mutations = {
  setPaymentIntent(state, data) {
    state.setupIntent = data
  },
  setPaymentMethods(state, data) {
    state.paymentMethods = data
  },
  setDefaultPaymentMethod(state, data) {
    state.defaultPaymentMethod = data
  },
}

export const actions = {
  async setupIntent({ commit, error }, payload) {
    await this.$axios.get('/payments/cards/setup')
    .then((res) => {
      if (res.status === 200) {
        commit('setPaymentIntent', res.data)
      }
    })
  },

  async savePaymentMethod({ dispatch, error }, payload) {
    await this.$axios.post('/payments/cards/create', payload).then((res) => {
      if (res.status === 200) {
        dispatch('getPaymentMethods')
        dispatch('setupIntent')
      }
    }).catch((error) => {
      dispatch('setupIntent')
      this.$toast.error(error.response.data.message).goAway(15000);
    })
  },

  async getPaymentMethods({ commit, error }, payload) {
    await this.$axios.get('/payments/cards')
    .then((res) => {
      if (res.status === 200) {
        commit('setPaymentMethods', res.data.payment_methods)
        commit('setDefaultPaymentMethod', res.data.default_payment_method)
      }
    }).catch((error) => {
      this.$toast.error(error.response.data.message).goAway(15000);
    })
  },

  async deletePaymentMethod({ dispatch }, payload) {
    await this.$axios.post('/payments/cards/delete', payload)
    .then((res) => {
      if (res.status === 200) {
        this.$toast.success('Successfully deleted card').goAway(3000);
        dispatch('getPaymentMethods')
      }
    }).catch((error) => {
      this.$toast.error(error.response.data.message).goAway(15000);
    })
  },
  
  async makePrimary({ dispatch }, payload) {
    await this.$axios.post('/payments/cards/update', payload)
    .then((res) => {
      if (res.status === 200) {
        this.$toast.success('Successfully updated primary card').goAway(3000);
        dispatch('getPaymentMethods')
      }
    }).catch((error) => {
      this.$toast.error(error.response.data.message).goAway(15000);
    })
  },
}

Zerion Mini Shell 1.0