feat: missing payment method alert banner

This commit is contained in:
Arman authored and Torsten Dittmann committed 2024-02-15 13:18:03 +00:00
1 parent a411fecd1a
commit 7757d8dbb8
4 files changed
+51 -2

No files matched your search

@@ -0,0 +1,27 @@
<script lang="ts">
import { page } from '$app/stores';
import { BillingPlan } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import { toLocaleDate } from '$lib/helpers/date';
import { HeaderAlert } from '$lib/layout';
import { orgMissingPaymentMethod } from '$routes/console/store';
</script>
{#if ($orgMissingPaymentMethod.billingPlan === BillingPlan.PRO || $orgMissingPaymentMethod.billingPlan === BillingPlan.SCALE) && !$orgMissingPaymentMethod.paymentMethodId && !$orgMissingPaymentMethod.backupPaymentMethodId && !$page.url.pathname.includes('/console/account')}
<HeaderAlert
type="error"
title={`Payment method required for ${$orgMissingPaymentMethod.name}`}>
<svelte:fragment>
Add a payment method to {$orgMissingPaymentMethod.name} before {toLocaleDate(
$orgMissingPaymentMethod.billingCurrentInvoiceDate
)} to avoid service interruptions to your projects.
</svelte:fragment>
<svelte:fragment slot="buttons">
<Button
secondary
href={`/console/organization-${$orgMissingPaymentMethod.$id}/billing`}>
Add payment method
</Button>
</svelte:fragment>
</HeaderAlert>
{/if}
+19 -1
View File
@@ -11,9 +11,10 @@ import PaymentAuthRequired from '$lib/components/billing/alerts/paymentAuthRequi
import { addNotification, notifications } from './notifications';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { activeHeaderAlert } from '$routes/console/store';
import { activeHeaderAlert, orgMissingPaymentMethod } from '$routes/console/store';
import MarkedForDeletion from '$lib/components/billing/alerts/markedForDeletion.svelte';
import { BillingPlan } from '$lib/constants';
import MissingPaymentMethod from '$lib/components/billing/alerts/missingPaymentMethod.svelte';
export type Tier = 'tier-0' | 'tier-1' | 'tier-2';
@@ -265,3 +266,20 @@ export function checkForMarkedForDeletion(org: Organization) {
});
}
}
export async function checkForMissingPaymentMethod() {
const orgs = await sdk.forConsole.teams.list([
Query.notEqual('billingPlan', BillingPlan.STARTER),
Query.isNull('paymentMethodId'),
Query.isNull('backupPaymentMethodId')
]);
if (orgs?.total) {
orgMissingPaymentMethod.set(orgs.teams[0] as Organization);
headerAlert.add({
id: 'missingPaymentMethod',
component: MissingPaymentMethod,
show: true,
importance: 8
});
}
}
+3 -1
View File
@@ -19,7 +19,8 @@
checkPaymentAuthorizationRequired,
calculateTrialDay,
paymentExpired,
checkForMarkedForDeletion
checkForMarkedForDeletion,
checkForMissingPaymentMethod
} from '$lib/stores/billing';
import { goto } from '$app/navigation';
import { CommandCenter, registerCommands, registerSearchers } from '$lib/commandCenter';
@@ -245,6 +246,7 @@
if (isCloud && hasStripePublicKey) {
$stripe = await loadStripe(VARS.STRIPE_PUBLIC_KEY);
await checkForMissingPaymentMethod();
}
});
+2
View File
@@ -1,5 +1,6 @@
import { page } from '$app/stores';
import type { HeaderAlert } from '$lib/stores/headerAlert';
import type { Organization } from '$lib/stores/organization';
import type { Models } from '@appwrite.io/console';
import { derived, writable } from 'svelte/store';
@@ -10,3 +11,4 @@ export const consoleVariables = derived(
);
export const activeHeaderAlert = writable<HeaderAlert>(null);
export const orgMissingPaymentMethod = writable<Organization>(null);