From 431c5c2cf35c1b9fab4cf8e5530ec1bf2134d571 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 2 Feb 2024 16:54:13 +0100 Subject: [PATCH 1/4] 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 ad6f5ab71f..181592ef0c 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 963adcf9e6..ac8163af5a 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 d0b628c72a..8ca0b69d91 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 0000000000..b2aa266deb --- /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. +

+ + + + + + +
From 62adbd503aba7cfedefa387cd0e6227c35044e11 Mon Sep 17 00:00:00 2001 From: Arman Date: Mon, 5 Feb 2024 15:35:50 +0100 Subject: [PATCH 2/4] fix and expand paymentBoxes --- .../components/billing/paymentBoxes.svelte | 41 +++++- src/lib/components/radioBoxes.svelte | 8 +- .../billing/paymentHistory.svelte | 2 +- .../billing/replaceCard.svelte | 132 ++---------------- .../billing/retryPaymentModal.svelte | 20 +++ 5 files changed, 74 insertions(+), 129 deletions(-) diff --git a/src/lib/components/billing/paymentBoxes.svelte b/src/lib/components/billing/paymentBoxes.svelte index 240ad1c0cc..32a010718d 100644 --- a/src/lib/components/billing/paymentBoxes.svelte +++ b/src/lib/components/billing/paymentBoxes.svelte @@ -1,12 +1,18 @@ - + - - - {element.brand} ending in {element.last4} - + + + + + {element.brand} ending in {element.last4} + + + {#if element.$id === backupMethod} + Backup + {:else if element.$id === defaultMethod} + Default + {/if} + + {#if !!defaultMethod && element.$id !== defaultMethod && group === element.$id && showSetAsDefault} +
    + +
+ {/if}
diff --git a/src/lib/components/radioBoxes.svelte b/src/lib/components/radioBoxes.svelte index 4e3b4bf924..4a798660be 100644 --- a/src/lib/components/radioBoxes.svelte +++ b/src/lib/components/radioBoxes.svelte @@ -13,7 +13,7 @@ {#if total} {#each elements as element} {@const value = element[variableName]?.toString()} -
+
    -
+ {/each} {/if} -
+
    {#if total} @@ -37,5 +37,5 @@ {#if group === null} {/if} -
+ diff --git a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte b/src/routes/console/organization-[organization]/billing/paymentHistory.svelte index 8ca0b69d91..0057863c7f 100644 --- a/src/routes/console/organization-[organization]/billing/paymentHistory.svelte +++ b/src/routes/console/organization-[organization]/billing/paymentHistory.svelte @@ -127,7 +127,7 @@ event="download_invoice"> Download PDF - {#if status === 'overdue' || status === 'failed'} + {#if status === 'overdue' || status === 'failed' || true} { diff --git a/src/routes/console/organization-[organization]/billing/replaceCard.svelte b/src/routes/console/organization-[organization]/billing/replaceCard.svelte index 8dfc4fe501..e253489906 100644 --- a/src/routes/console/organization-[organization]/billing/replaceCard.svelte +++ b/src/routes/console/organization-[organization]/billing/replaceCard.svelte @@ -1,16 +1,16 @@