Skip to content

Commit 32c2309

Browse files
committed
fix: if sats and fiat checkout conversion currency
1 parent 680b035 commit 32c2309

7 files changed

Lines changed: 59 additions & 16 deletions

File tree

migrations.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,13 @@ async def m007_add_allow_fiat(db):
185185
ALTER TABLE events.events
186186
ADD COLUMN allow_fiat BOOLEAN NOT NULL DEFAULT FALSE;
187187
""")
188+
189+
190+
async def m008_add_fiat_currency(db):
191+
"""
192+
Add a fiat_currency column for sat-denominated events using fiat checkout.
193+
"""
194+
await db.execute("""
195+
ALTER TABLE events.events
196+
ADD COLUMN fiat_currency TEXT NOT NULL DEFAULT 'GBP';
197+
""")

models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class CreateEvent(BaseModel):
3737
event_end_date: str
3838
currency: str = "sat"
3939
allow_fiat: bool = False
40+
fiat_currency: str = "GBP"
4041
amount_tickets: int = Query(..., ge=0)
4142
price_per_ticket: float = Query(..., ge=0)
4243
banner: str | None = None
@@ -54,6 +55,7 @@ class Event(BaseModel):
5455
event_end_date: str
5556
currency: str
5657
allow_fiat: bool = False
58+
fiat_currency: str = "GBP"
5759
amount_tickets: int
5860
price_per_ticket: float
5961
time: datetime
@@ -72,6 +74,7 @@ class PublicEvent(BaseModel):
7274
event_end_date: str
7375
currency: str
7476
allow_fiat: bool = False
77+
fiat_currency: str = "GBP"
7578
price_per_ticket: float
7679
banner: str | None
7780
extra: EventExtra = Field(default_factory=EventExtra)

static/js/display.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ window.PageEventsDisplay = {
4141
return LNbits.utils.convertMarkdown(this.event?.info || '')
4242
},
4343
allowFiatCheckout() {
44-
const currency = (this.event?.currency || '').toLowerCase()
45-
return this.event?.allow_fiat && !['sat', 'sats'].includes(currency)
44+
return Boolean(this.event?.allow_fiat)
45+
},
46+
fiatCheckoutLabel() {
47+
if (!this.allowFiatCheckout) return 'Fiat'
48+
const unit = ['sat', 'sats'].includes(
49+
(this.event?.currency || '').toLowerCase()
50+
)
51+
? this.event?.fiat_currency
52+
: this.event?.currency
53+
return `Fiat (${(unit || 'GBP').toUpperCase()})`
4654
},
4755
allowEmailNotifications() {
4856
return Boolean(this.event?.extra?.email_notifications)

static/js/display.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
:options="[
7373
{label: 'Lightning', value: 'lightning'},
7474
{
75-
label: `Fiat (${event.currency.toUpperCase()})`,
75+
label: fiatCheckoutLabel,
7676
value: 'fiat'
7777
}
7878
]"

static/js/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ window.PageEvents = {
9999
data: {
100100
currency: 'sats',
101101
allow_fiat: false,
102+
fiat_currency: 'GBP',
102103
extra: {
103104
promo_codes: []
104105
}
@@ -171,7 +172,9 @@ window.PageEvents = {
171172
}))
172173
}
173174
if (!this.isFiatCurrency(data.currency)) {
174-
data.allow_fiat = false
175+
if (!data.allow_fiat) {
176+
data.fiat_currency = 'GBP'
177+
}
175178
}
176179

177180
if (data.id) {
@@ -188,6 +191,7 @@ window.PageEvents = {
188191
this.formDialog.data = {
189192
currency: 'sats',
190193
allow_fiat: false,
194+
fiat_currency: 'GBP',
191195
extra: {
192196
conditional: false,
193197
min_tickets: 1,
@@ -204,6 +208,7 @@ window.PageEvents = {
204208
this.formDialog.data = {
205209
currency: 'sats',
206210
allow_fiat: false,
211+
fiat_currency: 'GBP',
207212
extra: {
208213
email_notifications: false,
209214
nostr_notifications: false,

static/js/index.vue

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,27 @@
373373
</div>
374374
<q-toggle
375375
v-model="formDialog.data.allow_fiat"
376-
:disable="
377-
formDialog.data.currency == null ||
378-
['sat', 'sats'].includes(
379-
(formDialog.data.currency || '').toLowerCase()
380-
)
381-
"
382376
label="Allow fiat checkout"
383377
left-label
384378
hint="Lets attendees pay through a configured fiat provider using the event currency."
385379
></q-toggle>
380+
<q-select
381+
v-if="
382+
formDialog.data.allow_fiat &&
383+
['sat', 'sats'].includes(
384+
(formDialog.data.currency || '').toLowerCase()
385+
)
386+
"
387+
filled
388+
dense
389+
v-model="formDialog.data.fiat_currency"
390+
label="Fiat checkout currency"
391+
:options="
392+
currencies.filter(
393+
c => !['sat', 'sats'].includes((c || '').toLowerCase())
394+
)
395+
"
396+
></q-select>
386397
<q-expansion-item
387398
group="advanced"
388399
icon="settings"

views_api.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from lnbits.utils.exchange_rates import (
2626
fiat_amount_as_satoshis,
2727
get_fiat_rate_satoshis,
28+
satoshis_amount_as_fiat,
2829
)
2930
from lnbits.utils.nostr import normalize_public_key
3031

@@ -266,13 +267,18 @@ async def api_ticket_create(
266267
price = await fiat_amount_as_satoshis(price, event.currency)
267268

268269
invoice_unit = event.currency
270+
fiat_amount = price
269271
fiat_provider = None
270272
if payment_method == "fiat":
271-
if not _is_fiat_currency(event.currency):
272-
raise HTTPException(
273-
status_code=HTTPStatus.BAD_REQUEST,
274-
detail="Fiat checkout requires a fiat-denominated ticket price.",
275-
)
273+
if _is_fiat_currency(event.currency):
274+
invoice_unit = event.currency
275+
else:
276+
invoice_unit = event.fiat_currency
277+
fiat_amount = await satoshis_amount_as_fiat(price, invoice_unit)
278+
extra["fiat"] = True
279+
extra["currency"] = invoice_unit
280+
extra["fiatAmount"] = fiat_amount
281+
extra["rate"] = await get_fiat_rate_satoshis(invoice_unit)
276282
wallet = await get_wallet(event.wallet)
277283
if not wallet:
278284
raise HTTPException(
@@ -293,7 +299,7 @@ async def api_ticket_create(
293299
wallet_id=event.wallet,
294300
invoice_data=CreateInvoice(
295301
out=False,
296-
amount=price,
302+
amount=fiat_amount if payment_method == "fiat" else price,
297303
unit=invoice_unit,
298304
fiat_provider=fiat_provider,
299305
memo=f"{event_id}",

0 commit comments

Comments
 (0)