Skip to content

Commit 20c2a99

Browse files
committed
pass in logger to revokeGrantByOperationId
1 parent 5e0a028 commit 20c2a99

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

packages/billing/src/grant-credits.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import db from '@codebuff/common/db'
55
import * as schema from '@codebuff/common/db/schema'
66
import { DEFAULT_FREE_CREDITS_GRANT } from '@codebuff/common/old-constants'
77
import { getNextQuotaReset } from '@codebuff/common/util/dates'
8-
import { logger } from '@codebuff/common/util/logger'
98
import { withRetry } from '@codebuff/common/util/promise'
109
import { logSyncFailure } from '@codebuff/common/util/sync-failure'
1110
import { and, desc, eq, gt, isNull, lte, or, sql } from 'drizzle-orm'
@@ -292,10 +291,13 @@ export async function processAndGrantCredit(params: {
292291
* @param reason The reason for revoking the credits (e.g. refund)
293292
* @returns true if the grant was found and revoked, false otherwise
294293
*/
295-
export async function revokeGrantByOperationId(
296-
operationId: string,
297-
reason: string,
298-
): Promise<boolean> {
294+
export async function revokeGrantByOperationId(params: {
295+
operationId: string
296+
reason: string
297+
logger: Logger
298+
}): Promise<boolean> {
299+
const { operationId, reason, logger } = params
300+
299301
return await db.transaction(async (tx) => {
300302
const grant = await tx.query.creditLedger.findFirst({
301303
where: eq(schema.creditLedger.operation_id, operationId),

web/src/app/api/stripe/webhook/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,11 @@ const webhookHandler = async (req: NextRequest): Promise<NextResponse> => {
375375
'Processing refund, attempting to revoke credits'
376376
)
377377

378-
const revoked = await revokeGrantByOperationId(
378+
const revoked = await revokeGrantByOperationId({
379379
operationId,
380-
`Refund for charge ${charge.id}`
381-
)
380+
reason: `Refund for charge ${charge.id}`,
381+
logger,
382+
})
382383

383384
if (!revoked) {
384385
logger.error(

0 commit comments

Comments
 (0)