Skip to content

devnet-io/creditcard-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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"
      ]
    }
  ]
}

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 - Defines rules for validating different types of credit cards
  • 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 and the AWS CLI

  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): image
  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:

cd backend
npm install
npm run tests

Example results: image

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors