more work on the mandate flow

This commit is contained in:
Arman committed 2024-02-13 16:06:01 +01:00
1 parent 63805945bd
commit b482a7a3da
3 files changed
+41 -10

No files matched your search

@@ -0,0 +1,29 @@
<script lang="ts">
import { page } from '$app/stores';
import { Button } from '$lib/elements/forms';
import { HeaderAlert } from '$lib/layout';
import { actionRequiredInvoices } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { VARS } from '$lib/system';
const endpoint = VARS.APPWRITE_ENDPOINT ?? `${$page.url.origin}/v1`;
</script>
{#if $actionRequiredInvoices && $actionRequiredInvoices?.invoices?.length && !$page.url.pathname.includes('/console/account')}
<HeaderAlert title="Authorization required" type="error">
Please authorize your upcoming payment for {$organization.name}. Your bank requires this
security measure to proceed with payment.
<svelte:fragment slot="buttons">
<Button
text
href={`${endpoint}/organizations/${$organization.$id}/invoices/${$actionRequiredInvoices.invoices[0].$id}/view`}>
View invoice
</Button>
<Button
secondary
href={`/console/organization-${$organization.$id}/billing?type=confirmation&invoice=${$actionRequiredInvoices.invoices[0].$id}`}>
Authorize payment
</Button>
</svelte:fragment>
</HeaderAlert>
{/if}
+9 -1
View File
@@ -261,7 +261,15 @@ export function checkForMarkedForDeletion(org: Organization) {
id: 'markedForDeletion',
component: MarkedForDeletion,
show: true,
importance: 5
importance: 10
});
}
}
export async function checkForMandate(org: Organization) {
const paymentId = org.paymentMethodId ?? org.backupPaymentMethodId;
const paymentMethod = await sdk.forConsole.billing.getPaymentMethod(paymentId);
if (paymentMethod.mandateId === null && paymentMethod.country === 'in') {
const method = sdk.forConsole.billing.setupPaymentMandate(org.$id, paymentId);
}
}
+3 -9
View File
@@ -19,7 +19,8 @@
checkPaymentAuthorizationRequired,
calculateTrialDay,
paymentExpired,
checkForMarkedForDeletion
checkForMarkedForDeletion,
checkForMandate
} from '$lib/stores/billing';
import { goto } from '$app/navigation';
import { CommandCenter, registerCommands, registerSearchers } from '$lib/commandCenter';
@@ -40,7 +41,6 @@
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
@@ -249,13 +249,6 @@
}
});
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);
@@ -277,6 +270,7 @@
await checkForUsageLimit(org);
checkForMarkedForDeletion(org);
await checkPaymentAuthorizationRequired(org);
await checkForMandate(org);
}
});