From 0177707921c5c8d2d18473192a82bc2db86e9f0d Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 30 Oct 2025 12:54:45 +0100 Subject: [PATCH] Fix portfolio ID validation to accept Wren API portfolio IDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed backend validation from hardcoded [1, 2, 3] to accept any positive integer portfolio ID. The Wren API returns portfolios with their real IDs (not limited to 1-3), so the backend needs to accept dynamic portfolio IDs. - Changed validation to check for positive integers instead of [1, 2, 3] - Added logging to show which portfolio ID is being processed - Pricing calculation already has fallback to $18/ton for unknown IDs This fixes the "Invalid portfolio ID" error when trying to checkout. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- server/routes/checkout.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/routes/checkout.js b/server/routes/checkout.js index 28270f9..240ce75 100644 --- a/server/routes/checkout.js +++ b/server/routes/checkout.js @@ -47,10 +47,14 @@ router.post('/create-session', async (req, res) => { return res.status(400).json({ error: 'Invalid tons value' }); } - if (!portfolioId || ![1, 2, 3].includes(portfolioId)) { + // Accept any valid positive integer portfolio ID (from Wren API) + if (!portfolioId || !Number.isInteger(portfolioId) || portfolioId <= 0) { + console.error('❌ Invalid portfolio ID received:', portfolioId); return res.status(400).json({ error: 'Invalid portfolio ID' }); } + console.log(`📦 Creating checkout for portfolio ID: ${portfolioId}, tons: ${tons}`); + // Calculate pricing const { baseAmount, processingFee, totalAmount, pricePerTon } = calculatePricing(tons, portfolioId);