fix: errors when stripe key is missing

This commit is contained in:
Arman committed 2023-07-17 20:52:23 +02:00
1 parent e796a96331
commit 4dd3b28ca7
6 files changed
+12 -17

No files matched your search

-4
View File
@@ -430,10 +430,6 @@ export class Billing {
// }
}
export const publicStripeKey = import.meta.env?.VITE_STRIPE_PUBLIC_KEY?.toString() as
| string
| undefined;
export const tierFree = {
price: 0,
name: 'Free',
+3 -1
View File
@@ -11,7 +11,8 @@ export const VARS = {
CONSOLE_MODE: import.meta.env?.VITE_CONSOLE_MODE?.toString() as string | undefined,
CONSOLE_TIER: import.meta.env?.VITE_CONSOLE_TIER?.toString() as string | undefined,
VERCEL_ENV: import.meta.env?.VITE_VERCEL_ENV?.toString() as string | undefined,
GOOGLE_ANALYTICS: import.meta.env?.VITE_GA_PROJECT?.toString() as string | undefined
GOOGLE_ANALYTICS: import.meta.env?.VITE_GA_PROJECT?.toString() as string | undefined,
STRIPE_PUBLIC_KEY: import.meta.env?.VITE_STRIPE_PUBLIC_KEY?.toString() as string | undefined
};
export const ENV = {
@@ -24,3 +25,4 @@ export const ENV = {
export const MODE = VARS.CONSOLE_MODE === Mode.CLOUD ? Mode.CLOUD : Mode.SELF_HOSTED;
export const isCloud = MODE === Mode.CLOUD;
export const isSelfHosted = MODE === Mode.SELF_HOSTED;
export const hasStripePublicKey = !!VARS.STRIPE_PUBLIC_KEY;
@@ -1,6 +1,7 @@
<script lang="ts">
import { Heading } from '$lib/components';
import { Container } from '$lib/layout';
import { hasStripePublicKey, isCloud } from '$lib/system';
import AvailableCredit from './availableCredit.svelte';
import BillingAddress from './billingAddress.svelte';
import PaymentMethods from './paymentMethods.svelte';
@@ -19,6 +20,6 @@
<AvailableCredit />
</Container>
{#if showPayment}
{#if showPayment && isCloud && hasStripePublicKey}
<PaymentModal bind:show={showPayment} />
{/if}
@@ -10,12 +10,8 @@
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { app } from '$lib/stores/app';
import {
apperanceDark,
apperanceLight,
publicStripeKey,
type PaymentMethodData
} from '$lib/stores/billing';
import { apperanceDark, apperanceLight, type PaymentMethodData } from '$lib/stores/billing';
import { VARS } from '$lib/system';
export let show = false;
@@ -28,7 +24,7 @@
let paymentMethod: PaymentMethodData;
onMount(async () => {
stripe = await loadStripe(publicStripeKey);
stripe = await loadStripe(VARS.STRIPE_PUBLIC_KEY);
try {
clientSecret = $paymentMethods?.paymentMethods[0]?.clientSecret;
if (!clientSecret) {
@@ -1,6 +1,4 @@
import { page } from '$app/stores';
import { derived } from 'svelte/store';
export const publicKey = import.meta.env?.VITE_STRIPE_PUBLIC_KEY?.toString() as string | undefined;
export const paymentMethods = derived(page, ($page) => $page.data.paymentMethods);
+4 -2
View File
@@ -13,7 +13,8 @@
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { app } from '$lib/stores/app';
import { apperanceDark, apperanceLight, publicStripeKey } from '$lib/stores/billing';
import { apperanceDark, apperanceLight } from '$lib/stores/billing';
import { VARS, hasStripePublicKey } from '$lib/system';
let methods: PaymentList;
let name: string;
@@ -35,7 +36,8 @@
});
async function initialize() {
stripe = await loadStripe(publicStripeKey);
if (!hasStripePublicKey) return;
stripe = await loadStripe(VARS.STRIPE_PUBLIC_KEY);
isStripeInitialized = true;
try {