|
33 | 33 | import { onMount } from 'svelte';
|
34 | 34 | import { loadAvailableRegions } from '$routes/(console)/regions';
|
35 | 35 | import EstimatedTotalBox from '$lib/components/billing/estimatedTotalBox.svelte';
|
| 36 | + import { Query } from '@appwrite.io/console'; |
36 | 37 |
|
37 | 38 | export let data;
|
38 | 39 |
|
|
105 | 106 | }
|
106 | 107 | }
|
107 | 108 |
|
| 109 | + async function trackDowngradeFeedback() { |
| 110 | + const paidInvoices = await sdk.forConsole.billing.listInvoices(data.organization.$id, [ |
| 111 | + Query.equal('status', 'succeeded'), |
| 112 | + Query.greaterThan('grossAmount', 0) |
| 113 | + ]); |
| 114 | +
|
| 115 | + await fetch(`${VARS.GROWTH_ENDPOINT}/feedback/billing`, { |
| 116 | + method: 'POST', |
| 117 | + headers: { |
| 118 | + 'Content-Type': 'application/json' |
| 119 | + }, |
| 120 | + body: JSON.stringify({ |
| 121 | + from: tierToPlan(data.organization.billingPlan).name, |
| 122 | + to: tierToPlan(selectedPlan).name, |
| 123 | + email: data.account.email, |
| 124 | + reason: feedbackDowngradeOptions.find( |
| 125 | + (option) => option.value === feedbackDowngradeReason |
| 126 | + )?.label, |
| 127 | + orgId: data.organization.$id, |
| 128 | + userId: data.account.$id, |
| 129 | + orgAge: data.organization.$createdAt, |
| 130 | + userAge: data.account.$createdAt, |
| 131 | + paidInvoices: paidInvoices.total, |
| 132 | + message: feedbackMessage ?? '' |
| 133 | + }) |
| 134 | + }); |
| 135 | + } |
| 136 | +
|
108 | 137 | async function downgrade() {
|
109 | 138 | try {
|
110 | 139 | await sdk.forConsole.billing.updatePlan(
|
|
114 | 143 | null
|
115 | 144 | );
|
116 | 145 |
|
117 |
| - await fetch(`${VARS.GROWTH_ENDPOINT}/feedback/billing`, { |
118 |
| - method: 'POST', |
119 |
| - headers: { |
120 |
| - 'Content-Type': 'application/json' |
121 |
| - }, |
122 |
| - body: JSON.stringify({ |
123 |
| - from: tierToPlan(data.organization.billingPlan).name, |
124 |
| - to: tierToPlan(selectedPlan).name, |
125 |
| - email: data.account.email, |
126 |
| - reason: feedbackDowngradeOptions.find( |
127 |
| - (option) => option.value === feedbackDowngradeReason |
128 |
| - )?.label, |
129 |
| - orgId: data.organization.$id, |
130 |
| - userId: data.account.$id, |
131 |
| - message: feedbackMessage ?? '' |
132 |
| - }) |
133 |
| - }); |
| 146 | + trackDowngradeFeedback(); |
134 | 147 |
|
135 | 148 | await invalidate(Dependencies.ORGANIZATION);
|
136 | 149 |
|
|
0 commit comments