#!/bin/bash # Paystack API End-to-End Test Script # Make sure the server is running: npm run dev BASE_URL="${BASE_URL:-http://localhost:3000}" EMAIL="${TEST_EMAIL:-test@example.com}" PASSWORD="${TEST_PASSWORD:-testpass123}" echo "🧪 Testing Paystack API Endpoints" echo "==================================" echo "" # Step 1: Register/Login user to get token echo "1️⃣ Registering test user..." REGISTER_RESPONSE=$(curl -s -X POST "$BASE_URL/api/auth/register" \ -H "Content-Type: application/json" \ -d "{ \"email\": \"$EMAIL\", \"password\": \"$PASSWORD\", \"name\": \"Test User\" }") TOKEN=$(echo $REGISTER_RESPONSE | grep -o '"token":"[^"]*' | cut -d'"' -f4) if [ -z "$TOKEN" ]; then echo " ⚠️ User might already exist, trying login..." LOGIN_RESPONSE=$(curl -s -X POST "$BASE_URL/api/auth/login" \ -H "Content-Type: application/json" \ -d "{ \"email\": \"$EMAIL\", \"password\": \"$PASSWORD\" }") TOKEN=$(echo $LOGIN_RESPONSE | grep -o '"token":"[^"]*' | cut -d'"' -f4) fi if [ -z "$TOKEN" ]; then echo " ❌ Failed to get auth token" exit 1 fi echo " ✅ Got auth token" echo "" # Step 2: Check wallet balance echo "2️⃣ Checking wallet balance..." WALLET_RESPONSE=$(curl -s -X GET "$BASE_URL/api/wallet" \ -H "Authorization: Bearer $TOKEN") echo " Response: $WALLET_RESPONSE" echo "" # Step 3: Initialize payment echo "3️⃣ Initializing payment (1000 NGN)..." FUND_RESPONSE=$(curl -s -X POST "$BASE_URL/api/wallet/fund" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "amount": 1000 }') echo " Response:" echo "$FUND_RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$FUND_RESPONSE" echo "" # Extract reference and authorization URL REFERENCE=$(echo $FUND_RESPONSE | grep -o '"reference":"[^"]*' | cut -d'"' -f4) AUTH_URL=$(echo $FUND_RESPONSE | grep -o '"authorization_url":"[^"]*' | cut -d'"' -f4) if [ -n "$REFERENCE" ]; then echo " ✅ Payment initialized" echo " Reference: $REFERENCE" echo " Authorization URL: $AUTH_URL" echo "" echo " 📝 Next steps:" echo " 1. Open the authorization URL in your browser" echo " 2. Complete payment with test card: 4084084084084081" echo " 3. After payment, run: curl -X GET \"$BASE_URL/api/wallet/verify/$REFERENCE\" -H \"Authorization: Bearer $TOKEN\"" echo "" else echo " ❌ Failed to initialize payment" exit 1 fi