|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BASE_URL="${BASE_URL:-http://localhost:3000}" |
|
|
EMAIL="${TEST_EMAIL:-test@example.com}" |
|
|
PASSWORD="${TEST_PASSWORD:-testpass123}" |
|
|
|
|
|
echo "π§ͺ Testing Paystack API Endpoints" |
|
|
echo "==================================" |
|
|
echo "" |
|
|
|
|
|
|
|
|
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 "" |
|
|
|
|
|
|
|
|
echo "2οΈβ£ Checking wallet balance..." |
|
|
WALLET_RESPONSE=$(curl -s -X GET "$BASE_URL/api/wallet" \ |
|
|
-H "Authorization: Bearer $TOKEN") |
|
|
|
|
|
echo " Response: $WALLET_RESPONSE" |
|
|
echo "" |
|
|
|
|
|
|
|
|
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 "" |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|