mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: add changes from Damodar
This commit is contained in:
1 parent
828646447a
commit
76e25db3c8
10 files changed
+189
-98
No files matched your search
Generated
+10
-29
@@ -19,7 +19,6 @@
|
||||
"echarts": "^5.4.1",
|
||||
"pretty-bytes": "^6.1.0",
|
||||
"prismjs": "^1.29.0",
|
||||
"stripe": "^11.11.0",
|
||||
"tippy.js": "^6.3.7",
|
||||
"web-vitals": "^3.1.1"
|
||||
},
|
||||
@@ -2274,7 +2273,8 @@
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.11.19",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.19.tgz",
|
||||
"integrity": "sha512-YUgMWAQBWLObABqrvx8qKO1enAvBUdjZOAWQ5grBAkp5LQv45jBvYKZ3oFS9iKRCQyFjqw6iuEa1vmFqtxYLZw=="
|
||||
"integrity": "sha512-YUgMWAQBWLObABqrvx8qKO1enAvBUdjZOAWQ5grBAkp5LQv45jBvYKZ3oFS9iKRCQyFjqw6iuEa1vmFqtxYLZw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/prettier": {
|
||||
"version": "2.7.2",
|
||||
@@ -3041,6 +3041,7 @@
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
|
||||
"integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.1",
|
||||
"get-intrinsic": "^1.0.2"
|
||||
@@ -4316,7 +4317,8 @@
|
||||
"node_modules/function-bind": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
|
||||
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/functions-have-names": {
|
||||
"version": "1.2.3",
|
||||
@@ -4360,6 +4362,7 @@
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.0.tgz",
|
||||
"integrity": "sha512-L049y6nFOuom5wGyRc3/gdTLO94dySVKRACj1RmJZBQXlbTMhtNIgkWkUHq+jYmZvKf14EW1EoJnnjbmoHij0Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.1",
|
||||
"has": "^1.0.3",
|
||||
@@ -4499,6 +4502,7 @@
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
|
||||
"integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"function-bind": "^1.1.1"
|
||||
},
|
||||
@@ -4540,6 +4544,7 @@
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
|
||||
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
@@ -6598,6 +6603,7 @@
|
||||
"version": "1.12.3",
|
||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz",
|
||||
"integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==",
|
||||
"dev": true,
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
@@ -7182,20 +7188,6 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "6.11.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
||||
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
|
||||
"dependencies": {
|
||||
"side-channel": "^1.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.6"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/querystringify": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz",
|
||||
@@ -7589,6 +7581,7 @@
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
||||
"integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"call-bind": "^1.0.0",
|
||||
"get-intrinsic": "^1.0.2",
|
||||
@@ -7926,18 +7919,6 @@
|
||||
"url": "https://github.com/sponsors/antfu"
|
||||
}
|
||||
},
|
||||
"node_modules/stripe": {
|
||||
"version": "11.11.0",
|
||||
"resolved": "https://registry.npmjs.org/stripe/-/stripe-11.11.0.tgz",
|
||||
"integrity": "sha512-CT8TZJ+bUaMmqCOljHdKwHTWym0bscrCHrKmvK2KoTaz/9gDIzG+lXTJOFUOb3K7Jwaoaori4yEVzOgA7U46+g==",
|
||||
"dependencies": {
|
||||
"@types/node": ">=8.1.0",
|
||||
"qs": "^6.11.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.*"
|
||||
}
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
"echarts": "^5.4.1",
|
||||
"pretty-bytes": "^6.1.0",
|
||||
"prismjs": "^1.29.0",
|
||||
"stripe": "^11.11.0",
|
||||
"tippy.js": "^6.3.7",
|
||||
"web-vitals": "^3.1.1"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ export const CARD_LIMIT = 6; // default card limit
|
||||
export const INTERVAL = 5 * 60000; // default interval to check for feedback
|
||||
|
||||
export enum Dependencies {
|
||||
PAYMENT_METHODS = 'dependency:paymentMethods',
|
||||
ORGANIZATION = 'dependency:organization',
|
||||
PROJECT = 'dependency:project',
|
||||
PROJECTS = 'dependency:projects',
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import type { Client, Payload } from '@aw-labs/appwrite-console';
|
||||
|
||||
export class Billing {
|
||||
client: Client;
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
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) {
|
||||
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 updatePaymentMethod(teamId: string, paymentMethodId: string, providerMethodId: string) {
|
||||
const path = `/teams/${teamId}/payment-methods/${paymentMethodId}`;
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'PUT',
|
||||
uri,
|
||||
{ 'content-type': 'application/json' },
|
||||
{
|
||||
providerMethodId
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async updateProjectPlan(projectId: string, billingPlan: string) {
|
||||
const path = `/project/${projectId}/plan`;
|
||||
const params: Payload = {
|
||||
billingPlan
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call('patch', uri, { 'content-type': 'application/json' }, params);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
Teams,
|
||||
Users
|
||||
} from '@aw-labs/appwrite-console';
|
||||
import { Billing } from './billing';
|
||||
|
||||
const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`;
|
||||
const clientConsole = new Client();
|
||||
@@ -31,7 +32,8 @@ const sdkForConsole = {
|
||||
locale: new Locale(clientConsole),
|
||||
projects: new Projects(clientConsole),
|
||||
teams: new Teams(clientConsole),
|
||||
users: new Users(clientConsole)
|
||||
users: new Users(clientConsole),
|
||||
billing: new Billing(clientConsole)
|
||||
};
|
||||
|
||||
const sdkForProject = {
|
||||
|
||||
@@ -8,12 +8,14 @@ import { Dependencies } from '$lib/constants';
|
||||
export const load: LayoutLoad = async ({ params, parent, depends }) => {
|
||||
await parent();
|
||||
depends(Dependencies.ORGANIZATION);
|
||||
depends(Dependencies.PAYMENT_METHODS);
|
||||
|
||||
try {
|
||||
return {
|
||||
header: Header,
|
||||
breadcrumbs: Breadcrumbs,
|
||||
organization: await sdkForConsole.teams.get(params.organization),
|
||||
paymentMethods: await sdkForConsole.billing.listPaymentMethods(params.organization),
|
||||
members: await sdkForConsole.teams.listMemberships(params.organization)
|
||||
};
|
||||
} catch (e) {
|
||||
|
||||
@@ -18,4 +18,6 @@
|
||||
<AvailableCredit />
|
||||
</Container>
|
||||
|
||||
<PaymentModal bind:show={showPayment} />
|
||||
{#if showPayment}
|
||||
<PaymentModal bind:show={showPayment} />
|
||||
{/if}
|
||||
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { CardGrid, Empty, Heading } from '$lib/components';
|
||||
import { paymentMethods } from './store';
|
||||
export let showPayment = false;
|
||||
</script>
|
||||
|
||||
@@ -8,8 +9,18 @@
|
||||
|
||||
<p class="text">View or update your organization payment methods here.</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<Empty on:click={() => (showPayment = true)}>
|
||||
<p class="text">Add a payment method</p>
|
||||
</Empty>
|
||||
{#if $paymentMethods.length > 0}
|
||||
{#each $paymentMethods.paymentMethods as paymentMethod}
|
||||
<p>
|
||||
{paymentMethod.brand}
|
||||
{paymentMethod.last4}, expiring: {paymentMethod.expiryMonth}/{paymentMethod.expiryYear}
|
||||
{#if paymentMethod.default} <span class="icon-check-circle" /> {/if}
|
||||
</p>
|
||||
{/each}
|
||||
{:else}
|
||||
<Empty on:click={() => (showPayment = true)}>
|
||||
<p class="text">Add a payment method</p>
|
||||
</Empty>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
@@ -4,94 +4,140 @@
|
||||
import { InputText, Button, FormList, Label } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
|
||||
import { publicKey } from './stripe';
|
||||
import { loadStripe } from '@stripe/stripe-js';
|
||||
import { paymentMethods, publicKey } from './store';
|
||||
import {
|
||||
loadStripe,
|
||||
type Stripe,
|
||||
type StripeElement,
|
||||
type StripeElements
|
||||
} from '@stripe/stripe-js';
|
||||
import { onMount } from 'svelte';
|
||||
import FormItem from '$lib/elements/forms/formItem.svelte';
|
||||
import { app } from '$lib/stores/app';
|
||||
import { browser } from '$app/environment';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
|
||||
export let show = false;
|
||||
|
||||
let name: string;
|
||||
let error: string;
|
||||
let isCreating = false;
|
||||
let stripe;
|
||||
let elements;
|
||||
let elements: StripeElements;
|
||||
let cardElement: StripeElement;
|
||||
let cardNumber: HTMLDivElement;
|
||||
let cardExpiry: HTMLDivElement;
|
||||
let complete = false;
|
||||
const appearance = {
|
||||
theme: $app.themeInUse === 'dark' ? 'stripe' : 'stripe',
|
||||
variables: {
|
||||
colorPrimary: $app.themeInUse === 'dark' ? '#ffffff' : '#000000'
|
||||
let stripe: Stripe;
|
||||
|
||||
let paymentMethod;
|
||||
let paymentIntent;
|
||||
|
||||
const styleLight = {
|
||||
base: {
|
||||
fontSize: '16px',
|
||||
color: '#32325d',
|
||||
fontFamily: 'Inter, arial, sans-serif',
|
||||
fontSmoothing: 'antialiased',
|
||||
'::placeholder': {
|
||||
color: '#c5c7d8'
|
||||
}
|
||||
},
|
||||
invalid: {
|
||||
color: '#FF4238',
|
||||
iconColor: '#FF4238'
|
||||
}
|
||||
};
|
||||
const styleDark = {
|
||||
base: {
|
||||
fontSize: '16px',
|
||||
color: '#C5C7D8',
|
||||
fontFamily: 'Inter, arial, sans-serif',
|
||||
fontSmoothing: 'antialiased',
|
||||
'::placeholder': {
|
||||
color: '#606a7b'
|
||||
}
|
||||
},
|
||||
invalid: {
|
||||
color: '#FF4238',
|
||||
iconColor: '#FF4238'
|
||||
}
|
||||
};
|
||||
let paymentIntent;
|
||||
let clientSecret;
|
||||
|
||||
onMount(async () => {
|
||||
stripe = await loadStripe(publicKey);
|
||||
elements = stripe.elements(appearance);
|
||||
// paymentIntent = await createIntent();
|
||||
// clientSecret = paymentIntent.client_secret;
|
||||
|
||||
try {
|
||||
paymentMethod = await sdkForConsole.billing.createPaymentMethod($organization.$id);
|
||||
const options = {
|
||||
clientSecret: paymentMethod.clientSecret,
|
||||
// Fully customizable with appearance API.
|
||||
appearance: {
|
||||
/*...*/
|
||||
}
|
||||
};
|
||||
// Set up Stripe.js and Elements to use in checkout form, passing the client secret obtained in step 3
|
||||
elements = stripe.elements(options);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
message: error.toString(),
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
createForm();
|
||||
});
|
||||
|
||||
async function createForm() {
|
||||
const cardElement = elements.create('cardNumber', {
|
||||
style: {
|
||||
base: {
|
||||
height: '40px',
|
||||
fontSize: '16px',
|
||||
color: '#32325d',
|
||||
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
|
||||
fontSmoothing: 'antialiased',
|
||||
'::placeholder': {
|
||||
color: '#aab7c4'
|
||||
}
|
||||
},
|
||||
invalid: {
|
||||
color: '#fa755a',
|
||||
iconColor: '#fa755a'
|
||||
}
|
||||
}
|
||||
cardElement = elements.create('card', {
|
||||
style: $app.themeInUse === 'dark' ? styleDark : styleLight
|
||||
});
|
||||
cardElement.mount(cardNumber);
|
||||
|
||||
// cardElement.on('change', (e) => (complete = e.complete));
|
||||
|
||||
// const cardExpiry = elements.create('cardExpiry');
|
||||
// cardExpiry.mount(cardExpiry);
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
isCreating = true;
|
||||
|
||||
trackEvent(Submit.ProjectCreate);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${name} has been created`
|
||||
});
|
||||
} catch (e) {
|
||||
isCreating = false;
|
||||
error = e.message;
|
||||
trackError(e, Submit.ProjectCreate);
|
||||
const { error: StripeError } = await stripe.confirmSetup({
|
||||
//`Elements` instance that was used to create the Payment Element
|
||||
elements,
|
||||
confirmParams: {
|
||||
return_url: 'http://localhost:3000'
|
||||
},
|
||||
redirect: 'if_required'
|
||||
});
|
||||
if (StripeError) {
|
||||
error = StripeError.message;
|
||||
// trackError(StripeError, Submit.ProjectCreate);
|
||||
} else {
|
||||
if (paymentMethod) {
|
||||
const { error: PaymentError, setupIntent } = await stripe.retrieveSetupIntent(
|
||||
paymentMethod.clientSecret
|
||||
);
|
||||
if (PaymentError) {
|
||||
error = PaymentError.message;
|
||||
// trackError(StripeError, Submit.ProjectCreate);
|
||||
} else if (setupIntent && setupIntent.status === 'succeeded') {
|
||||
//update payment method
|
||||
await sdkForConsole.billing.updatePaymentMethod(
|
||||
$organization.$id,
|
||||
paymentMethod.$id,
|
||||
setupIntent.payment_method as string
|
||||
);
|
||||
// const paymentElement = elements.getElement('payment');
|
||||
// paymentElement.destroy();
|
||||
await invalidate(Dependencies.PAYMENT_METHODS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$: if (show) {
|
||||
createForm();
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal {error} on:submit={handleSubmit} size="big" bind:show>
|
||||
<svelte:fragment slot="header">Add Payment Method</svelte:fragment>
|
||||
This payment method will be added to the Acme Org billing details.
|
||||
This payment method will be added to the {$organization.name} billing details.
|
||||
<FormList>
|
||||
<InputText
|
||||
id="name"
|
||||
label="Cardholder name"
|
||||
placeholder="Cardholder name"
|
||||
bind:value={name}
|
||||
required
|
||||
autofocus={true}
|
||||
@@ -102,12 +148,6 @@
|
||||
<div class="input-text" bind:this={cardNumber} />
|
||||
</div>
|
||||
</FormItem>
|
||||
<FormItem>
|
||||
<div class="input-text-wrapper">
|
||||
<Label required for="cardnumber">Card expiry</Label>
|
||||
<div bind:this={cardExpiry} />
|
||||
</div>
|
||||
</FormItem>
|
||||
</FormList>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary on:click={() => (show = false)}>Cancel</Button>
|
||||
|
||||
+5
-3
@@ -1,9 +1,9 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import Stripe from 'stripe';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
import { derived, writable } from 'svelte/store';
|
||||
|
||||
export const publicKey = import.meta.env?.VITE_STRIPE_PUBLIC_KEY?.toString() as string | undefined;
|
||||
export const secretKey = import.meta.env?.VITE_STRIPE_SECRET_KEY?.toString() as string | undefined;
|
||||
export const stripe = new Stripe(secretKey, undefined);
|
||||
|
||||
function createCustomerStore() {
|
||||
const { subscribe, set } = writable<Stripe.Customer | Stripe.DeletedCustomer>(undefined);
|
||||
@@ -31,3 +31,5 @@ function createCustomerStore() {
|
||||
}
|
||||
|
||||
export const customer = createCustomerStore();
|
||||
|
||||
export const paymentMethods = derived(page, ($page) => $page.data.paymentMethods);
|
||||
Reference in new issue
Block a user