diff --git a/src/lib/stores/billing.ts b/src/lib/stores/billing.ts index 36a325e84..b81cd7c08 100644 --- a/src/lib/stores/billing.ts +++ b/src/lib/stores/billing.ts @@ -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 { + async listInvoices( + organizationId: string, + queries: [] = [], + search: string = '' + ): Promise { 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 { + 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 { - const path = `/teams/${teamId}/payment-methods`; + async getPaymentMethod(paymentMethodId: string): Promise { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + // 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 = { diff --git a/src/routes/console/account/payments/paymentModal.svelte b/src/routes/console/account/payments/paymentModal.svelte index ff7fae0d2..742e286b5 100644 --- a/src/routes/console/account/payments/paymentModal.svelte +++ b/src/routes/console/account/payments/paymentModal.svelte @@ -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 diff --git a/src/routes/console/organization-[organization]/billing/paymentModal.svelte b/src/routes/console/organization-[organization]/billing/paymentModal.svelte index ff7fae0d2..742e286b5 100644 --- a/src/routes/console/organization-[organization]/billing/paymentModal.svelte +++ b/src/routes/console/organization-[organization]/billing/paymentModal.svelte @@ -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 diff --git a/src/routes/console/wizard/step1.svelte b/src/routes/console/wizard/step1.svelte index cb735b6e5..6dec604a9 100644 --- a/src/routes/console/wizard/step1.svelte +++ b/src/routes/console/wizard/step1.svelte @@ -51,7 +51,7 @@ style="--p-grid-item-size:16em; --p-grid-item-size-small-screens:16rem; --grid-gap: 1rem;"> {#if !anyOrgFree}
  • - +

    @@ -64,7 +64,7 @@

  • {/if}
  • - +

    @@ -79,7 +79,7 @@

  • - +

    diff --git a/src/routes/console/wizard/step3.svelte b/src/routes/console/wizard/step3.svelte index 8c184609e..6fe1bdb2b 100644 --- a/src/routes/console/wizard/step3.svelte +++ b/src/routes/console/wizard/step3.svelte @@ -43,10 +43,10 @@ - {#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}