|
|
@ -4,10 +4,10 @@ from lnbits.core.crud import get_user |
|
|
|
from lnbits.core.utils import create_invoice |
|
|
|
from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_request |
|
|
|
from lnbits.helpers import Status |
|
|
|
|
|
|
|
from lnbits.settings import WALLET, FEE_RESERVE |
|
|
|
from lnbits.extensions.tpos import tpos_ext |
|
|
|
from .crud import create_tpos, get_tpos, get_tposs, delete_tpos |
|
|
|
|
|
|
|
from .crud import create_tpos, get_tpos, get_tposs, delete_tpos |
|
|
|
|
|
|
|
@tpos_ext.route("/api/v1/tposs", methods=["GET"]) |
|
|
|
@api_check_wallet_macaroon(key_type="invoice") |
|
|
@ -53,21 +53,27 @@ def api_tpos_delete(tpos_id): |
|
|
|
|
|
|
|
|
|
|
|
@tpos_ext.route("/api/v1/tposs/invoice/<tpos_id>", methods=["POST"]) |
|
|
|
@api_check_wallet_macaroon(key_type="invoice") |
|
|
|
@api_validate_post_request(schema={"amount": {"type": "integer", "min": 1, "required": True}}) |
|
|
|
def api_tpos_create_invoice(tpos_id): |
|
|
|
tpos = get_tpos(tpos_id) |
|
|
|
|
|
|
|
tpos = get_tpos(tpos_id) |
|
|
|
|
|
|
|
if not tpos: |
|
|
|
return jsonify({"message": "TPoS does not exist."}), Status.NOT_FOUND |
|
|
|
|
|
|
|
if tpos.wallet != g.wallet.id: |
|
|
|
return jsonify({"message": "Not your TPoS."}), Status.FORBIDDEN |
|
|
|
|
|
|
|
try: |
|
|
|
memo = f"TPoS {tpos_id}" |
|
|
|
checking_id, payment_request = create_invoice(wallet_id=g.wallet.id, amount=g.data["amount"], memo=memo) |
|
|
|
checking_id, payment_request = create_invoice(wallet_id=tpos.wallet, amount=g.data["amount"], memo=memo) |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
return jsonify({"message": str(e)}), Status.INTERNAL_SERVER_ERROR |
|
|
|
|
|
|
|
return jsonify({"checking_id": checking_id, "payment_request": payment_request}), Status.CREATED |
|
|
|
return jsonify({"checking_id": checking_id, "payment_request": payment_request}), Status.OK |
|
|
|
|
|
|
|
@tpos_ext.route("/api/v1/tposs/invoice/<checking_id>", methods=["GET"]) |
|
|
|
def api_tpos_check_invoice(checking_id): |
|
|
|
print(checking_id) |
|
|
|
PAID = WALLET.get_invoice_status(checking_id).paid |
|
|
|
|
|
|
|
if PAID == True: |
|
|
|
return jsonify({"PAID": True}), Status.OK |
|
|
|
return jsonify({"PAID": False}), Status.OK |
|
|
|