Skip to content

Beautiful Open-Source Form Builder

Update error response status code and refactor Billing component layout

Julien Nahumb4ac90d16b90
diff --git a/api/app/Http/Middleware/AuthenticateJWT.php b/api/app/Http/Middleware/AuthenticateJWT.php
index e4da8d31d..b0ac579e4 100644
--- a/api/app/Http/Middleware/AuthenticateJWT.php
+++ b/api/app/Http/Middleware/AuthenticateJWT.php
@@ -56,7 +56,7 @@ class AuthenticateJWT
return response()->json([
'message' => $error,
- ], 403);
+ ], 401);
}
}
diff --git a/client/components/users/settings/Billing.vue b/client/components/users/settings/Billing.vue
index 2d8a488cb..a463f88b9 100644
--- a/client/components/users/settings/Billing.vue
+++ b/client/components/users/settings/Billing.vue
@@ -1,5 +1,5 @@
<template>
- <div class="space-y-6">
+ <div class="space-y-4">
<!-- Header -->
<div class="flex flex-col items-start justify-between gap-4 sm:flex-row sm:items-center">
<div>
@@ -12,7 +12,7 @@
<!-- Billing Management -->
<template v-if="user.has_customer_id">
- <div class="space-y-4 rounded-lg border border-neutral-200 p-4 shadow-sm">
+ <div class="space-y-4">
<p
v-if="usersCount"
class="text-neutral-600"
@@ -27,18 +27,8 @@
:to="{ name: 'redirect-billing-portal' }"
target="_blank"
>
- <span v-if="canCancel">Manage Subscription & Invoices</span>
- <span v-else>Billing & Invoices</span>
- </UButton>
- <UButton
- v-if="canCancel"
- color="error"
- variant="soft"
- :loading="cancelLoading"
- @click.prevent="cancelSubscription"
- >
- Cancel Subscription
+ Billing & Invoices
</UButton>
</div>
</div>
@@ -50,16 +40,13 @@
</template>
<script setup>
-import { computed } from "vue"
-
import AppSumoBilling from "../../vendor/appsumo/AppSumoBilling.vue"
-import { billingApi, authApi } from '~/api'
+import { billingApi } from '~/api'
const alert = useAlert()
const { data: user } = useAuth().user()
const billingLoading = ref(false)
-const cancelLoading = ref(false)
const usersCount = ref(0)
onMounted(() => {
@@ -76,47 +63,4 @@ const loadUsersCount = () => {
})
}
-const canCancel = computed(() => {
- return user.value.subscriptions.some(sub => (sub.stripe_status === 'active') || (sub.stripe_status === 'trialing' && sub.ends_at == null))
-})
-
-const cancelSubscription = () => {
- cancelLoading.value = true
- billingApi.getSubscription().then((data) => {
- if (data && data.length) {
- window.profitwell('init_cancellation_flow', { subscription_id: data[0].stripe_id }).then(result => {
- // This means the customer either aborted the flow (i.e.
- // they clicked on "never mind, I don't want to cancel"), or
- // accepted a salvage attempt or salvage offer.
- // Thus, do nothing since they won't cancel.
- if (result.status === 'retained' || result.status === 'aborted') {
- console.log('Retained 🥳')
- } else {
- billingApi.cancelSubscription(data[0].id)
- .then(() => {
- alert.success('Subscription cancelled. Sorry to see you leave 😢')
- })
- .catch(() => {
- alert.error('Sorry to see you leave 😢 We\'re currently having issues with subscriptions. Please ' +
- 'send us a message via the livechat, and we will cancel your subscription.')
- }).finally(() => {
- cancelLoading.value = false
- useAmplitude().logEvent('subscription_cancelled')
- useCrisp().pushEvent('subscription_cancelled')
-
- // Now we need to reload workspace and user
- authApi.user.get().then((_userData) => {
- useAuth().invalidateUser()
- })
- const { invalidateAll } = useWorkspaces()
- invalidateAll() // Refresh all workspace data
- })
- }
- })
- }
- }).finally(() => {
- useCrisp().pushEvent('subscription_cancelled')
- cancelLoading.value = false
- })
-}
</script>
\ No newline at end of file