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 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.2.tar.gz (17.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_btcpay_donation-0.0.2-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_btcpay_donation-0.0.2.tar.gz
  • Upload date:
  • Size: 17.7 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.2.tar.gz
Algorithm Hash digest
SHA256 1559be28a58b54b25e30653c976738edcce7d862a64ff132a0183ab34bc9998d
MD5 0625ee5266fccdd25fb7832d1539c1a2
BLAKE2b-256 4792806a1fb0018082bc39c12a04ca271bf2e1e44f6216caaeb1519ff2d0aba0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_btcpay_donation-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8dc33c5352a51bb1da48178449514eb4de4464b0cf14f0b80edc50f4e35a8405
MD5 1ae9c866ca5f59279a29f56e4dd25c01
BLAKE2b-256 934d80624ef0cf20e0537685add95b6d8324d6ea30c6599b9b93f4bfab9c6a0e

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