Skip to main content

A plug-and-play Django library for accepting online payments via the Solana blockchain

Project description

Django Solana Payments

Documentation Status Coverage Status PyPI version Python versions License

A Django library for integrating Solana payments into your project. This library provides a flexible and customizable way to accept Solana payments with support for customizable models, an easy-to-use API, and management commands for processing online payments using the Solana blockchain.

Key Features

  • Transaction verification and automatic payment confirmation: Monitors the Solana blockchain, verifies incoming transactions, and automatically confirms payments when the expected amount is received.
  • Multi-token support (SOL and SPL tokens): Configure a list of active payment tokens (for example, SOL and USDC) and the library will use them for pricing and verification flows.
  • Flexibility and customization: Use your own custom models for payments and tokens to fit your project's needs. Add custom logic using signals or callabacks.
  • Ease of integration: Provides ready-to-use endpoints that can be used in existing DRF applications, or ready-to-use methods for Django applications that are not part of DRF.
  • Security and encryption: Provides an out-of-the-box encryption mechanism that helps keep one-time payment wallets secure.
  • Management commands: Includes management commands for handling expired payments and sending funds from one-time wallets.

Documentation

See the full documentation at https://django-solana-payments.readthedocs.io/

Installation

  1. Install the package

    pip install django-solana-payments
    

    For DRF support, which provides API endpoints for creating and managing payments, install the drf extra:

    pip install "django-solana-payments[drf]"
    

    This provides ready-to-use API endpoints for creating and managing payments.

  2. Configure settings.py

    INSTALLED_APPS = [
        ...,
        'django_solana_payments',
    ]
    
    SOLANA_PAYMENTS = {
        "RPC_URL": "https://api.mainnet-beta.solana.com",
        "RECEIVER_ADDRESS": "YOUR_WALLET_ADDRESS", # Wallet that receives funds
        "FEE_PAYER_KEYPAIR": "WALLET_KEYPAIR", # Wallet keypair that pays network fees (address will be derived from the keypair)
        # FEE_PAYER_ADDRESS is derived from FEE_PAYER_KEYPAIR; you don't normally need to set it separately.
        "ONE_TIME_WALLETS_ENCRYPTION_ENABLED": True, # Enables encryption for one-time payments wallets
        "ONE_TIME_WALLETS_ENCRYPTION_KEY": "ONE_TIME_WALLETS_ENCRYPTION_KEY", # Generate with the Fernet.generate_key()
        "SOLANA_PAYMENT_MODEL": "payments.CustomSolanaPayment", # Custom model for solana payment
        "PAYMENT_CRYPTO_TOKEN_MODEL": "payments.CustomPaymentToken", # Custom model for solana payment token
        "RPC_COMMITMENT": "Confirmed", # RPC Commitment
        "PAYMENT_ACCEPTANCE_COMMITMENT": "Confirmed", # Commitment for payment acceptance
        "MAX_ATAS_PER_TX": 8, # Max associated token accounts to create/close per transaction (needed for oen time wallets creation)
        "PAYMENT_VALIDITY_SECONDS": 30 * 60, # Payment validity window in seconds (default: 30 minutes)
    }
    
  3. Migrate and Route

python manage.py migrate
# Add this to your urls.py
urlpatterns = [
    path('solana-payments/', include('django_solana_payments.urls')),
]
  1. Open the admin panel and create payment token records, specifying the correct mint addresses for SPL tokens.

Integration in 3 simple steps

Start accepting Solana payments with a fast, production-ready flow designed for real checkout UX.

Integration flow

Typical API flow:

  1. Call POST /solana-payments/initiate/ to create a payment and receive payment_address.
  2. Show that address/QR code to the payer, then the payer sends funds to the payment_address.
  3. Poll GET /solana-payments/verify-transfer/{payment_address}?token_type=... until status becomes confirmed or finalized.

Common UI examples:

  • Connect crypto wallet -> show payment summary in the wallet extension -> user signs and sends transaction -> app checks payment status.
  • Open wallet app (Phantom/Solflare/mobile wallet) -> scan the QR code -> send expected amount -> return to your app -> app payment checks status.

Optionally call GET /solana-payments/payments/{payment_address}/ for details.

Demo

Postman demo

Running the Example Project

The included example project provides a demonstration of how to use the library and what it can do. To run it:

  1. Navigate to the example project directory

    cd examples/demo_project
    
  2. Install dependencies

    pip install -r requirements.txt
    
  3. Run migrations

    python mange.py makemigrations
    python manage.py migrate
    
  4. Start the development server

    ./dev_server.sh
    

Running Tests

To run the tests for the library:

  1. Install test dependencies

    pip install pytest pytest-django
    
  2. Run the tests

    pytest
    

License

This package is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md for setup instructions, testing, feature proposals, and pull request guidelines.

If you find this project useful, consider giving it a star to support its development!

Developer Guide

Local setup

  1. Clone the repository and create a virtual environment:

    git clone https://github.com/Artemooon/django-solana-payments.git
    cd django-solana-payments
    python -m venv .venv
    source .venv/bin/activate
    
  2. Install development dependencies:

    pip install -e ".[dev,docs,drf]"
    
  3. Run tests:

    pytest
    

Install pre-commit

Install and enable git hooks:

pip install pre-commit # (if not installed)
pre-commit install

Release process

  1. Bump version in pyproject.toml.

  2. Commit and tag:

    git add -A
    git commit -m "Release x.y.z"
    git tag vx.y.z
    git push origin main --tags
    

The GitHub Release workflow publish automatically on pushed tags.

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

django_solana_payments-0.2.2.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_solana_payments-0.2.2-py3-none-any.whl (68.8 kB view details)

Uploaded Python 3

File details

Details for the file django_solana_payments-0.2.2.tar.gz.

File metadata

  • Download URL: django_solana_payments-0.2.2.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_solana_payments-0.2.2.tar.gz
Algorithm Hash digest
SHA256 6532c5973de1b130338ede4bfd5479a9f23632bd48e743562b0c3125c5375574
MD5 3bdaa0819cf093a51cba7475e4602a19
BLAKE2b-256 ff71064df5a728e5fe73db17fdea7916392d4c63ce968b670d61f81665c4c683

See more details on using hashes here.

File details

Details for the file django_solana_payments-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_solana_payments-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 411d57d4f51596f7e752192fdaba91dd2c35eb6b506042d5e94cbd429ca5f447
MD5 10d1625b41fbcc88d7b8fcdc264a29ee
BLAKE2b-256 2f531942bff8ae311eb78100f553c01adac7d659d5b57633921981c827250648

See more details on using hashes here.

Supported by

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