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.
- Python 3.6+
- Redis
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 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. |
Health check to see if the service is up.
$ 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
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
}
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.
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¤cy=GBP&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6ImFsaWNlIiwiY2FuX3RyYW5zYWN0Ijp0cnVlLCJleHAiOjE0ODc5MzY4NzF9.5XC95XPFzvsi84vkJ9vp46fV1p3pHx70TSiNln7i2WM
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
}