Sell and send digital product

We will see how to automate the sending of digital products such as an ebook when making a purchase in the store using webhooks.  .
A webhook (also called a web callback or HTTP push API) is a way for an app to provide other applications with real-time information. A webhook delivers data to other applications as it happens, meaning you get data immediately.

In our example, we are going to use the shop webhook in the 'offline payment' version, but you can very well perform the same process using the stripe webhook for example. 

First of all, to use the shop's webhook, we must pass it the url of our API function : 

 TipsYou can do the same thing on your stripe dashboard/webhook

Let's now create our front-end using the page builder, our table 'ebooks' and our API 
which will receive our webhook, retrieve the ebook file in our 'ebooks' table and send it via email :

- Create our front-end with the page-builder :

- Create a table 'ebooks' :

- Create a node.js API function :

Let's explain our function 😎:

Line 10-18 : We iterate on our purchased products in order to retrieve the SKU references, and we insert them in the 'skus' array.
Line 21-27 : We retrieve from the 'ebooks' table the right ebooks file that suits us (In this case, I am only looking for the first ebook skus [0] of our purchase) .
Line 30-41 : We send an email inserting the ebook file (line 34).

Let's check the visual rendering when we place order :

When i click on the link , i can see my ebook !