Skip to content

Commit 69a4e4f

Browse files
committed
move validation to apiadmin
1 parent a813911 commit 69a4e4f

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

routes/keyManagement.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,6 @@ keys
245245
return res.status(402).json(err);
246246
}
247247
}
248-
// Validate the payment source
249-
const card = await stripe.sources.retrieve(token.id);
250-
const BANNED_CARDS: string[] = [];
251-
if (BANNED_CARDS.includes(card.card?.fingerprint ?? '')) {
252-
return res.status(402).json({ error: 'This card is not allowed' });
253-
}
254248

255249
const apiKey = uuid.v4();
256250
const sub = await stripe.subscriptions.create({

svc/apiadmin.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ async function updateStripeUsage(cb: ErrorCb) {
107107
);
108108
continue;
109109
}
110+
// Deactivate any keys belonging to an invalid card
111+
const BANNED_CARDS: string[] = [];
112+
const sourceId = sub.default_source;
113+
if (sourceId) {
114+
const source = await stripe.sources.retrieve(sourceId as string);
115+
if (source.card?.fingerprint && BANNED_CARDS.includes(source.card?.fingerprint)) {
116+
await db.raw(
117+
`UPDATE api_keys SET is_canceled = true WHERE subscription_id = ?`,
118+
[sub.id]
119+
);
120+
}
121+
}
110122
const startTime = moment
111123
.unix(sub.current_period_end - 1)
112124
.startOf('month');

0 commit comments

Comments
 (0)