Skip to content

Commit

Permalink
Allow renewing after receiving an expiration email
Browse files Browse the repository at this point in the history
We email people that their subscription is about to expire, then
mark them as having received the email. We check whether we have
marked someone as having received the email when collecting the
list of subscribers to email, which means that we shouldn't use
that list when determining whether someone can renew.

I've updated it to use a similar check, but to skip the check for
`churn_prevention_email_sent_at`.
  • Loading branch information
Vinnl committed Feb 4, 2025
1 parent 5329df8 commit 0a13f8e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { logger } from "../../../../../functions/server/logging";
import { checkChurnCouponCode } from "../../../../../functions/server/applyCoupon";
import { applyRenewalCoupon } from "./actions";
import { getEnabledFeatureFlags } from "../../../../../../db/tables/featureFlags";
import { getChurnsToEmail } from "../../../../../../db/tables/subscriber_churns";
import { getUpcomingChurns } from "../../../../../../db/tables/subscriber_churns";

export default async function PlusExpirationPage() {
const session = await getServerSession();
Expand Down Expand Up @@ -41,7 +41,7 @@ export default async function PlusExpirationPage() {
}

const couponCheckResult = await checkChurnCouponCode(subscriber);
const subscribersToEmail = await getChurnsToEmail();
const expiringSubscriptions = await getUpcomingChurns();

return (
<View
Expand All @@ -50,9 +50,9 @@ export default async function PlusExpirationPage() {
applyCouponAction={applyRenewalCoupon}
manageSubscriptionsUrl={process.env.FXA_SUBSCRIPTIONS_URL!}
isOnExpirationList={
typeof subscribersToEmail.find(
(subscriberToEmail) =>
subscriberToEmail.userid === subscriber.fxa_uid,
typeof expiringSubscriptions.find(
(expiringSubscription) =>
expiringSubscription.userid === subscriber.fxa_uid,
) !== "undefined"
}
/>
Expand Down
24 changes: 24 additions & 0 deletions src/db/tables/subscriber_churns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ async function getAllSubscriberChurns(): Promise<SubscriberChurnRow[]> {
}
}

async function getUpcomingChurns(): Promise<Array<SubscriberChurnRow>> {
try {
const res = await knex("subscriber_churns")
.select("*")
.where("intervl", "year")
.whereNotNull("current_period_end")
.where(knex.raw("current_period_end::timestamptz"), ">=", knex.fn.now())
.where(
knex.raw("current_period_end::timestamptz"),
"<=",
knex.raw("CURRENT_TIMESTAMP + interval '7 days'"),
);

logger.info("get_upcoming_churns_success", { count: res.length });
return res;
} catch (e) {
logger.error("get_upcoming_churns_error", {
error: JSON.stringify(e),
});
throw e;
}
}

async function getChurnsToEmail(): Promise<
Array<SubscriberChurnRow & SubscriberRow>
> {
Expand Down Expand Up @@ -92,5 +115,6 @@ export {
upsertSubscriberChurns,
getAllSubscriberChurns,
deleteSubscriberChurns,
getUpcomingChurns,
getChurnsToEmail,
};

0 comments on commit 0a13f8e

Please sign in to comment.