Download test-paystack-api.sh from nexusbert/zurri: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/spaces/nexusbert/zurri/resolve/main/test-paystack-api.sh
- Command line
-
hf download hf://spaces/nexusbert/zurri/test-paystack-api.sh
-
curl -L -o test-paystack-api.sh https://huggingface.co/spaces/nexusbert/zurri/resolve/main/test-paystack-api.sh
2.46 kB
| # 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 | |