Skip to content

Commit

Permalink
include cost info in subscription cancelation message
Browse files Browse the repository at this point in the history
  • Loading branch information
williamstein committed Dec 14, 2024
1 parent e824674 commit 73d843c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/packages/server/purchases/cancel-subscription.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import getPool, { PoolClient } from "@cocalc/database/pool";
import send, { support, url, name } from "@cocalc/server/messages/send";
import adminAlert from "@cocalc/server/messages/admin-alert";
import { currency } from "@cocalc/util/misc";

interface Options {
account_id: string;
Expand Down Expand Up @@ -34,17 +35,18 @@ export async function sendCancelNotification({
}) {
const pool = client ?? getPool();
const { rows } = await pool.query(
"SELECT account_id, canceled_reason FROM subscriptions where id=$1",
"SELECT account_id, canceled_reason, cost, interval FROM subscriptions where id=$1",
[subscription_id],
);
if (rows.length == 0) {
return;
}
const { account_id, canceled_reason } = rows[0];
const { account_id, canceled_reason, cost, interval } = rows[0];

const subject = `Subscription Id=${subscription_id} Canceled`;
const body = `
This is a confirmation that your subscription (id=${subscription_id}) was canceled.
This is a confirmation that your subscription (id=${subscription_id}) that
costs ${currency(cost)}/${interval} was canceled.
**REASON:** ${JSON.stringify(canceled_reason)}
Expand All @@ -60,12 +62,14 @@ ${await support()}
});

adminAlert({
subject: `Alert -- User Subscription Id=${subscription_id} was Canceled`,
subject: `Alert -- User Subscription for ${currency(cost)}/${interval} Id=${subscription_id} was Canceled`,
body: `
- User: ${await name(account_id)}, account_id=${account_id}
- User provided reason: "${JSON.stringify(canceled_reason)}"
- Cost: ${currency(cost)}/${interval}
- subscription_id=${subscription_id}
`,
Expand Down

0 comments on commit 73d843c

Please sign in to comment.