Hack A Lapp: Introduction to Bitcoins Lightning Network App Development/C-Lightning with python/Check if your customer has paid the invoice
Check if your customer has paid the invoice
- find a specific invoice with its payment hash
- Check if a specific invoice has been paid
- change the response to the customer depending on the payment status of the invoice
I have decided that users could check the results by using their payment hash as the path of the url. Of course this could be handled differently. Meanwhile I have updated the do_GET method in order to handle this logic an invoke the __show_rankings_page function So let us implement this function. now the first thing that we need to do is to check if a file with the votings exists. Like in the other code snippet I do this rather hacky in a try except block. if the file exists I display the casted votes of the user and otherwise tell the user that the payment hash is not known to me. I made this quick here because it is not lightning specific now as with the counting of paid votes we invoke our rpc interface and list all the invoices again we use a for function to iterate over all invoices.
Our goal is to find the invoice which matches the payment hash that was provided by the user
now comes the crucial part. we check if the status of the invoice is "paid"
if yes we output some html to for the user and
we call the function from the first part that has counted the rankings
we iterate over the results
and append them to the message
and of course we should not forget the fact that the invoice might not have been paid.
in this case we have to disply the invoice to the user and state that it has to be paid in order to see the results. Also when you look at the page you will see that I have added a qr code for your convenience. all of this is handled in the add_invoice_payment_string-function.