Examples
Description
This application helps manage all donation links generated on your own Bitcoin node, based on BTCPay Server. It has minimal installation requirements, is managed via database entries, and is easily hosted and placed on your website.
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 and Set up
Install the package via pip:
Then you need to update the settings.py file, add the app in INSTALLED_APPS:
Then add the middleware to your MIDDLEWARE list to enable template context injection:
You also can define global parameters for your BTCPay Server. If they are set, the application will automatically replace the domain and store ID in any saved links to match these values:
There is only one thing left, and it is database migration:
Usage
Set up locations in templates
First of all, you need to select and insert code snippets into your website structure. That is whenever you want to be able to see a donation button. It is important to note that this package did not provide any default templates to display any button, so you need to create one on your own.
And then use it like this:
Please note that "FOOTER" is just a definitive name to know where this button will appear. You can type any name as you wish and as you think is necessary.
Or if you wish to add some default fallback if there is no location added:
And do not forget to load the checkLocation template tag, shipped with the package.
Let's just discuss the flow of how to add new donation buttons in your Django app. First of all, always check if middleware is connected in the first place, that is, isBTCPayDonationMiddlewareConnected. Then use the automatically added in the template context the donation_link_locations.
When looping through, via the for tag or using the template tag checkLocation, it doesn't matter. You will obtain a location object with two properties:
- link - actual saved link
- linklocation_name - a location name to check
Records and model configuration
Now, you have all the needed locations set up, and then you need to create a configuration links, and the link's location. To do this, log in to your admin panel and:
- BTCPayDonationLink: Add your raw BTCPay invoice URLs.
- BTCPayDonationLinkLocation: Assign links to specific named locations (e.g., FOOTER).
- BTCPayDonationConfiguration: Create a named group of locations. Plus select created locations
- BTCPayDonationCurrentConfiguration: Select which configuration is currently "Live" on the site.
Everything is set up and configured, and you must see immediate results, that is, donation links pointing to invoices.
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.
Reviews
(0)