Hack A Lapp/Introduction to Bitcoins Lightning Network App Development/C-Lightning with python/Check if your customer has paid the invoice

From Wikiversity
Jump to navigation Jump to search

Check if your customer has paid the invoice

Learning goals

  1. find a specific invoice with its payment hash
  2. Check if a specific invoice has been paid
  3. 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.


1 you want to see if the invoice with the payment hash ph="e21b2df94d678ebb84924ad6a2c6f571a4662d321bf13bdb731d031bb7a87bfa" was paid. what do you do?

rpc_interface.invoices(ph) == "paid"
rpc_interface.invoices(ph)["status"] == "paid"
iterate over all invoices by calling rpc_interface.invoices() and check for each invoice if the payment hash matches and then check the status.

2 You have an invoice stored on invoice how can you access the amount?