Skip to content

Latest commit

 

History

History

transaction-api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Transaction Service

This services processes transactions 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 loyalty worker in the background via a message queue.

Dependencies

  • Python 3.6+
  • Redis

Quickstart

Example:

$ python --version
Python 3.6.0
$ 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=supersecret
$ python run.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 http://127.0.0.1:5000/health
GET /health HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: 127.0.0.1:5000
User-Agent: HTTPie/0.9.8

Response

HTTP/1.0 200 OK
Content-Length: 22
Content-Type: application/json
Date: Thu, 24 Feb 2017 12:00:00 GMT
Server: Werkzeug/0.11.15 Python/3.6.0

{
    "healthy": true
}

POST /transactions - Create a transaction

A valid authentication token generated by the Auth API is required. The can_transact 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.

Example:

$ http --form post http://127.0.0.1:5000/transactions \
    amount=2000 \
    currency=GBP
    token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6ImFsaWNlIiwiY2FuX3RyYW5zYWN0Ijp0cnVlLCJleHAiOjE0ODc5MzY4NzF9.5XC95XPFzvsi84vkJ9vp46fV1p3pHx70TSiNln7i2WM \
POST /transactions HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 204
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: 127.0.0.1:5000
User-Agent: HTTPie/0.9.8

amount=2000&currency=GBP&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6ImFsaWNlIiwiY2FuX3RyYW5zYWN0Ijp0cnVlLCJleHAiOjE0ODc5MzY4NzF9.5XC95XPFzvsi84vkJ9vp46fV1p3pHx70TSiNln7i2WM

Response

HTTP/1.0 200 OK
Content-Length: 60
Content-Type: application/json
Date: Fri, 24 Feb 2017 12:00:00 GMT
Server: Werkzeug/0.11.15 Python/3.6.0

{
    "amount": 2000,
    "currency": "GBP",
    "user_id": 1
}