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.

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. If you encounter a bug, have a feature request, or see an opportunity for improvement, please open an issue to discuss it. Pull requests are also welcome.

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.1.2.tar.gz (43.7 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.1.2-py3-none-any.whl (68.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_solana_payments-0.1.2.tar.gz
  • Upload date:
  • Size: 43.7 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.1.2.tar.gz
Algorithm Hash digest
SHA256 675005199085ca9aa67e4d4c47581a9a003a3754bcd93ba1f7285e953f9448f9
MD5 e653b454c3d22500b23cb0c6b4831fbb
BLAKE2b-256 b34a5910e5a960b2979542a23fa3b4fed88e9bf136aba01dcfc8f891f77686f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_solana_payments-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 10c2ebfa0f01e85cd07318d30b5c348f21aea8f124f885d18b9a7ef4717e6dcb
MD5 63b9f9e74bd308175b82714622188698
BLAKE2b-256 81920ea9efa043c8983cb8a080841dab1ae3d71082788007de281eb7c2fa750c

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