We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d82b0b4 commit 7eddd37Copy full SHA for 7eddd37
README.md
@@ -191,6 +191,19 @@ $ curl $CHARGE/invoice/OYwwaOQAPMFvg039gj_Rb
191
{"id":"OYwwaOQAPMFvg039gj_Rb","msatoshi":"3738106","quoted_currency":"EUR","quoted_amount":"0.5","status":"unpaid",...}
192
```
193
194
+### `DELETE /invoice/:id`
195
+
196
+Delete the specified invoice.
197
198
+*Body parameters:* `status`
199
200
+The current status of the invoice needs to be specified in the request body.
201
202
+```bash
203
+$ curl -X DELETE $CHARGE/invoice/OYwwaOQAPMFvg039gj_Rb -d status=unpaid
204
+204 No Content
205
+```
206
207
### `GET /invoice/:id/wait?timeout=[sec]`
208
209
Long-polling invoice payment notification.
src/invoicing.js
@@ -6,7 +6,7 @@ const debug = require('debug')('lightning-charge')
6
const maxWait = +process.env.MAX_WAIT || 600
7
8
module.exports = (app, payListen, model, auth, lnconf) => {
9
- const { newInvoice, fetchInvoice, listInvoices, delExpired } = model
+ const { newInvoice, fetchInvoice, listInvoices, delInvoice, delExpired } = model
10
11
app.on('listening', server => server.timeout = maxWait*1000 + 500)
12
@@ -38,6 +38,11 @@ module.exports = (app, payListen, model, auth, lnconf) => {
38
// @TODO remove listener on client disconnect
39
}))
40
41
+ app.delete('/invoice/:invoice', auth, wrap(async (req, res) => {
42
+ await delInvoice(req.params.invoice, req.body.status)
43
+ res.sendStatus(204)
44
+ }))
45
46
// Enable automatic cleanup for expired invoices if enabled on c-lightning,
47
// using the same configurations.
48
src/model.js
@@ -45,6 +45,11 @@ module.exports = (db, ln) => {
const fetchInvoice = id =>
db('invoice').where({ id }).first().then(r => r && format(r))
+ const delInvoice = async (id, status) => {
49
+ await ln.delinvoice(id, status)
50
+ await db('invoice').where({ id }).del()
51
+ }
52
53
const markPaid = (id, pay_index, paid_at, msatoshi_received) =>
54
db('invoice').where({ id, pay_index: null })
55
.update({ pay_index, paid_at, msatoshi_received })
@@ -79,7 +84,7 @@ module.exports = (db, ln) => {
79
84
!err ? { requested_at: now(), success: true, resp_code: res.status }
80
85
: { requested_at: now(), success: false, resp_error: err })
81
86
82
- return { newInvoice, listInvoices, fetchInvoice
87
+ return { newInvoice, listInvoices, fetchInvoice, delInvoice
83
88
, getLastPaid, markPaid, delExpired
89
, addHook, getHooks, logHook }
90
}
test/invoice.js
@@ -115,6 +115,30 @@ describe('Invoice API', function() {
115
})
116
117
118
+ describe('DELETE /invoice/:invoice', () => {
119
+ it('deletes an invoice by its id and status', async () => {
120
+ const inv = await mkInvoice()
121
+ charge.del(`/invoice/${ inv.id }`)
122
+ .send({ status: 'unpaid' })
123
+ .expect(204)
124
+ })
125
126
+ it("won't delete the invoice if the status mismatches", async () => {
127
128
129
+ await charge.del(`/invoice/${ inv.id }`)
130
+ .send({ status: 'paid' })
131
+ .expect(400)
132
133
+ await lnBob.pay(inv.payreq, 1000)
134
135
136
137
138
139
140
141
142
describe('GET /invoice/:invoice/wait', function() {
143
this.slow(500)
144
0 commit comments