📚 Documentation Postman - Nelsius Pay API 🌐 Configuration de base Variables d'environnement Postman CrĂ©e un environnement nommĂ© "Nelsius Pay - Local" avec : text base_url: http://localhost:8000 token: (laissĂ© vide, sera automatiquement rempli) user_email: votre@email.com user_password: VotreMotDePasse 🔐 ENDPOINTS D'AUTHENTIFICATION 1. Inscription MĂ©thode : POST URL : {{base_url}}/api/auth/register Headers : text Content-Type: application/json Body (JSON) : json { "nom": "Kamga", "prenom": "Jean", "email": "jean.kamga@test.com", "phone": "+237699887766", "password": "Test@1234", "password_confirmation": "Test@1234", "role": "user" } RĂ©ponse attendue (201 Created) : json { "success": true, "message": "Inscription rĂ©ussie. Veuillez vĂ©rifier votre email.", "data": { "user": { "id": 2, "nom": "Kamga", "prenom": "Jean", "email": "jean.kamga@test.com", "phone": "+237699887766", "role": "user", "email_verified": false, "kyc_status": "pending", "is_active": true, "two_factor_enabled": false, "last_login": null, "created_at": "2025-12-05T10:00:00.000000Z", "updated_at": "2025-12-05T10:00:00.000000Z" } } } Test Postman (Ă  ajouter dans Tests) : javascript // Sauvegarder l'email pour les tests suivants pm.environment.set("user_email", pm.response.json().data.user.email); pm.environment.set("user_id", pm.response.json().data.user.id); console.log("Utilisateur créé avec ID: " + pm.response.json().data.user.id); 2. Connexion MĂ©thode : POST URL : {{base_url}}/api/auth/login Headers : text Content-Type: application/json Body (JSON) : json { "email": "{{user_email}}", "password": "Test@1234", "device_name": "Postman Desktop" } RĂ©ponse attendue (200 OK) : json { "success": true, "message": "Connexion rĂ©ussie.", "data": { "user": { ... }, "tokens": { "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...", "refresh_token": "abc123def456ghi789...", "token_type": "bearer", "expires_in": 3600, "refresh_expires_in": 86400 } } } Test Postman (Ă  ajouter dans Tests) : javascript // Sauvegarder le token pour les requĂȘtes suivantes const token = pm.response.json().data.tokens.access_token; pm.environment.set("token", token); // VĂ©rifier que le token est prĂ©sent pm.test("Token reçu", function() { pm.expect(token).to.not.be.empty; }); // VĂ©rifier la structure de la rĂ©ponse pm.test("Structure de rĂ©ponse correcte", function() { pm.expect(pm.response.json().success).to.be.true; pm.expect(pm.response.json().data).to.have.property('tokens'); pm.expect(pm.response.json().data.tokens).to.have.property('access_token'); pm.expect(pm.response.json().data.tokens).to.have.property('refresh_token'); }); 3. Profil utilisateur (protĂ©gĂ©) MĂ©thode : GET URL : {{base_url}}/api/auth/me Headers : text Authorization: Bearer {{token}} Content-Type: application/json RĂ©ponse attendue (200 OK) : json { "success": true, "message": "Informations utilisateur rĂ©cupĂ©rĂ©es.", "data": { "user": { "id": 2, "nom": "Kamga", "prenom": "Jean", "email": "jean.kamga@test.com", "phone": "+237699887766", "role": "user", "email_verified": false, "kyc_status": "pending", "is_active": true, "two_factor_enabled": false, "last_login": "2025-12-05T10:05:00.000000Z", "created_at": "2025-12-05T10:00:00.000000Z", "updated_at": "2025-12-05T10:05:00.000000Z" } } } Test Postman : javascript // VĂ©rifier que l'utilisateur est correct pm.test("Utilisateur connectĂ©", function() { pm.expect(pm.response.json().data.user.email).to.equal(pm.environment.get("user_email")); pm.expect(pm.response.json().data.user.id).to.equal(parseInt(pm.environment.get("user_id"))); }); 4. DĂ©connexion (protĂ©gĂ©) MĂ©thode : POST URL : {{base_url}}/api/auth/logout Headers : text Authorization: Bearer {{token}} Content-Type: application/json RĂ©ponse attendue (200 OK) : json { "success": true, "message": "DĂ©connexion rĂ©ussie." } Test Postman : javascript // AprĂšs dĂ©connexion, supprimer le token pm.environment.unset("token"); pm.test("DĂ©connexion rĂ©ussie", function() { pm.expect(pm.response.json().success).to.be.true; }); 5. RafraĂźchissement de token MĂ©thode : POST URL : {{base_url}}/api/auth/refresh Headers : text Content-Type: application/json Body (JSON) : json { "refresh_token": "{{refresh_token}}" } Note : Le refresh_token doit ĂȘtre sauvegardĂ© aprĂšs la connexion 6. VĂ©rification d'email MĂ©thode : POST URL : {{base_url}}/api/auth/email/verify Headers : text Content-Type: application/json Body (JSON) : json { "code": "ABC123" // Code reçu par email } 7. Renvoyer l'email de vĂ©rification MĂ©thode : POST URL : {{base_url}}/api/auth/email/resend Headers : text Content-Type: application/json Body (JSON) : json { "email": "{{user_email}}" } 8. RĂ©initialisation de mot de passe - Demande MĂ©thode : POST URL : {{base_url}}/api/auth/password/request Headers : text Content-Type: application/json Body (JSON) : json { "email": "{{user_email}}" } 9. RĂ©initialisation de mot de passe - Confirmation MĂ©thode : POST URL : {{base_url}}/api/auth/password/reset Headers : text Content-Type: application/json Body (JSON) : json { "token": "token_reçu_par_email", "password": "Nouveau@1234", "password_confirmation": "Nouveau@1234" } 10. Connexion Google - Redirection MĂ©thode : GET URL : {{base_url}}/api/auth/google/redirect RĂ©ponse attendue : json { "success": true, "message": "Redirection vers Google.", "data": { "redirect_url": "https://accounts.google.com/o/oauth2/auth?..." } } 11. Connexion Google - Callback MĂ©thode : GET URL : {{base_url}}/api/auth/google/callback?code=CODE_GOOGLE Note : Cette URL est appelĂ©e automatiquement par Google aprĂšs authentification 📁 Collection Postman Ă  importer JSON de la collection : json { "info": { "_postman_id": "nelsius-pay-auth", "name": "Nelsius Pay - Authentication", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { "name": "Inscription", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"nom\": \"Kamga\",\n \"prenom\": \"Jean\",\n \"email\": \"jean.kamga@test.com\",\n \"phone\": \"+237699887766\",\n \"password\": \"Test@1234\",\n \"password_confirmation\": \"Test@1234\",\n \"role\": \"user\"\n}" }, "url": { "raw": "{{base_url}}/api/auth/register", "host": ["{{base_url}}"], "path": ["api", "auth", "register"] } }, "response": [] }, { "name": "Connexion", "request": { "method": "POST", "header": [ { "key": "Content-Type", "value": "application/json" } ], "body": { "mode": "raw", "raw": "{\n \"email\": \"{{user_email}}\",\n \"password\": \"Test@1234\",\n \"device_name\": \"Postman Desktop\"\n}" }, "url": { "raw": "{{base_url}}/api/auth/login", "host": ["{{base_url}}"], "path": ["api", "auth", "login"] } }, "response": [] }, { "name": "Profil utilisateur", "request": { "method": "GET", "header": [ { "key": "Authorization", "value": "Bearer {{token}}" }, { "key": "Content-Type", "value": "application/json" } ], "url": { "raw": "{{base_url}}/api/auth/me", "host": ["{{base_url}}"], "path": ["api", "auth", "me"] } }, "response": [] }, { "name": "DĂ©connexion", "request": { "method": "POST", "header": [ { "key": "Authorization", "value": "Bearer {{token}}" }, { "key": "Content-Type", "value": "application/json" } ], "url": { "raw": "{{base_url}}/api/auth/logout", "host": ["{{base_url}}"], "path": ["api", "auth", "logout"] } }, "response": [] } ], "variable": [ { "key": "base_url", "value": "http://localhost:8000" }, { "key": "token", "value": "" }, { "key": "user_email", "value": "jean.kamga@test.com" } ] } 🎯 Flux de test recommandĂ© Test 1 : Flux complet utilisateur Inscription → VĂ©rifie que l'utilisateur est créé VĂ©rifier dans Mailtrap → Code de vĂ©rification Connexion → RĂ©cupĂšre les tokens /me → VĂ©rifie que le token fonctionne DĂ©connexion → VĂ©rifie que le token est blacklistĂ© /me aprĂšs dĂ©co → Devrait Ă©chouer (401) Test 2 : Gestion des erreurs bash # Tentative avec mauvais mot de passe POST /api/auth/login {"email": "test@test.com", "password": "wrong"} # Tentative avec email non vĂ©rifiĂ© POST /api/auth/login {"email": "nonverifie@test.com", "password": "..."} # Tentative avec token expirĂ© GET /api/auth/me Authorization: Bearer expired_token Test 3 : Tests de sĂ©curitĂ© bash # Tentatives multiples de connexion (rate limiting) # Connexion depuis diffĂ©rentes IP # Token blacklistĂ© aprĂšs dĂ©connexion # Refresh token rĂ©voquĂ© aprĂšs changement de mot de passe 📊 Scripts Postman utiles PrĂ©-request Script (pour automatiser) : javascript // GĂ©nĂ©rer un email unique pour chaque test const timestamp = new Date().getTime(); const uniqueEmail = `test${timestamp}@nelsiuspay.com`; pm.environment.set("unique_email", uniqueEmail); Test Script (pour valider) : javascript // Valider la structure de rĂ©ponse JWT pm.test("Response is JSON", function () { pm.response.to.have.header("Content-Type"); pm.response.to.be.json; }); pm.test("Response has success status", function () { const jsonData = pm.response.json(); pm.expect(jsonData).to.have.property("success"); pm.expect(jsonData).to.have.property("message"); pm.expect(jsonData).to.have.property("data"); }); // VĂ©rifier les codes HTTP pm.test("Status code is 200", function () { pm.response.to.have.status(200); }); 🔍 VĂ©rification des logs pendant les tests Pendant que tu testes avec Postman, ouvre un terminal pour voir les logs : bash # Terminal 1 : Voir les logs Laravel tail -f storage/logs/laravel.log # Terminal 2 : Voir les requĂȘtes SQL php artisan tinker >>> DB::listen(function($sql) { echo $sql->sql . "\n"; }); đŸ“± Variables d'environnement Postman CrĂ©e ce fichier JSON et importe-le dans Postman : nelsius-pay-env.json : json { "id": "nelsius-pay-env", "name": "Nelsius Pay - Local", "values": [ { "key": "base_url", "value": "http://localhost:8000", "type": "default", "enabled": true }, { "key": "token", "value": "", "type": "default", "enabled": true }, { "key": "user_email", "value": "test@example.com", "type": "default", "enabled": true }, { "key": "user_password", "value": "Test@1234", "type": "default", "enabled": true } ], "_postman_variable_scope": "environment", "_postman_exported_at": "2025-12-05T10:00:00.000Z", "_postman_exported_using": "Postman/10.0.0" } 🚀 Tests rapides via cURL (alternative) Si tu prĂ©fĂšres cURL : bash # Inscription curl -X POST http://localhost:8000/api/auth/register \ -H "Content-Type: application/json" \ -d '{"nom":"Test","prenom":"User","email":"test@example.com","password":"Test@1234","password_confirmation":"Test@1234"}' # Connexion et sauvegarde du token curl -X POST http://localhost:8000/api/auth/login \ -H "Content-Type: application/json" \ -d '{"email":"test@example.com","password":"Test@1234"}' \ | jq -r '.data.tokens.access_token' > token.txt # Utiliser le token TOKEN=$(cat token.txt) curl -X GET http://localhost:8000/api/auth/me \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" 📝 Checklist de test Inscription : CrĂ©ation utilisateur + portefeuille Email : Reçu dans Mailtrap Connexion : Token JWT gĂ©nĂ©rĂ© Middleware : Route /me protĂ©gĂ©e DĂ©connexion : Token blacklistĂ© Refresh : Nouveau token gĂ©nĂ©rĂ© VĂ©rification email : Statut mis Ă  jour RĂ©initialisation MDP : Email envoyĂ© + MDP changĂ© SĂ©curitĂ© : Logs dans security_events