feat: add more methods and some fixes

This commit is contained in:
Arman
2023-07-05 21:45:37 +02:00
parent b819f1f2cb
commit 3b7ea5a753
5 changed files with 164 additions and 15 deletions
+157 -8
View File
@@ -88,7 +88,7 @@ export class Billing {
);
}
async updatePaymentMethod(organizationId: string, paymentMethodId: string) {
async updateOrganizationPaymentMethod(organizationId: string, paymentMethodId: string) {
const path = `/organizations/${organizationId}/payment-method`;
const params = {
organizationId,
@@ -105,7 +105,7 @@ export class Billing {
);
}
async updatePaymentMethodBackup(organizationId: string, paymentMethodId: string) {
async updateOrganizationPaymentMethodBackup(organizationId: string, paymentMethodId: string) {
const path = `/organizations/${organizationId}/payment-method/backup`;
const params = {
organizationId,
@@ -122,7 +122,11 @@ export class Billing {
);
}
async listInvoices(organizationId: string, queries: [], search: string): Promise<string> {
async listInvoices(
organizationId: string,
queries: [] = [],
search: string = ''
): Promise<string> {
const path = `/organizations/${organizationId}/plan`;
const params = {
organizationId,
@@ -191,14 +195,42 @@ export class Billing {
);
}
async listPaymentMethods(teamId: string) {
const path = `/teams/${teamId}/payment-methods`;
//ACCOUNT
async listPaymentMethods(queries: [] = []): Promise<PaymentMethod> {
const path = `/account/payment-methods`;
const params = {
queries
};
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call('GET', uri);
return await this.client.call(
'GET',
uri,
{
'content-type': 'application/json'
},
params
);
}
async createPaymentMethod(teamId: string): Promise<PaymentMethod> {
const path = `/teams/${teamId}/payment-methods`;
async getPaymentMethod(paymentMethodId: string): Promise<PaymentMethod> {
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<PaymentMethod> {
const path = `/account/payment-methods`;
const params = {};
const uri = new URL(this.client.config.endpoint + path);
return await this.client.call(
@@ -210,6 +242,123 @@ export class Billing {
params
);
}
async updatePaymentMethod(
paymentMethodId: string,
providerMethodId: string
): Promise<PaymentMethod> {
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<PaymentMethod> {
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<PaymentMethod> {
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(couponId: string): Promise<PaymentMethod> {
const path = `/account/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(queries = []): Promise<PaymentMethod> {
const path = `/account/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(creditId: string): Promise<PaymentMethod> {
const path = `/account/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 tierFree = {
@@ -64,7 +64,7 @@
paymentMethod = await sdk.forConsole.billing.createPaymentMethod($organization.$id);
const { setupIntent } = await stripe.retrieveSetupIntent(paymentMethod.clientSecret);
if (setupIntent && setupIntent.status === 'succeeded') {
await sdk.forConsole.billing.updatePaymentMethod(
await sdk.forConsole.billing.updateOrganizationPaymentMethod(
$organization.$id,
paymentMethod.$id,
setupIntent.payment_method as string
@@ -64,7 +64,7 @@
paymentMethod = await sdk.forConsole.billing.createPaymentMethod($organization.$id);
const { setupIntent } = await stripe.retrieveSetupIntent(paymentMethod.clientSecret);
if (setupIntent && setupIntent.status === 'succeeded') {
await sdk.forConsole.billing.updatePaymentMethod(
await sdk.forConsole.billing.updateOrganizationPaymentMethod(
$organization.$id,
paymentMethod.$id,
setupIntent.payment_method as string
+3 -3
View File
@@ -51,7 +51,7 @@
style="--p-grid-item-size:16em; --p-grid-item-size-small-screens:16rem; --grid-gap: 1rem;">
{#if !anyOrgFree}
<li>
<LabelCard name="plan" bind:group={$createOrganization.tier} value="tier-0">
<LabelCard name="plan" bind:group={$createOrganization.billingPlan} value="tier-0">
<svelte:fragment slot="custom">
<div class="u-flex u-flex-vertical u-gap-4 u-width-full-line">
<h4 class="body-text-2 u-bold">
@@ -64,7 +64,7 @@
</li>
{/if}
<li>
<LabelCard name="plan" bind:group={$createOrganization.tier} value="tier-1">
<LabelCard name="plan" bind:group={$createOrganization.billingPlan} value="tier-1">
<svelte:fragment slot="custom">
<div class="u-flex u-flex-vertical u-gap-4 u-width-full-line">
<h4 class="body-text-2 u-bold">
@@ -79,7 +79,7 @@
</LabelCard>
</li>
<li>
<LabelCard name="plan" bind:group={$createOrganization.tier} value="tier-2">
<LabelCard name="plan" bind:group={$createOrganization.billingPlan} value="tier-2">
<svelte:fragment slot="custom">
<div class="u-flex u-flex-vertical u-gap-4 u-width-full-line">
<h4 class="body-text-2 u-bold">
+2 -2
View File
@@ -43,10 +43,10 @@
</svelte:fragment>
<Alert type="info">
{#if $createOrganization.tier === 'tier-2'}
{#if $createOrganization.billingPlan === 'tier-2'}
You can add unlimited organization members on the Pro plan for $20 each. Each member
added will receive an email invite to your organization on completion.
{:else if $createOrganization.tier === 'tier-1'}
{:else if $createOrganization.billingPlan === 'tier-1'}
You can add up to three organization members with the Starter plan for $10 each. Each
member added will receive an email invite to your organization on completion.
{:else}