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
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.
Each time donation, the project gets:
- date
- time
- user name
- message
- amount
- currency
- url
Each time sales, the project gets:
- date
- time
- user name
- amount
- currency
- shop items
- shop items links
- shipping name
- country
- shipping
- url
- date
- time
- user name
- amount
- currency
- country
- full address
- url
Install all the python modules from pip:
$ pip install -r requirements.txt
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 protected]
EMAIL_PASS=yourpass123*
EMAIL_SUBJECT_STORE=your-store-name
[email protected]
Note: you can see as reference the sample.env file
You Kofi token. You can get it ko-fi.com/manage/webhooks, in the advanced
section.
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 sales
with the columns:
- date
- time
- user name
- amount
- currency
- shop items
- shop items links
- shipping name
- country
- shipping
- url
- And a sheet names
kofi commissions
with 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
Your email user, who will send the notifications email to the clients. The project supports gmail, outlook, hotmail, live, yahoo and aol.
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
Store name to generate the thanks email subject, like:
- Thanks for your support to your-store-name
- Thanks for purchasing your-store-name
An email where you'll get a notification if something was wrong. It can be the same as EMAIL_USER
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
After deploying the project, update the link provided by your hosting, in ko-fi.com/manage/webhooks
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 the flask app with python
python app.py
The project has been created to be hosted in Heroku, this is because it is the recommended hosting.
- 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