Skip to content

Simple Flask API for generating c-lightning invoices and detecting payment using pylightning

Notifications You must be signed in to change notification settings

conscott/get-lightning-paid

Repository files navigation

Description

A simple Flask REST API to generate lightning invoices and wait for payment confirmation / check invoice status. This is experimential fun and not enterprise ready. Use with caution!

Files

The app requires a locally running version of c-lightning

Install Environment

sudo apt-get install python3-dev
python3 -v venv venv
source venv/bin/activate
pip install -r requirements.txt

Run Server

For development/test server

./run_dev.sh

For production server using uWSGI

./run_prod.sh

You can tweak uwsgi configuration in uwsgi.ini

API

Generate Invoice

POST /api/generate_invoice

{
    "msatoshi": <amount>       (required)
    "description": <string>    (optional, defatul '')
    "expiry": <seconds>        (optional, default 600)
}

Response

{
    "payment_hash": <string>
    "expires_at": <unix timestamp>
    "bolt11": <bolt11 string>
    "label": <string label_id for payment>
}

Note the label is needed to check invoice status later

Check Invoice

GET /api/check_invoice/<label>

Check the status of the invoice with the given label

Response

{
    "status": "paid|unpaid|expired"
    "expires_at": <unix timesamp>
}

Wait For Invoice Payment

GET /api/wait_invoice/<label>

Will wait until the invoice associated with the label has been paid

Response

{
  "label": <string>
  "bolt11": <string>
  "payment_hash": <string>
  "msatoshi": <int>
  "status": "paid", 
  "pay_index": <int>
  "msatoshi_received": <int>
  "paid_at": <unix timestamp>
  "description": <string>
  "expires_at": <unix timesamp>
}

Try it out

Check out the script gen_invoice_and_pay.py to see a sample backend flow

About

Simple Flask API for generating c-lightning invoices and detecting payment using pylightning

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published