Skip to content

Commit b69648a

Browse files
authored
Merge pull request #2041 from appwrite/update-billing-feedback
2 parents 0531bd8 + 2e55b3c commit b69648a

File tree

1 file changed

+30
-17
lines changed
  • src/routes/(console)/organization-[organization]/change-plan

1 file changed

+30
-17
lines changed

src/routes/(console)/organization-[organization]/change-plan/+page.svelte

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import { onMount } from 'svelte';
3434
import { loadAvailableRegions } from '$routes/(console)/regions';
3535
import EstimatedTotalBox from '$lib/components/billing/estimatedTotalBox.svelte';
36+
import { Query } from '@appwrite.io/console';
3637
3738
export let data;
3839
@@ -105,6 +106,34 @@
105106
}
106107
}
107108
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+
108137
async function downgrade() {
109138
try {
110139
await sdk.forConsole.billing.updatePlan(
@@ -114,23 +143,7 @@
114143
null
115144
);
116145
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();
134147
135148
await invalidate(Dependencies.ORGANIZATION);
136149

0 commit comments

Comments
 (0)