From 9e621042db85ec64f237b8e231696caa07695cae Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 29 Oct 2025 22:07:06 +0100 Subject: [PATCH] Add WREN_DRY_RUN environment variable for safe testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent accidental creation of real carbon offsets during development: - Add WREN_DRY_RUN environment variable (default: true for dev) - Update webhook fulfillment to use env variable instead of hardcoded value - Log warning when in dry run mode for visibility - Production deployments should set WREN_DRY_RUN=false This allows safe testing with Stripe test cards without creating real Wren offset orders. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- server/.env.example | 2 ++ server/routes/webhooks.js | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/.env.example b/server/.env.example index a649a0b..4281f55 100644 --- a/server/.env.example +++ b/server/.env.example @@ -4,6 +4,8 @@ STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here # Wren Climate API WREN_API_TOKEN=35c025d9-5dbb-404b-85aa-19b09da0578d +# Set to 'true' for testing (no real offsets created), 'false' for production +WREN_DRY_RUN=true # Server Configuration PORT=3001 diff --git a/server/routes/webhooks.js b/server/routes/webhooks.js index f33091b..639901f 100644 --- a/server/routes/webhooks.js +++ b/server/routes/webhooks.js @@ -144,6 +144,13 @@ async function fulfillOrder(order, session) { try { console.log(`🌱 Fulfilling order ${order.id} via Wren API...`); + // Determine if we should use dry run mode based on environment + const isDryRun = process.env.WREN_DRY_RUN === 'true'; + + if (isDryRun) { + console.log('⚠️ DRY RUN MODE: No real offset will be created'); + } + // Create Wren offset order const wrenOrder = await createWrenOffsetOrder({ tons: order.tons, @@ -151,7 +158,7 @@ async function fulfillOrder(order, session) { customerEmail: session.customer_details?.email || order.customer_email, currency: order.currency, amountCents: order.total_amount, - dryRun: false, // Set to true for testing without creating real offsets + dryRun: isDryRun, }); // Update order with Wren order ID