From 4bde8faf1b9d91898447bdf2c63b0afd227f978c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 9 Jul 2021 12:58:14 -0700 Subject: add webhooks to invoices --- lib/webhooks.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/webhooks.js (limited to 'lib/webhooks.js') diff --git a/lib/webhooks.js b/lib/webhooks.js new file mode 100644 index 00000000..f21607fb --- /dev/null +++ b/lib/webhooks.js @@ -0,0 +1,28 @@ +const wretch = require("wretch"); +const fetch = require("node-fetch"); +wretch().polyfills({ fetch }); + +callWebhook = (invoice, payment) => { + if (!invoice || !payment) return; + + let { address, text, webhook } = invoice; + + if (webhook) { + let { amount, confirmed, hash, memo } = payment; + + l.info("calling webhook", webhook); + return wretch() + .url(webhook) + .post({ + address, + amount, + hash, + memo, + confirmed, + text, + webhook + }) + .json() + .catch(console.log); + } +}; -- cgit v1.2.3