billing V2 frontend
This commit is contained in:
@@ -149,6 +149,53 @@ export const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
getCreditBalance: async () => {
|
||||
const response = await EnterpriseAccountAPI.getCreditBalance();
|
||||
return response.data;
|
||||
},
|
||||
|
||||
getV2PricingPlans: async ({ commit }) => {
|
||||
commit(types.default.SET_ACCOUNT_UI_FLAG, { isFetchingItem: true });
|
||||
try {
|
||||
const response = await EnterpriseAccountAPI.getV2PricingPlans();
|
||||
commit(types.default.SET_ACCOUNT_UI_FLAG, { isFetchingItem: false });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
commit(types.default.SET_ACCOUNT_UI_FLAG, { isFetchingItem: false });
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
subscribeToV2Plan: async ({ commit }, { pricing_plan_id, quantity = 1 }) => {
|
||||
commit(types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: true });
|
||||
try {
|
||||
const response = await EnterpriseAccountAPI.subscribeToV2Plan(
|
||||
pricing_plan_id,
|
||||
quantity
|
||||
);
|
||||
commit(types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: false });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
commit(types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: false });
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
cancelSubscription: async ({ commit }, options = {}) => {
|
||||
commit(types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: true });
|
||||
try {
|
||||
const response = await EnterpriseAccountAPI.cancelSubscription(options);
|
||||
commit(types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: false });
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
commit(types.default.SET_ACCOUNT_UI_FLAG, { isUpdating: false });
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
getCacheKeys: async () => {
|
||||
return AccountAPI.getCacheKeys();
|
||||
},
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import EnterpriseAccountAPI from 'dashboard/api/enterprise/account';
|
||||
import { throwErrorMessage } from '../utils/api';
|
||||
|
||||
const state = {
|
||||
topupOptions: [],
|
||||
uiFlags: {
|
||||
isLoading: false,
|
||||
isProcessing: false,
|
||||
},
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
topupOptions($state) {
|
||||
return $state.topupOptions;
|
||||
},
|
||||
uiFlags($state) {
|
||||
return $state.uiFlags;
|
||||
},
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
async fetchTopupOptions({ commit }) {
|
||||
commit('SET_UI_FLAG', { isLoading: true });
|
||||
try {
|
||||
const response = await EnterpriseAccountAPI.getV2TopupOptions();
|
||||
commit('SET_TOPUP_OPTIONS', response.data.topup_options);
|
||||
return response.data.topup_options;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit('SET_UI_FLAG', { isLoading: false });
|
||||
}
|
||||
},
|
||||
|
||||
async purchaseTopup({ commit }, { credits }) {
|
||||
commit('SET_UI_FLAG', { isProcessing: true });
|
||||
try {
|
||||
const response = await EnterpriseAccountAPI.purchaseTopup(credits);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
throw error;
|
||||
} finally {
|
||||
commit('SET_UI_FLAG', { isProcessing: false });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
SET_UI_FLAG($state, data) {
|
||||
$state.uiFlags = {
|
||||
...$state.uiFlags,
|
||||
...data,
|
||||
};
|
||||
},
|
||||
SET_TOPUP_OPTIONS($state, options) {
|
||||
$state.topupOptions = options || [];
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations,
|
||||
};
|
||||
Reference in New Issue
Block a user