/** * Test script to verify PAN API is working correctly * Usage: node scripts/test-pan-api.js */ require('dotenv').config(); const axios = require('axios'); async function testPanAPI() { console.log('\n🧪 Testing PAN API Configuration...\n'); console.log('=' .repeat(60)); // Check environment variables console.log('\n1. Checking Environment Variables:'); const requiredVars = { 'PAN_PROVIDER_URL': process.env.PAN_PROVIDER_URL, 'PAN_CLIENT_ID': process.env.PAN_CLIENT_ID, 'PAN_CLIENT_SECRET': process.env.PAN_CLIENT_SECRET, 'PAN_PRODUCT_INSTANCE_ID': process.env.PAN_PRODUCT_INSTANCE_ID }; let allSet = true; for (const [key, value] of Object.entries(requiredVars)) { if (value) { const masked = key === 'PAN_CLIENT_SECRET' && value.length > 10 ? value.substring(0, 4) + '***' + value.substring(value.length - 4) : value; console.log(` ✅ ${key}: ${masked}`); } else { console.log(` ❌ ${key}: NOT SET`); allSet = false; } } if (!allSet) { console.log('\n❌ Missing environment variables! Please check your .env file.\n'); process.exit(1); } // Test Setu API directly console.log('\n2. Testing Setu API Directly:'); try { const setuResponse = await axios.post( process.env.PAN_PROVIDER_URL, { pan: 'ABCDE1234A', consent: 'Y', reason: 'Testing PAN verification' }, { headers: { 'Content-Type': 'application/json', 'x-client-id': process.env.PAN_CLIENT_ID, 'x-client-secret': process.env.PAN_CLIENT_SECRET, 'x-product-instance-id': process.env.PAN_PRODUCT_INSTANCE_ID }, timeout: 30000 } ); if (setuResponse.status === 200 && setuResponse.data) { console.log(' ✅ Setu API is working!'); console.log(` Response: ${setuResponse.data.message || 'Success'}`); } else { console.log(' ⚠️ Setu API returned unexpected response'); console.log(` Status: ${setuResponse.status}`); } } catch (error) { console.log(' ❌ Setu API test failed!'); if (error.response) { console.log(` Status: ${error.response.status}`); console.log(` Error: ${error.response.data?.message || error.response.data?.error || 'Unknown error'}`); } else { console.log(` Error: ${error.message}`); } console.log('\n⚠️ Your Setu credentials may be incorrect or the API is down.\n'); process.exit(1); } // Test local API (if server is running) console.log('\n3. Testing Local API (make sure server is running on port 3000):'); try { // First, get a test API key console.log(' ℹ️ You need an API key to test the local endpoint.'); console.log(' Run: npm run create-test-key'); console.log(' Then test with:'); console.log(' curl -X POST http://localhost:3000/v1/pan/verify \\'); console.log(' -H "Content-Type: application/json" \\'); console.log(' -H "x-api-key: YOUR_API_KEY" \\'); console.log(' -d \'{"pan": "ABCDE1234A", "reason": "Testing"}\''); } catch (error) { console.log(' ⚠️ Could not test local API:', error.message); } console.log('\n' + '=' .repeat(60)); console.log('\n✅ Configuration check complete!\n'); } testPanAPI().catch(error => { console.error('\n❌ Test failed:', error.message); process.exit(1); });