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.3.tar.gz (17.8 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.3-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_btcpay_donation-0.0.3.tar.gz
  • Upload date:
  • Size: 17.8 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.3.tar.gz
Algorithm Hash digest
SHA256 f3376d78ee1c9a2ea14672d6dbcc55855318828594c4a0308522ee77de8ca04c
MD5 9596f52bf8505fb8dd89aad29c0892e7
BLAKE2b-256 ad5700216f1c853dcee94d57980073e9ce9d1b5577208eae4e9d4731a31b4754

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_btcpay_donation-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b651ef32455b5db43a48ccf16dd8956a227e381e2933eb2a67c1de86e5621a3f
MD5 c58afbccd6f2a9bdc3625112e5282515
BLAKE2b-256 df6aed0f501bdee91e54b67c3c2b8061860d4f47b1f0f6bbddbe5e9296bc7084

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