From b91f8012cdbb474a294ba03946392362881d830b Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma Date: Wed, 29 Oct 2025 03:58:44 +0530 Subject: [PATCH] add pricing plan api fix --- .../billing-v2/components/PricingPlans.vue | 38 +++++++++++++------ .../dashboard/store/modules/accounts.js | 12 +++--- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/app/javascript/dashboard/routes/dashboard/settings/billing-v2/components/PricingPlans.vue b/app/javascript/dashboard/routes/dashboard/settings/billing-v2/components/PricingPlans.vue index f11b7d1e6..eec62c9ad 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/billing-v2/components/PricingPlans.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/billing-v2/components/PricingPlans.vue @@ -60,10 +60,18 @@ const subscriptionEndsAt = computed(() => { return customAttributes.value.subscription_ends_at; }); +const stripeSubscriptionId = computed(() => { + return customAttributes.value.stripe_subscription_id; +}); + const hasActiveSubscription = computed(() => { return !!currentPlanId.value; }); +const hasStripeSubscription = computed(() => { + return !!stripeSubscriptionId.value; +}); + const isCancellingAtPeriodEnd = computed(() => { return subscriptionStatus.value === 'cancel_at_period_end'; }); @@ -125,18 +133,23 @@ const openSubscribeModal = plan => { }; const handleSubscribe = async data => { - // If there's an active subscription, use change plan API instead - if (hasActiveSubscription.value) { + // Use change plan API only if stripe_subscription_id exists + // Otherwise, always use subscribe API + if (hasStripeSubscription.value) { const result = await store.dispatch('accounts/v2ChangePlan', data); if (result.success) { useAlert(t('BILLING_SETTINGS_V2.PRICING_PLANS.CHANGE_PLAN_SUCCESS')); showSubscribeModal.value = false; + } else if (result.error) { + useAlert(result.error); } } else { const result = await store.dispatch('accounts/v2Subscribe', data); if (result.success) { useAlert(t('BILLING_SETTINGS_V2.PRICING_PLANS.SUBSCRIBE_SUCCESS')); showSubscribeModal.value = false; + } else if (result.error) { + useAlert(result.error); } } }; @@ -152,6 +165,8 @@ const handleCancelSubscription = async reason => { if (result.success) { useAlert(t('BILLING_SETTINGS_V2.PRICING_PLANS.CANCEL_SUCCESS')); showCancelModal.value = false; + } else if (result.error) { + useAlert(result.error); } }; @@ -201,6 +216,8 @@ const handleUpdateQuantity = async () => { }); if (result.success) { useAlert(t('BILLING_SETTINGS_V2.PRICING_PLANS.UPDATE_QUANTITY_SUCCESS')); + } else if (result.error) { + useAlert(result.error); } } finally { isUpdatingQuantity.value = false; @@ -218,14 +235,11 @@ const isCurrentPlan = plan => { :title="$t('BILLING_SETTINGS_V2.PRICING_PLANS.TITLE')" :description="$t('BILLING_SETTINGS_V2.PRICING_PLANS.DESCRIPTION')" > -