From 79730d8b47789870a6b3140fcb4b6aa99e67289b Mon Sep 17 00:00:00 2001 From: Arman Date: Mon, 12 Feb 2024 15:51:26 +0100 Subject: [PATCH] Add payment mandate setup and check for missing mandate --- src/lib/sdk/billing.ts | 21 +++++++++++++++++++++ src/routes/console/+layout.svelte | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index 698f78377..751e42e58 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -18,6 +18,7 @@ export type PaymentMethodData = { clientSecret: string; failed: boolean; name: string; + mandateId?: string; }; export type PaymentList = { @@ -849,6 +850,26 @@ export class Billing { ); } + async setupPaymentMandate( + organizationId: string, + paymentMethodId: string + ): Promise { + const path = `/account/payment-methods/${paymentMethodId}/setup`; + const params = { + organizationId, + paymentMethodId + }; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call( + 'post', + uri, + { + 'content-type': 'application/json' + }, + params + ); + } + async listAddresses(queries: Query[] = []): Promise { const path = `/account/billing-addresses`; const params = { diff --git a/src/routes/console/+layout.svelte b/src/routes/console/+layout.svelte index dccfe71a4..8cd889e91 100644 --- a/src/routes/console/+layout.svelte +++ b/src/routes/console/+layout.svelte @@ -40,6 +40,7 @@ import UsageRates from './wizard/cloudOrganization/usageRates.svelte'; import { activeHeaderAlert, consoleVariables } from './store'; import { headerAlert } from '$lib/stores/headerAlert'; + import { sdk } from '$lib/stores/sdk'; function kebabToSentenceCase(str: string) { return str @@ -248,6 +249,13 @@ } }); + async function checkForMandate() { + const paymentMethods = await sdk.forConsole.billing.listPaymentMethods(); + const missingMandate = paymentMethods.paymentMethods.filter( + (method) => method.mandateId === null && method.country === 'in' + ); + } + function checkForFeedback(interval: number) { const minutes = interval / 60000; feedback.increaseElapsed(minutes);