aboutsummaryrefslogtreecommitdiffstats
path: root/lib/webhooks.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-07-09 12:58:14 -0700
committerAdam Soltys <[email protected]>2021-07-09 12:58:14 -0700
commit4bde8faf1b9d91898447bdf2c63b0afd227f978c (patch)
tree7feb055b4c5434e253b351655fe1ad4a2d7fd92f /lib/webhooks.js
parent0fb703b85d99c888d1df971e7c3562f7918e0ff8 (diff)
downloadcoinos-server-4bde8faf1b9d91898447bdf2c63b0afd227f978c.tar.gz
coinos-server-4bde8faf1b9d91898447bdf2c63b0afd227f978c.zip
add webhooks to invoices
Diffstat (limited to 'lib/webhooks.js')
-rw-r--r--lib/webhooks.js28
1 files changed, 28 insertions, 0 deletions
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);
+ }
+};