Download test-paystack.ts from nexusbert/zurri: direct link, hf CLI and curl.
- Browser
- Download file 4.35 kB
-
https://huggingface.co/spaces/nexusbert/zurri/resolve/main/test-paystack.ts
- Command line
-
hf download hf://spaces/nexusbert/zurri/test-paystack.ts
-
curl -L -o test-paystack.ts https://huggingface.co/spaces/nexusbert/zurri/resolve/main/test-paystack.ts
4.35 kB
| /** | |
| * Paystack Integration Test Script | |
| * Run with: npx ts-node test-paystack.ts | |
| */ | |
| import dotenv from 'dotenv'; | |
| import { PaystackService } from './src/services/paystackService'; | |
| // Load environment variables | |
| dotenv.config(); | |
| async function testPaystack() { | |
| console.log('π§ͺ Testing Paystack Integration\n'); | |
| // Check environment variables | |
| console.log('π Checking environment variables...'); | |
| const secretKey = process.env.PAYSTACK_SECRET_KEY; | |
| const publicKey = process.env.PAYSTACK_PUBLIC_KEY; | |
| if (!secretKey) { | |
| console.error('β PAYSTACK_SECRET_KEY is not set in .env'); | |
| process.exit(1); | |
| } | |
| if (!publicKey) { | |
| console.error('β PAYSTACK_PUBLIC_KEY is not set in .env'); | |
| process.exit(1); | |
| } | |
| console.log('β PAYSTACK_SECRET_KEY is set'); | |
| console.log('β PAYSTACK_PUBLIC_KEY is set'); | |
| console.log(` Using ${secretKey.startsWith('sk_live') ? 'LIVE' : 'TEST'} keys\n`); | |
| try { | |
| // Initialize PaystackService | |
| console.log('π§ Initializing PaystackService...'); | |
| const paystackService = new PaystackService(); | |
| console.log('β PaystackService initialized\n'); | |
| // Test public key retrieval | |
| console.log('π Testing public key retrieval...'); | |
| const retrievedKey = paystackService.getPublicKey(); | |
| if (retrievedKey === publicKey) { | |
| console.log('β Public key matches\n'); | |
| } else { | |
| console.log('β οΈ Public key mismatch (this might be okay)\n'); | |
| } | |
| // Test transaction initialization (with test data) | |
| console.log('π³ Testing transaction initialization...'); | |
| const testEmail = 'test@example.com'; | |
| const testAmount = 1000; // 1000 NGN = 10 NGN (1000 kobo) | |
| const testReference = `test_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; | |
| console.log(` Email: ${testEmail}`); | |
| console.log(` Amount: ${testAmount} kobo (${testAmount / 100} NGN)`); | |
| console.log(` Reference: ${testReference}`); | |
| try { | |
| const initResult = await paystackService.initializeTransaction({ | |
| email: testEmail, | |
| amount: testAmount, | |
| reference: testReference, | |
| metadata: { | |
| userId: 'test-user-id', | |
| test: true, | |
| }, | |
| callback_url: 'http://localhost:3000/payment/callback', | |
| }); | |
| console.log('β Transaction initialized successfully'); | |
| console.log(` Authorization URL: ${initResult.authorization_url}`); | |
| console.log(` Access Code: ${initResult.access_code}`); | |
| console.log(` Reference: ${initResult.reference}\n`); | |
| // Test verification (this will fail for test reference, but tests the API call) | |
| console.log('π Testing transaction verification...'); | |
| try { | |
| const verifyResult = await paystackService.verifyTransaction(testReference); | |
| console.log('β Verification API call successful'); | |
| console.log(` Status: ${verifyResult.status}`); | |
| console.log(` Amount: ${verifyResult.amount}`); | |
| console.log(` Reference: ${verifyResult.reference}\n`); | |
| } catch (verifyError: any) { | |
| if (verifyError.message.includes('not found') || verifyError.message.includes('No transaction')) { | |
| console.log('β οΈ Transaction not found (expected for test reference)'); | |
| console.log(' This is normal - verification will work after actual payment\n'); | |
| } else { | |
| throw verifyError; | |
| } | |
| } | |
| } catch (initError: any) { | |
| console.error('β Transaction initialization failed:', initError.message); | |
| if (initError.message.includes('Invalid key')) { | |
| console.error(' Check that your PAYSTACK_SECRET_KEY is correct'); | |
| } | |
| process.exit(1); | |
| } | |
| console.log('π All Paystack service tests passed!\n'); | |
| console.log('π Next steps:'); | |
| console.log(' 1. Start the server: npm run dev'); | |
| console.log(' 2. Test the API endpoints:'); | |
| console.log(' - POST /api/wallet/fund (with user auth token)'); | |
| console.log(' - GET /api/wallet/verify/:reference'); | |
| console.log(' 3. Use test cards: 4084084084084081 (success)'); | |
| console.log(' 4. Check PAYMENT_TEST.md for frontend integration examples\n'); | |
| } catch (error: any) { | |
| console.error('β Test failed:', error.message); | |
| console.error(error); | |
| process.exit(1); | |
| } | |
| } | |
| // Run tests | |
| testPaystack(); | |