Skip to main content

This package allows you to easily track and manage generated links on the BTCPay Server for further use via invoices.

Project description

Django BTCPay Donation

django-btcpay-donation is a Django application designed to help you easily track and manage generated links on a BTCPay Server for use via invoices. It allows you to centrally store links, group them by location, and switch between different configurations through the Django admin panel, automatically injecting active links into your template context.

Features:

  • URL Management: Save and automatically format BTCPay URLs by overriding the domain and Store ID via Django settings.
  • Location Grouping: Map specific donation links to physical locations on your site (e.g., "Sidebar", "Footer").
  • Flexible Configurations: Create sets of link locations and switch the "Active" set globally with a single click.
  • Automatic Context Injection: A custom middleware provides your templates with active donation links without manual view updates.

Installation

Install the package via pip:

pip install django-btcpay-donation

Requirements:

  • Python >= 3.10
  • Django >= 5.2

Configuration

  1. Update settings.py

    Add the app label to your INSTALLED_APPS list to enable app:

    INSTALLED_APPS = [
        ...,
        'django_btcpay_donation.apps.BtcpaydonationConfig',
        ...,
    ]
    

    Add the middleware to your MIDDLEWARE list to enable template context injection:

    MIDDLEWARE = [
        ...,
        'django_btcpay_donation.middleware.BTCPayDonationMiddleware', 
        ...,
    ]
    
  2. (Optional) Global BTCPay Settings

    You can define global parameters for your BTCPay Server. If these are set, the application will automatically replace the domain and Store ID in any saved links to match these values:

    # The domain of your BTCPay Server
    BTCPAY_DOMAIN = "https://btc-node.of.by"
    # Your specific Store ID
    BTCPAY_STORE_ID = "YourStoreID"
    
  3. Database Migrations

    Run migrations to create the necessary database tables:

    python manage.py makemigrations
    python manage.py migrate
    

Usage

  1. In Admin Interface

    Use the Django Admin to manage your setup:

    • BTCPay Donation Links: Add your raw BTCPay invoice URLs.
    • BTCPay Donation Link Locations: Assign links to specific named locations (e.g., top_banner).
    • BTCPay Donation Configurations: Create a named group of locations.
    • BTCPay Donation Current Configuration: Select which configuration is currently "Live" on the site.
    1. Templates

    The middleware automatically adds donation_link_locations to your template context. You can loop through them like this:

    {% if isBTCPayDonationMiddlewareConnected %}
        {% for location in donation_link_locations %}
            <a href="{{location.link}}">
                Donate
            </a>
        {% endfor %}
    {% endif %}
    

    Or select the spefic one:

    {% if isBTCPayDonationMiddlewareConnected %}
        {% for location in donation_link_locations %}
            {% if location.linklocation_name == "FOOTER" %}
                <a href="{{location.link}}">
                    Donate
                </a>
            {% endif %}
        {% endfor %}
    {% endif %}
    

    Where is the FOOTER is a name of a location assigned in admin while creating BTCPay Donation Link Locations.

URL Logic

When a BTCPayDonationLink is saved, the application parses the URL:

  • It replaces the host with BTCPAY_DOMAIN if configured.
  • It updates the storeId query parameter with BTCPAY_STORE_ID if configured.
  • This ensures that even if you migrate your BTCPay Server or change stores, you only need to update your settings.py.

License

This project is licensed under the MIT License. Author: Tim The Webmaster - timachuduk@gmail.com

Project Links

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_btcpay_donation-0.0.4.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

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

django_btcpay_donation-0.0.4-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file django_btcpay_donation-0.0.4.tar.gz.

File metadata

  • Download URL: django_btcpay_donation-0.0.4.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for django_btcpay_donation-0.0.4.tar.gz
Algorithm Hash digest
SHA256 6d5655937919d566c61dfab5f3517a9e49f58bb80ea940f395a165a44b66f8d4
MD5 1ea6f08a0ed8b5ac52e33d468235a7d1
BLAKE2b-256 d27fcac94d5dd720f8fa0f0a247cefdead148d1e8bae8c51347e2fc2719a4486

See more details on using hashes here.

File details

Details for the file django_btcpay_donation-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_btcpay_donation-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d5d52ae8dff9687614d8ebce6fca8587afcfb89cd05aa469b3ff2e50f1e56575
MD5 931ab6207191c04b3f94e6dafcfbe14b
BLAKE2b-256 9c7567826aee43cfb55d992accfd6d2c53611984f53c8df981406907189f7ee4

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