commerce-vuex
Version:
Commerce vuex module
53 lines (51 loc) • 1.56 kB
JavaScript
import humps from 'lodash-humps';
import stripeCard from './stripe_card.service';
const { doFetchPaymentMethodList } = stripeCard
export default {
namespaced: true,
state: {
list: [],
selected: [],
recordsCount: 0,
inProgress: false,
error: null,
paymentMethodList: []
},
mutations: {
inProgress(state, yesOrNo) {
state.inProgress = yesOrNo
},
setList(state, list) {
state.selected = [];
for (let i in state.paymentMethodList) {
state.selected.push(false);
state.selected[i] = false;
}
state.paymentMethodList = list;
},
setListCount(state, number) {
state.recordsCount = number;
}
},
actions: {
fetchPaymentMethodList : async ({ commit }, { stripeCustomerId }) => {
commit('inProgress', true);
try {
let paymentMethods = await doFetchPaymentMethodList({ stripeCustomerId });
paymentMethods = humps(paymentMethods.data)
commit('setList', paymentMethods);
commit('inProgress', false)
return paymentMethods
}
// eslint-disable-next-line no-useless-catch
catch (err) {
commit('setList', []);
commit('inProgress', false);
throw err
}
finally {
commit('inProgress', false)
}
},
}
}