{"id":15173974,"url":"https://github.com/andregit1/payment-system","last_synced_at":"2026-02-23T23:36:19.028Z","repository":{"id":253884940,"uuid":"844811785","full_name":"andregit1/payment-system","owner":"andregit1","description":"payment system","archived":false,"fork":false,"pushed_at":"2024-08-25T02:39:32.000Z","size":84,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-30T12:26:24.423Z","etag":null,"topics":["docker","docker-compose","fastify","fastify-cors","fastify-swagger","fastify-swagger-ui","node","node-cron","nodejs","postgresql","prisma-orm","supertokens","supertokens-backend","typescript"],"latest_commit_sha":null,"homepage":"","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/andregit1.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}},"created_at":"2024-08-20T02:40:37.000Z","updated_at":"2024-08-25T02:39:35.000Z","dependencies_parsed_at":"2024-09-23T04:02:53.668Z","dependency_job_id":"8ec4184c-bc03-48d2-af8a-f20de2715401","html_url":"https://github.com/andregit1/payment-system","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"53e43406b83fbee4d8faf34a7bf5b2a93cc1a441"},"previous_names":["andregit1/payment-system"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/andregit1/payment-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andregit1%2Fpayment-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andregit1%2Fpayment-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andregit1%2Fpayment-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andregit1%2Fpayment-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andregit1","download_url":"https://codeload.github.com/andregit1/payment-system/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andregit1%2Fpayment-system/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263464185,"owners_count":23470473,"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","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":["docker","docker-compose","fastify","fastify-cors","fastify-swagger","fastify-swagger-ui","node","node-cron","nodejs","postgresql","prisma-orm","supertokens","supertokens-backend","typescript"],"created_at":"2024-09-27T11:22:08.670Z","updated_at":"2026-02-23T23:36:13.959Z","avatar_url":"https://github.com/andregit1.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overview\n\nThis is a backend service for managing user accounts and transactions, including recurring payments.\n\n## Features\n\n- **User Registration and Authentication**:\n\n  - `POST /auth/signup` - Register a new user\n  - `POST /auth/signin` - Sign in a user\n  - `POST /auth/signout` - Sign out a user\n\n- **Account Management**:\n\n  - `GET /api/accounts` - View all user's account details and balances\n  - `POST /api/accounts` - Create new user's account\n  - `GET /api/accounts/{id}/history` - View specific account transaction history\n\n- **Transaction**:\n\n  - `POST /api/send` - Send funds from one account to another\n  - `POST /api/withdraw` - Withdraw funds from an account\n  - Note: Transactions (send and withdraw) are processed x seconds after the endpoint is hit. The value of 'x' can be adjusted in the '.env' file.\n\n- **Recurring Payments**:\n\n  - `GET /api/recurring-payments` - Retrieve all recurring payments\n  - `PUT /api/recurring-payments{id}` - Set up or update recurring payments\n\n## Tech Stack\n\n- **Node.js** with **TypeScript**\n- **Fastify** for the API server\n- **Prisma** as the ORM\n- **PostgreSQL** for the database\n- **SuperTokens** for authentication\n- **Swagger** for API documentation\n\n## Getting Started\n\n### Prerequisites\n\n- **Node.js** (v20 or later)\n- **PostgreSQL** (v14 or later)\n\n### Installation\n\n1. **Clone the Repository**:\n\n   ```bash\n   git clone https://github.com/andregit1/payment-system.git\n   cd payment-system\n   ```\n\n2. **Install Dependencies**:\n\n   ```bash\n   npm install\n   ```\n\n3. **Set Up Environment Variables**:\n   Create a `.env` file in the project root with the following content:\n\n   ```plaintext\n   DATABASE_URL=\"postgresql://root:123123123@localhost:5432/concreteai_dev?schema=public\"  # for local\n   DATABASE_URL=\"postgresql://root:123123123@db:5432/concreteai_dev?schema=public\"         # with Docker\n   ```\n\n4. **Set Up the Database**:\n   Run the following command to apply database migrations:\n\n   ```bash\n   npx prisma migrate dev\n   ```\n\n5. **Start the Server**:\n   ```bash\n   npm run dev\n   ```\n   The API server should now be running at `http://localhost:3001`.\n\n### Seed Data (Optional)\n\nTo seed the database with initial data, add the following to your `package.json`:\n\n```json\n\"prisma\": {\n  \"seed\": \"ts-node-dev prisma/seed.ts\"\n}\n```\n\nThen, run the seed command:\n\n```bash\nnpx prisma db seed\n```\n\n## API Documentation\n\nAPI documentation is available at `http://localhost:3001/documentation` when the server is running.\n\n**Demo Video Link**: [swagger-authorized-demo](https://drive.google.com/file/d/13whWf2FzeiqASVtXUXD_9oI8Fw_yoRgG/view?usp=sharing)\n\n### Accessing Authorized API Documentation\n\n1. **Open the Swagger UI**:\n   Navigate to `http://localhost:3001/documentation` in your browser to access the API documentation.\n\n2. **Sign Up and Sign In**:\n\n   - Use the `POST /auth/signup` endpoint to create a new user account.\n   - Use the `POST /auth/signin` endpoint to sign in and obtain an access token from the response.\n\n3. **Authorize with the Token**:\n   - Copy the `st-access-token` value from the response header of the `POST /auth/signin` request.\n   - Click the **Authorize** button in the Swagger UI (usually located in the top right corner).\n   - Paste the token value into the authorization dialog and click **Authorize**.\n   - Click **Close** to exit the authorization dialog.\n\nNow, you can use the Swagger UI to test the endpoints with the provided authorization.\n\n## Running in Development with Docker\n\nTo run the application using Docker:\n\n1. **Build the Docker Images**:\n\n   ```bash\n   docker compose build\n   ```\n\n2. **Start the Docker Containers**:\n\n   ```bash\n   docker compose up -d\n   ```\n\n3. **Access the Docker Container**:\n\n   ```bash\n   docker compose exec app sh\n   ```\n\n4. **Stop the Docker Containers**:\n   ```bash\n   docker compose down\n   ```\n\n## Recurring Payment Cron Job\n\nA cron job is set up to handle recurring payments, currently scheduled to run at midnight every day.\n\n```js\n// src/app.ts\n// Schedule recurring payments processing\nprocessRecurringPaymentsTask('0 0 * * *'); // Daily at midnight\n```\n\nThis job checks for any recurring payments that need to be processed and executes the required transactions accordingly.\n\n## Schema Definition\n\nHere's an overview of the data relations:\n\n- **User**:\n\n  - Each `User` has a unique `supertokensId` (which mimics the SuperTokens user_id for authentication and matches the relationship data table), `username`, `email`, and `password`.\n  - A `User` can have multiple `PaymentAccounts`.\n\n- **PaymentAccount**:\n\n  - Each `PaymentAccount` belongs to a `User`.\n  - It has a unique `accountNumber`, `accountType`, and `balance`.\n  - A `PaymentAccount` can have multiple, `Transaction` records as the sender or recipient, and `RecurringPayment` records as the sender or recipient.\n  - The `PaymentAccount` entity represents accounts in the payload, distinct from `userId`, as it holds balance information and related data.\n\n- **Transaction**:\n\n  - Each `Transaction` involves a `senderAccount` and `recipientAccount`.\n  - It records the amount, currency, timestamp, status, and optional address.\n\n- **RecurringPayment**:\n  - Each `RecurringPayment` involves a `senderAccount` and `recipientAccount`.\n  - It records the amount, currency, interval, next payment date, and status.\n\n## Troubleshooting\n\n### Running Locally\n\n- Ensure that **PostgreSQL** is installed and running on your local machine.\n- Verify that the `DATABASE_URL` in your `.env` file is correctly configured for your local setup.\n\n### Using Docker\n\n- Make sure the **PostgreSQL** service on your local machine is **shut down** before running the application in Docker. Docker will manage the PostgreSQL instance, and having two instances running simultaneously can cause conflicts.\n\n## Future Development\n\n- **Currency Conversion**:\n  - If transactions involve different currencies, they must be converted to the recipient's currency before processing. Future development will include support for real-time currency conversion to handle such scenarios seamlessly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandregit1%2Fpayment-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandregit1%2Fpayment-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandregit1%2Fpayment-system/lists"}