+
+
parseInt(str))) : JSON.stringify([])),
+ tip_wallet: this.formDialog.data.tip_wallet || "",
}
var self = this
diff --git a/lnbits/extensions/tpos/templates/tpos/tpos.html b/lnbits/extensions/tpos/templates/tpos/tpos.html
index 49d88140..277a463a 100644
--- a/lnbits/extensions/tpos/templates/tpos/tpos.html
+++ b/lnbits/extensions/tpos/templates/tpos/tpos.html
@@ -1,5 +1,16 @@
-{% extends "public.html" %} {% block toolbar_title %}{{ tpos.name }}{% endblock
-%} {% block footer %}{% endblock %} {% block page_container %}
+{% extends "public.html" %}
+{% block toolbar_title %}
+{{ tpos.name }}
+
+{% endblock %}
+{% block footer %}{% endblock %} {% block page_container %}
@@ -43,16 +54,6 @@
color="primary"
>3
- C
9
- OK
#C
+ OK
@@ -176,6 +178,38 @@
+
+
+
+
+ Would you like to leave a tip?
+
+
+ {% raw %}{{ tip }}{% endraw %}%
+
+
+
+ Close
+
+
+
+
@@ -214,6 +248,10 @@
{% endblock %} {% block styles %}
{% endblock %} {% block scripts %}
@@ -241,14 +278,19 @@
return {
tposId: '{{ tpos.id }}',
currency: '{{ tpos.currency }}',
+ tip_options: JSON.parse('{{ tpos.tip_options }}'),
exchangeRate: null,
stack: [],
+ tipAmount: 0.00,
invoiceDialog: {
show: false,
data: null,
dismissMsg: null,
paymentChecker: null
},
+ tipDialog: {
+ show: false,
+ },
urlDialog: {
show: false
},
@@ -269,6 +311,10 @@
if (!this.exchangeRate) return 0
return Math.ceil((this.amount / this.exchangeRate) * 100000000)
},
+ tipAmountSat: function () {
+ if (!this.exchangeRate) return 0
+ return Math.ceil((this.tipAmount / this.exchangeRate) * 100000000)
+ },
fsat: function () {
console.log('sat', this.sat, LNbits.utils.formatSat(this.sat))
return LNbits.utils.formatSat(this.sat)
@@ -277,12 +323,46 @@
methods: {
closeInvoiceDialog: function () {
this.stack = []
+ this.tipAmount = 0.00
var dialog = this.invoiceDialog
setTimeout(function () {
clearInterval(dialog.paymentChecker)
dialog.dismissMsg()
}, 3000)
},
+ processTipSelection: function (selectedTipOption) {
+ this.tipDialog.show = false
+
+ if(selectedTipOption) {
+ const tipAmount = parseFloat(parseFloat((selectedTipOption / 100) * this.amount))
+ const subtotal = parseFloat(this.amount)
+ const grandTotal = parseFloat((tipAmount + subtotal).toFixed(2))
+ const totalString = grandTotal.toFixed(2).toString()
+
+ this.stack = []
+ for (var i = 0; i < totalString.length; i++) {
+ const char = totalString[i]
+
+ if(char !== ".") {
+ this.stack.push(char)
+ }
+ }
+
+ this.tipAmount = tipAmount
+ }
+
+ this.showInvoice()
+ },
+ submitForm: function() {
+ if(this.tip_options.length) {
+ this.showTipModal()
+ } else {
+ this.showInvoice()
+ }
+ },
+ showTipModal: function() {
+ this.tipDialog.show = true
+ },
showInvoice: function () {
var self = this
var dialog = this.invoiceDialog
@@ -290,7 +370,8 @@
axios
.post('/tpos/api/v1/tposs/' + this.tposId + '/invoices', null, {
params: {
- amount: this.sat
+ amount: this.sat,
+ tipAmount: this.tipAmountSat,
}
})
.then(function (response) {
diff --git a/lnbits/extensions/tpos/views_api.py b/lnbits/extensions/tpos/views_api.py
index ae457b61..e39a9814 100644
--- a/lnbits/extensions/tpos/views_api.py
+++ b/lnbits/extensions/tpos/views_api.py
@@ -52,7 +52,7 @@ async def api_tpos_delete(
@tpos_ext.post("/api/v1/tposs/{tpos_id}/invoices", status_code=HTTPStatus.CREATED)
-async def api_tpos_create_invoice(amount: int = Query(..., ge=1), tpos_id: str = None):
+async def api_tpos_create_invoice(amount: int = Query(..., ge=1), tipAmount: int = None, tpos_id: str = None):
tpos = await get_tpos(tpos_id)
if not tpos:
@@ -65,7 +65,7 @@ async def api_tpos_create_invoice(amount: int = Query(..., ge=1), tpos_id: str =
wallet_id=tpos.wallet,
amount=amount,
memo=f"{tpos.name}",
- extra={"tag": "tpos"},
+ extra={"tag": "tpos", "tipAmount": tipAmount, "tposId": tpos_id},
)
except Exception as e:
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
@@ -84,6 +84,7 @@ async def api_tpos_check_invoice(tpos_id: str, payment_hash: str):
)
try:
status = await api_payment(payment_hash)
+
except Exception as exc:
print(exc)
return {"paid": False}