Skip to content

Commit

Permalink
Merge pull request #5572 from mozilla/MNTOR-3897-1
Browse files Browse the repository at this point in the history
MNTOR-3897: reactivate as a part of renew coupon code
  • Loading branch information
mansaj authored Jan 30, 2025
2 parents 2aa0394 + 36eaf0a commit e3e6fc8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getSubscriberByFxaUid } from "../../../../../../db/tables/subscribers";
import { applyChurnCouponCode } from "../../../../../functions/server/applyCoupon";
import { getServerSession } from "../../../../../functions/server/getServerSession";
import { logger } from "../../../../../functions/server/logging";

import { reactivateAccount } from "../../../../../functions/server/reactivateAccount";
export type ApplyRenewalCouponResult =
| {
success: false;
Expand Down Expand Up @@ -39,6 +39,7 @@ export async function applyRenewalCoupon(): Promise<ApplyRenewalCouponResult> {
}
try {
await applyChurnCouponCode(subscriber);
await reactivateAccount(subscriber);
return { success: true };
} catch (e) {
logger.error("apply_renewal_coupon_error", { error: e });
Expand Down
43 changes: 43 additions & 0 deletions src/app/functions/server/reactivateAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { SubscriberRow } from "knex/types/tables";
import { logger } from "./logging";
import { reactivate } from "../../../utils/fxa";
import { record } from "./glean";

export async function reactivateAccount(subscriber: SubscriberRow) {
logger.info("fxa_reactivate_user", {
subscriber: subscriber.id,
});

record("account", "reactivate", {
string: {
monitorUserId: subscriber.id.toString(),
},
});

// try to reactivate from subplat
if (subscriber.fxa_access_token) {
try {
await reactivate(subscriber.fxa_access_token);
logger.info("reactivate_from_subplat", {
subscriber_id: subscriber.id,
success: true,
});
} catch (ex) {
logger.error("reactivate_from_subplat", {
subscriber_id: subscriber.id,
exception: ex,
});
throw ex;
}
} else {
logger.error("reactivate_from_subplat_no_bearer_token", {
subscriber_id: subscriber.id,
exception: "Subscriber does not have permission or missing token",
});
throw new Error("Subscriber does not have permission or missing token");
}
}
5 changes: 4 additions & 1 deletion src/utils/fxa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,10 @@ async function applyCoupon(
}
} catch (e) {
if (e instanceof Error) {
logger.error("apply_fxa_coupon", { stack: e.stack, message: e.message });
logger.error(
"apply_fxa_coupon",
JSON.stringify({ stack: e.stack, message: e.message }),
);
}
throw e;
}
Expand Down

0 comments on commit e3e6fc8

Please sign in to comment.