Fixed paywall, unnecessary key check added
This commit is contained in:
parent
0764f4fdf1
commit
3c5fac3874
2 changed files with 54 additions and 50 deletions
|
|
@ -77,8 +77,8 @@
|
||||||
mixins: [windowMixin],
|
mixins: [windowMixin],
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
userAmount: {{ paywall.amount }},
|
userAmount: '{{ paywall.amount }}',
|
||||||
paywallAmount: {{ paywall.amount }},
|
paywallAmount: '{{ paywall.amount }}',
|
||||||
paymentReq: null,
|
paymentReq: null,
|
||||||
redirectUrl: null,
|
redirectUrl: null,
|
||||||
paymentDialog: {
|
paymentDialog: {
|
||||||
|
|
@ -89,7 +89,9 @@
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
amount: function () {
|
amount: function () {
|
||||||
return (this.paywallAmount > this.userAmount) ? this.paywallAmount : this.userAmount
|
return this.paywallAmount > this.userAmount
|
||||||
|
? this.paywallAmount
|
||||||
|
: this.userAmount
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -102,48 +104,55 @@
|
||||||
},
|
},
|
||||||
createInvoice: function () {
|
createInvoice: function () {
|
||||||
var self = this
|
var self = this
|
||||||
console.log(this.amount)
|
LNbits.api
|
||||||
axios
|
.request(
|
||||||
.post(
|
'POST',
|
||||||
'/paywall/api/v1/paywalls/{{ paywall.id }}/invoice',
|
'/paywall/api/v1/paywalls/invoice/{{ paywall.id }}',
|
||||||
{amount: self.amount}
|
'filler',
|
||||||
|
{
|
||||||
|
amount: self.amount
|
||||||
|
}
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.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({
|
self.paymentDialog.checker = setInterval(function () {
|
||||||
timeout: 0,
|
LNbits.api
|
||||||
message: 'Waiting for payment...'
|
.request(
|
||||||
})
|
'POST',
|
||||||
|
'/paywall/api/v1/paywalls/check_invoice/{{ paywall.id }}',
|
||||||
self.paymentDialog.checker = setInterval(function () {
|
'filler',
|
||||||
axios
|
{payment_hash: response.data.payment_hash}
|
||||||
.post(
|
)
|
||||||
'/paywall/api/v1/paywalls/{{ paywall.id }}/check_invoice',
|
.then(function (response) {
|
||||||
{payment_hash: response.data.payment_hash}
|
if (response.data) {
|
||||||
)
|
if (response.data.paid) {
|
||||||
.then(function (res) {
|
self.cancelPayment()
|
||||||
if (res.data.paid) {
|
self.redirectUrl = response.data.url
|
||||||
self.cancelPayment()
|
if (response.data.remembers) {
|
||||||
self.redirectUrl = res.data.url
|
self.$q.localStorage.set(
|
||||||
if (res.data.remembers) {
|
'lnbits.paywall.{{ paywall.id }}',
|
||||||
self.$q.localStorage.set(
|
response.data.url
|
||||||
'lnbits.paywall.{{ paywall.id }}',
|
)
|
||||||
res.data.url
|
}
|
||||||
)
|
self.$q.notify({
|
||||||
|
type: 'positive',
|
||||||
|
message: 'Payment received!',
|
||||||
|
icon: null
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
self.$q.notify({
|
.catch(function (error) {
|
||||||
type: 'positive',
|
LNbits.utils.notifyApiError(error)
|
||||||
message: 'Payment received!',
|
})
|
||||||
icon: null
|
}, 2000)
|
||||||
})
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
LNbits.utils.notifyApiError(error)
|
|
||||||
})
|
|
||||||
}, 2000)
|
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
|
|
|
||||||
|
|
@ -52,20 +52,17 @@ async def api_paywall_delete(
|
||||||
raise HTTPException(status_code=HTTPStatus.NO_CONTENT)
|
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(
|
async def api_paywall_create_invoice(
|
||||||
paywall_id,
|
|
||||||
data: CreatePaywallInvoice,
|
data: CreatePaywallInvoice,
|
||||||
wallet: WalletTypeInfo = Depends(get_key_type),
|
paywall_id: str = Query(None)
|
||||||
):
|
):
|
||||||
paywall = await get_paywall(paywall_id)
|
paywall = await get_paywall(paywall_id)
|
||||||
|
|
||||||
if data.amount < paywall.amount:
|
if data.amount < paywall.amount:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
detail=f"Minimum amount is {paywall.amount} sat.",
|
detail=f"Minimum amount is {paywall.amount} sat.",
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
amount = data.amount if data.amount > paywall.amount else paywall.amount
|
amount = data.amount if data.amount > paywall.amount else paywall.amount
|
||||||
payment_hash, payment_request = await create_invoice(
|
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}
|
return {"payment_hash": payment_hash, "payment_request": payment_request}
|
||||||
|
|
||||||
|
|
||||||
@paywall_ext.post("/api/v1/paywalls/{paywall_id}/check_invoice")
|
@paywall_ext.post("/api/v1/paywalls/check_invoice/{paywall_id}")
|
||||||
async def api_paywal_check_invoice(data: CheckPaywallInvoice, paywall_id):
|
async def api_paywal_check_invoice(data: CheckPaywallInvoice, paywall_id: str = Query(None)):
|
||||||
paywall = await get_paywall(paywall_id)
|
paywall = await get_paywall(paywall_id)
|
||||||
payment_hash = data.payment_hash
|
payment_hash = data.payment_hash
|
||||||
if not paywall:
|
if not paywall:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="Paywall does not exist."
|
status_code=HTTPStatus.NOT_FOUND, detail="Paywall does not exist."
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
status = await check_invoice_status(paywall.wallet, payment_hash)
|
status = await check_invoice_status(paywall.wallet, payment_hash)
|
||||||
is_paid = not status.pending
|
is_paid = not status.pending
|
||||||
|
|
@ -101,5 +97,4 @@ async def api_paywal_check_invoice(data: CheckPaywallInvoice, paywall_id):
|
||||||
await payment.set_pending(False)
|
await payment.set_pending(False)
|
||||||
|
|
||||||
return {"paid": True, "url": paywall.url, "remembers": paywall.remembers}
|
return {"paid": True, "url": paywall.url, "remembers": paywall.remembers}
|
||||||
|
|
||||||
return {"paid": False}
|
return {"paid": False}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue