[FEAT] Fiat event tickets (#10)
This commit is contained in:
parent
ff73bc749b
commit
5e391a04bc
7 changed files with 237 additions and 237 deletions
12
crud.py
12
crud.py
|
|
@ -9,7 +9,8 @@ from .models import CreateEvent, Event, Ticket
|
||||||
|
|
||||||
|
|
||||||
async def create_ticket(
|
async def create_ticket(
|
||||||
payment_hash: str, wallet: str, event: str, name: str, email: str) -> Ticket:
|
payment_hash: str, wallet: str, event: str, name: str, email: str
|
||||||
|
) -> Ticket:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO events.ticket (id, wallet, event, name, email, registered, paid)
|
INSERT INTO events.ticket (id, wallet, event, name, email, registered, paid)
|
||||||
|
|
@ -22,9 +23,12 @@ async def create_ticket(
|
||||||
assert ticket, "Newly created ticket couldn't be retrieved"
|
assert ticket, "Newly created ticket couldn't be retrieved"
|
||||||
return ticket
|
return ticket
|
||||||
|
|
||||||
|
|
||||||
async def set_ticket_paid(payment_hash: str) -> Ticket:
|
async def set_ticket_paid(payment_hash: str) -> Ticket:
|
||||||
ticket = await get_ticket(payment_hash)
|
ticket = await get_ticket(payment_hash)
|
||||||
assert ticket, "Ticket couldn't be retrieved"
|
assert ticket, "Ticket couldn't be retrieved"
|
||||||
|
if ticket.paid:
|
||||||
|
return ticket
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
|
|
@ -39,6 +43,7 @@ async def set_ticket_paid(payment_hash: str) -> Ticket:
|
||||||
|
|
||||||
return ticket
|
return ticket
|
||||||
|
|
||||||
|
|
||||||
async def update_event_sold(event_id: str):
|
async def update_event_sold(event_id: str):
|
||||||
event = await get_event(event_id)
|
event = await get_event(event_id)
|
||||||
assert event, "Couldn't get event from ticket being paid"
|
assert event, "Couldn't get event from ticket being paid"
|
||||||
|
|
@ -87,8 +92,8 @@ async def create_event(data: CreateEvent) -> Event:
|
||||||
event_id = urlsafe_short_hash()
|
event_id = urlsafe_short_hash()
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO events.events (id, wallet, name, info, closing_date, event_start_date, event_end_date, amount_tickets, price_per_ticket, sold)
|
INSERT INTO events.events (id, wallet, name, info, closing_date, event_start_date, event_end_date, currency, amount_tickets, price_per_ticket, sold)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
event_id,
|
event_id,
|
||||||
|
|
@ -98,6 +103,7 @@ async def create_event(data: CreateEvent) -> Event:
|
||||||
data.closing_date,
|
data.closing_date,
|
||||||
data.event_start_date,
|
data.event_start_date,
|
||||||
data.event_end_date,
|
data.event_end_date,
|
||||||
|
data.currency,
|
||||||
data.amount_tickets,
|
data.amount_tickets,
|
||||||
data.price_per_ticket,
|
data.price_per_ticket,
|
||||||
0,
|
0,
|
||||||
|
|
|
||||||
|
|
@ -88,3 +88,68 @@ async def m003_add_register_timestamp(db):
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"ALTER TABLE events.ticket ADD COLUMN reg_timestamp TIMESTAMP;"
|
"ALTER TABLE events.ticket ADD COLUMN reg_timestamp TIMESTAMP;"
|
||||||
) # NULL means not registered, or old ticket
|
) # NULL means not registered, or old ticket
|
||||||
|
|
||||||
|
|
||||||
|
async def m004_add_currency(db):
|
||||||
|
"""
|
||||||
|
Add a currency table to allow fiat denomination
|
||||||
|
of tickets. Make price a float.
|
||||||
|
"""
|
||||||
|
await db.execute("ALTER TABLE events.events RENAME TO events_old")
|
||||||
|
await db.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE events.events (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
wallet TEXT NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
info TEXT NOT NULL,
|
||||||
|
closing_date TEXT NOT NULL,
|
||||||
|
event_start_date TEXT NOT NULL,
|
||||||
|
event_end_date TEXT NOT NULL,
|
||||||
|
currency TEXT NOT NULL,
|
||||||
|
amount_tickets INTEGER NOT NULL,
|
||||||
|
price_per_ticket REAL NOT NULL,
|
||||||
|
sold INTEGER NOT NULL,
|
||||||
|
time TIMESTAMP NOT NULL DEFAULT """
|
||||||
|
+ db.timestamp_now
|
||||||
|
+ """
|
||||||
|
);
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in [
|
||||||
|
list(row) for row in await db.fetchall("SELECT * FROM events.events_old")
|
||||||
|
]:
|
||||||
|
await db.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO events.events (
|
||||||
|
id,
|
||||||
|
wallet,
|
||||||
|
name,
|
||||||
|
info,
|
||||||
|
closing_date,
|
||||||
|
event_start_date,
|
||||||
|
event_end_date,
|
||||||
|
currency,
|
||||||
|
amount_tickets,
|
||||||
|
price_per_ticket,
|
||||||
|
sold
|
||||||
|
)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
row[0],
|
||||||
|
row[1],
|
||||||
|
row[2],
|
||||||
|
row[3],
|
||||||
|
row[4],
|
||||||
|
row[5],
|
||||||
|
row[6],
|
||||||
|
"sat",
|
||||||
|
row[7],
|
||||||
|
row[8],
|
||||||
|
row[9],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
await db.execute("DROP TABLE events.events_old")
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,9 @@ class CreateEvent(BaseModel):
|
||||||
closing_date: str
|
closing_date: str
|
||||||
event_start_date: str
|
event_start_date: str
|
||||||
event_end_date: str
|
event_end_date: str
|
||||||
|
currency: str = "sat"
|
||||||
amount_tickets: int = Query(..., ge=0)
|
amount_tickets: int = Query(..., ge=0)
|
||||||
price_per_ticket: int = Query(..., ge=0)
|
price_per_ticket: float = Query(..., ge=0)
|
||||||
|
|
||||||
|
|
||||||
class CreateTicket(BaseModel):
|
class CreateTicket(BaseModel):
|
||||||
|
|
@ -27,8 +28,9 @@ class Event(BaseModel):
|
||||||
closing_date: str
|
closing_date: str
|
||||||
event_start_date: str
|
event_start_date: str
|
||||||
event_end_date: str
|
event_end_date: str
|
||||||
|
currency: str
|
||||||
amount_tickets: int
|
amount_tickets: int
|
||||||
price_per_ticket: int
|
price_per_ticket: float
|
||||||
sold: int
|
sold: int
|
||||||
time: int
|
time: int
|
||||||
|
|
||||||
|
|
|
||||||
1
tasks.py
1
tasks.py
|
|
@ -24,6 +24,5 @@ async def on_invoice_paid(payment: Payment) -> None:
|
||||||
and payment.extra.get("name")
|
and payment.extra.get("name")
|
||||||
and payment.extra.get("email")
|
and payment.extra.get("email")
|
||||||
):
|
):
|
||||||
|
|
||||||
await set_ticket_paid(payment.payment_hash)
|
await set_ticket_paid(payment.payment_hash)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -5,35 +5,22 @@
|
||||||
<q-card-section class="q-pa-none">
|
<q-card-section class="q-pa-none">
|
||||||
<h3 class="q-my-none">{{ event_name }}</h3>
|
<h3 class="q-my-none">{{ event_name }}</h3>
|
||||||
<br />
|
<br />
|
||||||
<h5 class="q-my-none">{{ event_info }}</h5>
|
<div v-html="formatDescription"></div>
|
||||||
<br />
|
<br />
|
||||||
|
</q-card-section>
|
||||||
|
</q-card>
|
||||||
|
<q-card class="q-pa-lg">
|
||||||
|
<q-card-section class="q-pa-none">
|
||||||
|
<h5 class="q-mt-none">Buy Ticket</h5>
|
||||||
<q-form @submit="Invoice()" class="q-gutter-md">
|
<q-form @submit="Invoice()" class="q-gutter-md">
|
||||||
<q-input
|
<q-input filled dense v-model.trim="formDialog.data.name" type="name" label="Your name "></q-input>
|
||||||
filled
|
<q-input filled dense v-model.trim="formDialog.data.email" type="email" label="Your email "></q-input>
|
||||||
dense
|
|
||||||
v-model.trim="formDialog.data.name"
|
|
||||||
type="name"
|
|
||||||
label="Your name "
|
|
||||||
></q-input>
|
|
||||||
<q-input
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.trim="formDialog.data.email"
|
|
||||||
type="email"
|
|
||||||
label="Your email "
|
|
||||||
></q-input>
|
|
||||||
|
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg">
|
||||||
<q-btn
|
<q-btn unelevated color="primary"
|
||||||
unelevated
|
:disable="formDialog.data.name == '' || formDialog.data.email == '' || Boolean(paymentReq)"
|
||||||
color="primary"
|
type="submit">Submit</q-btn>
|
||||||
:disable="formDialog.data.name == '' || formDialog.data.email == '' || paymentReq"
|
<q-btn @click="resetForm" flat color="grey" class="q-ml-auto">Cancel</q-btn>
|
||||||
type="submit"
|
|
||||||
>Submit</q-btn
|
|
||||||
>
|
|
||||||
<q-btn @click="resetForm" flat color="grey" class="q-ml-auto"
|
|
||||||
>Cancel</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</q-form>
|
</q-form>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
|
@ -41,15 +28,8 @@
|
||||||
|
|
||||||
<q-card v-show="ticketLink.show" class="q-pa-lg">
|
<q-card v-show="ticketLink.show" class="q-pa-lg">
|
||||||
<div class="text-center q-mb-lg">
|
<div class="text-center q-mb-lg">
|
||||||
<q-btn
|
<q-btn unelevated size="xl" :href="ticketLink.data.link" target="_blank" color="primary" type="a">Link to your
|
||||||
unelevated
|
ticket!</q-btn>
|
||||||
size="xl"
|
|
||||||
:href="ticketLink.data.link"
|
|
||||||
target="_blank"
|
|
||||||
color="primary"
|
|
||||||
type="a"
|
|
||||||
>Link to your ticket!</q-btn
|
|
||||||
>
|
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<p>You'll be redirected in a few moments...</p>
|
<p>You'll be redirected in a few moments...</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -57,27 +37,19 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<q-dialog v-model="receive.show" position="top" @hide="closeReceiveDialog">
|
<q-dialog v-model="receive.show" position="top" @hide="closeReceiveDialog">
|
||||||
<q-card
|
<q-card v-if="!receive.paymentReq" class="q-pa-lg q-pt-xl lnbits__dialog-card">
|
||||||
v-if="!receive.paymentReq"
|
|
||||||
class="q-pa-lg q-pt-xl lnbits__dialog-card"
|
|
||||||
>
|
|
||||||
</q-card>
|
</q-card>
|
||||||
<q-card v-else class="q-pa-lg q-pt-xl lnbits__dialog-card">
|
<q-card v-else class="q-pa-lg q-pt-xl lnbits__dialog-card">
|
||||||
<div class="text-center q-mb-lg">
|
<div class="text-center q-mb-lg">
|
||||||
<a class="text-secondary" :href="'lightning:' + receive.paymentReq">
|
<a class="text-secondary" :href="'lightning:' + receive.paymentReq">
|
||||||
<q-responsive :ratio="1" class="q-mx-xl">
|
<q-responsive :ratio="1" class="q-mx-xl">
|
||||||
<qrcode
|
<qrcode :value="'lightning:' + receive.paymentReq.toUpperCase()" :options="{width: 340}"
|
||||||
:value="'lightning:' + receive.paymentReq.toUpperCase()"
|
class="rounded-borders"></qrcode>
|
||||||
:options="{width: 340}"
|
|
||||||
class="rounded-borders"
|
|
||||||
></qrcode>
|
|
||||||
</q-responsive>
|
</q-responsive>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg">
|
||||||
<q-btn outline color="grey" @click="copyText(receive.paymentReq)"
|
<q-btn outline color="grey" @click="copyText(receive.paymentReq)">Copy invoice</q-btn>
|
||||||
>Copy invoice</q-btn
|
|
||||||
>
|
|
||||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn>
|
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn>
|
||||||
</div>
|
</div>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -115,7 +87,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
this.info = '{{ event_info | tojson }}'
|
||||||
|
this.info = this.info.substring(1, this.info.length - 1)
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
formatDescription() {
|
||||||
|
return LNbits.utils.convertMarkdown(this.info)
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
resetForm: function (e) {
|
resetForm: function (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
@ -128,7 +108,7 @@
|
||||||
dismissMsg()
|
dismissMsg()
|
||||||
|
|
||||||
clearInterval(paymentChecker)
|
clearInterval(paymentChecker)
|
||||||
setTimeout(function () {}, 10000)
|
setTimeout(function () { }, 10000)
|
||||||
},
|
},
|
||||||
Invoice: function () {
|
Invoice: function () {
|
||||||
var self = this
|
var self = this
|
||||||
|
|
@ -136,11 +116,11 @@
|
||||||
|
|
||||||
.get(
|
.get(
|
||||||
'/events/api/v1/tickets/' +
|
'/events/api/v1/tickets/' +
|
||||||
'{{ event_id }}' +
|
'{{ event_id }}' +
|
||||||
'/' +
|
'/' +
|
||||||
self.formDialog.data.name +
|
self.formDialog.data.name +
|
||||||
'/' +
|
'/' +
|
||||||
self.formDialog.data.email
|
self.formDialog.data.email
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
self.paymentReq = response.data.payment_request
|
self.paymentReq = response.data.payment_request
|
||||||
|
|
@ -161,8 +141,8 @@
|
||||||
axios
|
axios
|
||||||
.post(
|
.post(
|
||||||
'/events/api/v1/tickets/' +
|
'/events/api/v1/tickets/' +
|
||||||
'{{ event_id }}/' +
|
'{{ event_id }}/' +
|
||||||
self.paymentCheck,
|
self.paymentCheck,
|
||||||
{
|
{
|
||||||
event: '{{ event_id }}',
|
event: '{{ event_id }}',
|
||||||
event_name: '{{ event_name }}',
|
event_name: '{{ event_name }}',
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@
|
||||||
<div class="col-12 col-md-8 col-lg-7 q-gutter-y-md">
|
<div class="col-12 col-md-8 col-lg-7 q-gutter-y-md">
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<q-btn unelevated color="primary" @click="formDialog.show = true"
|
<q-btn unelevated color="primary" @click="formDialog.show = true">New Event</q-btn>
|
||||||
>New Event</q-btn
|
|
||||||
>
|
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
||||||
|
|
@ -17,19 +15,11 @@
|
||||||
<h5 class="text-subtitle1 q-my-none">Events</h5>
|
<h5 class="text-subtitle1 q-my-none">Events</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<q-btn flat color="grey" @click="exporteventsCSV"
|
<q-btn flat color="grey" @click="exporteventsCSV">Export to CSV</q-btn>
|
||||||
>Export to CSV</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-table
|
<q-table dense flat :data="events" row-key="id" :columns="eventsTable.columns"
|
||||||
dense
|
:pagination.sync="eventsTable.pagination">
|
||||||
flat
|
|
||||||
:data="events"
|
|
||||||
row-key="id"
|
|
||||||
:columns="eventsTable.columns"
|
|
||||||
:pagination.sync="eventsTable.pagination"
|
|
||||||
>
|
|
||||||
{% raw %}
|
{% raw %}
|
||||||
<template v-slot:header="props">
|
<template v-slot:header="props">
|
||||||
<q-tr :props="props">
|
<q-tr :props="props">
|
||||||
|
|
@ -45,49 +35,20 @@
|
||||||
<template v-slot:body="props">
|
<template v-slot:body="props">
|
||||||
<q-tr :props="props">
|
<q-tr :props="props">
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
<q-btn
|
<q-btn unelevated dense size="xs" icon="link" :color="($q.dark.isActive) ? 'grey-7' : 'grey-5'" type="a"
|
||||||
unelevated
|
:href="props.row.displayUrl" target="_blank"></q-btn>
|
||||||
dense
|
<q-btn unelevated dense size="xs" icon="how_to_reg" :color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||||
size="xs"
|
type="a" :href="'/events/register/' + props.row.id" target="_blank"></q-btn>
|
||||||
icon="link"
|
|
||||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
|
||||||
type="a"
|
|
||||||
:href="props.row.displayUrl"
|
|
||||||
target="_blank"
|
|
||||||
></q-btn>
|
|
||||||
<q-btn
|
|
||||||
unelevated
|
|
||||||
dense
|
|
||||||
size="xs"
|
|
||||||
icon="how_to_reg"
|
|
||||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
|
||||||
type="a"
|
|
||||||
:href="'/events/register/' + props.row.id"
|
|
||||||
target="_blank"
|
|
||||||
></q-btn>
|
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||||
{{ col.value }}
|
{{ col.value }}
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
<q-btn
|
<q-btn flat dense size="xs" @click="updateformDialog(props.row.id)" icon="edit"
|
||||||
flat
|
color="light-blue"></q-btn>
|
||||||
dense
|
|
||||||
size="xs"
|
|
||||||
@click="updateformDialog(props.row.id)"
|
|
||||||
icon="edit"
|
|
||||||
color="light-blue"
|
|
||||||
></q-btn>
|
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
<q-btn
|
<q-btn flat dense size="xs" @click="deleteEvent(props.row.id)" icon="cancel" color="pink"></q-btn>
|
||||||
flat
|
|
||||||
dense
|
|
||||||
size="xs"
|
|
||||||
@click="deleteEvent(props.row.id)"
|
|
||||||
icon="cancel"
|
|
||||||
color="pink"
|
|
||||||
></q-btn>
|
|
||||||
</q-td>
|
</q-td>
|
||||||
</q-tr>
|
</q-tr>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -103,19 +64,11 @@
|
||||||
<h5 class="text-subtitle1 q-my-none">Tickets</h5>
|
<h5 class="text-subtitle1 q-my-none">Tickets</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<q-btn flat color="grey" @click="exportticketsCSV"
|
<q-btn flat color="grey" @click="exportticketsCSV">Export to CSV</q-btn>
|
||||||
>Export to CSV</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<q-table
|
<q-table dense flat :data="tickets" row-key="id" :columns="ticketsTable.columns"
|
||||||
dense
|
:pagination.sync="ticketsTable.pagination">
|
||||||
flat
|
|
||||||
:data="tickets"
|
|
||||||
row-key="id"
|
|
||||||
:columns="ticketsTable.columns"
|
|
||||||
:pagination.sync="ticketsTable.pagination"
|
|
||||||
>
|
|
||||||
{% raw %}
|
{% raw %}
|
||||||
<template v-slot:header="props">
|
<template v-slot:header="props">
|
||||||
<q-tr :props="props">
|
<q-tr :props="props">
|
||||||
|
|
@ -128,16 +81,9 @@
|
||||||
<template v-slot:body="props">
|
<template v-slot:body="props">
|
||||||
<q-tr :props="props">
|
<q-tr :props="props">
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
<q-btn
|
<q-btn unelevated dense size="xs" icon="local_activity"
|
||||||
unelevated
|
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'" type="a" :href="'/events/ticket/' + props.row.id"
|
||||||
dense
|
target="_blank"></q-btn>
|
||||||
size="xs"
|
|
||||||
icon="local_activity"
|
|
||||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
|
||||||
type="a"
|
|
||||||
:href="'/events/ticket/' + props.row.id"
|
|
||||||
target="_blank"
|
|
||||||
></q-btn>
|
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
||||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||||
|
|
@ -145,14 +91,7 @@
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
<q-btn
|
<q-btn flat dense size="xs" @click="deleteTicket(props.row.id)" icon="cancel" color="pink"></q-btn>
|
||||||
flat
|
|
||||||
dense
|
|
||||||
size="xs"
|
|
||||||
@click="deleteTicket(props.row.id)"
|
|
||||||
icon="cancel"
|
|
||||||
color="pink"
|
|
||||||
></q-btn>
|
|
||||||
</q-td>
|
</q-td>
|
||||||
</q-tr>
|
</q-tr>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -180,116 +119,72 @@
|
||||||
<q-form @submit="sendEventData" class="q-gutter-md">
|
<q-form @submit="sendEventData" class="q-gutter-md">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<q-input
|
<q-input filled dense v-model.trim="formDialog.data.name" type="name" label="Title of event "></q-input>
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.trim="formDialog.data.name"
|
|
||||||
type="name"
|
|
||||||
label="Title of event "
|
|
||||||
></q-input>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col q-pl-sm">
|
<div class="col q-pl-sm">
|
||||||
<q-select
|
<q-select filled dense emit-value v-model="formDialog.data.wallet" :options="g.user.walletOptions"
|
||||||
filled
|
label="Wallet *">
|
||||||
dense
|
|
||||||
emit-value
|
|
||||||
v-model="formDialog.data.wallet"
|
|
||||||
:options="g.user.walletOptions"
|
|
||||||
label="Wallet *"
|
|
||||||
>
|
|
||||||
</q-select>
|
</q-select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<q-input
|
<q-input filled dense v-model.trim="formDialog.data.info" type="textarea" label="Info about the event"
|
||||||
filled
|
hint="Markdown supported"></q-input>
|
||||||
dense
|
|
||||||
v-model.trim="formDialog.data.info"
|
|
||||||
type="textarea"
|
|
||||||
label="Info about the event "
|
|
||||||
></q-input>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Ticket closing date</div>
|
<div class="col-4">Ticket closing date</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<q-input
|
<q-input filled dense v-model.trim="formDialog.data.closing_date" type="date"></q-input>
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.trim="formDialog.data.closing_date"
|
|
||||||
type="date"
|
|
||||||
></q-input>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Event begins</div>
|
<div class="col-4">Event begins</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<q-input
|
<q-input filled dense v-model.trim="formDialog.data.event_start_date" type="date"></q-input>
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.trim="formDialog.data.event_start_date"
|
|
||||||
type="date"
|
|
||||||
></q-input>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">Event ends</div>
|
<div class="col-4">Event ends</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<q-input
|
<q-input filled dense v-model.trim="formDialog.data.event_end_date" type="date"></q-input>
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model.trim="formDialog.data.event_end_date"
|
|
||||||
type="date"
|
|
||||||
></q-input>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row q-col-gutter-sm">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<q-input
|
<q-select filled dense v-model="formDialog.data.currency" type="text" label="Unit"
|
||||||
filled
|
:options="currencies"></q-select>
|
||||||
dense
|
|
||||||
v-model.number="formDialog.data.amount_tickets"
|
|
||||||
type="number"
|
|
||||||
label="Amount of tickets "
|
|
||||||
></q-input>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col q-pl-sm">
|
<div class="col">
|
||||||
<q-input
|
<q-input filled dense v-model.number="formDialog.data.amount_tickets" type="number"
|
||||||
filled
|
label="Amount of tickets "></q-input>
|
||||||
dense
|
</div>
|
||||||
v-model.number="formDialog.data.price_per_ticket"
|
<div class="col">
|
||||||
type="number"
|
<q-input filled dense v-model.number="formDialog.data.price_per_ticket" type="number"
|
||||||
label="Sats per ticket "
|
:label="'Price (' + formDialog.data.currency + ') *'"
|
||||||
></q-input>
|
:step="formDialog.data.currency != 'sat' ? '0.01' : '1'"
|
||||||
|
:mask="formDialog.data.currency != 'sat' ? '#.##' : '#'" fill-mask="0" reverse-fill-mask></q-input>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg">
|
||||||
<q-btn
|
<q-btn v-if="formDialog.data.id" unelevated color="primary" type="submit">Update Event</q-btn>
|
||||||
v-if="formDialog.data.id"
|
<q-btn v-else unelevated color="primary"
|
||||||
unelevated
|
|
||||||
color="primary"
|
|
||||||
type="submit"
|
|
||||||
>Update Event</q-btn
|
|
||||||
>
|
|
||||||
<q-btn
|
|
||||||
v-else
|
|
||||||
unelevated
|
|
||||||
color="primary"
|
|
||||||
:disable="formDialog.data.wallet == null || formDialog.data.name == null || formDialog.data.info == null || formDialog.data.closing_date == null || formDialog.data.event_start_date == null || formDialog.data.event_end_date == null || formDialog.data.amount_tickets == null || formDialog.data.price_per_ticket == null"
|
:disable="formDialog.data.wallet == null || formDialog.data.name == null || formDialog.data.info == null || formDialog.data.closing_date == null || formDialog.data.event_start_date == null || formDialog.data.event_end_date == null || formDialog.data.amount_tickets == null || formDialog.data.price_per_ticket == null"
|
||||||
type="submit"
|
type="submit">Create Event</q-btn>
|
||||||
>Create Event</q-btn
|
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Cancel</q-btn>
|
||||||
>
|
|
||||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
|
||||||
>Cancel</q-btn
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</q-form>
|
</q-form>
|
||||||
</q-card>
|
</q-card>
|
||||||
</q-dialog>
|
</q-dialog>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %} {% block scripts %} {{ window_vars(user) }}
|
{% endblock %} {% block scripts %} {{ window_vars(user) }}
|
||||||
|
<style>
|
||||||
|
.q-field__native span {
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
<script>
|
<script>
|
||||||
var mapEvents = function (obj) {
|
var mapEvents = function (obj) {
|
||||||
obj.date = Quasar.utils.date.formatDate(
|
obj.date = Quasar.utils.date.formatDate(
|
||||||
|
|
@ -308,11 +203,12 @@
|
||||||
return {
|
return {
|
||||||
events: [],
|
events: [],
|
||||||
tickets: [],
|
tickets: [],
|
||||||
|
currencies: [],
|
||||||
eventsTable: {
|
eventsTable: {
|
||||||
columns: [
|
columns: [
|
||||||
{name: 'id', align: 'left', label: 'ID', field: 'id'},
|
{ name: 'id', align: 'left', label: 'ID', field: 'id' },
|
||||||
{name: 'name', align: 'left', label: 'Name', field: 'name'},
|
{ name: 'name', align: 'left', label: 'Name', field: 'name' },
|
||||||
{name: 'info', align: 'left', label: 'Info', field: 'info'},
|
{ name: 'info', align: 'left', label: 'Info', field: 'info' },
|
||||||
{
|
{
|
||||||
name: 'event_start_date',
|
name: 'event_start_date',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
|
@ -335,7 +231,15 @@
|
||||||
name: 'price_per_ticket',
|
name: 'price_per_ticket',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
label: 'Price',
|
label: 'Price',
|
||||||
field: 'price_per_ticket'
|
field: row => {
|
||||||
|
if (row.currency != 'sat') {
|
||||||
|
return LNbits.utils.formatCurrency(
|
||||||
|
row.price_per_ticket.toFixed(2),
|
||||||
|
row.currency
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return row.price_per_ticket
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'amount_tickets',
|
name: 'amount_tickets',
|
||||||
|
|
@ -356,10 +260,10 @@
|
||||||
},
|
},
|
||||||
ticketsTable: {
|
ticketsTable: {
|
||||||
columns: [
|
columns: [
|
||||||
{name: 'id', align: 'left', label: 'ID', field: 'id'},
|
{ name: 'id', align: 'left', label: 'ID', field: 'id' },
|
||||||
{name: 'event', align: 'left', label: 'Event', field: 'event'},
|
{ name: 'event', align: 'left', label: 'Event', field: 'event' },
|
||||||
{name: 'name', align: 'left', label: 'Name', field: 'name'},
|
{ name: 'name', align: 'left', label: 'Name', field: 'name' },
|
||||||
{name: 'email', align: 'left', label: 'Email', field: 'email'},
|
{ name: 'email', align: 'left', label: 'Email', field: 'email' },
|
||||||
{
|
{
|
||||||
name: 'registered',
|
name: 'registered',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
|
|
@ -394,7 +298,7 @@
|
||||||
},
|
},
|
||||||
deleteTicket: function (ticketId) {
|
deleteTicket: function (ticketId) {
|
||||||
var self = this
|
var self = this
|
||||||
var tickets = _.findWhere(this.tickets, {id: ticketId})
|
var tickets = _.findWhere(this.tickets, { id: ticketId })
|
||||||
|
|
||||||
LNbits.utils
|
LNbits.utils
|
||||||
.confirmDialog('Are you sure you want to delete this ticket')
|
.confirmDialog('Are you sure you want to delete this ticket')
|
||||||
|
|
@ -403,7 +307,7 @@
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/events/api/v1/tickets/' + ticketId,
|
'/events/api/v1/tickets/' + ticketId,
|
||||||
_.findWhere(self.g.user.wallets, {id: tickets.wallet}).inkey
|
_.findWhere(self.g.user.wallets, { id: tickets.wallet }).inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
self.tickets = _.reject(self.tickets, function (obj) {
|
self.tickets = _.reject(self.tickets, function (obj) {
|
||||||
|
|
@ -432,6 +336,7 @@
|
||||||
self.events = response.data.map(function (obj) {
|
self.events = response.data.map(function (obj) {
|
||||||
return mapEvents(obj)
|
return mapEvents(obj)
|
||||||
})
|
})
|
||||||
|
console.log(self.events)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
sendEventData: function () {
|
sendEventData: function () {
|
||||||
|
|
@ -461,9 +366,9 @@
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
updateformDialog: function (formId) {
|
updateformDialog: function (formId) {
|
||||||
var link = _.findWhere(this.events, {id: formId})
|
var link = _.findWhere(this.events, { id: formId })
|
||||||
|
|
||||||
this.formDialog.data = {...link}
|
this.formDialog.data = { ...link }
|
||||||
|
|
||||||
this.formDialog.show = true
|
this.formDialog.show = true
|
||||||
},
|
},
|
||||||
|
|
@ -491,7 +396,7 @@
|
||||||
},
|
},
|
||||||
deleteEvent: function (eventsId) {
|
deleteEvent: function (eventsId) {
|
||||||
var self = this
|
var self = this
|
||||||
var events = _.findWhere(this.events, {id: eventsId})
|
var events = _.findWhere(this.events, { id: eventsId })
|
||||||
|
|
||||||
LNbits.utils
|
LNbits.utils
|
||||||
.confirmDialog('Are you sure you want to delete this form link?')
|
.confirmDialog('Are you sure you want to delete this form link?')
|
||||||
|
|
@ -500,7 +405,7 @@
|
||||||
.request(
|
.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
'/events/api/v1/events/' + eventsId,
|
'/events/api/v1/events/' + eventsId,
|
||||||
_.findWhere(self.g.user.wallets, {id: events.wallet}).inkey
|
_.findWhere(self.g.user.wallets, { id: events.wallet }).inkey
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
self.events = _.reject(self.events, function (obj) {
|
self.events = _.reject(self.events, function (obj) {
|
||||||
|
|
@ -514,13 +419,27 @@
|
||||||
},
|
},
|
||||||
exporteventsCSV: function () {
|
exporteventsCSV: function () {
|
||||||
LNbits.utils.exportCSV(this.eventsTable.columns, this.events)
|
LNbits.utils.exportCSV(this.eventsTable.columns, this.events)
|
||||||
|
},
|
||||||
|
async getCurrencies() {
|
||||||
|
try {
|
||||||
|
const { data } = await LNbits.api.request(
|
||||||
|
'GET',
|
||||||
|
'/events/api/v1/currencies',
|
||||||
|
this.inkey
|
||||||
|
)
|
||||||
|
|
||||||
|
this.currencies = ['sat', ...data]
|
||||||
|
} catch (error) {
|
||||||
|
LNbits.utils.notifyApiError(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created: function () {
|
created: async function () {
|
||||||
if (this.g.user.wallets.length) {
|
if (this.g.user.wallets.length) {
|
||||||
this.getTickets()
|
this.getTickets()
|
||||||
this.getEvents()
|
this.getEvents()
|
||||||
|
await this.getCurrencies()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
39
views_api.py
39
views_api.py
|
|
@ -6,6 +6,11 @@ from starlette.exceptions import HTTPException
|
||||||
from lnbits.core.crud import get_standalone_payment, get_user
|
from lnbits.core.crud import get_standalone_payment, get_user
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
from lnbits.decorators import WalletTypeInfo, get_key_type
|
from lnbits.decorators import WalletTypeInfo, get_key_type
|
||||||
|
from lnbits.utils.exchange_rates import (
|
||||||
|
currencies,
|
||||||
|
fiat_amount_as_satoshis,
|
||||||
|
get_fiat_rate_satoshis,
|
||||||
|
)
|
||||||
|
|
||||||
from . import events_ext
|
from . import events_ext
|
||||||
from .crud import (
|
from .crud import (
|
||||||
|
|
@ -23,7 +28,7 @@ from .crud import (
|
||||||
set_ticket_paid,
|
set_ticket_paid,
|
||||||
update_event,
|
update_event,
|
||||||
)
|
)
|
||||||
from .models import CreateEvent, CreateTicket
|
from .models import CreateEvent
|
||||||
|
|
||||||
# Events
|
# Events
|
||||||
|
|
||||||
|
|
@ -103,12 +108,24 @@ async def api_ticket_make_ticket(event_id, name, email):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=HTTPStatus.NOT_FOUND, detail="Event does not exist."
|
status_code=HTTPStatus.NOT_FOUND, detail="Event does not exist."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
price = event.price_per_ticket
|
||||||
|
extra = {"tag": "events", "name": name, "email": email}
|
||||||
|
|
||||||
|
if event.currency != "sat":
|
||||||
|
price = await fiat_amount_as_satoshis(event.price_per_ticket, event.currency)
|
||||||
|
|
||||||
|
extra["fiat"] = True
|
||||||
|
extra["currency"] = event.currency
|
||||||
|
extra["fiatAmount"] = event.price_per_ticket
|
||||||
|
extra["rate"] = await get_fiat_rate_satoshis(event.currency)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payment_hash, payment_request = await create_invoice(
|
payment_hash, payment_request = await create_invoice(
|
||||||
wallet_id=event.wallet,
|
wallet_id=event.wallet,
|
||||||
amount=event.price_per_ticket,
|
amount=price, # type: ignore
|
||||||
memo=f"{event_id}",
|
memo=f"{event_id}",
|
||||||
extra={"tag": "events", "name": name, "email": email},
|
extra=extra,
|
||||||
)
|
)
|
||||||
await create_ticket(
|
await create_ticket(
|
||||||
payment_hash=payment_hash,
|
payment_hash=payment_hash,
|
||||||
|
|
@ -137,10 +154,17 @@ async def api_ticket_send_ticket(event_id, payment_hash):
|
||||||
status_code=HTTPStatus.NOT_FOUND,
|
status_code=HTTPStatus.NOT_FOUND,
|
||||||
detail="Ticket could not be fetched.",
|
detail="Ticket could not be fetched.",
|
||||||
)
|
)
|
||||||
|
|
||||||
payment = await get_standalone_payment(payment_hash)
|
payment = await get_standalone_payment(payment_hash)
|
||||||
assert payment
|
assert payment
|
||||||
if not payment.pending and event.price_per_ticket * 1000 == payment.amount:
|
price = (
|
||||||
|
event.price_per_ticket * 1000
|
||||||
|
if event.currency == "sat"
|
||||||
|
else await fiat_amount_as_satoshis(event.price_per_ticket, event.currency)
|
||||||
|
* 1000
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
not payment.pending and abs(price - payment.amount) < price * 0.01
|
||||||
|
): # allow 1% error
|
||||||
await set_ticket_paid(payment_hash)
|
await set_ticket_paid(payment_hash)
|
||||||
return {"paid": True, "ticket_id": ticket.id}
|
return {"paid": True, "ticket_id": ticket.id}
|
||||||
|
|
||||||
|
|
@ -193,3 +217,8 @@ async def api_event_register_ticket(ticket_id):
|
||||||
)
|
)
|
||||||
|
|
||||||
return [ticket.dict() for ticket in await reg_ticket(ticket_id)]
|
return [ticket.dict() for ticket in await reg_ticket(ticket_id)]
|
||||||
|
|
||||||
|
|
||||||
|
@events_ext.get("/api/v1/currencies")
|
||||||
|
async def api_list_currencies_available():
|
||||||
|
return list(currencies.keys())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue