Skip to main content

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

  1. Install testing dependencies:
pip install pytest pytest-cov
  1. Run tests:
pytest --cov=app tests/

Deployment

Docker Deployment

Use Docker to containerize the application for easier deployment.

  1. Build the Docker image:
docker build -t pepecoin-payment-gateway .
  1. 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:

  1. Fork the repository.
  2. Create a new feature branch: git checkout -b feature/my-feature.
  3. Commit your changes: git commit -m 'Add some feature'.
  4. Push to the branch: git push origin feature/my-feature.
  5. 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

pepecoin-0.0.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

pepecoin-0.0.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

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

Hashes for pepecoin-0.0.0.tar.gz
Algorithm Hash digest
SHA256 d8af39a963b2df92ae0cac9c24cc77ea660c4e2d8d7bff42eb2e43d700fca3e7
MD5 e24cc9bebb80bdbd7c6d48d29b079855
BLAKE2b-256 dcaa69366948b0b0ea29e7eda8def92241a09c838df91246b63d004ec67c4782

See more details on using hashes here.

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

Hashes for pepecoin-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ed13fb5a1932c0117439a81f42fd1fa8d3e75fb0b31fe0d4d246b5949e687ab
MD5 623a34b9576d8117f801827ec0d66a14
BLAKE2b-256 d929101274f9859a42a0caf5c6cb0a84b4dd5e69c1fa0728f42b8f71be71bebb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page