feat: add endpoints for billing

This commit is contained in:
Arman committed 2023-07-02 02:52:54 +02:00
1 parent cf4b25c942
commit 057dce5f8d
1 file changed
+172 -1
+172 -1
View File
@@ -8,6 +8,173 @@ export class Billing {
this.client = client;
}
async createOrganization(
organizationId: string,
name: string,
billingPlan: string,
paymentMethodId: string
): Promise<string> {
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<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 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<string> {
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(