A Dockerized Flask application for managing OpenPAYGO devices, generating tokens, and handling credit updates. It uses the OpenPAYGO Python library and exposes a PaygOps compatible Device API for OpenPAYGO devices.
- Docker installed on your system
- (Optional) PostgreSQL database for production use
-
Copy the example environment file:
cp example.env .env
-
Edit
.envand configure the following variables:API_BEARER_TOKEN: Bearer token for API authentication. Leave empty to disable authentication (for development only).
CSV_UPLOAD_USERNAME: Username for the CSV upload web interface (default:admin)CSV_UPLOAD_PASSWORD: Password for the CSV upload web interface (default:admin)
For SQLite (default, for development):
DB_PROVIDER: Set tosqliteor leave unsetSQLITE_FILE: Path to SQLite database file (default:openpaygo.db)
For PostgreSQL (recommended for production):
DB_PROVIDER: Set topostgresDB_HOST: PostgreSQL host (default:localhost)DB_USER: PostgreSQL username (default:postgres)DB_PASSWORD: PostgreSQL passwordDB_NAME: Database name (default:openpaygo)
Example
.envfile:API_BEARER_TOKEN=your-secure-api-token-here CSV_UPLOAD_USERNAME=admin CSV_UPLOAD_PASSWORD=your-secure-password DB_PROVIDER=postgres DB_HOST=localhost DB_USER=postgres DB_PASSWORD=your-db-password DB_NAME=openpaygo
make buildOr manually:
docker build -t openpaygo-docker .Interactive mode (foreground):
make upOr manually:
docker run --rm -p 5001:8000 --env-file .env --name openpaygo-docker openpaygo-dockerDaemon mode (background):
make up_daemonOr manually:
docker run -d -p 5001:8000 --env-file .env --name openpaygo-docker openpaygo-dockerThe application will be available at http://localhost:5001
docker stop openpaygo-dockerBy default, the application uses SQLite, which stores data in a file. The database file is created automatically when the container starts. If using SQLite, the database file will be stored inside the container.
To persist SQLite data across container restarts, mount a volume:
docker run --rm -p 5001:8000 --env-file .env -v $(pwd)/data:/app/data --name openpaygo-docker openpaygo-dockerThen set SQLITE_FILE=/app/data/openpaygo.db in your .env file.
- Ensure PostgreSQL is running and accessible
- Create a database (if it doesn't exist):
CREATE DATABASE openpaygo;
- Configure the database connection in your
.envfile as shown above - The application will automatically create the necessary tables on first run
Note: If running PostgreSQL in Docker, ensure the database container is on the same network or use the host's IP address.
- Start the application (see "Running with Docker" above)
- Navigate to
http://localhost:5001/upload-devicesin your browser - Log in using the credentials configured in
CSV_UPLOAD_USERNAMEandCSV_UPLOAD_PASSWORD - Upload a CSV file with the following columns (case-insensitive):
- Serial Number: Unique device identifier
- Starting Code: Starting code/seed for token generation
- Key: 32-hex-character OpenPAYGO secret key
- Count: Token count
- Time Divider: Value divider for token generation
- Restricted Digit Mode: Whether to use restricted digit set (true/false)
- Hardware Model: Device model name
- Version: (optional, ignored)
- Test Code: (optional, ignored)
The CSV upload interface will display the results of the import, including any errors or successful imports.
You can also upload devices programmatically using the REST API. Refer to the API documentation for endpoint details.
For instructions on how to connect this application to PAYGOPS, please refer to the PAYGOPS documentation.
Run the test suite:
make testOr manually:
docker run --rm openpaygo-docker pytest tests/