Skip to content

Commit

Permalink
improve payg budget limit message
Browse files Browse the repository at this point in the history
  • Loading branch information
williamstein committed Dec 10, 2024
1 parent dee6f46 commit 199fbba
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/packages/frontend/purchases/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {
} from "@cocalc/util/stripe/types";
import throttle from "@cocalc/util/api/throttle";
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
import { QUOTA_SPEC } from "@cocalc/util/db-schema/purchase-quotas";

async function api(endpoint: string, args?: object) {
throttle({ endpoint });
Expand Down Expand Up @@ -129,11 +130,22 @@ export async function isPurchaseAllowed(
if (result.allowed && result.discouraged) {
if (Date.now() - lastPurchaseAlert >= 3000) {
lastPurchaseAlert = Date.now();
const display = QUOTA_SPEC[service]?.display ?? service;
try {
// fire off a warning to the user so they know they are hitting a budget.
await send({
subject: "Pay as You Go Budget Alert",
body: `You recently made a purchase. ${result.reason} \n\n [View and edit your Pay As You Go budgets](/settings/payg) or [browse all your purchases](/settings/purchases).`,
subject: `Budget Alert: ${display}`,
body: `You recently made a purchase of ${display}.
${result.reason}
<br/>
- [Pay As You Go Budgets](/settings/payg) -- raise your ${display} budget to stop these messages.
- [All Purchases](/settings/purchases)
`,
});
} catch (err) {
console.warn(err);
Expand Down

0 comments on commit 199fbba

Please sign in to comment.