diff --git a/src/lib/stores/stripe.ts b/src/lib/stores/stripe.ts
index 586178a65..a083e3ad1 100644
--- a/src/lib/stores/stripe.ts
+++ b/src/lib/stores/stripe.ts
@@ -49,10 +49,13 @@ export async function initializeStripe() {
paymentElement.mount('#payment-element');
} catch (e) {
console.log(e);
+ throw e;
}
}
-export async function submitStripeCard(name: string) {
+// TODO: fix redirect
+
+export async function submitStripeCard(name?: string) {
try {
// If a payment method was during initialization, use it, otherwise create a new one
if (!paymentMethod) {
@@ -77,7 +80,41 @@ export async function submitStripeCard(name: string) {
redirect: 'if_required'
});
- // console.log(setupIntent);
+ if (setupIntent && setupIntent.status === 'succeeded') {
+ const method = await sdk.forConsole.billing.updatePaymentMethod(
+ paymentMethod.$id,
+ setupIntent.payment_method
+ );
+ paymentElement.destroy();
+ return method;
+ } else {
+ console.log('something went wrong');
+ throw new Error('Something went wrong');
+ }
+ } catch (e) {
+ console.log(e);
+ throw e;
+ }
+}
+
+// TODO: fix update
+
+export async function updateStripeCard(selectedPaymentMethod?: string) {
+ try {
+ paymentMethod = await sdk.forConsole.billing.getPaymentMethod(selectedPaymentMethod);
+ clientSecret = paymentMethod.clientSecret;
+
+ // Element needs to be submitted before confirming the setup intent
+ elements.submit();
+
+ const { setupIntent } = await stripe.confirmSetup({
+ elements,
+ clientSecret,
+ confirmParams: {
+ return_url: 'https://example.com'
+ },
+ redirect: 'if_required'
+ });
if (setupIntent && setupIntent.status === 'succeeded') {
const method = await sdk.forConsole.billing.updatePaymentMethod(
@@ -86,10 +123,12 @@ export async function submitStripeCard(name: string) {
);
paymentElement.destroy();
return method;
- } else console.log('something went wrong');
+ } else {
+ console.log('something went wrong');
+ throw new Error('Something went wrong');
+ }
} catch (e) {
console.log(e);
- console.log(e.message);
- // trackError(StripeError, Submit.ProjectCreate);
+ throw e;
}
}
diff --git a/src/routes/console/account/payments/+page.svelte b/src/routes/console/account/payments/+page.svelte
index fcc6ae0a6..244c6f9dd 100644
--- a/src/routes/console/account/payments/+page.svelte
+++ b/src/routes/console/account/payments/+page.svelte
@@ -1,10 +1,8 @@
+
+
+ Update payment method
+
+
+
+
+
+
+
+
+
+
diff --git a/src/routes/console/account/payments/paymentMethods.svelte b/src/routes/console/account/payments/paymentMethods.svelte
index 5d400bbfd..23f884d88 100644
--- a/src/routes/console/account/payments/paymentMethods.svelte
+++ b/src/routes/console/account/payments/paymentMethods.svelte
@@ -17,19 +17,22 @@
TableHeader,
TableRow
} from '$lib/elements/table';
- import DeletePayment from './deletePayment.svelte';
import { paymentMethods } from './store';
import type { PaymentMethodData } from '$lib/sdk/billing';
import { organizationList, type Organization } from '$lib/stores/organization';
import { tooltip } from '$lib/actions/tooltip';
import { base } from '$app/paths';
+ import EditPaymentModal from './editPaymentModal.svelte';
+ import DeletePaymentModal from './deletePaymentModal.svelte';
+ import { hasStripePublicKey, isCloud } from '$lib/system';
+ import PaymentModal from './paymentModal.svelte';
export let showPayment = false;
let showDropdown = [];
let selectedMethod: string;
+ let selectedLinkedOrgs: Organization[] = [];
let showDelete = false;
-
- console.log($paymentMethods);
+ let showEdit = false;
$: orgList = $organizationList.teams as unknown as Organization[];
@@ -79,22 +82,6 @@
)
.join('')}
`
-
- // onShow(instance) {
- // if (isFetching || data) {
- // return;
- // }
- // getData(role)
- // .then((n) => {
- // data = n;
- // })
- // .finally(() => {
- // tick().then(() => {
- // instance.setContent(content);
- // });
- // });
- // }
- // }
}}>
linked to organization
@@ -117,7 +104,9 @@
{
- console.log('test');
+ showEdit = true;
+ showDropdown[i] = false;
+ selectedMethod = paymentMethod.$id;
}}>
Edit
@@ -125,6 +114,7 @@
icon="trash"
on:click={() => {
selectedMethod = paymentMethod.$id;
+ selectedLinkedOrgs = linkedOrgs;
showDelete = true;
showDropdown[i] = false;
}}>
@@ -151,6 +141,13 @@
+{#if showPayment && isCloud && hasStripePublicKey}
+
+{/if}
+{#if showEdit && isCloud && hasStripePublicKey}
+
+{/if}
+
{#if selectedMethod}
-
+
{/if}
diff --git a/src/routes/console/account/payments/paymentModal.svelte b/src/routes/console/account/payments/paymentModal.svelte
index 90dcfd486..c429632a5 100644
--- a/src/routes/console/account/payments/paymentModal.svelte
+++ b/src/routes/console/account/payments/paymentModal.svelte
@@ -6,6 +6,7 @@
import { initializeStripe, submitStripeCard } from '$lib/stores/stripe';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
+ import { addNotification } from '$lib/stores/notifications';
export let show = false;
@@ -21,6 +22,10 @@
await submitStripeCard(name);
show = false;
invalidate(Dependencies.PAYMENT_METHODS);
+ addNotification({
+ type: 'success',
+ message: 'A new payment method has been added to your account'
+ });
} catch (e) {
error = e.message;
console.log(e.message);
@@ -29,7 +34,7 @@
- Add Payment Method
+ Add payment method
{#each $invoiceList?.invoices as invoice, i}
+ {@const status = invoice.status}
- {toLocaleDate(invoice.dueAt)}
+
+ {toLocaleDate(invoice.dueAt)}
+
- {invoice.status}
+
+ {status}
+
{invoice.amount}