|
5 | 5 | import { CardGrid, CreditCardBrandImage, CreditCardInfo } from '$lib/components';
|
6 | 6 | import { BillingPlan, Dependencies } from '$lib/constants';
|
7 | 7 | import { addNotification } from '$lib/stores/notifications';
|
8 |
| - import { organization } from '$lib/stores/organization'; |
| 8 | + import { type Organization } from '$lib/stores/organization'; |
9 | 9 | import { Button } from '$lib/elements/forms';
|
10 | 10 | import { hasStripePublicKey, isCloud } from '$lib/system';
|
11 | 11 | import type { PaymentList, PaymentMethodData } from '$lib/sdk/billing';
|
|
34 | 34 | IconTrash
|
35 | 35 | } from '@appwrite.io/pink-icons-svelte';
|
36 | 36 |
|
| 37 | + export let organization: Organization; |
37 | 38 | export let methods: PaymentList;
|
38 | 39 |
|
39 | 40 | let showPayment = false;
|
|
47 | 48 | async function addPaymentMethod(paymentMethodId: string) {
|
48 | 49 | try {
|
49 | 50 | await sdk.forConsole.billing.setOrganizationPaymentMethod(
|
50 |
| - $organization.$id, |
| 51 | + organization.$id, |
51 | 52 | paymentMethodId
|
52 | 53 | );
|
53 | 54 | addNotification({
|
54 | 55 | type: 'success',
|
55 |
| - message: `A new payment method has been added to ${$organization.name}` |
| 56 | + message: `A new payment method has been added to ${organization.name}` |
56 | 57 | });
|
57 | 58 | trackEvent(Submit.OrganizationPaymentUpdate);
|
58 | 59 | invalidate(Dependencies.ORGANIZATION);
|
|
68 | 69 | async function addBackupPaymentMethod(paymentMethodId: string) {
|
69 | 70 | try {
|
70 | 71 | await sdk.forConsole.billing.setOrganizationPaymentMethodBackup(
|
71 |
| - $organization.$id, |
| 72 | + organization.$id, |
72 | 73 | paymentMethodId
|
73 | 74 | );
|
74 | 75 | addNotification({
|
75 | 76 | type: 'success',
|
76 |
| - message: `A new payment method has been added to ${$organization.name}` |
| 77 | + message: `A new payment method has been added to ${organization.name}` |
77 | 78 | });
|
78 | 79 | invalidate(Dependencies.ORGANIZATION);
|
79 | 80 | } catch (error) {
|
|
85 | 86 | }
|
86 | 87 | }
|
87 | 88 |
|
88 |
| - $: if ($organization?.backupPaymentMethodId) { |
| 89 | + $: if (organization?.backupPaymentMethodId) { |
89 | 90 | sdk.forConsole.billing
|
90 |
| - .getOrganizationPaymentMethod($organization.$id, $organization.backupPaymentMethodId) |
| 91 | + .getOrganizationPaymentMethod(organization.$id, organization.backupPaymentMethodId) |
91 | 92 | .then((res) => (backupPaymentMethod = res));
|
92 | 93 | }
|
93 | 94 |
|
94 |
| - $: if ($organization?.paymentMethodId) { |
| 95 | + $: if (organization?.paymentMethodId) { |
95 | 96 | sdk.forConsole.billing
|
96 |
| - .getOrganizationPaymentMethod($organization.$id, $organization.paymentMethodId) |
| 97 | + .getOrganizationPaymentMethod(organization.$id, organization.paymentMethodId) |
97 | 98 | .then((res) => (defaultPaymentMethod = res));
|
98 | 99 | }
|
99 | 100 |
|
|
112 | 113 | <svelte:fragment slot="title">Payment methods</svelte:fragment>
|
113 | 114 | View or update your organization payment methods here.
|
114 | 115 | <svelte:fragment slot="aside">
|
115 |
| - {#if $organization?.paymentMethodId} |
| 116 | + {#if organization?.paymentMethodId} |
116 | 117 | <Table.Root
|
117 | 118 | let:root
|
118 | 119 | columns={[
|
|
168 | 169 | </Popover>
|
169 | 170 | </Table.Cell>
|
170 | 171 | </Table.Row.Base>
|
171 |
| - {#if $organization?.backupPaymentMethodId} |
| 172 | + {#if organization?.backupPaymentMethodId} |
172 | 173 | <Table.Row.Base {root}>
|
173 | 174 | <CreditCardInfo {root} isBackup paymentMethod={backupPaymentMethod} />
|
174 | 175 | <Table.Cell column="actions" {root}>
|
|
209 | 210 | </Table.Row.Base>
|
210 | 211 | {/if}
|
211 | 212 | </Table.Root>
|
212 |
| - {#if !$organization?.backupPaymentMethodId} |
| 213 | + {#if !organization?.backupPaymentMethodId} |
213 | 214 | {@const filteredPaymentMethods = methods.paymentMethods.filter(
|
214 |
| - (o) => !!o.last4 && o.$id !== $organization?.paymentMethodId |
| 215 | + (o) => !!o.last4 && o.$id !== organization?.paymentMethodId |
215 | 216 | )}
|
216 | 217 | <div>
|
217 | 218 | <Popover let:toggle placement="bottom-start" padding="none">
|
|
264 | 265 | {/if}
|
265 | 266 | {:else}
|
266 | 267 | {@const filteredPaymentMethods = methods.paymentMethods.filter(
|
267 |
| - (o) => !!o.last4 && o.$id !== $organization?.backupPaymentMethodId |
| 268 | + (o) => !!o.last4 && o.$id !== organization?.backupPaymentMethodId |
268 | 269 | )}
|
269 | 270 | <Card.Base>
|
270 | 271 | <Layout.Stack justifyContent="center" alignItems="center" gap="m">
|
|
319 | 320 | bind:show={showEdit} />
|
320 | 321 | {/if}
|
321 | 322 | {#if isCloud && hasStripePublicKey}
|
322 |
| - <ReplaceCard {methods} bind:show={showReplace} isBackup={isSelectedBackup} /> |
| 323 | + <ReplaceCard {organization} {methods} bind:show={showReplace} isBackup={isSelectedBackup} /> |
323 | 324 | {/if}
|
324 | 325 | {#if showDelete && isCloud && hasStripePublicKey}
|
325 | 326 | {@const hasOtherMethod = isSelectedBackup
|
326 |
| - ? !!$organization?.paymentMethodId |
327 |
| - : !!$organization?.backupPaymentMethodId} |
| 327 | + ? !!organization?.paymentMethodId |
| 328 | + : !!organization?.backupPaymentMethodId} |
328 | 329 | <DeleteOrgPayment
|
329 | 330 | bind:showDelete
|
330 | 331 | {hasOtherMethod}
|
331 | 332 | isBackup={isSelectedBackup}
|
332 |
| - disabled={$organization?.billingPlan !== BillingPlan.FREE && !hasOtherMethod} /> |
| 333 | + disabled={organization?.billingPlan !== BillingPlan.FREE && !hasOtherMethod} /> |
333 | 334 | {/if}
|
0 commit comments