mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-09 20:12:34 +02:00
Added webhook for tickets
This commit is contained in:
@@ -4,7 +4,7 @@ from lnbits.helpers import urlsafe_short_hash
|
|||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
from .models import Tickets, Forms
|
from .models import Tickets, Forms
|
||||||
|
import httpx
|
||||||
|
|
||||||
async def create_ticket(
|
async def create_ticket(
|
||||||
payment_hash: str,
|
payment_hash: str,
|
||||||
@@ -54,8 +54,23 @@ async def set_ticket_paid(payment_hash: str) -> Tickets:
|
|||||||
)
|
)
|
||||||
|
|
||||||
ticket = await get_ticket(payment_hash)
|
ticket = await get_ticket(payment_hash)
|
||||||
assert ticket, "Newly updated ticket couldn't be retrieved"
|
async with httpx.AsyncClient() as client:
|
||||||
|
try:
|
||||||
|
r = await client.post(
|
||||||
|
formdata.webhook,
|
||||||
|
json={
|
||||||
|
"form": ticket.form,
|
||||||
|
"name": ticket.name,
|
||||||
|
"email": ticket.email,
|
||||||
|
"comment": ticket.ltext
|
||||||
|
},
|
||||||
|
timeout=40,
|
||||||
|
)
|
||||||
|
except AssertionError:
|
||||||
|
webhook = None
|
||||||
return ticket
|
return ticket
|
||||||
|
ticket = await get_ticket(payment_hash)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
async def get_ticket(ticket_id: str) -> Optional[Tickets]:
|
async def get_ticket(ticket_id: str) -> Optional[Tickets]:
|
||||||
|
@@ -164,29 +164,30 @@
|
|||||||
.get('/lnticket/api/v1/tickets/' + self.paymentCheck)
|
.get('/lnticket/api/v1/tickets/' + self.paymentCheck)
|
||||||
.then(function (res) {
|
.then(function (res) {
|
||||||
if (res.data.paid) {
|
if (res.data.paid) {
|
||||||
self.$q.notify({
|
clearInterval(paymentChecker)
|
||||||
type: 'positive',
|
|
||||||
message: 'Sent, thank you!',
|
|
||||||
icon: null
|
|
||||||
})
|
|
||||||
self.receive = {
|
self.receive = {
|
||||||
show: false,
|
show: false,
|
||||||
status: 'complete',
|
status: 'complete',
|
||||||
paymentReq: null
|
paymentReq: null
|
||||||
}
|
}
|
||||||
clearInterval(paymentChecker)
|
|
||||||
dismissMsg()
|
dismissMsg()
|
||||||
|
|
||||||
|
|
||||||
self.formDialog.data.name = ''
|
self.formDialog.data.name = ''
|
||||||
self.formDialog.data.email = ''
|
self.formDialog.data.email = ''
|
||||||
self.formDialog.data.text = ''
|
self.formDialog.data.text = ''
|
||||||
|
self.$q.notify({
|
||||||
|
type: 'positive',
|
||||||
|
message: 'Sent, thank you!',
|
||||||
|
icon: 'thumb_up',
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
})
|
})
|
||||||
}, 2000)
|
}, 2000)
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
|
@@ -139,7 +139,7 @@ async def api_ticket_send_ticket(payment_hash):
|
|||||||
payment = await wallet.get_payment(payment_hash)
|
payment = await wallet.get_payment(payment_hash)
|
||||||
await payment.set_pending(False)
|
await payment.set_pending(False)
|
||||||
ticket = await set_ticket_paid(payment_hash=payment_hash)
|
ticket = await set_ticket_paid(payment_hash=payment_hash)
|
||||||
return jsonify({"paid": True, "ticket_id": ticket.id}), HTTPStatus.OK
|
return jsonify({"paid": True}), HTTPStatus.OK
|
||||||
|
|
||||||
return jsonify({"paid": False}), HTTPStatus.OK
|
return jsonify({"paid": False}), HTTPStatus.OK
|
||||||
|
|
||||||
|
@@ -205,7 +205,7 @@
|
|||||||
v-model="formDialog.data.webhook_url"
|
v-model="formDialog.data.webhook_url"
|
||||||
type="text"
|
type="text"
|
||||||
label="Webhook URL (optional)"
|
label="Webhook URL (optional)"
|
||||||
hint="An URL to be called whenever this link receives a payment."
|
hint="A URL to be called whenever this link receives a payment."
|
||||||
></q-input>
|
></q-input>
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
|
Reference in New Issue
Block a user