Skip to content

Commit

Permalink
api/stripe: Use logger instead of console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Jun 11, 2024
1 parent 243a58e commit 3fa27e6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/api/src/controllers/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Router } from "express";
import sql from "sql-template-strings";
import Stripe from "stripe";
import { products } from "../config";
import logger from "../logger";
import { authorizer } from "../middleware";
import { CliArgs } from "../parse-cli";
import { User } from "../schema/types";
Expand Down Expand Up @@ -46,7 +47,7 @@ export const reportUsage = async (
);
updatedUsers.push(userUpdated);
} catch (e) {
console.log(
logger.error(
`Failed to create usage record for user=${user.id} with error=${e.message}`
);
updatedUsers.push({
Expand Down Expand Up @@ -149,7 +150,7 @@ async function reportUsageForUser(
},
{} as Record<string, string>
);
console.log(`
logger.info(`
usage: reporting usage to stripe for user=${user.id} email=${user.email} from=${billingCycleStart} to=${billingCycleEnd}
`);
await sendUsageRecordToStripe(
Expand Down Expand Up @@ -294,7 +295,7 @@ app.post("/webhook", async (req, res) => {

const user = users[0];

console.log(`
logger.info(`
invoice=${invoice.id} payment failed for user=${user.id} notifying support team
`);

Expand All @@ -307,7 +308,7 @@ app.post("/webhook", async (req, res) => {
let diff = now - lastNotification;
let days = diff / (1000 * 60 * 60 * 24);
if (days < 7) {
console.log(`
logger.warn(`
Not sending email for payment failure of user=${user.id} because team was notified less than 7 days ago
`);
return res.sendStatus(200);
Expand Down Expand Up @@ -385,7 +386,7 @@ app.post("/webhook", async (req, res) => {
}
}
} catch (e) {
console.log(`
logger.error(`
Failed to send email for payment failure of user=${user.id} with error=${e.message}
`);
}
Expand Down Expand Up @@ -491,7 +492,7 @@ app.post(
user.stripeCustomerSubscriptionId
);
} catch (e) {
console.log(`
logger.error(`
error- subscription not found for user=${user.id} email=${user.email} subscriptionId=${user.stripeCustomerSubscriptionId}
`);
await db.user.update(user.id, {
Expand Down

0 comments on commit 3fa27e6

Please sign in to comment.