Fixed paywall, unnecessary key check added

This commit is contained in:
benarc 2022-02-17 09:23:33 +00:00
parent 0764f4fdf1
commit 3c5fac3874
2 changed files with 54 additions and 50 deletions

View File

@ -77,8 +77,8 @@
mixins: [windowMixin],
data: function () {
return {
userAmount: {{ paywall.amount }},
paywallAmount: {{ paywall.amount }},
userAmount: '{{ paywall.amount }}',
paywallAmount: '{{ paywall.amount }}',
paymentReq: null,
redirectUrl: null,
paymentDialog: {
@ -89,7 +89,9 @@
},
computed: {
amount: function () {
return (this.paywallAmount > this.userAmount) ? this.paywallAmount : this.userAmount
return this.paywallAmount > this.userAmount
? this.paywallAmount
: this.userAmount
}
},
methods: {
@ -102,48 +104,55 @@
},
createInvoice: function () {
var self = this
console.log(this.amount)
axios
.post(
'/paywall/api/v1/paywalls/{{ paywall.id }}/invoice',
{amount: self.amount}
LNbits.api
.request(
'POST',
'/paywall/api/v1/paywalls/invoice/{{ paywall.id }}',
'filler',
{
amount: self.amount
}
)
.then(function (response) {
self.paymentReq = response.data.payment_request.toUpperCase()
if (response.data) {
self.paymentReq = response.data.payment_request.toUpperCase()
self.paymentDialog.dismissMsg = self.$q.notify({
timeout: 0,
message: 'Waiting for payment...'
})
self.paymentDialog.dismissMsg = self.$q.notify({
timeout: 0,
message: 'Waiting for payment...'
})
self.paymentDialog.checker = setInterval(function () {
axios
.post(
'/paywall/api/v1/paywalls/{{ paywall.id }}/check_invoice',
{payment_hash: response.data.payment_hash}
)
.then(function (res) {
if (res.data.paid) {
self.cancelPayment()
self.redirectUrl = res.data.url
if (res.data.remembers) {
self.$q.localStorage.set(
'lnbits.paywall.{{ paywall.id }}',
res.data.url
)
self.paymentDialog.checker = setInterval(function () {
LNbits.api
.request(
'POST',
'/paywall/api/v1/paywalls/check_invoice/{{ paywall.id }}',
'filler',
{payment_hash: response.data.payment_hash}
)
.then(function (response) {
if (response.data) {
if (response.data.paid) {
self.cancelPayment()
self.redirectUrl = response.data.url
if (response.data.remembers) {
self.$q.localStorage.set(
'lnbits.paywall.{{ paywall.id }}',
response.data.url
)
}
self.$q.notify({
type: 'positive',
message: 'Payment received!',
icon: null
})
}
}
self.$q.notify({
type: 'positive',
message: 'Payment received!',
icon: null
})
}
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
}, 2000)
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
}, 2000)
}
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)

View File

@ -52,20 +52,17 @@ async def api_paywall_delete(
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
@paywall_ext.post("/api/v1/paywalls/{paywall_id}/invoice")
@paywall_ext.post("/api/v1/paywalls/invoice/{paywall_id}")
async def api_paywall_create_invoice(
paywall_id,
data: CreatePaywallInvoice,
wallet: WalletTypeInfo = Depends(get_key_type),
paywall_id: str = Query(None)
):
paywall = await get_paywall(paywall_id)
if data.amount < paywall.amount:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail=f"Minimum amount is {paywall.amount} sat.",
)
try:
amount = data.amount if data.amount > paywall.amount else paywall.amount
payment_hash, payment_request = await create_invoice(
@ -80,15 +77,14 @@ async def api_paywall_create_invoice(
return {"payment_hash": payment_hash, "payment_request": payment_request}
@paywall_ext.post("/api/v1/paywalls/{paywall_id}/check_invoice")
async def api_paywal_check_invoice(data: CheckPaywallInvoice, paywall_id):
@paywall_ext.post("/api/v1/paywalls/check_invoice/{paywall_id}")
async def api_paywal_check_invoice(data: CheckPaywallInvoice, paywall_id: str = Query(None)):
paywall = await get_paywall(paywall_id)
payment_hash = data.payment_hash
if not paywall:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Paywall does not exist."
)
try:
status = await check_invoice_status(paywall.wallet, payment_hash)
is_paid = not status.pending
@ -101,5 +97,4 @@ async def api_paywal_check_invoice(data: CheckPaywallInvoice, paywall_id):
await payment.set_pending(False)
return {"paid": True, "url": paywall.url, "remembers": paywall.remembers}
return {"paid": False}