Valex is a voucher card API. The API is responsible for creating, reloading, activating, as well as processing purchases.
-
Clone the repository:
git clone https://github.com/akiraTatesawa/valex-API.git
-
Navigate to the project directory:
cd valex-API
-
Install the dependencies:
npm install
-
Navigate to the postgres db directory and install the database:
cd src/dbStrategy/postgres/database bash ./create-database
-
Set your environment variables following the .env.sample file:
Notes:
PORT
must be a number,DATABASE_URL
andCRYPTR_SECRET_KEY
must be stringsPORT= DATABASE_URL= CRYPTR_SECRET_KEY=
-
Run the project on dev mode
npm run dev
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;
- 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" }
- Endpoint:
PATCH /cards/:cardId/activate
- Request Body:
{ "password": "1234", "CVC": "123" }
- Endpoint:
PATCH /cards/:cardId/block
- Request Body:
{ "password": "1234" }
- Endpoint:
PATCH /cards/:cardId/unblock
- Request Body:
{ "password": "1234" }
- Endpoint:
POST /cards/:cardId/recharge
- Request Body:
{ "amount": 1000 }
- Request Header:
x-api-key: "key.example.123"
- 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 } ] }
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 }
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 }
- 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" }
- Endpoint:
DELETE /cards/virtual/delete
- Request Body:
{ "virtualCardId": 3, "password": "1234" }