mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: stripe has now the correct styling and uses a different method, miscellaneous fixes
This commit is contained in:
1 parent
98418691f0
commit
ed51179ceb
6 files changed
+224
-146
No files matched your search
+33
-21
@@ -4,14 +4,18 @@ import type { PaymentMethod } from '@stripe/stripe-js';
|
||||
|
||||
export type PaymentMethodData = {
|
||||
$id: string;
|
||||
$createdAt: string;
|
||||
$updatedAt: string;
|
||||
providerMethodId: string;
|
||||
providerUserId: string;
|
||||
expiryMonth: number;
|
||||
expiryYear: number;
|
||||
expired: boolean;
|
||||
last4: string;
|
||||
country: string;
|
||||
brand: string;
|
||||
clientSecret?: string;
|
||||
name?: string;
|
||||
clientSecret: string;
|
||||
failed: boolean;
|
||||
};
|
||||
|
||||
export type PaymentList = {
|
||||
@@ -127,6 +131,20 @@ export type AggregationList = {
|
||||
aggregations: Aggregation[];
|
||||
total: number;
|
||||
};
|
||||
|
||||
export type Region = {
|
||||
$id: string;
|
||||
name: string;
|
||||
disabled: boolean;
|
||||
default: boolean;
|
||||
flag: string;
|
||||
};
|
||||
|
||||
export type RegionList = {
|
||||
regions: Region[];
|
||||
total: number;
|
||||
};
|
||||
|
||||
export class Billing {
|
||||
client: Client;
|
||||
|
||||
@@ -500,23 +518,17 @@ export class Billing {
|
||||
);
|
||||
}
|
||||
|
||||
// async listPaymentMethods(teamId: string) {
|
||||
// const path = `/teams/${teamId}/payment-methods`;
|
||||
// const uri = new URL(this.client.config.endpoint + path);
|
||||
// return await this.client.call('GET', uri);
|
||||
// }
|
||||
|
||||
// async createPaymentMethod(teamId: string): Promise<PaymentMethod> {
|
||||
// const path = `/teams/${teamId}/payment-methods`;
|
||||
// const params = {};
|
||||
// const uri = new URL(this.client.config.endpoint + path);
|
||||
// return await this.client.call(
|
||||
// 'POST',
|
||||
// uri,
|
||||
// {
|
||||
// 'content-type': 'application/json'
|
||||
// },
|
||||
// params
|
||||
// );
|
||||
// }
|
||||
async listRegions(): Promise<RegionList> {
|
||||
const path = `/console/regions`;
|
||||
const params = {};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'GET',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
}
|
||||
+27
-12
@@ -1,5 +1,10 @@
|
||||
import { hasStripePublicKey, VARS } from '$lib/system';
|
||||
import { loadStripe, type Stripe, type StripeCardElement } from '@stripe/stripe-js';
|
||||
import {
|
||||
loadStripe,
|
||||
type Stripe,
|
||||
type StripeElement,
|
||||
type StripeElements
|
||||
} from '@stripe/stripe-js';
|
||||
import { sdk } from './sdk';
|
||||
import { app } from './app';
|
||||
import { get, writable } from 'svelte/store';
|
||||
@@ -9,7 +14,8 @@ import type { PaymentMethodData } from '$lib/sdk/billing';
|
||||
let stripe: Stripe;
|
||||
let paymentMethod: PaymentMethodData;
|
||||
let clientSecret: string;
|
||||
let paymentElement: StripeCardElement;
|
||||
let elements: StripeElements;
|
||||
let paymentElement: StripeElement;
|
||||
|
||||
export const isStripeInitialized = writable(false);
|
||||
|
||||
@@ -38,8 +44,8 @@ export async function initializeStripe() {
|
||||
appearance: get(app).themeInUse === 'dark' ? apperanceDark : apperanceLight
|
||||
};
|
||||
// Set up Elements and then create form
|
||||
const elements = stripe.elements(options);
|
||||
paymentElement = elements.create('card');
|
||||
elements = stripe.elements(options);
|
||||
paymentElement = elements.create('payment');
|
||||
paymentElement.mount('#payment-element');
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
@@ -53,17 +59,26 @@ export async function submitStripeCard(name: string) {
|
||||
paymentMethod = await sdk.forConsole.billing.createPaymentMethod();
|
||||
clientSecret = paymentMethod.clientSecret;
|
||||
}
|
||||
await stripe.retrieveSetupIntent(clientSecret);
|
||||
// Confirm the setup intent with the payment method
|
||||
const { setupIntent } = await stripe.confirmCardSetup(clientSecret, {
|
||||
payment_method: {
|
||||
card: paymentElement,
|
||||
billing_details: {
|
||||
name: name
|
||||
|
||||
// Element needs to be submitted before confirming the setup intent
|
||||
elements.submit();
|
||||
|
||||
const { setupIntent } = await stripe.confirmSetup({
|
||||
elements,
|
||||
clientSecret,
|
||||
confirmParams: {
|
||||
return_url: 'https://example.com',
|
||||
payment_method_data: {
|
||||
billing_details: {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
redirect: 'if_required'
|
||||
});
|
||||
|
||||
// console.log(setupIntent);
|
||||
|
||||
if (setupIntent && setupIntent.status === 'succeeded') {
|
||||
const method = await sdk.forConsole.billing.updatePaymentMethod(
|
||||
paymentMethod.$id,
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
} from '$lib/elements/table';
|
||||
import DeletePayment from './deletePayment.svelte';
|
||||
import { paymentMethods } from './store';
|
||||
import type { PaymentMethodData } from '$lib/sdk/billing';
|
||||
import { organizationList, type Organization } from '$lib/stores/organization';
|
||||
import { tooltip } from '$lib/actions/tooltip';
|
||||
import { base } from '$app/paths';
|
||||
|
||||
export let showPayment = false;
|
||||
let showDropdown = [];
|
||||
@@ -27,7 +31,11 @@
|
||||
|
||||
console.log($paymentMethods);
|
||||
|
||||
$: filteredMethods = $paymentMethods?.paymentMethods.filter((method) => !!method?.last4);
|
||||
$: orgList = $organizationList.teams as unknown as Organization[];
|
||||
|
||||
$: filteredMethods = $paymentMethods?.paymentMethods.filter(
|
||||
(method: PaymentMethodData) => !!method?.last4
|
||||
);
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
@@ -38,18 +46,61 @@
|
||||
created.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
{#if $paymentMethods.total > 0}
|
||||
{#if $paymentMethods?.total}
|
||||
<Table noMargin noStyles>
|
||||
<TableHeader>
|
||||
<TableCellHead>Payment methods</TableCellHead>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each filteredMethods as paymentMethod, i}
|
||||
{@const linkedOrgs = orgList?.filter(
|
||||
(org) =>
|
||||
paymentMethod.$id === org.paymentMethodId ||
|
||||
paymentMethod.$id === org.backupPaymentMethodId
|
||||
)}
|
||||
|
||||
<TableRow>
|
||||
<TableCell>
|
||||
<CreditCardInfo {paymentMethod}>
|
||||
<div class="u-flex u-gap-16">
|
||||
<Pill>test</Pill>
|
||||
<div class="u-flex u-gap-16 u-cross-center">
|
||||
{#if linkedOrgs?.length > 0}
|
||||
<div
|
||||
use:tooltip={{
|
||||
interactive: true,
|
||||
allowHTML: true,
|
||||
trigger: 'click',
|
||||
content: `
|
||||
<div class="u-flex u-flex-vertical u-gap-8">
|
||||
<p class="text">This payment method is linked to the following organizations:</p>
|
||||
${linkedOrgs
|
||||
.map(
|
||||
(org) =>
|
||||
`<a href="${base}/console/organization-${org.$id}/billing" class="link">${org.name}</a>`
|
||||
)
|
||||
.join('')}
|
||||
</div>`
|
||||
|
||||
// onShow(instance) {
|
||||
// if (isFetching || data) {
|
||||
// return;
|
||||
// }
|
||||
// getData(role)
|
||||
// .then((n) => {
|
||||
// data = n;
|
||||
// })
|
||||
// .finally(() => {
|
||||
// tick().then(() => {
|
||||
// instance.setContent(content);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
}}>
|
||||
<Pill button>
|
||||
<span class="icon-info" /> linked to organization
|
||||
</Pill>
|
||||
</div>
|
||||
{/if}
|
||||
<DropList
|
||||
bind:show={showDropdown[i]}
|
||||
placement="bottom-start"
|
||||
|
||||
@@ -14,56 +14,59 @@
|
||||
let showPricing = false;
|
||||
|
||||
$: currentTier =
|
||||
$organization.billingPlan === 'tier-2'
|
||||
$organization?.billingPlan === 'tier-2'
|
||||
? tierScale
|
||||
: $organization?.billingPlan === 'tier-1'
|
||||
? tierPro
|
||||
: tierFree;
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
<Heading tag="h2" size="6">Plan summary</Heading>
|
||||
{#if $organization}
|
||||
<CardGrid>
|
||||
<Heading tag="h2" size="6">Plan summary</Heading>
|
||||
|
||||
<p class="text">
|
||||
Your current project plan. For more information on Appwrite plans, <button
|
||||
type="button"
|
||||
class="link"
|
||||
on:click|preventDefault={() => (showPricing = true)}>
|
||||
view our pricing guide.
|
||||
</button>
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<div class="box u-flex u-main-space-between u-cross-center">
|
||||
<div class="u-flex u-gap-8 u-cross-center">
|
||||
<h6 class="u-bold u-trim-1">
|
||||
{currentTier.name}
|
||||
</h6>
|
||||
{#if $organization.billingPlan !== 'tier-0' && $organization.billingTrialDays}
|
||||
<Pill>FREE TRIAL</Pill>
|
||||
{/if}
|
||||
<p class="text">
|
||||
Your current project plan. For more information on Appwrite plans, <button
|
||||
type="button"
|
||||
class="link"
|
||||
on:click|preventDefault={() => (showPricing = true)}>
|
||||
view our pricing guide.
|
||||
</button>
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<div class="box u-flex u-main-space-between u-cross-center">
|
||||
<div class="u-flex u-gap-8 u-cross-center">
|
||||
<h6 class="u-bold u-trim-1">
|
||||
{currentTier.name}
|
||||
</h6>
|
||||
{#if $organization.billingPlan !== 'tier-0' && $organization.billingTrialDays}
|
||||
<Pill>FREE TRIAL</Pill>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<p class="text">
|
||||
{#if $organization.billingPlan !== 'tier-0' && $organization.billingTrialDays}
|
||||
<span class="u-color-text-gray"> Esimated total: </span>
|
||||
{/if}
|
||||
${currentTier.price}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p class="text">
|
||||
{#if $organization.billingPlan !== 'tier-0' && $organization.billingTrialDays}
|
||||
<span class="u-color-text-gray"> Esimated total: </span>
|
||||
{/if}
|
||||
${currentTier.price}
|
||||
</p>
|
||||
</div>
|
||||
<div class="u-flex u-main-space-between u-cross-center">
|
||||
<p class="text">
|
||||
Billing period: {toLocaleDate($organization.billingCurrentInvoiceDate)} - {toLocaleDate(
|
||||
$organization.billingNextInvoiceDate
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
<!-- TODO: add change plan method -->
|
||||
<Button text on:click={() => wizard.start(ChangeOrganizationTierCloud)}>Change plan</Button>
|
||||
<Button secondary href={`${base}/console/organization-${$organization.$id}/usage`}
|
||||
>View estimated usage</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
<div class="u-flex u-main-space-between u-cross-center">
|
||||
<p class="text">
|
||||
Billing period: {toLocaleDate($organization?.billingCurrentInvoiceDate)} - {toLocaleDate(
|
||||
$organization?.billingNextInvoiceDate
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
<!-- TODO: add change plan method -->
|
||||
<Button text on:click={() => wizard.start(ChangeOrganizationTierCloud)}
|
||||
>Change plan</Button>
|
||||
<Button secondary href={`${base}/console/organization-${$organization?.$id}/usage`}
|
||||
>View estimated usage</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
{/if}
|
||||
|
||||
<UsageRates bind:show={showPricing} tier={$organization?.billingPlan} />
|
||||
@@ -3,27 +3,14 @@
|
||||
import { Pill } from '$lib/elements';
|
||||
import { WizardStep } from '$lib/layout';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { onMount } from 'svelte';
|
||||
import { createProject } from './store';
|
||||
import type { RegionList } from '$lib/sdk/billing';
|
||||
|
||||
const regions = [
|
||||
{ name: 'eu-central-1', label: 'EU (Frankfurt)', flag: 'de', disabled: false },
|
||||
{ name: 'eu-west-1', label: 'EU (Ireland)', flag: 'ie', disabled: true },
|
||||
{ name: 'eu-west-2', label: 'EU (London)', flag: 'gb', disabled: true },
|
||||
{ name: 'eu-west-3', label: 'EU (Paris)', flag: 'fr', disabled: true },
|
||||
{ name: 'eu-north-1', label: 'EU (Stockholm)', flag: 'se', disabled: true },
|
||||
{ name: 'eu-south-1', label: 'EU (Milan)', flag: 'it', disabled: true },
|
||||
{ name: 'us-east-1', label: 'US (Virginia)', flag: 'us', disabled: true },
|
||||
{ name: 'us-east-2', label: 'US (Ohio)', flag: 'us', disabled: true },
|
||||
{ name: 'us-west-1', label: 'US (N. California)', flag: 'us', disabled: true },
|
||||
{ name: 'us-west-2', label: 'US (Oregon)', flag: 'us', disabled: true },
|
||||
{ name: 'ap-northeast-1', label: 'Asia Pacific (Tokyo)', flag: 'jp', disabled: true },
|
||||
{ name: 'ap-northeast-2', label: 'Asia Pacific (Seoul)', flag: 'kr', disabled: true },
|
||||
{ name: 'ap-northeast-3', label: 'Asia Pacific (Osaka-Local)', flag: 'jp', disabled: true },
|
||||
{ name: 'ap-southeast-1', label: 'Asia Pacific (Singapore)', flag: 'sg', disabled: true },
|
||||
{ name: 'ap-southeast-2', label: 'Asia Pacific (Sydney)', flag: 'au', disabled: true },
|
||||
{ name: 'ap-south-1', label: 'Asia Pacific (Mumbai)', flag: 'in', disabled: true },
|
||||
{ name: 'ca-central-1', label: 'Canada (Central)', flag: 'ca', disabled: true }
|
||||
];
|
||||
let regions: RegionList;
|
||||
onMount(async () => {
|
||||
regions = await sdk.forConsole.billing.listRegions();
|
||||
});
|
||||
|
||||
function getFlag(country: string) {
|
||||
let flag = sdk.forProject.avatars.getFlag(country, 80, 60)?.toString();
|
||||
@@ -39,50 +26,51 @@
|
||||
<svelte:fragment slot="subtitle">
|
||||
Choose a deployment region for your project. This region cannot be changed.
|
||||
</svelte:fragment>
|
||||
{#if regions?.total}
|
||||
<ul
|
||||
class="grid-box u-margin-block-start-16"
|
||||
style="--p-grid-item-size:12em; --p-grid-item-size-small-screens:12rem; --grid-gap: 1rem;">
|
||||
{#each regions.regions as region}
|
||||
<li>
|
||||
<RegionCard
|
||||
name="region"
|
||||
bind:group={$createProject.region}
|
||||
value={region.name}
|
||||
disabled={region.disabled}>
|
||||
<div
|
||||
class="u-flex u-flex-vertical u-gap-12 u-justify-main-center u-cross-center u-margin-inline-auto">
|
||||
{#if region.disabled}
|
||||
<img
|
||||
src={getFlag(region.flag)}
|
||||
alt={region.name}
|
||||
width="40"
|
||||
height="30" />
|
||||
<p class:u-opacity-50={region.disabled}>{region.name}</p>
|
||||
<Pill button>
|
||||
<span class="icon-bell" aria-hidden="true" />
|
||||
<span class="text">Notify me</span>
|
||||
</Pill>
|
||||
{:else}
|
||||
<img
|
||||
src={getFlag(region.flag)}
|
||||
alt={region.name}
|
||||
width="40"
|
||||
height="30" />
|
||||
{region.name}
|
||||
{/if}
|
||||
</div>
|
||||
</RegionCard>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
<ul
|
||||
class="grid-box u-margin-block-start-16"
|
||||
style="--p-grid-item-size:12em; --p-grid-item-size-small-screens:12rem; --grid-gap: 1rem;">
|
||||
{#each regions as region}
|
||||
<li>
|
||||
<RegionCard
|
||||
name="region"
|
||||
bind:group={$createProject.region}
|
||||
value={region.name}
|
||||
disabled={region.disabled}>
|
||||
<div
|
||||
class="u-flex u-flex-vertical u-gap-12 u-justify-main-center u-cross-center u-margin-inline-auto">
|
||||
{#if region.disabled}
|
||||
<img
|
||||
src={getFlag(region.flag)}
|
||||
alt={region.name}
|
||||
width="40"
|
||||
height="30" />
|
||||
<p class:u-opacity-50={region.disabled}>{region.label}</p>
|
||||
<Pill button>
|
||||
<span class="icon-bell" aria-hidden="true" />
|
||||
<span class="text">Notify me</span>
|
||||
</Pill>
|
||||
{:else}
|
||||
<img
|
||||
src={getFlag(region.flag)}
|
||||
alt={region.name}
|
||||
width="40"
|
||||
height="30" />
|
||||
{region.label}
|
||||
{/if}
|
||||
</div>
|
||||
</RegionCard>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
<p class="text u-margin-block-start-16">
|
||||
Edge Network is enabled on all regions. For more details, check out our <a
|
||||
class="link"
|
||||
href="http://#"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">Documentation</a
|
||||
>.
|
||||
</p>
|
||||
<p class="text u-margin-block-start-16">
|
||||
Edge Network is enabled on all regions. For more details, check out our <a
|
||||
class="link"
|
||||
href="http://#"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer">Documentation</a
|
||||
>.
|
||||
</p>
|
||||
{/if}
|
||||
</WizardStep>
|
||||
@@ -2,7 +2,7 @@
|
||||
import { Pill } from '$lib/elements';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { WizardStep } from '$lib/layout';
|
||||
import { tierToPlan } from '$lib/stores/billing';
|
||||
import { getCreditCardImage, tierToPlan } from '$lib/stores/billing';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { createOrganization } from './store';
|
||||
|
||||
@@ -52,7 +52,16 @@
|
||||
<div class="loader is-small" />
|
||||
</div>
|
||||
{:then card}
|
||||
<p class="text">Card ending in {card.last4} {card.brand}</p>
|
||||
<span class="u-flex u-cross-center u-gap-8">
|
||||
<p class="text u-bold">
|
||||
<span class="u-capitalize">{card?.brand}</span> ending in {card?.last4}
|
||||
</p>
|
||||
<img
|
||||
width="23"
|
||||
height="16"
|
||||
src={getCreditCardImage(card?.brand)}
|
||||
alt={card?.brand} />
|
||||
</span>
|
||||
{/await}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in new issue
Block a user