From 057dce5f8dc46266e83c79819532db9ca9b1b779 Mon Sep 17 00:00:00 2001 From: Arman Date: Sun, 2 Jul 2023 02:52:54 +0200 Subject: [PATCH] feat: add endpoints for billing --- src/lib/stores/billing.ts | 173 +++++++++++++++++++++++++++++++++++++- 1 file changed, 172 insertions(+), 1 deletion(-) diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 8ca747d85..1215904ec 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -8,6 +8,173 @@ export class Billing { this.client = client; } + async createOrganization( + organizationId: string, + name: string, + billingPlan: string, + paymentMethodId: string + ): Promise { + 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 updatePlan( + organizationId: string, + billingPlan: string, + paymentMethodId: string + ): Promise { + 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 { + 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 updatePaymentMethod(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 updatePaymentMethodBackup(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: [], search: string): Promise { + const path = `/organizations/${organizationId}/plan`; + 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) { + 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) { + 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) { + 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 listPaymentMethods(teamId: string) { const path = `/teams/${teamId}/payment-methods`; const uri = new URL(this.client.config.endpoint + path); @@ -28,7 +195,11 @@ export class Billing { ); } - async updatePaymentMethod(teamId: string, paymentMethodId: string, providerMethodId: string) { + async updatePaymentMethodOld( + 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(