File size: 2,458 Bytes
4a285d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #!/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
|