def lndhub_payinvoice(): try: pay_invoice( wallet_id=g.wallet.id, payment_request=g.data["invoice"], extra={"tag": "lndhub"}, ) except Exception as e: return jsonify({ "error": True, "code": 10, "message": "Payment failed: " + str(e), }) invoice: bolt11.Invoice = bolt11.decode(g.data["invoice"]) return jsonify({ "payment_error": "", "payment_preimage": "0" * 64, "route": {}, "payment_hash": invoice.payment_hash, "decoded": decoded_as_lndhub(invoice), "fee_msat": 0, "type": "paid_invoice", "fee": 0, "value": invoice.amount_msat / 1000, "timestamp": int(time.time()), "memo": invoice.description, })
def api_lnurl_callback(unique_hash): link = get_withdraw_link_by_hash(unique_hash) k1 = request.args.get("k1", type=str) payment_request = request.args.get("pr", type=str) now = int(datetime.now().timestamp()) if not link: return jsonify({"status": "ERROR", "reason": "LNURL-withdraw not found."}), HTTPStatus.OK if link.is_spent: return jsonify({"status": "ERROR", "reason": "Withdraw is spent."}), HTTPStatus.OK if link.k1 != k1: return jsonify({"status": "ERROR", "reason": "Bad request."}), HTTPStatus.OK if now < link.open_time: return jsonify({"status": "ERROR", "reason": f"Wait {link.open_time - now} seconds."}), HTTPStatus.OK try: pay_invoice(wallet_id=link.wallet, bolt11=payment_request, max_sat=link.max_withdrawable) changes = { "open_time": link.wait_time + now, } update_withdraw_link(link.id, **changes) except ValueError as e: return jsonify({"status": "ERROR", "reason": str(e)}), HTTPStatus.OK except PermissionError: return jsonify({"status": "ERROR", "reason": "Withdraw link is empty."}), HTTPStatus.OK except Exception as e: return jsonify({"status": "ERROR", "reason": str(e)}), HTTPStatus.OK return jsonify({"status": "OK"}), HTTPStatus.OK
async def api_payments_pay_invoice(): try: payment_hash = pay_invoice(wallet_id=g.wallet.id, payment_request=g.data["bolt11"]) except ValueError as e: return jsonify({"message": str(e)}), HTTPStatus.BAD_REQUEST except PermissionError as e: return jsonify({"message": str(e)}), HTTPStatus.FORBIDDEN except Exception as e: print(e) g.db.rollback() return jsonify({"message": str(e)}), HTTPStatus.INTERNAL_SERVER_ERROR return ( jsonify({ "payment_hash": payment_hash, # maintain backwards compatibility with API clients: "checking_id": payment_hash, }), HTTPStatus.CREATED, )