Simple PEPECOIN payment gateway via FastAPI
Project description
** ๐ธ Pepecoin Payment Gateway**
Pepecoin Payment Gateway is a Python-based backend server built using FastAPI to handle transactions, monitor payments, and automate order management for applications and merchants accepting Pepecoin cryptocurrency payments.
Features
- ๐ FastAPI: High-performance API implementation with OpenAPI documentation.
- ๐ณ Payment Processing: Automatically generate payment addresses, monitor transactions, and confirm payments.
- ๐ Order Management: Create, list, cancel, and track orders with real-time updates.
- ๐ง Customizable: Add metadata and descriptions to orders for better tracking.
- ๐ Secure: API key authentication and secure database storage.
- ๐ Transaction Monitoring: Automatic transaction validation with Pepecoin blockchain.
Installation
Prerequisites
- Python 3.7+
- A running Pepecoin full node with RPC enabled, or access to a Pepecoin blockchain API.
- PostgreSQL or another supported database.
Step 1: Install the Library
Install the package via pip:
pip install pepecoin
Step 2: Set Up Environment Variables
Create a .env
file in the project root:
DATABASE_URL=postgresql://user:password@localhost/pepecoin_db
PEPECOIN_RPC_URL=http://localhost:12345/
PEPECOIN_RPC_USER=your_rpc_username
PEPECOIN_RPC_PASSWORD=your_rpc_password
API_KEY=your_api_key_here
Step 3: Initialize the Database
Run database migrations to set up tables:
alembic upgrade head
Step 4: Start the Server
Run the FastAPI server:
uvicorn app.main:app --host 0.0.0.0 --port 8000
The server will start on http://localhost:8000
.
Endpoints
1. Create an Order
- POST
/v1/orders
- Request:
{
"amount": 10.5,
"currency": "PEPE",
"description": "Purchase of digital artwork",
"customer_email": "customer@example.com",
"metadata": {
"order_number": "12345"
}
}
- Response:
{
"order_id": "ord_123456789",
"payment_address": "PpK1q2w3e4r5t6y7u8i9o0pLkJhGfDsA",
"amount_due": 10.5,
"amount_paid": 0.0,
"status": "Pending",
"created_at": "2023-10-15T12:34:56Z",
"expires_at": "2023-10-15T13:34:56Z",
"transactions": [],
"metadata": {
"order_number": "12345"
}
}
2. Retrieve Order Details
- GET
/v1/orders/{order_id}
- Response:
{
"order_id": "ord_123456789",
"payment_address": "PpK1q2w3e4r5t6y7u8i9o0pLkJhGfDsA",
"amount_due": 10.5,
"amount_paid": 10.5,
"status": "Paid",
"created_at": "2023-10-15T12:34:56Z",
"expires_at": "2023-10-15T13:34:56Z",
"transactions": [
{
"txid": "b6f6991d3c...e8e8e8e8e8",
"amount": 10.5,
"confirmations": 3,
"timestamp": "2023-10-15T12:35:00Z"
}
],
"metadata": {
"order_number": "12345"
}
}
3. List Orders
- GET
/v1/orders
- Query Parameters:
status
(Optional): Filter by order status (e.g.,Pending
,Paid
).limit
(Optional): Number of results to return (default: 20).offset
(Optional): Pagination offset (default: 0).
4. Cancel an Order
- DELETE
/v1/orders/{order_id}
- Response:
{
"order_id": "ord_123456789",
"status": "Cancelled"
}
Development
Project Structure
pepecoin_payment_gateway/
โโโ app/
โ โโโ main.py # Entry point of the application
โ โโโ api/ # API routes and dependencies
โ โโโ models/ # Database models
โ โโโ schemas/ # Pydantic schemas for requests/responses
โ โโโ services/ # Business logic and Pepecoin node interactions
โ โโโ db.py # Database initialization
โ โโโ config.py # Configuration and environment variables
โ โโโ utils.py # Helper utilities
โโโ alembic/ # Database migrations
โโโ tests/ # Unit and integration tests
โโโ requirements.txt # Python dependencies
โโโ README.md # Project documentation
โโโ .env # Environment variables (do not commit this!)
โโโ .gitignore # Git ignore file
Testing
- Install testing dependencies:
pip install pytest pytest-cov
- Run tests:
pytest --cov=app tests/
Deployment
Docker Deployment
Use Docker to containerize the application for easier deployment.
- Build the Docker image:
docker build -t pepecoin-payment-gateway .
- Run the container:
docker run -p 8000:8000 --env-file .env pepecoin-payment-gateway
Production Ready
- Use Gunicorn with Uvicorn workers for production.
- Deploy behind a reverse proxy (e.g., Nginx) for SSL termination.
Contributing
Contributions are welcome! Follow these steps to contribute:
- Fork the repository.
- Create a new feature branch:
git checkout -b feature/my-feature
. - Commit your changes:
git commit -m 'Add some feature'
. - Push to the branch:
git push origin feature/my-feature
. - Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE
file for details.
Acknowledgments
- Thanks to the Pepecoin community for blockchain insights.
- Built with โค๏ธ using FastAPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pepecoin-0.0.0.tar.gz
.
File metadata
- Download URL: pepecoin-0.0.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8af39a963b2df92ae0cac9c24cc77ea660c4e2d8d7bff42eb2e43d700fca3e7 |
|
MD5 | e24cc9bebb80bdbd7c6d48d29b079855 |
|
BLAKE2b-256 | dcaa69366948b0b0ea29e7eda8def92241a09c838df91246b63d004ec67c4782 |
File details
Details for the file pepecoin-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: pepecoin-0.0.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ed13fb5a1932c0117439a81f42fd1fa8d3e75fb0b31fe0d4d246b5949e687ab |
|
MD5 | 623a34b9576d8117f801827ec0d66a14 |
|
BLAKE2b-256 | d929101274f9859a42a0caf5c6cb0a84b4dd5e69c1fa0728f42b8f71be71bebb |