{"id":30310343,"url":"https://github.com/rafiqdevhub/jobpsych_payment","last_synced_at":"2025-08-17T14:10:54.906Z","repository":{"id":303170618,"uuid":"1013724722","full_name":"Rafiqdevhub/jobpsych_payment","owner":"Rafiqdevhub","description":null,"archived":false,"fork":false,"pushed_at":"2025-08-13T00:39:34.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-13T02:35:53.656Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://jobpsych-payment.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rafiqdevhub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-04T11:09:56.000Z","updated_at":"2025-08-13T00:39:38.000Z","dependencies_parsed_at":"2025-07-06T05:36:05.220Z","dependency_job_id":"7c8dac36-e536-430c-9b84-7f8cb1f26f1a","html_url":"https://github.com/Rafiqdevhub/jobpsych_payment","commit_stats":null,"previous_names":["rafiqdevhub/jobpsych_payment"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Rafiqdevhub/jobpsych_payment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2Fjobpsych_payment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2Fjobpsych_payment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2Fjobpsych_payment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2Fjobpsych_payment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rafiqdevhub","download_url":"https://codeload.github.com/Rafiqdevhub/jobpsych_payment/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rafiqdevhub%2Fjobpsych_payment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270856775,"owners_count":24657700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-17T14:10:52.140Z","updated_at":"2025-08-17T14:10:54.884Z","avatar_url":"https://github.com/Rafiqdevhub.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JobPsych Payment \u0026 Subscription API Documentation\n\n## Overview\n\nJobPsych Payment \u0026 Subscription API is a modern RESTful service for managing subscription plans, payments, and Stripe integration. It supports Free, Pro, and Premium plans, with secure MongoDB storage for subscriptions and robust validation/error handling.\n\n## Features\n\n- 🆓 **Free Plan**: Up to 2 resume uploads\n- 💼 **Pro Plan**: $50/month, unlimited resume uploads\n- � **Premium Plan**: Contact for pricing and access\n- 💳 **Stripe-powered payment processing**\n- 📦 **MongoDB subscription storage**\n- 🔒 **Input validation \u0026 error handling**\n- 🌐 **CORS support for frontend integration**\n- ⚡ **Streamlined endpoints for easy integration**\n\n## API Endpoints\n\n### Base URL\n\n```\nhttp://localhost:5000\n```\n\n### 1. Get Available Plans\n\n```http\nGET /api/plans\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"plans\": {\n      \"pro\": {\n        \"name\": \"JobPsych Pro\",\n        \"price\": 29.99,\n        \"description\": \"Professional plan with advanced features\",\n        \"features\": [\n          \"Advanced job matching\",\n          \"Detailed personality insights\",\n          \"Career recommendations\",\n          \"Priority support\"\n        ]\n      },\n      \"premium\": {\n        \"name\": \"JobPsych Premium\",\n        \"price\": 49.99,\n        \"description\": \"Premium plan with all features\",\n        \"features\": [\n          \"All Pro features\",\n          \"Expert career coaching\",\n          \"Custom assessment reports\",\n          \"1-on-1 consultation\",\n          \"Premium support\"\n        ]\n      }\n    },\n    \"currency\": \"usd\",\n    \"supported_payment_methods\": [\"card\"],\n    \"publishable_key\": \"pk_test_...\"\n  }\n}\n```\n\n### 1. API Documentation \u0026 Plans\n\n```http\nGET /api\n```\n\nReturns API documentation, available plans, and endpoint descriptions.\n\n### 2. Get Available Plans\n\n```http\nGET /api/\n```\n\nReturns Free, Pro, and Premium plan details, pricing, and features.\n\n### 3. Subscribe to Free or Pro Plan\n\n```http\nPOST /api/subscription\nContent-Type: application/json\n```\n\n**Request Body:**\n\n```json\n{\n  \"plan\": \"free\" | \"pro\",\n  \"customer_email\": \"user@example.com\",\n  \"customer_name\": \"John Doe\"\n}\n```\n\n**Response (Success):**\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"plan\": \"pro\",\n    \"status\": \"active\",\n    \"amount\": 50,\n    \"currency\": \"usd\",\n    \"customer_email\": \"user@example.com\",\n    \"description\": \"Professional plan with unlimited resume uploads\",\n    \"resumeLimit\": -1\n  },\n  \"plan_details\": {\n    \"name\": \"JobPsych Pro\",\n    \"price\": 50,\n    \"features\": [\"Unlimited resume uploads\", \"Priority support\", ...]\n  }\n}\n```\n\n### 4. Get Subscription/Payment Status\n\n```http\nGET /api/subscription/:id\n```\n\nReturns payment/subscription status by Stripe payment intent ID.\n\n### 5. Store Subscription Data in MongoDB\n\n```http\nPOST /api/subscription/store\nContent-Type: application/json\n```\n\n**Request Body:**\n\n```json\n{\n  \"user_email\": \"user@example.com\",\n  \"user_id\": \"abc123\",\n  \"stripe_customer_id\": \"cus_123\",\n  \"stripe_subscription_id\": \"sub_456\",\n  \"subscription_status\": \"active\",\n  \"subscription_end\": \"2025-12-31T23:59:59.000Z\"\n}\n```\n\n**Response (Success):**\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"_id\": \"...\",\n    \"user_email\": \"user@example.com\",\n    \"user_id\": \"abc123\",\n    \"stripe_customer_id\": \"cus_123\",\n    \"stripe_subscription_id\": \"sub_456\",\n    \"subscription_status\": \"active\",\n    \"subscription_end\": \"2025-12-31T23:59:59.000Z\"\n  }\n}\n```\n\n### 6. Health Check\n\n```http\nGET /health\n```\n\nReturns service status and uptime.\n\n## Error Handling\n\nAll errors return structured JSON responses with clear messages and details.\n\n**Validation Error Example:**\n\n```json\n{\n  \"error\": \"Validation Error\",\n  \"message\": \"Plan must be either 'free' or 'pro'\",\n  \"valid_plans\": [\"free\", \"pro\"]\n}\n```\n\n**Not Found Example:**\n\n```json\n{\n  \"error\": \"Not Found\",\n  \"message\": \"Route /api/invalid not found\",\n  \"available_routes\": [\n    \"GET /api - API documentation\",\n    \"GET /api/ - Available plans\",\n    \"POST /api/subscription - Subscribe to plan\",\n    \"GET /api/subscription/:id - Payment status\",\n    \"POST /api/subscription/store - Store subscription\",\n    \"GET /health - Health check\"\n  ]\n}\n```\n\n## Frontend Integration Example\n\n```javascript\n// Subscribe to a plan\nconst response = await fetch(\"http://localhost:5000/api/subscription\", {\n  method: \"POST\",\n  headers: { \"Content-Type\": \"application/json\" },\n  body: JSON.stringify({\n    plan: \"pro\",\n    customer_email: \"user@example.com\",\n    customer_name: \"John Doe\",\n  }),\n});\nconst data = await response.json();\nif (data.success) {\n  // Use Stripe client_secret for payment\n}\n```\n\n## Environment Variables\n\nCreate a `.env` file:\n\n```env\nSTRIPE_SECRET_KEY=sk_test_your_stripe_secret_key\nSTRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key\nMONGODB_URI=mongodb://localhost:27017/jobpsych\nPORT=5000\nNODE_ENV=development\n```\n\n## Project Structure\n\n```\nsrc/\n├── index.ts                    # Main server file\n├── routes/\n│   └── planRoutes.ts           # API routes\n├── controllers/\n│   ├── planPaymentController.ts # Payment logic\n│   └── subscriptionStoreController.ts # MongoDB storage\n├── models/\n│   └── subscription.ts         # Subscription schema/model\n├── middleware/\n│   └── planValidation.ts       # Request validation\n│   └── errorHandler.ts         # Async error handler\n├── config/\n│   ├── stripe.ts               # Stripe configuration\n│   └── mongodb.ts              # MongoDB connection\n└── types/\n    └── payment.ts              # TypeScript types\n```\n\n## Quick Start\n\n1. `npm install`\n2. Add your `.env` file\n3. `npm run dev`\n4. Test endpoints with Postman, curl, or your frontend\n\n---\n\n**JobPsych Payment \u0026 Subscription API is production-ready for Free, Pro, and Premium plans with Stripe and MongoDB integration!**\n\n### 3. Get Payment Status\n\n```http\nGET /api/status/:payment_id\n```\n\n**Example:**\n\n```http\nGET /api/status/pi_3RgjWOBD8fyBOgMZ1TrI3hjG\n```\n\n## Error Handling\n\n### Validation Errors (400)\n\n```json\n{\n  \"error\": \"Validation Error\",\n  \"message\": \"Plan must be either 'pro' or 'premium'\",\n  \"valid_plans\": [\"pro\", \"premium\"]\n}\n```\n\n### Missing JSON Body (400)\n\n```json\n{\n  \"error\": \"Validation Error\",\n  \"message\": \"Request body is missing or invalid. Make sure to send JSON data with Content-Type: application/json\",\n  \"received_body\": null,\n  \"content_type\": null\n}\n```\n\n### Not Found (404)\n\n```json\n{\n  \"error\": \"Not Found\",\n  \"message\": \"Route /api/invalid not found\",\n  \"available_routes\": [\n    \"GET /api - API documentation\",\n    \"GET /api/plans - Available plans\",\n    \"POST /api/pay - Create payment\",\n    \"GET /api/status/:id - Payment status\"\n  ]\n}\n```\n\n## Frontend Integration\n\n### JavaScript/TypeScript Example\n\n```javascript\n// Get available plans\nconst plansResponse = await fetch(\"http://localhost:5000/api/plans\");\nconst plansData = await plansResponse.json();\n\n// Create payment\nconst paymentResponse = await fetch(\"http://localhost:5000/api/pay\", {\n  method: \"POST\",\n  headers: {\n    \"Content-Type\": \"application/json\",\n  },\n  body: JSON.stringify({\n    plan: \"pro\",\n    customer_email: \"user@example.com\",\n    customer_name: \"John Doe\",\n  }),\n});\n\nconst paymentData = await paymentResponse.json();\n\nif (paymentData.success) {\n  // Use the client_secret with Stripe.js to complete payment\n  const { client_secret } = paymentData.data;\n  // ... Stripe frontend integration\n}\n```\n\n### React Example\n\n```jsx\nconst handlePayment = async (plan) =\u003e {\n  try {\n    const response = await fetch(\"/api/pay\", {\n      method: \"POST\",\n      headers: {\n        \"Content-Type\": \"application/json\",\n      },\n      body: JSON.stringify({\n        plan,\n        customer_email: userEmail,\n        customer_name: userName,\n      }),\n    });\n\n    const data = await response.json();\n\n    if (data.success) {\n      // Redirect to Stripe Checkout or use Elements\n      const { client_secret } = data.data;\n      // ... handle payment completion\n    }\n  } catch (error) {\n    console.error(\"Payment failed:\", error);\n  }\n};\n```\n\n## Testing\n\n### Using curl\n\n```bash\n# Get plans\ncurl http://localhost:5000/api/plans\n\n# Create Pro payment\ncurl -X POST http://localhost:5000/api/pay \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"plan\":\"pro\",\"customer_email\":\"test@example.com\",\"customer_name\":\"Test User\"}'\n\n# Create Premium payment\ncurl -X POST http://localhost:5000/api/pay \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"plan\":\"premium\",\"customer_email\":\"premium@example.com\"}'\n```\n\n### Test Script\n\nRun the included test script:\n\n```bash\nnode test-payment.js\n```\n\n## Environment Variables\n\nCreate a `.env` file with:\n\n```env\nSTRIPE_SECRET_KEY=sk_test_your_stripe_secret_key\nSTRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key\nFRONTEND_URL=http://localhost:5173\nPORT=5000\nNODE_ENV=development\n```\n\n## Installation \u0026 Setup\n\n1. **Install dependencies:**\n\n   ```bash\n   npm install\n   ```\n\n2. **Set up environment variables:**\n\n   ```bash\n   cp .env.example .env\n   # Edit .env with your Stripe keys\n   ```\n\n3. **Start development server:**\n\n   ```bash\n   npm run dev\n   ```\n\n4. **Test the API:**\n   ```bash\n   node test-payment.js\n   ```\n\n## Project Structure\n\n```\nsrc/\n├── index.ts                    # Main server file\n├── routes/\n│   └── planRoutes.ts          # API routes\n├── controllers/\n│   └── planPaymentController.ts # Payment logic\n├── middleware/\n│   └── planValidation.ts      # Request validation\n├── config/\n│   └── stripe.ts              # Stripe configuration\n└── types/\n    └── payment.ts             # TypeScript types\n```\n\n## Key Features\n\n### ✅ Completed\n\n- [x] Simplified API with only Pro and Premium plans\n- [x] Stripe payment integration\n- [x] Input validation middleware\n- [x] Error handling\n- [x] CORS support\n- [x] TypeScript support\n- [x] Development hot-reload\n- [x] Environment variable configuration\n- [x] Test scripts\n\n### 🎯 Focused Design\n\n- Only 3 endpoints (plans, pay, status)\n- Only 2 plan types (pro, premium)\n- Streamlined payment flow\n- Clear error messages\n- Ready for frontend integration\n\n## Support\n\nFor questions or issues, please check:\n\n1. Environment variables are correctly set\n2. Stripe keys are valid and without quotes\n3. Content-Type header is set to application/json\n4. Request body contains valid JSON\n\n---\n\n**🚀 Your JobPsych Payment API is ready to use!**\n\n```bash\ncp .env.example .env\n# Add your Stripe keys to .env\n```\n\n3. **Run the service:**\n\n   ```bash\n   npm run dev\n   ```\n\n4. **Test the API:**\n   ```bash\n   node test-api.js\n   ```\n\n## 📡 API Endpoints\n\n### Base URL: `http://localhost:5000`\n\n| Method | Endpoint          | Description                            |\n| ------ | ----------------- | -------------------------------------- |\n| GET    | `/api/plans`      | Get available plans and pricing        |\n| POST   | `/api/pay`        | Create payment for pro or premium plan |\n| GET    | `/api/status/:id` | Get payment status by payment ID       |\n| GET    | `/health`         | Health check                           |\n| GET    | `/api`            | API documentation                      |\n\n## 📝 API Usage\n\n### 1. Get Available Plans\n\n```bash\nGET /api/plans\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"plans\": {\n      \"pro\": {\n        \"name\": \"JobPsych Pro\",\n        \"price\": 29.99,\n        \"description\": \"Professional plan with advanced features\",\n        \"features\": [\"Advanced job matching\", \"Priority support\", ...]\n      },\n      \"premium\": {\n        \"name\": \"JobPsych Premium\",\n        \"price\": 49.99,\n        \"description\": \"Premium plan with all features\",\n        \"features\": [\"All Pro features\", \"Expert coaching\", ...]\n      }\n    },\n    \"currency\": \"usd\",\n    \"supported_payment_methods\": [\"card\"],\n    \"publishable_key\": \"pk_test_...\"\n  }\n}\n```\n\n### 2. Create Payment\n\n```bash\nPOST /api/pay\n```\n\n**Request Body:**\n\n```json\n{\n  \"plan\": \"pro\", // Required: \"pro\" or \"premium\"\n  \"customer_email\": \"user@example.com\", // Required: Valid email\n  \"customer_name\": \"John Doe\", // Optional: Customer name\n  \"metadata\": {\n    // Optional: Additional data\n    \"source\": \"website\",\n    \"promotion\": \"first_time_user\"\n  }\n}\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"id\": \"pi_...\",\n    \"client_secret\": \"pi_..._secret_...\",\n    \"status\": \"requires_payment_method\",\n    \"plan\": \"pro\",\n    \"amount\": 29.99,\n    \"currency\": \"usd\",\n    \"customer_email\": \"user@example.com\",\n    \"description\": \"JobPsych Pro - Professional plan...\"\n  },\n  \"plan_details\": {\n    \"name\": \"JobPsych Pro\",\n    \"price\": 29.99,\n    \"features\": [...]\n  }\n}\n```\n\n### 3. Check Payment Status\n\n```bash\nGET /api/status/{payment_id}\n```\n\n**Response:**\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"id\": \"pi_...\",\n    \"status\": \"requires_payment_method\",\n    \"plan\": \"pro\",\n    \"amount\": 29.99,\n    \"customer_email\": \"user@example.com\"\n  },\n  \"plan_details\": {\n    \"name\": \"JobPsych Pro\",\n    \"price\": 29.99,\n    \"features\": [...]\n  }\n}\n```\n\n## ✅ Validation Rules\n\n### Plan Validation\n\n- Only `\"pro\"` and `\"premium\"` plans are accepted\n- Any other plan value will return a 400 error\n\n### Email Validation\n\n- `customer_email` is required\n- Must be a valid email format\n\n### Name Validation\n\n- `customer_name` is optional\n- If provided, must be a non-empty string\n\n## 🔧 Error Handling\n\nThe API returns consistent error responses:\n\n```json\n{\n  \"error\": \"Validation Error\",\n  \"message\": \"Plan must be either 'pro' or 'premium'\",\n  \"valid_plans\": [\"pro\", \"premium\"]\n}\n```\n\nCommon errors:\n\n- Invalid plan type (400)\n- Missing or invalid email (400)\n- Invalid payment ID format (400)\n- Payment not found (404)\n- Stripe API errors (400)\n\n## 🏗️ Project Structure\n\n```\nsrc/\n├── config/\n│   └── stripe.ts              # Stripe configuration\n├── controllers/\n│   └── planPaymentController.ts  # Payment logic for plans\n├── middleware/\n│   └── planValidation.ts      # Validation for plan payments\n├── routes/\n│   └── planRoutes.ts          # API routes\n├── types/\n│   └── payment.ts             # TypeScript types\n└── index.ts                   # Express server setup\n```\n\n## 🧪 Testing\n\nRun the comprehensive test suite:\n\n```bash\nnode test-api.js\n```\n\nTests include:\n\n- ✅ Health check\n- ✅ API documentation\n- ✅ Plan listing\n- ✅ Pro plan payment creation\n- ✅ Premium plan payment creation\n- ✅ Payment status retrieval\n- ✅ Invalid plan validation\n- ✅ Missing email validation\n\n## 💳 Payment Flow\n\n1. **Get Plans**: Client fetches available plans and pricing\n2. **Create Payment**: Client submits plan choice and customer details\n3. **Process Payment**: Frontend uses client_secret with Stripe Elements\n4. **Check Status**: Client can query payment status using payment ID\n\n## 🔒 Security Features\n\n- ✅ Input validation for all requests\n- ✅ Email format validation\n- ✅ Plan type restriction (only pro/premium)\n- ✅ Secure Stripe integration\n- ✅ Environment-based configuration\n- ✅ Error message standardization\n\n## 📦 Dependencies\n\n- **Express**: Web framework\n- **Stripe**: Payment processing\n- **TypeScript**: Type safety\n- **dotenv**: Environment configuration\n- **cors**: Cross-origin requests\n\n#\n\n## 📞 Support\n\nFor issues or questions about the payment service, check:\n\n- Server logs for detailed error information\n- Stripe Dashboard for payment status\n- Test script output for API validation\n\n---\n\n**Version**: 2.0.0 - Simplified for Pro \u0026 Premium Plans Only  \n**Status**: ✅ Production Ready\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafiqdevhub%2Fjobpsych_payment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafiqdevhub%2Fjobpsych_payment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafiqdevhub%2Fjobpsych_payment/lists"}