diff options
| author | Adam Soltys <[email protected]> | 2022-08-01 22:17:58 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-08-01 22:17:58 -0700 |
| commit | 99b7b4fbeb64e2e4512211c9c2a4a085bacd96d8 (patch) | |
| tree | b2b6b97328cb9ea4b86d7b32e89aa805af29b04b | |
| parent | 82f9acc60b7edbdfee96f1553d0fb1dcc705b866 (diff) | |
| download | coinos-server-99b7b4fbeb64e2e4512211c9c2a4a085bacd96d8.tar.gz coinos-server-99b7b4fbeb64e2e4512211c9c2a4a085bacd96d8.zip | |
record invoice status
| -rw-r--r-- | db/models/invoices.js | 9 | ||||
| -rw-r--r-- | routes/invoices.js | 9 | ||||
| -rw-r--r-- | routes/lightning/receive.js | 4 |
3 files changed, 20 insertions, 2 deletions
diff --git a/db/models/invoices.js b/db/models/invoices.js index 324da9ad..d985ce82 100644 --- a/db/models/invoices.js +++ b/db/models/invoices.js @@ -154,6 +154,15 @@ const attributes = { comment: null, field: "webhook" }, + status: { + type: DataTypes.TEXT, + allowNull: true, + defaultValue: "unpaid", + primaryKey: false, + autoIncrement: false, + comment: null, + field: "status" + }, tip: { type: DataTypes.DOUBLE, allowNull: true, diff --git a/routes/invoices.js b/routes/invoices.js index 1208e14e..b5650735 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -8,7 +8,12 @@ app.get( const invoice = await db.Invoice.findOne({ where: { uuid: req.query.uuid - } + }, + include: { + model: db.User, + as: "user", + attributes: ['username'] + } }); res.send(invoice); @@ -23,7 +28,7 @@ app.post( optionalAuth, ah(async (req, res, next) => { try { - let { liquidAddress, invoice, user, tx } = req.body; + let { liquidAddress, id, invoice, user, tx } = req.body; let { blindkey } = invoice; if (invoice.amount < 0) throw new Error("amount out of range"); diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index 89ad4c29..c9e7dec7 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -61,6 +61,9 @@ const handlePayment = async (msg) => { total = amount + tip; invoice.received += total; + invoice.status = 'paid'; + await invoice.save({ transaction }); + await account.increment({ balance: total }, { transaction }); // get the # of fee credits you would need to pay off this amount of bitcoin await account.increment({ lightning_credits: computeConversionFee(total) }, { transaction }); @@ -71,6 +74,7 @@ const handlePayment = async (msg) => { payment = payment.get({ plain: true }); payment.account = account.get({ plain: true }); + payment.invoice= invoice.get({ plain: true }); callWebhook(invoice, payment); |
