mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: org billing page (WIP)
This commit is contained in:
1 parent
4dd3b28ca7
commit
c7c4827086
22 files changed
+672
-573
No files matched your search
@@ -218,5 +218,7 @@ export enum Submit {
|
||||
PaymentMethodDeleted = 'submit_payment_method_deleted',
|
||||
BillingAddressDeleted = 'submit_billing_address_deleted',
|
||||
BillingAddressCreated = 'submit_billing_address_created',
|
||||
BillingAddressUpdated = 'submit_billing_address_updated'
|
||||
BillingAddressUpdated = 'submit_billing_address_updated',
|
||||
OrganizationPaymentAdded = 'submit_organization_payment_added',
|
||||
OrganizationBackupPaymentAdded = 'submit_organization_backup_payment_added'
|
||||
}
|
||||
@@ -5,5 +5,8 @@
|
||||
<slot name="title" />
|
||||
<slot />
|
||||
</div>
|
||||
{#if $$slots?.end}
|
||||
<div class="u-margin-inline-start-auto"><slot name="end" /></div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -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 {
|
||||
ORG_PAYMENT_METHODS = 'dependency:orgPaymentMethods',
|
||||
PAYMENT_METHODS = 'dependency:paymentMethods',
|
||||
ORGANIZATION = 'dependency:organization',
|
||||
PROJECT = 'dependency:project',
|
||||
@@ -257,7 +258,7 @@ export const eventServices: Array<EventService> = [
|
||||
];
|
||||
|
||||
export const usageRates = {
|
||||
free: [
|
||||
'tier-0': [
|
||||
{ resource: 'Organization members', limit: '1', rate: 'lorem' },
|
||||
{ resource: 'Bandwidth', limit: '1', rate: 'lorem' },
|
||||
{ resource: 'Storage', limit: '1', rate: 'lorem' },
|
||||
@@ -265,7 +266,7 @@ export const usageRates = {
|
||||
{ resource: 'Active users', limit: '1', rate: 'lorem' },
|
||||
{ resource: 'Concurrent connections', limit: '1', rate: 'lorem' }
|
||||
],
|
||||
starter: [
|
||||
'tier-1': [
|
||||
{ resource: 'Organization members', limit: '1', rate: 'lorem' },
|
||||
{ resource: 'Bandwidth', limit: '1', rate: 'lorem' },
|
||||
{ resource: 'Storage', limit: '1', rate: 'lorem' },
|
||||
@@ -273,7 +274,7 @@ export const usageRates = {
|
||||
{ resource: 'Active users', limit: '1', rate: 'lorem' },
|
||||
{ resource: 'Concurrent connections', limit: '1', rate: 'lorem' }
|
||||
],
|
||||
pro: [
|
||||
'tier-2': [
|
||||
{ resource: 'Organization members', limit: 'Unlimited', rate: '20$/member' },
|
||||
{ resource: 'Bandwidth', limit: '1TB', rate: '$0.04/GB' },
|
||||
{ resource: 'Storage', limit: '150GB', rate: '$0.025/GB' },
|
||||
|
||||
@@ -0,0 +1,431 @@
|
||||
import type { Client } from '@appwrite.io/console';
|
||||
import type { Organization } from '../stores/organization';
|
||||
|
||||
export type PaymentMethodData = {
|
||||
$id: string;
|
||||
providerMethodId: string;
|
||||
expiryMonth: number;
|
||||
expiryYear: number;
|
||||
last4: string;
|
||||
country: string;
|
||||
brand: string;
|
||||
clientSecret?: string;
|
||||
};
|
||||
|
||||
export type PaymentList = {
|
||||
paymentMethods: PaymentMethodData[];
|
||||
total: number;
|
||||
};
|
||||
|
||||
export type Invoice = {
|
||||
$id: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
date: number;
|
||||
status: string;
|
||||
paymentMethod: PaymentMethodData;
|
||||
};
|
||||
|
||||
export type InvoiceList = {
|
||||
invoices: Invoice[];
|
||||
total: number;
|
||||
};
|
||||
export class Billing {
|
||||
client: Client;
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
async createOrganization(
|
||||
organizationId: string,
|
||||
name: string,
|
||||
billingPlan: string,
|
||||
paymentMethodId: string
|
||||
): Promise<Organization> {
|
||||
const path = `/organizations`;
|
||||
const params = {
|
||||
organizationId,
|
||||
name,
|
||||
billingPlan,
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'POST',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getPlan(organizationId: string): Promise<string> {
|
||||
const path = `/organizations/${organizationId}/plan`;
|
||||
const params = {
|
||||
organizationId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async updatePlan(
|
||||
organizationId: string,
|
||||
billingPlan: string,
|
||||
paymentMethodId: string
|
||||
): Promise<string> {
|
||||
const path = `/organizations/${organizationId}/plan`;
|
||||
const params = {
|
||||
organizationId,
|
||||
billingPlan,
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async updateBudget(organizationId: string, budget: number, alert: number[]): Promise<string> {
|
||||
const path = `/organizations/${organizationId}/budget`;
|
||||
const params = {
|
||||
organizationId,
|
||||
budget,
|
||||
alert
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async setOrganizationPaymentMethod(organizationId: string, paymentMethodId: string) {
|
||||
const path = `/organizations/${organizationId}/payment-method`;
|
||||
const params = {
|
||||
organizationId,
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async setOrganizationPaymentMethodBackup(organizationId: string, paymentMethodId: string) {
|
||||
const path = `/organizations/${organizationId}/payment-method/backup`;
|
||||
const params = {
|
||||
organizationId,
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async listInvoices(
|
||||
organizationId: string,
|
||||
queries: string[] = [],
|
||||
search = ''
|
||||
): Promise<InvoiceList> {
|
||||
const path = `/organizations/${organizationId}/invoices`;
|
||||
const params = {
|
||||
organizationId,
|
||||
queries,
|
||||
search
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getInvoice(organizationId: string, invoiceId: string): Promise<Invoice> {
|
||||
const path = `/organizations/${organizationId}/invoices/${invoiceId}`;
|
||||
const params = {
|
||||
organizationId,
|
||||
invoiceId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getInvoiceView(organizationId: string, invoiceId: string): Promise<URL> {
|
||||
const path = `/organizations/${organizationId}/invoices/${invoiceId}/view`;
|
||||
const params = {
|
||||
organizationId,
|
||||
invoiceId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async downloadInvoice(organizationId: string, invoiceId: string): Promise<URL> {
|
||||
const path = `/organizations/${organizationId}/invoices/${invoiceId}/download`;
|
||||
const params = {
|
||||
organizationId,
|
||||
invoiceId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async listUsage(
|
||||
organizationId: string,
|
||||
queries: string[] = []
|
||||
): Promise<Record<string, unknown>> {
|
||||
const path = `/organizations/${organizationId}/aggregations`;
|
||||
const params = {
|
||||
organizationId,
|
||||
queries
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getUsage(
|
||||
organizationId: string,
|
||||
aggregationId: string
|
||||
): Promise<Record<string, unknown>> {
|
||||
const path = `/organizations/${organizationId}/aggregations/${aggregationId}`;
|
||||
const params = {
|
||||
organizationId,
|
||||
aggregationId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
//ACCOUNT
|
||||
|
||||
async listPaymentMethods(queries: [] = []): Promise<PaymentList> {
|
||||
const path = `/account/payment-methods`;
|
||||
const params = {
|
||||
queries
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'GET',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getPaymentMethod(paymentMethodId: string): Promise<PaymentMethodData> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}`;
|
||||
const params = {
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'GET',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async createPaymentMethod(): Promise<PaymentMethodData> {
|
||||
const path = `/account/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(
|
||||
paymentMethodId: string,
|
||||
providerMethodId: string
|
||||
): Promise<PaymentMethodData> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}`;
|
||||
const params = {
|
||||
paymentMethodId,
|
||||
providerMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async deletePaymentMethod(paymentMethodId: string): Promise<PaymentMethodData> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}`;
|
||||
const params = {
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'delete',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
async setDefaultPaymentMethod(paymentMethodId: string): Promise<PaymentMethodData> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}/default`;
|
||||
const params = {
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async addCredit(organizationId: string, couponId: string): Promise<PaymentMethodData> {
|
||||
const path = `/organizations/${organizationId}/credits`;
|
||||
const params = {
|
||||
couponId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'POST',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
async listCredits(organizationId: string, queries = []): Promise<PaymentMethodData> {
|
||||
const path = `/organizations/${organizationId}/credits`;
|
||||
const params = {
|
||||
queries
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getCredit(organizationId: string, creditId: string): Promise<PaymentMethodData> {
|
||||
const path = `/organizations/${organizationId}/credits/${creditId}`;
|
||||
const params = {
|
||||
creditId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'GET',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
// 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
|
||||
// );
|
||||
// }
|
||||
}
|
||||
+3
-430
@@ -1,434 +1,7 @@
|
||||
import type { Client } from '@appwrite.io/console';
|
||||
import type { Organization } from './organization';
|
||||
import { page } from '$app/stores';
|
||||
import { derived } from 'svelte/store';
|
||||
|
||||
export type PaymentMethodData = {
|
||||
$id: string;
|
||||
providerMethodId: string;
|
||||
expiryMonth: number;
|
||||
expiryYear: number;
|
||||
last4: string;
|
||||
country: string;
|
||||
brand: string;
|
||||
clientSecret?: string;
|
||||
};
|
||||
|
||||
export type PaymentList = {
|
||||
paymentMethods: PaymentMethodData[];
|
||||
total: number;
|
||||
};
|
||||
|
||||
export type Invoice = {
|
||||
$id: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
date: number;
|
||||
status: string;
|
||||
paymentMethod: PaymentMethodData;
|
||||
};
|
||||
|
||||
export type InvoiceList = {
|
||||
invoices: Invoice[];
|
||||
total: number;
|
||||
};
|
||||
export class Billing {
|
||||
client: Client;
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
async createOrganization(
|
||||
organizationId: string,
|
||||
name: string,
|
||||
billingPlan: string,
|
||||
paymentMethodId: string
|
||||
): Promise<Organization> {
|
||||
const path = `/organization`;
|
||||
const params = {
|
||||
organizationId,
|
||||
name,
|
||||
billingPlan,
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'POST',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getPlan(organizationId: string): Promise<string> {
|
||||
const path = `/organizations/${organizationId}/plan`;
|
||||
const params = {
|
||||
organizationId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async updatePlan(
|
||||
organizationId: string,
|
||||
billingPlan: string,
|
||||
paymentMethodId: string
|
||||
): Promise<string> {
|
||||
const path = `/organizations/${organizationId}/plan`;
|
||||
const params = {
|
||||
organizationId,
|
||||
billingPlan,
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async updateBudget(organizationId: string, budget: number, alert: number[]): Promise<string> {
|
||||
const path = `/organizations/${organizationId}/budget`;
|
||||
const params = {
|
||||
organizationId,
|
||||
budget,
|
||||
alert
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async setOrganizationPaymentMethod(organizationId: string, paymentMethodId: string) {
|
||||
const path = `/organizations/${organizationId}/payment-method`;
|
||||
const params = {
|
||||
organizationId,
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async setOrganizationPaymentMethodBackup(organizationId: string, paymentMethodId: string) {
|
||||
const path = `/organizations/${organizationId}/payment-method/backup`;
|
||||
const params = {
|
||||
organizationId,
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async listInvoices(
|
||||
organizationId: string,
|
||||
queries: string[] = [],
|
||||
search = ''
|
||||
): Promise<InvoiceList> {
|
||||
const path = `/organizations/${organizationId}/invoices`;
|
||||
const params = {
|
||||
organizationId,
|
||||
queries,
|
||||
search
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getInvoice(organizationId: string, invoiceId: string): Promise<Invoice> {
|
||||
const path = `/organizations/${organizationId}/invoices/${invoiceId}`;
|
||||
const params = {
|
||||
organizationId,
|
||||
invoiceId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getInvoiceView(organizationId: string, invoiceId: string): Promise<URL> {
|
||||
const path = `/organizations/${organizationId}/invoices/${invoiceId}/view`;
|
||||
const params = {
|
||||
organizationId,
|
||||
invoiceId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async downloadInvoice(organizationId: string, invoiceId: string): Promise<URL> {
|
||||
const path = `/organizations/${organizationId}/invoices/${invoiceId}/download`;
|
||||
const params = {
|
||||
organizationId,
|
||||
invoiceId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async listUsage(
|
||||
organizationId: string,
|
||||
queries: string[] = []
|
||||
): Promise<Record<string, unknown>> {
|
||||
const path = `/organizations/${organizationId}/aggregations`;
|
||||
const params = {
|
||||
organizationId,
|
||||
queries
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getUsage(
|
||||
organizationId: string,
|
||||
aggregationId: string
|
||||
): Promise<Record<string, unknown>> {
|
||||
const path = `/organizations/${organizationId}/aggregations/${aggregationId}`;
|
||||
const params = {
|
||||
organizationId,
|
||||
aggregationId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
//ACCOUNT
|
||||
|
||||
async listPaymentMethods(queries: [] = []): Promise<PaymentList> {
|
||||
const path = `/account/payment-methods`;
|
||||
const params = {
|
||||
queries
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'GET',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getPaymentMethod(paymentMethodId: string): Promise<PaymentMethodData> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}`;
|
||||
const params = {
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'GET',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async createPaymentMethod(): Promise<PaymentMethodData> {
|
||||
const path = `/account/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(
|
||||
paymentMethodId: string,
|
||||
providerMethodId: string
|
||||
): Promise<PaymentMethodData> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}`;
|
||||
const params = {
|
||||
paymentMethodId,
|
||||
providerMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async deletePaymentMethod(paymentMethodId: string): Promise<PaymentMethodData> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}`;
|
||||
const params = {
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'delete',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
async setDefaultPaymentMethod(paymentMethodId: string): Promise<PaymentMethodData> {
|
||||
const path = `/account/payment-methods/${paymentMethodId}/default`;
|
||||
const params = {
|
||||
paymentMethodId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'patch',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async addCredit(organizationId: string, couponId: string): Promise<PaymentMethodData> {
|
||||
const path = `/organizations/${organizationId}/credits`;
|
||||
const params = {
|
||||
couponId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'POST',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
async listCredits(organizationId: string, queries = []): Promise<PaymentMethodData> {
|
||||
const path = `/organizations/${organizationId}/credits`;
|
||||
const params = {
|
||||
queries
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'get',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async getCredit(organizationId: string, creditId: string): Promise<PaymentMethodData> {
|
||||
const path = `/organizations/${organizationId}/credits/${creditId}`;
|
||||
const params = {
|
||||
creditId
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'GET',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
// 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
|
||||
// );
|
||||
// }
|
||||
}
|
||||
export const paymentMethods = derived(page, ($page) => $page.data.paymentMethods);
|
||||
|
||||
export const tierFree = {
|
||||
price: 0,
|
||||
|
||||
@@ -8,8 +8,8 @@ export type Organization = Models.Team<Record<string, unknown>> & {
|
||||
budgetAlert: number[];
|
||||
paymentMethodId: string;
|
||||
backupPaymentMethodId: string;
|
||||
billingCurrentInvoiceDate: Date;
|
||||
billingNextInvoiceDate: Date;
|
||||
billingCurrentInvoiceDate: string;
|
||||
billingNextInvoiceDate: string;
|
||||
};
|
||||
|
||||
export const newOrgModal = writable<boolean>(false);
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
Teams,
|
||||
Users
|
||||
} from '@appwrite.io/console';
|
||||
import { Billing } from './billing';
|
||||
import { Billing } from '../sdk/billing';
|
||||
|
||||
const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`;
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { app } from '$lib/stores/app';
|
||||
import { apperanceDark, apperanceLight, type PaymentMethodData } from '$lib/stores/billing';
|
||||
import { apperanceDark, apperanceLight } from '$lib/stores/billing';
|
||||
import type { PaymentMethodData } from '$lib/sdk/billing';
|
||||
import { VARS } from '$lib/system';
|
||||
|
||||
export let show = false;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import { Container } from '$lib/layout';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { ID } from '@appwrite.io/console';
|
||||
|
||||
let name: string;
|
||||
@@ -41,7 +42,14 @@
|
||||
}
|
||||
|
||||
async function createOrganization() {
|
||||
return await sdk.forConsole.teams.create(ID.unique(), 'Personal Projects');
|
||||
if (isCloud) {
|
||||
return await sdk.forConsole.billing.createOrganization(
|
||||
ID.unique(),
|
||||
'Personal Projects',
|
||||
'tier-0',
|
||||
null
|
||||
);
|
||||
} else return await sdk.forConsole.teams.create(ID.unique(), 'Personal Projects');
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,31 +1,19 @@
|
||||
<script lang="ts">
|
||||
import { Container } from '$lib/layout';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import PaymentModal from '$routes/console/account/payments/paymentModal.svelte';
|
||||
import BudgetAlert from './budgetAlert.svelte';
|
||||
import BudgetCap from './budgetCap.svelte';
|
||||
// import AvailableCredit from './availableCredit.svelte';
|
||||
// import BillingAddress from './billingAddress.svelte';
|
||||
// import PaymentHistory from './paymentHistory.svelte';
|
||||
// import PaymentMethods from './paymentMethods.svelte';
|
||||
|
||||
// import PaymentSummary from './paymentSummary.svelte';
|
||||
|
||||
let showPayment = false;
|
||||
import PaymentSummary from './paymentSummary.svelte';
|
||||
import BillingAddress from './billingAddress.svelte';
|
||||
import PaymentMethods from './paymentMethods.svelte';
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
<!-- <PaymentSummary />
|
||||
<PaymentHistory />
|
||||
<PaymentMethods bind:showPayment />
|
||||
<PaymentSummary />
|
||||
<PaymentMethods />
|
||||
<BillingAddress />
|
||||
<AvailableCredit /> -->
|
||||
<BudgetCap />
|
||||
{#if $organization?.billingPlan !== 'tier-2'}
|
||||
{#if $organization?.billingPlan === 'tier-2'}
|
||||
<BudgetAlert />
|
||||
{/if}
|
||||
</Container>
|
||||
|
||||
{#if showPayment}
|
||||
<PaymentModal bind:show={showPayment} />
|
||||
{/if}
|
||||
@@ -5,6 +5,7 @@ import type { PageLoad } from './$types';
|
||||
export const load: PageLoad = async ({ parent, depends }) => {
|
||||
await parent();
|
||||
depends(Dependencies.PAYMENT_METHODS);
|
||||
depends(Dependencies.ORG_PAYMENT_METHODS);
|
||||
|
||||
return {
|
||||
paymentMethods: await sdk.forConsole.billing.listPaymentMethods()
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { CardGrid, Heading } from '$lib/components';
|
||||
import { Button, FormList, InputText } from '$lib/elements/forms';
|
||||
|
||||
let credit = 0;
|
||||
let coupon: string = null;
|
||||
|
||||
async function redeem() {
|
||||
const response = await fetch('/v1/billing/credit', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
coupon
|
||||
})
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
credit = data.sum;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
<Heading tag="h2" size="6">Available Credit</Heading>
|
||||
|
||||
<p class="text">Appwrite credit will automatically be applied to your next invoice.</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<p class="text u-bold">Credit balance: <span class="u-success">{credit}</span></p>
|
||||
|
||||
<FormList>
|
||||
<InputText
|
||||
placeholder="Coupon code"
|
||||
id="coupon"
|
||||
label="Add credit"
|
||||
bind:value={coupon} />
|
||||
</FormList>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button secondary on:click={redeem} event="redeem_code">Redeem</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
@@ -1,5 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { CardGrid, Empty, Heading } from '$lib/components';
|
||||
import { CardGrid, DropList, Empty, Heading } from '$lib/components';
|
||||
import DropListItem from '$lib/components/dropListItem.svelte';
|
||||
|
||||
let showDropdown = false;
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
@@ -9,8 +12,13 @@
|
||||
View or update your billing address. This address will appear on your invoice.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<Empty>
|
||||
<p class="text">Add a billing address</p>
|
||||
</Empty>
|
||||
<DropList bind:show={showDropdown} fullWidth noArrow>
|
||||
<Empty on:click={() => (showDropdown = true)}>
|
||||
<p class="text">Add a billing address</p>
|
||||
</Empty>
|
||||
<svelte:fragment slot="list">
|
||||
<DropListItem>Add new billing address</DropListItem>
|
||||
</svelte:fragment>
|
||||
</DropList>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
@@ -118,4 +118,4 @@
|
||||
</CardGrid>
|
||||
</Form>
|
||||
|
||||
<UsageRates bind:show={showRates} />
|
||||
<UsageRates bind:show={showRates} tier={$organization?.billingPlan} />
|
||||
@@ -68,9 +68,9 @@
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button submit>Update</Button>
|
||||
<Button disabled={$organization?.billingPlan !== 'tier-2'} submit>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
</Form>
|
||||
|
||||
<UsageRates bind:show={showRates} />
|
||||
<UsageRates bind:show={showRates} tier={$organization?.billingPlan} />
|
||||
@@ -1,20 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { CardGrid, EmptySearch, Heading } from '$lib/components';
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
<Heading tag="h2" size="6">Payment History</Heading>
|
||||
|
||||
<p class="text">
|
||||
Transaction history for this Organization. Download invoices for more details about your
|
||||
payments.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<EmptySearch cardOnly>
|
||||
<p class="text u-text-center">
|
||||
You have no payment history. After you receive your first invoice, you'll see it
|
||||
here.
|
||||
</p>
|
||||
</EmptySearch>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
@@ -1,33 +1,136 @@
|
||||
<script lang="ts">
|
||||
import { CardGrid, Empty, Heading } from '$lib/components';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Submit, trackError } from '$lib/actions/analytics';
|
||||
import { CardGrid, DropList, DropListItem, Heading } from '$lib/components';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { paymentMethods } from './store';
|
||||
export let showPayment = false;
|
||||
import PaymentModal from '$routes/console/account/payments/paymentModal.svelte';
|
||||
import { hasStripePublicKey, isCloud } from '$lib/system';
|
||||
import { paymentMethods } from '$lib/stores/billing';
|
||||
|
||||
export let showDropdown = false;
|
||||
export let showDropdownBackup = false;
|
||||
|
||||
let showPayment = false;
|
||||
|
||||
async function addPaymentMethod(paymentMethodId: string) {
|
||||
try {
|
||||
await sdk.forConsole.billing.setOrganizationPaymentMethod(
|
||||
$organization.$id,
|
||||
paymentMethodId
|
||||
);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `A new payment method has been added to ${$organization.name}`
|
||||
});
|
||||
invalidate(Dependencies.ORG_PAYMENT_METHODS);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
trackError(error, Submit.OrganizationPaymentAdded);
|
||||
}
|
||||
}
|
||||
|
||||
async function addBackupPaymentMethod(paymentMethodId: string) {
|
||||
try {
|
||||
await sdk.forConsole.billing.setOrganizationPaymentMethodBackup(
|
||||
$organization.$id,
|
||||
paymentMethodId
|
||||
);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `A new payment method has been added to ${$organization.name}`
|
||||
});
|
||||
invalidate(Dependencies.ORG_PAYMENT_METHODS);
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
trackError(error, Submit.OrganizationPaymentAdded);
|
||||
}
|
||||
}
|
||||
|
||||
console.log($paymentMethods);
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
<Heading tag="h2" size="6">Payment Methods</Heading>
|
||||
<Heading tag="h2" size="6">Payment methods</Heading>
|
||||
|
||||
<p class="text">View or update your organization payment methods here.</p>
|
||||
<p class="text">
|
||||
View or update your organization payment methods here. A maximum of two payment methods can
|
||||
be added.
|
||||
</p>
|
||||
<svelte:fragment slot="aside">
|
||||
{#if $paymentMethods.total > 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}
|
||||
<Button text noMargin on:click={() => (showPayment = true)}>
|
||||
<span class="icon-plus" />
|
||||
<span class="text">Add a payment method</span>
|
||||
</Button>
|
||||
{:else}
|
||||
<Empty on:click={() => (showPayment = true)}>
|
||||
<p class="text">Add a payment method</p>
|
||||
</Empty>
|
||||
{/if}
|
||||
<h4 class="u-bold body-text-2">Default</h4>
|
||||
<article class="card u-grid u-cross-center u-width-full-line dashed">
|
||||
<div class="u-flex u-cross-center u-flex-vertical u-main-center u-flex">
|
||||
<div class="common-section">
|
||||
<DropList bind:show={showDropdown} placement="bottom-end">
|
||||
<Button secondary round on:click={() => (showDropdown = !showDropdown)}>
|
||||
<i class="icon-plus" />
|
||||
</Button>
|
||||
<svelte:fragment slot="list">
|
||||
{#if $paymentMethods.total}
|
||||
{#each $paymentMethods.paymentMethods as paymentMethod}
|
||||
<DropListItem
|
||||
on:click={() => addPaymentMethod(paymentMethod?.$id)}>
|
||||
<p class="text">
|
||||
Card ending in {paymentMethod.last4}
|
||||
<span>{paymentMethod.brand}</span>
|
||||
</p>
|
||||
</DropListItem>
|
||||
{/each}
|
||||
{/if}
|
||||
<DropListItem>Add new billing address</DropListItem>
|
||||
</svelte:fragment>
|
||||
</DropList>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<span class="text"> Add a payment method </span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
<h4 class="u-bold body-text-2">Backup</h4>
|
||||
<article class="card u-grid u-cross-center u-width-full-line dashed">
|
||||
<div class="u-flex u-cross-center u-flex-vertical u-main-center u-flex">
|
||||
<div class="common-section">
|
||||
<DropList bind:show={showDropdownBackup} placement="bottom-end">
|
||||
<Button
|
||||
secondary
|
||||
round
|
||||
on:click={() => (showDropdownBackup = !showDropdownBackup)}>
|
||||
<i class="icon-plus" />
|
||||
</Button>
|
||||
<svelte:fragment slot="list">
|
||||
{#if $paymentMethods.total}
|
||||
{#each $paymentMethods.paymentMethods as paymentMethod}
|
||||
<DropListItem
|
||||
on:click={() => addBackupPaymentMethod(paymentMethod?.$id)}>
|
||||
<p class="text">
|
||||
Card ending in {paymentMethod.last4}
|
||||
<span>{paymentMethod.brand}</span>
|
||||
</p>
|
||||
</DropListItem>
|
||||
{/each}
|
||||
{/if}
|
||||
<DropListItem>Add new billing address</DropListItem>
|
||||
</svelte:fragment>
|
||||
</DropList>
|
||||
</div>
|
||||
<div class="common-section">
|
||||
<span class="text"> Add a backup payment method </span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
|
||||
{#if showPayment && isCloud && hasStripePublicKey}
|
||||
<PaymentModal bind:show={showPayment} />
|
||||
{/if}
|
||||
@@ -1,24 +1,66 @@
|
||||
<script lang="ts">
|
||||
import { Box, CardGrid, Heading } from '$lib/components';
|
||||
import { VARS } from '$lib/system';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { tierFree, tierPro, tierScale } from '$lib/stores/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
// import { sdk } from '$lib/stores/sdk';
|
||||
import UsageRates from '$routes/console/wizard/usageRates.svelte';
|
||||
|
||||
let showPricing = false;
|
||||
|
||||
$: currentTier =
|
||||
$organization.billingPlan === 'tier-2'
|
||||
? tierScale
|
||||
: $organization?.billingPlan === 'tier-1'
|
||||
? tierPro
|
||||
: tierFree;
|
||||
|
||||
// async function getInvoice() {
|
||||
// const invoiceList = await sdk.forConsole.billing.listInvoices($organization.$id);
|
||||
// return await sdk.forConsole.billing.getInvoiceView(
|
||||
// $organization.$id,
|
||||
// invoiceList.invoices[0].$id
|
||||
// );
|
||||
// }
|
||||
</script>
|
||||
|
||||
<CardGrid>
|
||||
<Heading tag="h2" size="6">Payment Summary</Heading>
|
||||
<Heading tag="h2" size="6">Plan summary</Heading>
|
||||
|
||||
<p class="text">An overview of your upcoming payments.</p>
|
||||
<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">
|
||||
<Box>
|
||||
<svelte:fragment slot="title">
|
||||
<h6 class="u-bold u-trim-1">PLACEHOLDER PLAN</h6>
|
||||
<h6 class="u-bold u-trim-1">
|
||||
{currentTier.name}
|
||||
</h6>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="end">
|
||||
<p class="text">${currentTier.price}</p>
|
||||
</svelte:fragment>
|
||||
<p class="u-trim-1">X projects</p>
|
||||
</Box>
|
||||
{#if VARS.CONSOLE_TIER && VARS.CONSOLE_TIER !== 'base'}
|
||||
<div class="u-flex">
|
||||
<p class="u-bold">Next billing data</p>
|
||||
<p class="text u-margin-inline-start-auto">XX DATE</p>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="u-flex u-main-space-between u-cross-center">
|
||||
<p class="text">
|
||||
Billing period: {toLocaleDate($organization.billingCurrentInvoiceDate)} - {toLocaleDate(
|
||||
$organization.billingNextInvoiceDate
|
||||
)}
|
||||
</p>
|
||||
<!-- <a class="link" href="/">View invoice</a> -->
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="actions">
|
||||
<Button text>Change plan</Button>
|
||||
<Button secondary>View estimated usage</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
|
||||
<UsageRates bind:show={showPricing} tier={$organization?.billingPlan} />
|
||||
@@ -1,4 +0,0 @@
|
||||
import { page } from '$app/stores';
|
||||
import { derived } from 'svelte/store';
|
||||
|
||||
export const paymentMethods = derived(page, ($page) => $page.data.paymentMethods);
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
export let data;
|
||||
|
||||
$: requests = data.response.requests;
|
||||
$: requests = data.requests;
|
||||
// $: network = data.response.network;
|
||||
// $: executions = data.response.executions;
|
||||
// $: documents = data.response.documents;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { createOrganization } from './store';
|
||||
import UsageRates from './usageRates.svelte';
|
||||
import type { PaymentList, PaymentMethodData } from '$lib/stores/billing';
|
||||
import type { PaymentList, PaymentMethodData } from '$lib/sdk/billing';
|
||||
import { paymentMethods } from '../account/payments/store';
|
||||
import { loadStripe, type Stripe, type StripeElements } from '@stripe/stripe-js';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
@@ -167,4 +167,4 @@
|
||||
</FormList>
|
||||
</WizardStep>
|
||||
|
||||
<UsageRates bind:show={showRates} />
|
||||
<UsageRates bind:show={showRates} tier={$createOrganization?.billingPlan} />
|
||||
@@ -1,4 +1,4 @@
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { Modal } from '$lib/components';
|
||||
import { usageRates } from '$lib/constants';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
@@ -10,16 +10,23 @@
|
||||
TableHeader,
|
||||
TableRow
|
||||
} from '$lib/elements/table';
|
||||
import { toLocaleDate } from '$lib/helpers/date';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { createOrganization } from './store';
|
||||
|
||||
export let show = false;
|
||||
export let tier: string;
|
||||
|
||||
$: nextDate = $createOrganization?.name
|
||||
? new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1).toString()
|
||||
: $organization?.billingNextInvoiceDate;
|
||||
</script>
|
||||
|
||||
<Modal bind:show size="big" headerDivider={false}>
|
||||
<svelte:fragment slot="header">Usage rates</svelte:fragment>
|
||||
<!-- TODO: add billing period -->
|
||||
<p>
|
||||
Usage on the Pro plan will be charged at the end of each billing period at the following
|
||||
rates. Next billing period: 05 Jun, 2023.
|
||||
rates. Next billing period: {toLocaleDate(nextDate)}
|
||||
</p>
|
||||
|
||||
<Table noStyles>
|
||||
@@ -29,7 +36,7 @@
|
||||
<TableCellHead>Rate</TableCellHead>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each usageRates[$createOrganization.billingPlan] as usage}
|
||||
{#each usageRates[tier] as usage}
|
||||
<TableRow>
|
||||
<TableCellText title="resource">{usage.resource}</TableCellText>
|
||||
<TableCellText title="limit">{usage.limit}</TableCellText>
|
||||
|
||||
Reference in new issue
Block a user