/valex-API

Valex is a voucher card API. The API is responsible for creating, reloading, activating, as well as processing purchases.

Primary LanguageTypeScript

Valex API 💳

Table of Contents

Project Description

Valex is a voucher card API. The API is responsible for creating, reloading, activating, as well as processing purchases.

status-finished

Technologies

TypeScript NodeJS Express.js Postgres

Running the project

  1. Clone the repository:

    git clone https://github.com/akiraTatesawa/valex-API.git
  2. Navigate to the project directory:

    cd valex-API
  3. Install the dependencies:

    npm install
  4. Navigate to the postgres db directory and install the database:

    cd src/dbStrategy/postgres/database
    
    bash ./create-database 
  5. Set your environment variables following the .env.sample file:

    Notes: PORT must be a number, DATABASE_URL and CRYPTR_SECRET_KEY must be strings

     PORT=
     DATABASE_URL=
     CRYPTR_SECRET_KEY=
  6. Run the project on dev mode

    npm run dev

Features

Notes:

  • cardType must only assume the following values: 'groceries', 'restaurants', 'transport', 'education', 'health';
  • employeeId must be a valid employee id;
  • x-api-key must be a valid company key;
  • password must be a string made up of four numbers;
  • CVC must be a string made up of 3 numbers and must be a valid card CVC;
  • amount must be an integer greater than zero;

Card Creation

  • Endpoint:
    POST /cards/create
  • Request Body:
    {
     "cardType": "health",
     "employeeId": 2
    }
  • Request Header: x-api-key: "key.example.123"
  • Response Example:
    {
      "cardId": 3,
      "number": "7175-2620-5613-5534",
      "cardholderName": "CICLANA M MADEIRA",
      "securityCode": "074",
      "expirationDate": "09/27",
      "type": "health"
    }

Card Activation

  • Endpoint:
    PATCH /cards/:cardId/activate
  • Request Body:
    {
     "password": "1234",
     "CVC": "123"
    }

Card Blocking

  • Endpoint:
    PATCH /cards/:cardId/block
  • Request Body:
    {
     "password": "1234"
    }

Card Unblocking

  • Endpoint:
    PATCH /cards/:cardId/unblock
  • Request Body:
    {
     "password": "1234"
    }

Card Recharge

  • Endpoint:
    POST /cards/:cardId/recharge
  • Request Body:
    {
     "amount": 1000
    }
  • Request Header: x-api-key: "key.example.123"

Card Balance

  • Endpoint:
    GET /cards/:cardId/balance
  • Response Example:
    {
        "balance": 800,
        "transactions": [
            {
                "id": 2,
                "cardId": 3,
                "businessId": 5,
                "timestamp": "2022-09-05T04:29:35.000Z",
                "amount": 200,
                "businessName": "Unimed"
            }
        ],
        "recharges": [
            {
                "id": 1,
                "cardId": 3,
                "timestamp": "2022-09-05T04:28:12.000Z",
                "amount": 1000
            }
        ]
    }

POS Payment

Notes: The card type must be the same as the business type.

  • Endpoint:
    POST /payments/pos
  • Request Body:
    {
     "cardId": 2,
     "password": "1234",
     "businessId": 5,
     "amount": 100
    }

Online Payment

Notes: The card type must be the same as the business type.

  • Endpoint:
    POST /payments/online
  • Request Body:
    {
     "cardInfo": {
         "cardNumber": "7175-2620-5613-5534",
         "cardholderName": "CICLANA M MADEIRA",
         "expirationDate": "09/27",
         "CVC": "053"
     },
     "businessId": 5,
     "amount": 100
    }

Virtual Card Creation

  • Endpoint:
    POST /cards/virtual/create
  • Request Body:
    {
     "originalCardId": 2,
     "password": "1234"
    }
  • Response Example:
    {
      "cardId": 3,
      "number": "6771-8953-1311-4172",
      "cardholderName": "CICLANA M MADEIRA",
      "securityCode": "094",
      "expirationDate": "09/27",
      "type": "health"
    }

Virtual Card Deletion

  • Endpoint:
    DELETE /cards/virtual/delete
  • Request Body:
    {
     "virtualCardId": 3,
     "password": "1234"
    }