Skip to content

Latest commit

 

History

History

core-api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Core API Service

This service processes transactions when given a valid authentication token, an amount and a currency.

Authentication tokens are issued by the authentication service and are valid for 30 seconds.

Transactions are then processed by a PSP connector in the background via a message queue.

Dependencies

  • Python 3.9
  • Redis

Quickstart

Example:

$ python --version
Python 3.9.7
$ redis-cli ping
PONG
$ pip install -r requirements.txt
$ export HTTP_PORT=5000
$ export REDIS_URL=redis://127.0.0.1:6379/0
$ export JWT_SECRET=secret
$ python main.py
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

Environment variables

Environment variable Description
HTTP_PORT Required. Port to bind HTTP server. Default: 5000.
REDIS_URL Required. Redis URL. Default: redis://127.0.0.1:6379/0
JWT_SECRET Required. JSON Web Tokens secret. Must be the same as that of Auth API.

Endpoints

GET /health - Health check

Health check to see if the service is up.

Request

$ http -v http://0.0.0.0:5000/health
GET /health HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: 0.0.0.0:5001
User-Agent: HTTPie/2.6.0

Response

HTTP/1.0 200 OK
Content-Length: 30
Content-Type: application/json
Date: Thu, 04 Nov 2021 11:53:44 GMT
Server: Werkzeug/2.0.2 Python/3.9.7

{
    "checks": {},
    "status": "pass"
}

POST /transaction - Create a transaction

A valid authentication token generated by the Auth API is required. The enabled property of a user must be true.

Remember that authentication tokens are valid for 30 seconds.

Request

Argument Description
token Required. Valid authentication token from the Auth API.
amount Required. Amount to charge.
currency Required. Currency in ISO 4217 format. Example: GBP, USD.
$ http -v POST http://0.0.0.0:5000/transaction \
  amount=100 \
  currency=USD \
  token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6ImFsaWNlIiwiZW5hYmxlZCI6dHJ1ZSwiZXhwIjoxNjM1ODg0NzkzfQ.t4fLg-F8Ev3nwDED18OiQaqCOCzG7bgIO0s1AbFoRZo
POST /transaction HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 216
Content-Type: application/json
Host: 0.0.0.0:5000
User-Agent: HTTPie/2.6.0

{
    "amount": "100",
    "currency": "USD",
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6ImFsaWNlIiwiZW5hYmxlZCI6dHJ1ZSwiZXhwIjoxNjM1ODg0NzkzfQ.t4fLg-F8Ev3nwDED18OiQaqCOCzG7bgIO0s1AbFoRZo"
}

Response

HTTP/1.0 200 OK
Content-Length: 44
Content-Type: application/json
Date: Thu, 04 Nov 2021 11:57:11 GMT
Server: Werkzeug/2.0.2 Python/3.9.7

{
    "amount": 100,
    "currency": "USD",
    "user_id": 1
}