Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,14 @@ async def m020_add_remote_mode_toggle(db: Database):
ALTER TABLE tpos.pos ADD enable_remote BOOLEAN DEFAULT false;
"""
)


async def m021_add_cash_settlement(db: Database):
"""
Add allow_cash_settlement toggle for fiat cash settlements.
"""
await db.execute(
"""
ALTER TABLE tpos.pos ADD allow_cash_settlement BOOLEAN DEFAULT false;
"""
)
2 changes: 2 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class CreateTposData(BaseModel):
fiat_provider: str | None = Field(None)
stripe_card_payments: bool = False
stripe_reader_id: str | None = None
allow_cash_settlement: bool = Field(False)

@validator("tax_default", pre=True, always=True)
def default_tax_when_none(cls, v):
Expand Down Expand Up @@ -104,6 +105,7 @@ class TposClean(BaseModel):
fiat_provider: str | None = None
stripe_card_payments: bool = False
stripe_reader_id: str | None = None
allow_cash_settlement: bool = False

@property
def withdraw_maximum(self) -> int:
Expand Down
16 changes: 14 additions & 2 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const mapTpos = obj => {
? omitTagString.split(',').filter(Boolean)
: []
obj.only_show_sats_on_bitcoin = obj.only_show_sats_on_bitcoin ?? true
obj.allow_cash_settlement = Boolean(obj.allow_cash_settlement)
obj.itemsMap = new Map()
obj.items.forEach((item, idx) => {
let id = `${obj.id}:${idx + 1}`
Expand Down Expand Up @@ -111,7 +112,8 @@ window.app = Vue.createApp({
only_show_sats_on_bitcoin: true,
fiat: false,
stripe_card_payments: false,
stripe_reader_id: ''
stripe_reader_id: '',
allow_cash_settlement: false
},
advanced: {
tips: false,
Expand Down Expand Up @@ -227,6 +229,12 @@ window.app = Vue.createApp({
label: tag,
value: tag
}))
},
isFiatCurrency() {
return (
!!this.formDialog.data.currency &&
this.formDialog.data.currency !== 'sats'
)
}
},
methods: {
Expand All @@ -248,7 +256,8 @@ window.app = Vue.createApp({
only_show_sats_on_bitcoin: true,
fiat: false,
stripe_card_payments: false,
stripe_reader_id: ''
stripe_reader_id: '',
allow_cash_settlement: false
}
this.formDialog.advanced = {tips: false, otc: false}
},
Expand Down Expand Up @@ -315,6 +324,9 @@ window.app = Vue.createApp({
data.withdraw_limit = null
data.withdraw_premium = null
}
if (data.currency === 'sats') {
data.allow_cash_settlement = false
}
const wallet = _.findWhere(this.g.user.wallets, {
id: this.formDialog.data.wallet
})
Expand Down
62 changes: 53 additions & 9 deletions static/js/tpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ window.app = Vue.createApp({
tposId: null,
currency: null,
fiatProvider: null,
allowCashSettlement: false,
payInFiat: false,
fiatMethod: 'checkout',
atmPremium: tpos.withdraw_premium / 100,
Expand Down Expand Up @@ -41,6 +42,7 @@ window.app = Vue.createApp({
paymentChecker: null,
internalMemo: null
},
cashValidating: false,
tipDialog: {
show: false
},
Expand Down Expand Up @@ -223,6 +225,12 @@ window.app = Vue.createApp({
fullScreenIcon() {
return this.isFullScreen ? 'fullscreen_exit' : 'fullscreen'
},
bitcoinSymbol() {
return LNbits.utils.getCurrencySymbol('BTC')
},
currencySymbol() {
return LNbits.utils.getCurrencySymbol(this.currency)
},
filteredItems() {
// filter out disabled items
let items = this.items.filter(item => !item.disabled)
Expand Down Expand Up @@ -332,11 +340,15 @@ window.app = Vue.createApp({
this.invoiceDialog.data.payment_hash = paymentHash
this.invoiceDialog.data.payment_request = paymentRequest
this.invoiceDialog.show = true
this.readNfcTag()
this.invoiceDialog.dismissMsg = Quasar.Notify.create({
timeout: 0,
message: 'Waiting for payment...'
})
if (paymentRequest !== 'cash') {
this.readNfcTag()
this.invoiceDialog.dismissMsg = Quasar.Notify.create({
timeout: 0,
message: 'Waiting for payment...'
})
} else {
this.invoiceDialog.dismissMsg = () => {}
}
},
setColor(category) {
if (!category || category.toLowerCase() === 'all') {
Expand Down Expand Up @@ -770,6 +782,7 @@ window.app = Vue.createApp({
closeInvoiceDialog() {
this.stack = []
this.tipAmount = 0.0
this.cashValidating = false
const dialog = this.invoiceDialog
setTimeout(() => {
clearInterval(dialog.paymentChecker)
Expand Down Expand Up @@ -838,6 +851,13 @@ window.app = Vue.createApp({
if (method == 'fiat_tap') {
this.fiatMethod = 'terminal'
method = 'fiat'
} else if (method == 'fiat') {
this.fiatMethod = 'checkout'
} else if (method == 'cash') {
this.fiatMethod = 'cash'
method = 'fiat'
} else if (method == 'btc') {
this.fiatMethod = 'checkout'
}
this._currencyResolver(method)
this._currencyResolver = null
Expand Down Expand Up @@ -907,7 +927,7 @@ window.app = Vue.createApp({
return
}

if (this.fiatProvider) {
if (this.fiatProvider || this.allowCashSettlement) {
const method = await this.showPaymentMethod()
this.payInFiat = method === 'fiat'
}
Expand All @@ -921,24 +941,47 @@ window.app = Vue.createApp({
params
)
let paymentRequest = 'lightning:' + data.bolt11.toUpperCase()
if (
data.extra.fiat_payment_request &&
if (data.extra?.fiat_method === 'cash') {
paymentRequest = 'cash'
} else if (
data.extra?.fiat_payment_request &&
!data.extra.fiat_payment_request.startsWith('pi_')
) {
paymentRequest = data.extra.fiat_payment_request
} else if (
data.extra.fiat_payment_request &&
data.extra?.fiat_payment_request &&
data.extra.fiat_payment_request.startsWith('pi_')
) {
paymentRequest = 'tap_to_pay'
}
if (
!data.extra?.fiat_payment_request &&
data.extra?.fiat_method !== 'cash'
) {
paymentRequest = 'lightning:' + data.bolt11.toUpperCase()
}
this.openInvoiceDialog(data.payment_hash, paymentRequest)
this.subscribeToPaymentWS(data.payment_hash)
} catch (error) {
console.error(error)
LNbits.utils.notifyApiError(error)
}
},
async validateCashInvoice() {
const paymentHash = this.invoiceDialog.data.payment_hash
if (!paymentHash || this.cashValidating) return
this.cashValidating = true
try {
await LNbits.api.request(
'POST',
`/tpos/api/v1/tposs/${this.tposId}/invoices/${paymentHash}/cash/validate`
)
} catch (error) {
LNbits.utils.notifyApiError(error)
} finally {
this.cashValidating = false
}
},
subscribeToPaymentWS(paymentHash) {
if (this.paymentWsByHash[paymentHash]) return
try {
Expand Down Expand Up @@ -1382,6 +1425,7 @@ window.app = Vue.createApp({
this.enablePrint = tpos.enable_receipt_print
this.enableRemote = Boolean(tpos.enable_remote)
this.fiatProvider = tpos.fiat_provider
this.allowCashSettlement = Boolean(tpos.allow_cash_settlement)

this.tip_options = tpos.tip_options == 'null' ? null : tpos.tip_options

Expand Down
122 changes: 94 additions & 28 deletions templates/tpos/dialogs.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ <h3>Waiting for card…</h3>
</div>
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn>
</div>
<div
v-else-if="invoiceDialog.data.payment_request == 'cash'"
class="text-center q-mb-xl"
>
<h3>CASH ${ currency }</h3>
<h3 class="q-my-md">${ amountWithTipFormatted }</h3>
<h5 class="q-mt-none q-mb-sm">
${ amountFormatted }
<span v-show="tip_options" style="font-size: 0.75rem"
>(+ ${ tipAmountFormatted } tip)</span
>
</h5>
<div class="row q-mt-lg full-width">
<q-btn
color="primary"
:loading="cashValidating"
@click="validateCashInvoice"
>VALIDATE</q-btn
>
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn>
</div>
</div>
<div v-else :class="isMobileLandscaped ? 'row flex-center' : ''">
<lnbits-qrcode
:show-buttons="false"
Expand Down Expand Up @@ -366,34 +388,78 @@ <h5 class="q-mt-none q-mb-sm">
<q-dialog v-model="currency_choice">
<q-card class="q-pa-md">
<div class="text-h6 q-mb-md">Payment Method</div>
<div class="column q-gutter-y-sm">
<q-btn
class="q-ma-sm"
size="xl"
label="Bitcoin"
color="primary"
rounded
@click="selectPaymentMethod('btc')"
>
</q-btn>
</div>
<div class="row q-gutter-sm q-pt-md justify-center">
<q-btn
class="q-ma-sm"
size="lg"
:label="currency + ' QR'"
color="secondary"
rounded
@click="selectPaymentMethod('fiat')"
></q-btn>
<q-btn
class="q-ma-sm"
size="lg"
:label="currency + ' TAP'"
color="secondary"
rounded
@click="selectPaymentMethod('fiat_tap')"
></q-btn>
<div class="row q-col-gutter-sm q-pt-xs">
<div class="col-6">
<q-btn
class="full-width q-px-lg q-py-sm"
size="xl"
color="primary"
rounded
aria-label="Bitcoin"
@click="selectPaymentMethod('btc')"
>
<div class="row items-center no-wrap q-gutter-x-sm">
<span
class="text-h4 text-weight-bold"
v-text="bitcoinSymbol"
></span>
</div>
</q-btn>
</div>
<div class="col-6" v-if="fiatProvider">
<q-btn
class="full-width q-px-lg q-py-sm"
size="xl"
color="secondary"
rounded
:aria-label="currency + ' QR'"
@click="selectPaymentMethod('fiat')"
>
<div class="row items-center no-wrap q-gutter-x-xs">
<span
class="text-h5 text-weight-bold"
v-text="currencySymbol"
></span>
<q-icon name="qr_code" size="30px"></q-icon>
</div>
</q-btn>
</div>
<div class="col-6" v-if="fiatProvider">
<q-btn
class="full-width q-px-lg q-py-sm"
size="xl"
color="secondary"
rounded
:aria-label="currency + ' TAP'"
@click="selectPaymentMethod('cash')"
>
<div class="row items-center no-wrap q-gutter-x-xs">
<span
class="text-h5 text-weight-bold"
v-text="currencySymbol"
></span>
<q-icon name="toll" size="30px"></q-icon>
</div>
</q-btn>
</div>
<div class="col-6" v-if="allowCashSettlement && currency != 'sats'">
<q-btn
class="full-width q-px-lg q-py-sm"
size="xl"
color="secondary"
rounded
:aria-label="`CASH ${currency}`"
@click="selectPaymentMethod('fiat_tap')"
>
<div class="row items-center no-wrap q-gutter-x-xs">
<span
class="text-h5 text-weight-bold"
v-text="currencySymbol"
></span>
<q-icon name="credit_card" size="30px"></q-icon>
</div>
</q-btn>
</div>
</div>
</q-card>
</q-dialog>
Expand Down
13 changes: 13 additions & 0 deletions templates/tpos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,19 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} TPoS extension</h6>
></q-input>
</div>
</div>
<div v-if="g.user.super_user" class="row q-mt-sm">
<div class="col">
<q-checkbox
v-model="formDialog.data.allow_cash_settlement"
:disable="!isFiatCurrency"
label="Allow cash settlement"
>
<q-tooltip v-if="!isFiatCurrency">
currency must be set to fiat
</q-tooltip>
</q-checkbox>
</div>
</div>
<div class="row">
<div class="col">
<q-checkbox
Expand Down
Loading
Loading