Package: bull
WTF isbull?On a Friday evening, not too long ago, I was lamenting the shortcomings
of the various services I’ve used to sell my digital book from my
personal website.Digital goods sales should be a solved problem by
now, but I ran into all sorts of issues when trying to send updates to
customers and integrate properly with Google Analytics.Long
storyshort, I took two hours and wrote a replacement using Python, Flask,
SQLAlchemy, and Stripe (as the payment processor).bullis to set upon your own domain. Why does the fact thatbullruns on your own
domain matter? Because it makes Google Analytics happy and report
conversions properly.The only things you need to get started usingbullare a Stripe
account (free) and a web server (free?).Installationpip install bull. This installs thebullcommand, which helps
setup your environmentbull setup. This creates a directory namedbullwith the
following contents:app.py: the main application script.get_appcan be used to
runbullas a WSGI applicationconfig.py:bull’s configuration file. This must be edited to
contain your installation-specific configuration details.filesdirectory: The directory that contains the files for your
digital productsAdd product entries to the database (usescripts/populate_dbas a
model)(Optional) Create an admin user for viewing/reportsby runningscripts/create_user.pyAddbullto your web server’s configurationProfit! (…literally)Analytics and Loginbullsupports simple sales analytics at the/reportsendpoint.
It requires authorization, which in turn requires you to create (at
least one) user using thescripts/create_user.pyscript. To see the
reports, hit/login, log in, and from then on you can go directly to/reportsto see reporting data. You should be good to go after that,
and no one else will be able to see the reports.If for some reason you need to logout, there is also a/logoutendpoint which will log you out (which should use HTTP POST instead of
GET, but whatever).Reporting includes:Email addresses and sales totals of recent purchasesSales data broken down by calendar daySales charts based on revenue/units sold per dayOverriding Default TemplatesSimply create atemplatesdirectory and create a file of the same
name as the template you want to replace.Testingbullhas a (small) suite of tests that are run via TravisCI, but can
(and should) also be tested manually once installed. Runpython app.pyand browse tohttp://localhost:5000/test/1. You should
see a single “Buy” button, which should be completely functional
(assuming you have at least one product in your database). Enter
Stripe’s test credit card number (4242 4242 4242 4242). You should be
successfully directed to a “success.html” page with your download link.
If your product is in thefilesdirectory, you’ll be able to
download it by clicking the link.DeploymentDon’t run ``app.py`` in production.The web server it uses is not
meant for such a purpose. Instead, deploy as you would normally deploy
an WSGI application. SeeFlask’s
documentationon the
subject.TODOStill need to add better documentation and (possibly) deployment
information. All of this is coming. I just wanted to getbullout as
fast as possible so that those who know what they’re doing can make use
of it.