{"id":35311440,"url":"https://github.com/jimasuen/lnbits-webhook-example","last_synced_at":"2026-04-01T23:01:45.745Z","repository":{"id":218112077,"uuid":"745630392","full_name":"jimasuen/lnbits-webhook-example","owner":"jimasuen","description":"Webhook handler example code for LNbits in PHP","archived":false,"fork":false,"pushed_at":"2024-01-28T18:27:08.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-28T00:42:35.850Z","etag":null,"topics":["lnbits","webhook"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimasuen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-19T18:47:35.000Z","updated_at":"2024-01-19T22:37:14.000Z","dependencies_parsed_at":"2024-01-28T19:42:13.474Z","dependency_job_id":null,"html_url":"https://github.com/jimasuen/lnbits-webhook-example","commit_stats":null,"previous_names":["jimasuen/lnbits-webhook-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jimasuen/lnbits-webhook-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimasuen%2Flnbits-webhook-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimasuen%2Flnbits-webhook-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimasuen%2Flnbits-webhook-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimasuen%2Flnbits-webhook-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimasuen","download_url":"https://codeload.github.com/jimasuen/lnbits-webhook-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimasuen%2Flnbits-webhook-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31292781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T21:15:39.731Z","status":"ssl_error","status_checked_at":"2026-04-01T21:15:34.046Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lnbits","webhook"],"created_at":"2025-12-30T17:46:09.797Z","updated_at":"2026-04-01T23:01:45.723Z","avatar_url":"https://github.com/jimasuen.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Webhook handler example code for LNbits in PHP\n\n\nVarious endpoints in the LNbits API support using webhooks in form of adding a webhook URL in the webhook field. This is an example of using PHP and the create or pay invoice endpoint in the LNbits API (https://legend.lnbits.com/docs#/default/api_payments_create_api_v1_payments_post).\n\nExample of adding the webhook URL using cURL (this could be done on the dashboard as well):\n\n    \n    curl -X 'POST'\n    https://your-lnbits-endpoint.com/api/v1/payments\n    -H \"X-Api-Key: \u003cINVOICE KEY\u003e\"\n    -H \"Content-type: application/json\"\n    -d '{\"out\": false, \"amount\": 1, \"memo\": \"test webhook\", \"webhook\": \"https://example.com/webhook.php\"}'\n    \n\nThe value of the webhook field refers to where you have the code that will process the data from the webhook. This example assumes that the code processing the data is found in https://example.com/webhook.php\n\n\nExample code in webhook.php to process the webhook data:\n\n    \n    \u003c?php\n    \n    if ($_SERVER['REQUEST_METHOD'] == 'POST') {\n\n        // Webhook json content\n        $json = file_get_contents('php://input'); \n    \n        // Decode the json content and store it in $object\n        $object = json_decode($json);\n    \n        // Check if the json is valid\n        if (json_last_error() !== JSON_ERROR_NONE) {\n        \n            die(header('HTTP/1.0 415 Unsupported Media Type'));\n            \n        } else {\n    \n            /** Log content to a file to inspect it to see the values of $object. \n             * This would give you the opportunity to see what you want to process. \n             * Don't forget to comment out or delete this part when you're done.\n            **/\n            \n            file_put_contents('object.txt', print_r($object, true));\n            \n            //In this example, I'm storing the checking_id into a variable.\n            $checking_id = $object-\u003echecking_id;\n            \n            \n            /**\n            ** From here, you write your code to process the data the way you want.\n            **\n            **\n            **/\n    \n        }\n    \n    }\n    \n    ?\u003e\n    \n\nNote:\n\nIf you use https://webhook.site/ in your initial tests, you can skip the step on logging the content to a file.\n\n\n# Webhook data and paying external invoices using the LNbits API\n\nWhen using the LNbits pay invoice API to pay an external invoice, the webhook field defaults to `null` despite adding a webhook URL. If you need to send webhook data after paying an external invoice, an approach that can be followed is to use the resulting `payment_hash` that is outputed to check an invoice and send the JSON output to the webhook URL:\n\nChecking the status of the bolt11 invoice:\n\n```\ncurl -X 'GET'\nhttps://your-lnbits-endpoint.com/api/v1/payments/\u003cpayment_hash\u003e\n-H \"X-Api-Key: \u003cinvoice key\u003e\"\n-H \"Content-type: application/json\"\n```\n\n\n\nExample of sending resulting JSON data to webhook URL:\n\n```\ncurl -X 'POST'\nhttps://example.com/webhook.php\n-H \"Content-type: application/json\"\n-d '{\n\u003cJSON output from checking invoice\u003e\n}'\n```\n\n\n\n# References\n\n1. https://stackoverflow.com/questions/47565321/how-to-get-webhook-response-data\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimasuen%2Flnbits-webhook-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimasuen%2Flnbits-webhook-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimasuen%2Flnbits-webhook-example/lists"}