{"id":18594679,"url":"https://github.com/ernitingarg/typescript-expressjs-postgres-typeorm-cryptopaymentmethod","last_synced_at":"2026-04-11T04:33:31.382Z","repository":{"id":181953992,"uuid":"666758789","full_name":"ernitingarg/typescript-expressjs-postgres-typeorm-cryptopaymentmethod","owner":"ernitingarg","description":"Typescript/Nodejs Backend API server for handling crypto payments using thirdparty payment gateway","archived":false,"fork":false,"pushed_at":"2024-07-21T03:21:40.000Z","size":88,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-29T18:50:55.741Z","etag":null,"topics":["api","api-services","cryptopayments","db-migration","docker-compose","expressjs","jwt-authentication","nodejs","postgresql","server","triplea","typeorm","typescript"],"latest_commit_sha":null,"homepage":"https://crypto-payment-method.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/ernitingarg.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":"2023-07-15T13:33:50.000Z","updated_at":"2024-07-21T03:21:42.000Z","dependencies_parsed_at":"2023-07-18T08:32:03.247Z","dependency_job_id":"baa49a2c-097a-41b7-8d47-f3529aba324d","html_url":"https://github.com/ernitingarg/typescript-expressjs-postgres-typeorm-cryptopaymentmethod","commit_stats":null,"previous_names":["ernitingarg09/cryptopaymentmethod","ernitingarg/crpto-payment-method-typescript-expressjs","ernitingarg/typescript-expressjs-postgres-typeorm-cryptopaymentmethod"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ernitingarg/typescript-expressjs-postgres-typeorm-cryptopaymentmethod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ernitingarg%2Ftypescript-expressjs-postgres-typeorm-cryptopaymentmethod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ernitingarg%2Ftypescript-expressjs-postgres-typeorm-cryptopaymentmethod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ernitingarg%2Ftypescript-expressjs-postgres-typeorm-cryptopaymentmethod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ernitingarg%2Ftypescript-expressjs-postgres-typeorm-cryptopaymentmethod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ernitingarg","download_url":"https://codeload.github.com/ernitingarg/typescript-expressjs-postgres-typeorm-cryptopaymentmethod/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ernitingarg%2Ftypescript-expressjs-postgres-typeorm-cryptopaymentmethod/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31669116,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T17:19:37.612Z","status":"online","status_checked_at":"2026-04-11T02:00:05.776Z","response_time":54,"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":["api","api-services","cryptopayments","db-migration","docker-compose","expressjs","jwt-authentication","nodejs","postgresql","server","triplea","typeorm","typescript"],"created_at":"2024-11-07T01:16:38.755Z","updated_at":"2026-04-11T04:33:31.348Z","avatar_url":"https://github.com/ernitingarg.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CryptoPaymentMethod project\n\nThis demo project is a backend server that exposes several API endpoints for managing different types of payments (eg: Nets, Visa, Crypto) by using various payment providers.\nThe server leverages the APIs provided by the external payment provider [TripleA](https://developers.triple-a.io/docs/triplea-api-doc/) for processing Crypto payments.\n\n## Features\n- The API server is implemented using `TypeScript` and runs on `Node.js`. It utilizes `Express.js` as the web framework.\n- The project uses a `Postgres` database, which is deployed locally in a Docker container.\n- Requested payload validation is implemented using the `express-validator` library, ensuring that incoming data is properly validated.\n- Error handling is efficiently managed through middleware, reducing the need for excessive try/catch blocks.\n- The project follows the factory and bridge design patterns to facilitate the integration of different payments methods and payment providers as needed.\n\t- The `TripleAPaymentProvider` is used for handling `Crypto` payments, utilizing the specific APIs provided by TripleA.\n\t- The `MockPaymentProvider` is used for handling `Nets` and `Visa` payments, using mock data for testing purposes.\n\t- The design allows for seamless integration of new payment methods and/or new payment providers by simply modifying the factory, without requiring changes to the overall design structure.\n- Access token is managed by `AccessTokenManager` which is responsible to generate new access token.\n- Payment providers can request access tokens and manage them in-memory or through a database for subsequent requests.\n- **API endpoints:** The server supports the following API endpoints:\n\t- `GET /payment-methods`: Retrieves a list of supported payment options from the database.\n\t- `POST /payment-collections`: Creates a payment using the TripleA API and stores the response in the database.\n\t- `GET /payment-collections/{id}`: Retrieves payment details from the database.\n\n## Directory structure\n```\n│   .env\n│   .gitignore\n│   docker-compose.yml\n│   package-lock.json\n│   package.json\n│   README.md\n│   tsconfig.json\n│\n├───postman\n│       postman_collection.json\n│\n└───src\n    │   config.ts\n    │   data-source.ts\n    │   index.ts\n    │   routes.ts\n    │\n    ├───controllers\n    │       PaymentCollectionController.ts\n    │       PaymentMethodController.ts\n    │\n    ├───entities\n    │       PaymentCollection.ts\n    │       PaymentMethod.ts\n    │\n    ├───enums\n    │       PaymentOption.ts\n    │\n    ├───middlewares\n    │       errorHandler.ts\n    │\n    ├───migrations\n    │       1689427418203-migration-seed.ts\n    │\n    ├───payment\n    │   ├───factories\n    │   │       PaymentFactory.ts\n    │   │\n    │   ├───interfaces\n    │   │       IPayment.ts\n    │   │       IPaymentProvider.ts\n    │   │\n    │   ├───methods\n    │   │       CryptoPayment.ts\n    │   │       NetsPayment.ts\n    │   │       VisaPayment.ts\n    │   │\n    │   ├───providers\n    │   │       MockPaymentProvider.ts\n    │   │       TripleAPaymentProvider.ts\n    │   │\n    │   ├───requests\n    │   │       AccessTokenRequest.ts\n    │   │       PaymentRequest.ts\n    │   │\n    │   └───responses\n    │           AccessTokenResponse.ts\n    │           PaymentResponse.ts\n    │\n    └───security\n            AccessTokenManager.ts\n```\n\n\n## Installation and Setup\n\nTo successfully run the application, please follow the steps below:\n\n### Clone the Repository\n\n```\ngit clone https://github.com/ernitingarg09/CryptoPaymentMethod.git\n```\n   \nNavigate to the CryptoPaymentMethod folder.\n\n### Set up Docker Environment for Postgres\n\n```\ndocker-compose up -d\n```\n\t\n### Start the Server\n```\n npm install\n npm run start\n```\n\nDefault port is `5000`\n\t\n### Run the db Migration\n```\nnpm run migration:run \n```\n\n### Enviornment Configuration\nIf you need to override any default configuration settings, please update the [.env](.env) file located in the project's root directory. \nModify the values according to your specific environment.\n\n\n### Import Postman Collection\nDownload the [postman_collection.json](postman/postman_collection.json) file and import it into Postman.\n\n### Demo Video\nFor a visual demonstration of the application, please refer to the video provided below:\n\n[![Watch the video](demo/demo.jpg)](https://www.dropbox.com/s/clwtjzqgyene851/demo.mp4?dl=0)\n\n## Questions\n\n### How to Safely Manage API keys in production environment?\n\nTo ensure the security of API keys in a production environment, Here are some recommended approaches for securely managing API keys:\n\n#### Utilize Environment Variables: \nSet API keys as environment variables on the server hosting the application.\nCloud providers like Azure App Service provide configuration options specifically for managing environment variables.\n\n#### Secrets Management Tools:\nUse of secrets management tool provided by cloud platforms such as Azure Key Vault or AWS Secrets Manager. These tools offer secure storage and management of sensitive information, including API keys. \n\n### How to make docker container down?\n```\ndocker-compose down\n```\n\n### How to cleanup dockerized environment?\n```\ndocker-compose down -v --rmi all\n```\n\nThe above command should remove container, image, network and also the data volume. \n\n### How to connect to Postgres database manually?\n\n- Run below commands to connect to db container\n```\n  docker exec -it postgres bash\n  psql -U admin -d paymentdb\n```\n- To see all tables, run below command \n```\npaymentdb=# \\dt;\n\n              List of relations\n Schema |        Name        | Type  | Owner\n--------+--------------------+-------+-------\n public | migrations         | table | admin\n public | payment_collection | table | admin\n public | payment_method     | table | admin\n(3 rows)\n```\n\n- Run select query\n\n```\t\npaymentdb=# select * from payment_collection ;\n             payment_reference             | order_currency | order_amount |       expiry_date       |      notify_secret       |               access_token               | token_type | expires_in |\n                                                        hosted_url                                                                  | crypto_currency | crypto_amount\n-------------------------------------------+----------------+--------------+-------------------------+--------------------------+------------------------------------------+------------+------------+---------------------------------------------------------------------------------------------------------------------------------------------+-----------------+---------------\nvisa_d1adc71c-9995-40bc-a20c-1b5b6ba30295 | JPY            |         1.70 | 2023-07-18 14:50:04.056 | visa_notify_secret       | visa_access_token                        | Bearer     |       3600 | https://visa-hosted-url                                                                                                                     |                 |\nnets_385483fc-68c8-491e-84c4-e5a6b54fc242 | JPY            |         1.70 | 2023-07-18 14:50:24.447 | nets_notify_secret       | nets_access_token                        | Bearer     |       3600 | https://nets-hosted-url                                                                                                                     |                 |\nQEG-647143-PMT                            | JPY            |         1.70 | 2023-07-18 18:08:33.93  | neyPT6hQhCFc8Ft4WbeEjEfH | 498bc3981da2af79bba2019ceef765c760cdf45f | Bearer     |       1499 | https://app.triple-a.io/app/v1/payment_form?access_token=498bc3981da2af79bba2019ceef765c760cdf45f\u0026payment_reference=QEG-647143-PMT\u0026select=1 | testBTC         |    0.00000041\nTYP-857692-PMT                            | SGD            |         1.70 | 2023-07-18 18:08:41.793 | 1RFwMaNa060AYXp7hNtu6T4V | 081e0fcae1e3133d1d3e9cf02dc67b9561effff1 | Bearer     |       1499 | https://app.triple-a.io/app/v1/payment_form?access_token=081e0fcae1e3133d1d3e9cf02dc67b9561effff1\u0026payment_reference=TYP-857692-PMT\u0026select=1 | testBTC         |    0.00004284\n(6 rows)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fernitingarg%2Ftypescript-expressjs-postgres-typeorm-cryptopaymentmethod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fernitingarg%2Ftypescript-expressjs-postgres-typeorm-cryptopaymentmethod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fernitingarg%2Ftypescript-expressjs-postgres-typeorm-cryptopaymentmethod/lists"}