From 431c5c2cf35c1b9fab4cf8e5530ec1bf2134d571 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 2 Feb 2024 16:54:13 +0100 Subject: [PATCH] feat: retry failed payments --- src/lib/actions/analytics.ts | 1 + src/lib/stores/stripe.ts | 10 ++- .../billing/paymentHistory.svelte | 26 ++++++- .../billing/retryPaymentModal.svelte | 76 +++++++++++++++++++ 4 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 src/routes/console/organization-[organization]/billing/retryPaymentModal.svelte diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index ad6f5ab71..181592ef0 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -263,6 +263,7 @@ export enum Submit { PaymentMethodCreate = 'submit_payment_method_create', PaymentMethodUpdate = 'submit_payment_method_update', PaymentMethodDelete = 'submit_payment_method_delete', + RetryPayment = 'submit_retry_payment', BillingAddressCreate = 'submit_billing_address_create', BillingAddressUpdate = 'submit_billing_address_update', BillingAddressDelete = 'submit_billing_address_delete', diff --git a/src/lib/stores/stripe.ts b/src/lib/stores/stripe.ts index 963adcf9e..ac8163af5 100644 --- a/src/lib/stores/stripe.ts +++ b/src/lib/stores/stripe.ts @@ -101,9 +101,15 @@ export async function submitStripeCard(name: string, urlRoute?: string) { } } -export async function confirmPayment(orgId: string, clientSecret: string, paymentMethodId: string) { +export async function confirmPayment( + orgId: string, + clientSecret: string, + paymentMethodId: string, + route?: string +) { try { - const url = `${window.location.origin}/console/organization-${orgId}/billing`; + const url = + window.location.origin + route ? route : `/console/organization-${orgId}/billing`; const paymentMethod = await sdk.forConsole.billing.getPaymentMethod(paymentMethodId); diff --git a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte b/src/routes/console/organization-[organization]/billing/paymentHistory.svelte index d0b628c72..8ca0b69d9 100644 --- a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte +++ b/src/routes/console/organization-[organization]/billing/paymentHistory.svelte @@ -3,6 +3,7 @@ import { CardGrid, DropList, + DropListItem, DropListLink, EmptySearch, Heading, @@ -20,13 +21,17 @@ TableScroll } from '$lib/elements/table'; import { toLocaleDate } from '$lib/helpers/date'; - import type { InvoiceList } from '$lib/sdk/billing'; + import type { Invoice, InvoiceList } from '$lib/sdk/billing'; import { sdk } from '$lib/stores/sdk'; import { VARS } from '$lib/system'; import { Query } from '@appwrite.io/console'; import { onMount } from 'svelte'; + import RetryPaymentModal from './retryPaymentModal.svelte'; + import { trackEvent } from '$lib/actions/analytics'; let showDropdown = []; + let showRetryModal = false; + let selectedInvoice: Invoice | null = null; let offset = 0; let invoiceList: InvoiceList = { @@ -122,6 +127,21 @@ event="download_invoice"> Download PDF + {#if status === 'overdue' || status === 'failed'} + { + selectedInvoice = invoice; + showRetryModal = true; + showDropdown[i] = !showDropdown[i]; + trackEvent(`click_retry_payment`, { + from: 'button', + source: 'billing_invoice_menu' + }); + }}> + Retry payment + + {/if} @@ -144,3 +164,7 @@ {/if} + +{#if selectedInvoice} + +{/if} diff --git a/src/routes/console/organization-[organization]/billing/retryPaymentModal.svelte b/src/routes/console/organization-[organization]/billing/retryPaymentModal.svelte new file mode 100644 index 000000000..b2aa266de --- /dev/null +++ b/src/routes/console/organization-[organization]/billing/retryPaymentModal.svelte @@ -0,0 +1,76 @@ + + + + +

+ Your payment of ${invoice.amount} due on {toLocaleDate( + invoice.dueAt + )} has failed. Retry your payment to avoid service interruptions with your projects. +

+ + + + + + +