$ git clone https://github.com/MissionBit/mb-text-donation
$ cd mb-text-donation
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
PUBLISHABLE_KEY
, SECRET_KEY
, WEBHOOK_SIGNING_SECRET
, APPINSIGHTS_INSTRUMENTATIONKEY
, and SENDGRID_API_KEY
$ FLASK_APP=application.py FLASK_DEBUG=1 flask run
Navigate to http://localhost:5000/ to test. You can also use a donation amount as the path, e.g. http://localhost:5000/123/ to prefill a $123 donation. The frequency can also be prefilled, e.g. http://localhost:5000/123/?frequency=monthly.
Currently, the only automated tests are doctests for the parse_cents module. These can be run with:
$ python parse_cents.py
…
Use the Stripe CLI to listen for webhooks while testing to ensure that emails are processed correctly.
$ stripe listen --forward-to=http://localhost:5000/hooks
> Ready! Your webhook signing secret is … (^C to quit)
For Python we are using the Flask web framework.
In JavaScript and CSS we are currently not using any framework at all. The application is not yet large enough to justify an asset pipeline.
We should keep an eye on making the front-end compatible with older browsers, particularly Android phones.
Ideally, our code would be automatically formatted. Here are the tools I'd recommend:
I would like to have, but don't know the right formatting tools for:
We should also consider adding linting (pylint, eslint) or even static type analysis (mypy, flow).
Deployment is currently done manually by pushing a master branch directly to the azure app
service. You can find the git URL and deployment credentials from
portal.azure.com, finding the mb-text-donation
App Service, and
look under the Deployment Center section. A typical workflow might look something like this:
$ git pull origin
$ git push azure master
In the future, this should really be automated with CI. Probably Azure DevOps.
We should consider having automated tests and a staging deployment or review apps, although we wouldn't be much worse off if master was automatically deployed as-is.
In https://dashboard.stripe.com/webhooks, you should add an
endpoint to the canonical host https://donate.missionbit.org/hooks for
checkout.session.completed
events and make note of the signing secret
for use with the WEBHOOK_SIGNING_SECRET
environment variable.
For recurring donations, the app expects that there be a monthly plan
with the id mb-monthly-001
that is $0.01/mo. In our Mission Bit account,
this plan should already be present in both test and live mode.
In the Azure Portal, go to the configuration for mb-text-donation and set any environment variables as Application Settings.
The CANONICAL_HOST
environment variable can be used when the app is hosted behind
an Azure Verizon Premium CDN to ensure visitors are redirected to a specific HTTPS url.
In production this is set to donate.missionbit.org
.
Alternative domains that should not get redirected may also be included, e.g.
CANONICAL_HOST=donate.missionbit.org gala.missionbit.org
When a request to https://donate.missionbit.org/ comes in, it is routed to the
mb-text-donation
Front Door endpoint, which uses the
mb-text-donation
App Service as its origin. The DNS for missionbit.org is in Azure,
and the DNS for missionbit.com is currently managed in Cloudflare.
Sendgrid is used to send transactional email. This is managed through the Azure portal.
Stripe is used to process credit card and paymentRequest transactions.
Analytics come from Google Analytics, and events are also sent to the Application Insights
instance mb-text-donation-insights
. The Application Insights instance is set to do
continuous streaming of data to the mb-text-donation-insights
container of the
mbanalyticsstore
storage account.
To analyze events sent to Application Insights, you can write AIQL (Kusto) queries in workbooks.