https://github.com/devnet-io/creditcard-validator
https://github.com/devnet-io/creditcard-validator
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/devnet-io/creditcard-validator
- Owner: devnet-io
- Created: 2025-02-13T15:14:35.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-13T15:30:58.000Z (over 1 year ago)
- Last Synced: 2025-02-13T16:37:19.656Z (over 1 year ago)
- Language: TypeScript
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# creditcard-validator
## Demo
Try the validator out now!
1. **Visit the demo site: https://d2smo6zr9j53ei.cloudfront.net**
2. Start typing a credit card number

Or try calling the backend directly:
```bash
curl 'https://4zi58jxkw7.execute-api.us-east-1.amazonaws.com/api/validateCreditCard' -X POST -H 'Content-Type: application/json' -s --data-raw '{"number":"6011000990139424","expirationDate":"12/29","cvc":"000"}'
```
Example result:
```json
{
"isValid": true,
"details": [
{
"label": "American Express",
"isValid": false,
"errors": [
"Invalid card number length",
"Invalid card number prefix"
]
},
{
"label": "Diners Club",
"isValid": false,
"errors": [
"Invalid card number length",
"Invalid card number prefix"
]
},
{
"label": "Discover",
"isValid": true,
"errors": []
},
{
"label": "MasterCard",
"isValid": false,
"errors": [
"Invalid card number prefix"
]
},
{
"label": "Visa",
"isValid": false,
"errors": [
"Invalid card number prefix"
]
}
]
}
```
## Structure
The project is divided into three folders / apps:
* backend
* **Purpose**: hosts REST API with credit card validator endpoint
* **Tech**: Node + Express app, run via AWS Lambda
* frontend
* **Purpose**: hosts UI to demo validation service
* **Tech**: React app, run via AWS Cloudfront + S3
* infra
* Terraform IAC to deploy both apps
### Points of Interest
* [rules.ts](https://github.com/devnet-io/creditcard-validator/blob/main/backend/src/validation/rules.ts) - Defines rules for validating different types of credit cards
* [cardValidator.ts](https://github.com/devnet-io/creditcard-validator/blob/main/backend/src/validation/cardValidator.ts) - Logic to apply the validation rules to the card details
## Deployment
This project is intended to be deployed to AWS.
Deployment instructions:
1. Install [Terraform](https://developer.hashicorp.com/terraform/install?product_intent=terraform) and the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
2. Go through the authentication flow for the AWS CLI. Ensure the user/session has the necessary permissions.
* Example permissions needed (illustrative only, this is insecure):

3. Run ```bash up.sh```
That's it! Terraform will take care of creating the resources and will output URLs for the backend and frontend projects when its finished:
## Testing
Run the tests via jest:
```bash
cd backend
npm install
npm run tests
```
Example results:

## Unfinished Business
* Input validation for APIs
* Error handling for APIs
* More reasonable unit test coverage (single "integration" test exists)
* Refine frontend components, seperate into presentational components and logic ones