Skip to content

Commit d021337

Browse files
committed
handle undefined keys
1 parent cf9dbc3 commit d021337

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

svc/api/keyManagement.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ keys.post("/checkout", async (req, res, next) => {
170170
return res.status(400).json({ error: "Failed validation" });
171171
}
172172
}
173-
// Returning customer: reuse the existing Stripe customer, block on unpaid invoices
174-
let customerId = allKeyRecords?.[0].customer_id;
173+
// Check if we already have a customer ID (using account_id to look up from keys)
174+
// If so, reuse the existing ID and block on unpaid invoices
175+
let customerId = allKeyRecords?.[0]?.customer_id;
175176
if (customerId) {
176177
const invoices = await getOpenInvoices(customerId);
177178
if (invoices.length > 0) {
@@ -186,7 +187,7 @@ keys.post("/checkout", async (req, res, next) => {
186187
}
187188
const session = await stripe.checkout.sessions.create({
188189
mode: "subscription",
189-
customer: customerId,
190+
customer: customerId ?? "",
190191
client_reference_id: String(req.user?.account_id ?? ""),
191192
line_items: [
192193
{

0 commit comments

Comments
 (0)