Skip to content

Commit

Permalink
automatic payments: improve messaging and alerting a little
Browse files Browse the repository at this point in the history
  • Loading branch information
williamstein committed Dec 10, 2024
1 parent f67cc5a commit ad1ad86
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/packages/frontend/i18n/trans/extracted.json
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@
"defaultMessage": "Search for projects (use /re/ for regexp)..."
},
"purchases.automatic-payments-warning.description": {
"defaultMessage": "Automatic payments are much <b>more convenient</b>, will <b>save you time</b>, and <b>ensure subscriptions don't get cancelled</b> by accident."
"defaultMessage": "Automatic payments are much <b>more convenient</b>, will <b>save you time</b>, and <b>ensure subscriptions don't get canceled</b> by accident."
},
"purchases.automatic-payments-warning.title": {
"defaultMessage": "Automatic payments are NOT required to have a subscription"
Expand Down
7 changes: 6 additions & 1 deletion src/packages/frontend/purchases/balance-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export default function BalanceButton({
<Button
size={minimal ? "small" : undefined}
type={"text"}
style={style}
style={{
...style,
...(balanceAlert
? { backgroundColor: "red", color: "white", marginRight: "5px" }
: undefined),
}}
onClick={() => {
handleRefresh();
setOpen(!open);
Expand Down
2 changes: 1 addition & 1 deletion src/packages/frontend/purchases/balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default function Balance({
completed yet and are not included in your balance.
Ensure you have automatic payments configured or add
credit to your account so that your subscriptions will
not be cancelled.
not be canceled.
</div>
}
>
Expand Down
12 changes: 9 additions & 3 deletions src/packages/frontend/purchases/payments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default function Payments({
{!!unfinished && (data?.length ?? 0) > 0 && (
<Badge
count={data?.length}
style={{ backgroundColor: "#688ff1", marginLeft: "15px" }}
style={{ backgroundColor: "red", marginLeft: "15px" }}
/>
)}
</Tooltip>
Expand Down Expand Up @@ -230,8 +230,14 @@ function PaymentIntentsTable({ paymentIntents, onFinished, account_id }) {
name="credit-card"
style={{ color: "#688ff1", marginRight: "5px" }}
/>
<Tag color="#688ff1" style={{ whiteSpace: "normal" }}>
Fill in details
<Tag
style={{
backgroundColor: "red",
color: "white",
whiteSpace: "normal",
}}
>
Fill in Details
</Tag>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default function StripeMeteredSubscription({ style }: Props) {
<FormattedMessage
id="purchases.automatic-payments-warning.description"
defaultMessage={
"Automatic payments are much <b>more convenient</b>, will <b>save you time</b>, and <b>ensure subscriptions don't get cancelled</b> by accident."
"Automatic payments are much <b>more convenient</b>, will <b>save you time</b>, and <b>ensure subscriptions don't get canceled</b> by accident."
}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion src/packages/next/components/store/usage-and-duration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function UsageAndDuration(props: Props) {
specific dates. Once you purchase a license,{" "}
<b>you can always edit it later, or cancel it for a prorated refund</b>{" "}
as credit that you can use to purchase something else. Subscriptions
will be cancelled at the end of the paid for period.{" "}
will be canceled at the end of the paid for period.{" "}
{duration == "range" && (
<i>
Licenses start and end at the indicated times in your local
Expand Down
2 changes: 1 addition & 1 deletion src/packages/server/purchases/maintain-subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PAYMENT FOLLOW-UP:
- In particular, if a user doesn't pay their monthly subscription for 90 days (say),
then their license would have not worked during the last 90 days and we didn't
try to charge them during the second two periods, and moreover their payment
got cancelled/expired. They can start their canceled subscription, paying for a
got canceled/expired. They can start their canceled subscription, paying for a
full subscription period at this point, and the billing day for this subscription
changes to the day when they resume the subscription.
Expand Down
4 changes: 2 additions & 2 deletions src/packages/server/purchases/resume-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Thank you!
${await support()}`,
});
adminAlert({
subject: `User manually resumed cancelled subscription ${subscription_id}`,
subject: `User manually resumed canceled subscription ${subscription_id}`,
body: `
**Good news** - The user ${await name(account_id)} with account_id=${account_id}
has manually resumed their canceled subscription id=${subscription_id}.
Expand Down Expand Up @@ -114,7 +114,7 @@ An unexpected error happened when manually resuming your subscription with id=${
${await support()}`,
});
adminAlert({
subject: `Unexpected error when user manually resumed cancelled subscription ${subscription_id}`,
subject: `Unexpected error when user manually resumed canceled subscription ${subscription_id}`,
body: `
PROBLEM: The user ${await name(account_id)} with account_id=${account_id} tried to manually resume
their canceled subscription id=${subscription_id}, but there was an unexpected
Expand Down
6 changes: 4 additions & 2 deletions src/packages/server/purchases/stripe/get-payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ export default async function getPayments({
(intent) => !intent.metadata?.deleted,
);

const numOpen = paymentIntents.data.filter(isOpenPaymentIntent).length;
await setBalanceAlert({ account_id, balance_alert: numOpen > 0 });
if (!(created || ending_before || starting_after)) {
const numOpen = paymentIntents.data.filter(isOpenPaymentIntent).length;
await setBalanceAlert({ account_id, balance_alert: numOpen > 0 });
}

// if any payments haven't been processed, i.e., credit added to cocalc, do that here:
await processPaymentIntents({ paymentIntents: paymentIntents.data });
Expand Down
11 changes: 8 additions & 3 deletions src/packages/server/purchases/stripe/process-payment-intents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
processSubscriptionRenewal,
processSubscriptionRenewalFailure,
} from "./create-subscription-payment";
import send, { support, url } from "@cocalc/server/messages/send";
import send, { support, url, name } from "@cocalc/server/messages/send";
import adminAlert from "@cocalc/server/messages/admin-alert";
import { currency, round2down } from "@cocalc/util/misc";
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
Expand Down Expand Up @@ -216,11 +216,16 @@ customer. So we don't know what to do with this. Please manually investigate.
${await support()}`,
});
const n = await name(account_id);
adminAlert({
subject: `A User's Payment (paymentIntent = ${paymentIntent.id}) was canceled`,
subject: `User's Payment (paymentIntent = ${paymentIntent.id}) was canceled`,
body: `
The user with account_id=${account_id} had a canceled payment intent. We told them
The user with had a canceled payment intent. We told them
the consequence is "${result}". Admins might want to investigate.
- User: ${n}, account_id=${account_id}
`,
});
} catch (err) {
Expand Down

0 comments on commit ad1ad86

Please sign in to comment.