pay lnurl
This commit is contained in:
parent
f6d922e1b7
commit
10e1bbcb66
4 changed files with 46 additions and 78 deletions
|
|
@ -65,3 +65,17 @@ async def update_scrub_link(link_id: int, **kwargs) -> Optional[ScrubLink]:
|
||||||
|
|
||||||
async def delete_scrub_link(link_id: int) -> None:
|
async def delete_scrub_link(link_id: int) -> None:
|
||||||
await db.execute("DELETE FROM scrub.scrub_links WHERE id = ?", (link_id,))
|
await db.execute("DELETE FROM scrub.scrub_links WHERE id = ?", (link_id,))
|
||||||
|
|
||||||
|
async def get_scrub_by_wallet(wallet_id) -> Optional[ScrubLink]:
|
||||||
|
row = await db.fetchone(
|
||||||
|
"SELECT * from scrub.scrub_links WHERE wallet = ?",
|
||||||
|
(wallet_id,),
|
||||||
|
)
|
||||||
|
return ScrubLink(**row) if row else None
|
||||||
|
|
||||||
|
async def unique_scrubed_wallet(wallet_id):
|
||||||
|
row, = await db.fetchone(
|
||||||
|
"SELECT COUNT(wallet) FROM scrub.scrub_links WHERE wallet = ?",
|
||||||
|
(wallet_id,),
|
||||||
|
)
|
||||||
|
return row
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,6 @@ new Vue({
|
||||||
mixins: [windowMixin],
|
mixins: [windowMixin],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
currencies: [],
|
|
||||||
fiatRates: {},
|
|
||||||
checker: null,
|
checker: null,
|
||||||
payLinks: [],
|
payLinks: [],
|
||||||
payLinksTable: {
|
payLinksTable: {
|
||||||
|
|
@ -37,7 +35,6 @@ new Vue({
|
||||||
},
|
},
|
||||||
formDialog: {
|
formDialog: {
|
||||||
show: false,
|
show: false,
|
||||||
fixedAmount: true,
|
|
||||||
data: {}
|
data: {}
|
||||||
},
|
},
|
||||||
qrCodeDialog: {
|
qrCodeDialog: {
|
||||||
|
|
@ -65,42 +62,11 @@ new Vue({
|
||||||
closeFormDialog() {
|
closeFormDialog() {
|
||||||
this.resetFormData()
|
this.resetFormData()
|
||||||
},
|
},
|
||||||
openQrCodeDialog(linkId) {
|
|
||||||
var link = _.findWhere(this.payLinks, {id: linkId})
|
|
||||||
if (link.currency) this.updateFiatRate(link.currency)
|
|
||||||
|
|
||||||
this.qrCodeDialog.data = {
|
|
||||||
id: link.id,
|
|
||||||
amount:
|
|
||||||
(link.min === link.max ? link.min : `${link.min} - ${link.max}`) +
|
|
||||||
' ' +
|
|
||||||
(link.currency || 'sat'),
|
|
||||||
currency: link.currency,
|
|
||||||
comments: link.comment_chars
|
|
||||||
? `${link.comment_chars} characters`
|
|
||||||
: 'no',
|
|
||||||
webhook: link.webhook_url || 'nowhere',
|
|
||||||
success:
|
|
||||||
link.success_text || link.success_url
|
|
||||||
? 'Display message "' +
|
|
||||||
link.success_text +
|
|
||||||
'"' +
|
|
||||||
(link.success_url ? ' and URL "' + link.success_url + '"' : '')
|
|
||||||
: 'do nothing',
|
|
||||||
lnurl: link.lnurl,
|
|
||||||
pay_url: link.pay_url,
|
|
||||||
print_url: link.print_url
|
|
||||||
}
|
|
||||||
this.qrCodeDialog.show = true
|
|
||||||
},
|
|
||||||
openUpdateDialog(linkId) {
|
openUpdateDialog(linkId) {
|
||||||
const link = _.findWhere(this.payLinks, {id: linkId})
|
const link = _.findWhere(this.payLinks, {id: linkId})
|
||||||
if (link.currency) this.updateFiatRate(link.currency)
|
|
||||||
|
|
||||||
this.formDialog.data = _.clone(link._data)
|
this.formDialog.data = _.clone(link._data)
|
||||||
this.formDialog.show = true
|
this.formDialog.show = true
|
||||||
this.formDialog.fixedAmount =
|
|
||||||
this.formDialog.data.min === this.formDialog.data.max
|
|
||||||
},
|
},
|
||||||
sendFormData() {
|
sendFormData() {
|
||||||
const wallet = _.findWhere(this.g.user.wallets, {
|
const wallet = _.findWhere(this.g.user.wallets, {
|
||||||
|
|
@ -166,35 +132,12 @@ new Vue({
|
||||||
LNbits.utils.notifyApiError(err)
|
LNbits.utils.notifyApiError(err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
|
||||||
updateFiatRate(currency) {
|
|
||||||
LNbits.api
|
|
||||||
.request('GET', '/scrub/api/v1/rate/' + currency, null)
|
|
||||||
.then(response => {
|
|
||||||
let rates = _.clone(this.fiatRates)
|
|
||||||
rates[currency] = response.data.rate
|
|
||||||
this.fiatRates = rates
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
LNbits.utils.notifyApiError(err)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if (this.g.user.wallets.length) {
|
if (this.g.user.wallets.length) {
|
||||||
var getScrubLinks = this.getScrubLinks
|
var getScrubLinks = this.getScrubLinks
|
||||||
getScrubLinks()
|
getScrubLinks()
|
||||||
// this.checker = setInterval(() => {
|
|
||||||
// getScrubLinks()
|
|
||||||
// }, 20000)
|
|
||||||
}
|
}
|
||||||
LNbits.api
|
|
||||||
.request('GET', '/scrub/api/v1/currencies')
|
|
||||||
.then(response => {
|
|
||||||
this.currencies = ['satoshis', ...response.data]
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
LNbits.utils.notifyApiError(err)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from lnbits.core import db as core_db
|
from lnbits.core import db as core_db
|
||||||
from .models import ScrubLink
|
from lnbits.core.crud import get_wallet
|
||||||
|
from lnbits.core.models import Payment
|
||||||
from lnbits.tasks import register_invoice_listener
|
from lnbits.tasks import register_invoice_listener
|
||||||
|
|
||||||
from .crud import get_scrub_link
|
from .crud import get_scrub_by_wallet, get_scrub_link
|
||||||
|
from .models import ScrubLink
|
||||||
|
|
||||||
|
|
||||||
async def wait_for_paid_invoices():
|
async def wait_for_paid_invoices():
|
||||||
|
|
@ -18,26 +21,34 @@ async def wait_for_paid_invoices():
|
||||||
await on_invoice_paid(payment)
|
await on_invoice_paid(payment)
|
||||||
|
|
||||||
|
|
||||||
async def on_invoice_paid(payment: ScrubLink) -> None:
|
async def on_invoice_paid(payment: Payment) -> None:
|
||||||
if "scrub" != payment.extra.get("tag"):
|
# (avoid loops)
|
||||||
# not an scrub invoice
|
if "scrub" == payment.extra.get("tag"):
|
||||||
|
# already scrubbed
|
||||||
return
|
return
|
||||||
|
|
||||||
if payment.extra.get("wh_status"):
|
scrub_link = await get_scrub_by_wallet(payment.wallet_id)
|
||||||
# this webhook has already been sent
|
|
||||||
|
if not scrub_link:
|
||||||
return
|
return
|
||||||
|
|
||||||
pay_link = await get_pay_link(payment.extra.get("link", -1))
|
from lnbits.core.views.api import (
|
||||||
# PAY LNURLP AND LNADDRESS
|
CreateLNURLData,
|
||||||
|
api_lnurlscan,
|
||||||
|
api_payments_pay_lnurl,
|
||||||
async def mark_webhook_sent(payment: ScrubLink, status: int) -> None:
|
|
||||||
payment.extra["wh_status"] = status
|
|
||||||
|
|
||||||
await core_db.execute(
|
|
||||||
"""
|
|
||||||
UPDATE apipayments SET extra = ?
|
|
||||||
WHERE hash = ?
|
|
||||||
""",
|
|
||||||
(json.dumps(payment.extra), payment.payment_hash),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
wallet = await get_wallet(wallet_id=payment.wallet_id)
|
||||||
|
assert wallet
|
||||||
|
|
||||||
|
# PAY LNURLP AND LNADDRESS
|
||||||
|
invoice = await api_lnurlscan(scrub_link.payoraddress)
|
||||||
|
invoice_data = CreateLNURLData(
|
||||||
|
callback = invoice["callback"],
|
||||||
|
description_hash = invoice["description_hash"],
|
||||||
|
amount = payment.amount
|
||||||
|
)
|
||||||
|
print("INV", invoice_data, wallet)
|
||||||
|
|
||||||
|
invoice_paid = await api_payments_pay_lnurl(data=invoice_data, wallet=wallet.adminkey)
|
||||||
|
print("PAID", invoice_paid)
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ async def api_scrub_create_or_update(
|
||||||
|
|
||||||
|
|
||||||
@scrub_ext.delete("/api/v1/links/{link_id}")
|
@scrub_ext.delete("/api/v1/links/{link_id}")
|
||||||
async def api_link_delete(link_id, wallet: WalletTypeInfo = Depends(get_key_type)):
|
async def api_link_delete(link_id, wallet: WalletTypeInfo = Depends(require_admin_key)):
|
||||||
link = await get_scrub_link(link_id)
|
link = await get_scrub_link(link_id)
|
||||||
|
|
||||||
if not link:
|
if not link:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue