Skip to content

Commit 1c63575

Browse files
committed
fix billing wizard
1 parent 16b0fe3 commit 1c63575

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/routes/(console)/organization-[organization]/billing/wizard/paymentDetails.svelte

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
<script lang="ts">
22
import { WizardStep } from '$lib/layout';
33
import { onMount } from 'svelte';
4-
import type { PaymentList } from '$lib/sdk/billing';
4+
import type { PaymentList, PaymentMethodData } from '$lib/sdk/billing';
55
import { invalidate } from '$app/navigation';
66
import { Dependencies } from '$lib/constants';
7-
import { isStripeInitialized, submitStripeCard } from '$lib/stores/stripe';
7+
import { isStripeInitialized, setPaymentMethod, submitStripeCard } from '$lib/stores/stripe';
88
import { sdk } from '$lib/stores/sdk';
99
import { PaymentBoxes } from '$lib/components/billing';
1010
import { addCreditWizardStore } from '../store';
1111
import { organization } from '$lib/stores/organization';
12+
import type { PaymentMethod } from '@stripe/stripe-js';
1213
1314
let methods: PaymentList;
1415
let name: string;
16+
let showState: boolean = false;
17+
let state: string = '';
18+
let paymentMethod: PaymentMethod | null = null;
1519
1620
onMount(async () => {
1721
methods = await sdk.forConsole.billing.listPaymentMethods();
@@ -21,7 +25,24 @@
2125
2226
async function handleSubmit() {
2327
try {
24-
const method = await submitStripeCard(name, $organization.$id);
28+
if (showState && !state) {
29+
throw Error('Please select a state');
30+
}
31+
let method: PaymentMethodData;
32+
if (showState) {
33+
method = await setPaymentMethod(paymentMethod.id, name, state);
34+
} else {
35+
const card = await submitStripeCard(name, $organization.$id);
36+
if (card && Object.hasOwn(card, 'id')) {
37+
if ((card as PaymentMethod).card.country === 'US') {
38+
paymentMethod = card as PaymentMethod;
39+
showState = true;
40+
return;
41+
}
42+
} else if (card && Object.hasOwn(card, '$id')) {
43+
method = card as PaymentMethodData;
44+
}
45+
}
2546
$addCreditWizardStore.paymentMethodId = method.$id;
2647
invalidate(Dependencies.PAYMENT_METHODS);
2748
} catch (e) {
@@ -45,6 +66,9 @@
4566

4667
<p class="text"><b>Payment method</b></p>
4768
<PaymentBoxes
69+
bind:paymentMethod
70+
bind:showState
71+
bind:state
4872
methods={filteredMethods}
4973
bind:name
5074
bind:group={$addCreditWizardStore.paymentMethodId} />

0 commit comments

Comments
 (0)