Update
This commit is contained in:
@@ -14,6 +14,33 @@ const usePricingStore = create(
|
||||
|
||||
isCheckingOut: false,
|
||||
|
||||
checkoutPurchase: async (price_id) => {
|
||||
console.log('checkoutPurchase', price_id);
|
||||
|
||||
set({ isCheckingOut: true });
|
||||
try {
|
||||
const response = await axiosInstance.post(route('api.user.purchase'), { price_id: price_id });
|
||||
console.log(response);
|
||||
if (response?.data?.success?.data) {
|
||||
if (response.data.success.data.redirect) {
|
||||
window.location.href = response.data.success.data.redirect;
|
||||
}
|
||||
} else {
|
||||
throw 'Invalid API response';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(route('api.user.purchase'));
|
||||
console.error('Error fetching:', error);
|
||||
set({ isCheckingOut: false });
|
||||
if (error?.response?.data?.error?.message?.length > 0) {
|
||||
toast.error(error.response.data.error.message);
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
set({ isCheckingOut: false });
|
||||
}
|
||||
},
|
||||
|
||||
checkoutSubscribe: async (price_id) => {
|
||||
console.log('checkoutSubscribe', price_id);
|
||||
|
||||
|
||||
@@ -14,9 +14,28 @@ const useUserStore = create(
|
||||
tier: 'free',
|
||||
},
|
||||
billing: null,
|
||||
credits: null,
|
||||
|
||||
isLoadingUser: false,
|
||||
|
||||
isRedirectingToBilling: false,
|
||||
|
||||
redirectBillingPortal: async () => {
|
||||
set({ isRedirectingToBilling: true });
|
||||
console.log('redirectBillingPortal');
|
||||
try {
|
||||
const response = await axiosInstance.post(route('api.user.billing_portal'));
|
||||
if (response?.data?.success?.data) {
|
||||
window.location.href = response.data.success.data.redirect;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(route('api.user.billing_portal'));
|
||||
console.error('Error fetching:', error);
|
||||
} finally {
|
||||
set({ isRedirectingToBilling: false });
|
||||
}
|
||||
},
|
||||
|
||||
// Fetch backgrounds
|
||||
fetchUser: async () => {
|
||||
set({ isLoadingUser: true });
|
||||
@@ -27,6 +46,7 @@ const useUserStore = create(
|
||||
user_usage: response.data.success.data.user.user_usage,
|
||||
plan: response.data.success.data.user.plan,
|
||||
billing: response.data.success.data.billing,
|
||||
credits: response.data.success.data.credits,
|
||||
});
|
||||
//return response.data.success.data;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user