Webhook to get Kofi payments and donations, save the data on Google Sheets, and submit confirmation emails to clients
Project type: client
Table of Contents
Build with
Related projects
Details
For run the project, you should host it, or use a tool link Ngrok, to make public a localhost project.
You need also your Kofi Token, Google Sheet API Key, and Email Credentials.
More details are in the Settings section.
Data from Kofi
Donations
Each time donation, the project gets:
- date
- time
- user name
- message
- amount
- currency
- url
Sales
Each time sales, the project gets:
- date
- time
- user name
- amount
- currency
- shop items
- shop items links
- shipping name
- country
- shipping
- url
Commissions
- date
- time
- user name
- amount
- currency
- country
- full address
- url
Install
Third party modules
Install all the python modules from pip:
$ pip install -r requirements.txt
Settings
Enviroment variables
In the file .env, are the main options and settings of the project.
Create a .env file, and place the following content
KOFI_TOKEN=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
GOOGLE_SHEETS=https://docs.google.com/spreadsheets/d/{random-chars}/edit?usp=sharing
EMAIL_USER=youremail@mail.com
EMAIL_PASS=yourpass123*
EMAIL_SUBJECT_STORE=your-store-name
DEBUG_EMAIL_TO=yourotheremail@mail.comNote: you can see as reference the sample.env file
KOFI_TOKEN
You Kofi token. You can get it ko-fi.com/manage/webhooks, in the advanced section.
GOOGLE_SHEETS
The link of the google sheet where data will be saved.
- The file can be named as you like, but you should have a sheet named
kofi donations, and the following columns in the same order:
- date
- time
- user name
- message
- amount
- currency
- url
- And a sheet names
kofi saleswith the columns:
- date
- time
- user name
- amount
- currency
- shop items
- shop items links
- shipping name
- country
- shipping
- url
- And a sheet names
kofi commissionswith the columns:
- date
- time
- user name
- amount
- currency
- country
- full address
- url
- After create them, be sure to generate the link with edit permisions. You can do it, following the this tutorial
EMAIL_USER
Your email user, who will send the notifications email to the clients. The project supports gmail, outlook, hotmail, live, yahoo and aol.
EMAIL_PASS
You email password.
Usually, the email services don't allow you to connect directly with your password, instead of that, you should create a secondary password, and use it. Here a tutorial about how to generate an alternative password (application password) in gmaill
EMAIL_SUBJECT_STORE
Store name to generate the thanks email subject, like:
- Thanks for your support to your-store-name
- Thanks for purchasing your-store-name
DEBUG_EMAIL_TO
An email where you'll get a notification if something was wrong. It can be the same as EMAIL_USER
Google Sheets credentials
You should create a credentials file from your Google Console, with the same account owner of the Google Sheets file, to allow connect to it.
- Generate if following this tutorial.
- Download the json file.
- Place in the project folder as
credentials.json
Setup Kofi Webhook
After deploying the project, update the link provided by your hosting, in ko-fi.com/manage/webhooks
HTML TEMPLATE
You can edit the HTML to submit to the client, after a sale or donation, editing the file templates/thanks.html.
You render the user name, using "user_name" and the event type (Donation, or Shop Order) using "res_type".
Here is the default code and the result email.
Note: if you want to use images, upload then to an image server or github, and place in the HTML only the link
<style> @import url('https://fonts.googleapis.com/css2?family=Asap+Condensed:wght@700&display=swap'); h1 { font-family: 'Asap Condensed', sans-serif; font-size: 2.5rem; text-align: center; color:#2c3333; } </style> <h1>user_name Thanks for your res_type</h1> <img width="800" src="https://raw.githubusercontent.com/darideveloper/kofi-api-sheets-email/master/imgs/banner.webp">
Run
Run the flask app with python
Deploy
The project has been created to be hosted in Heroku, this is because it is the recommended hosting.
Roadmap
- WebHook for get donations and payments
- Save donations data in google sheets
- Save sales data in google sheets
- Send email to clients with html template
- Send email when error happens



