Try the validator out now!
- Visit the demo site: https://d2smo6zr9j53ei.cloudfront.net
- Start typing a credit card number
Or try calling the backend directly:
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:
{
"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"
]
}
]
}
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
- rules.ts - Defines rules for validating different types of credit cards
- cardValidator.ts - Logic to apply the validation rules to the card details
This project is intended to be deployed to AWS.
Deployment instructions:
-
Go through the authentication flow for the AWS CLI. Ensure the user/session has the necessary permissions.
-
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:
Run the tests via jest:
cd backend
npm install
npm run tests- 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

