Esempio n. 1
0
async def api_paywal_check_invoice(paywall_id):
    paywall = get_paywall(paywall_id)

    if not paywall:
        return jsonify({"message":
                        "Paywall does not exist."}), HTTPStatus.NOT_FOUND

    try:
        is_paid = not check_invoice_status(paywall.wallet,
                                           g.data["payment_hash"]).pending
    except Exception:
        return jsonify({"paid": False}), HTTPStatus.OK

    if is_paid:
        wallet = get_wallet(paywall.wallet)
        payment = wallet.get_payment(g.data["payment_hash"])
        payment.set_pending(False)

        return jsonify({
            "paid": True,
            "url": paywall.url,
            "remembers": paywall.remembers
        }), HTTPStatus.OK

    return jsonify({"paid": False}), HTTPStatus.OK
Esempio n. 2
0
def api_ticket_send_ticket(payment_hash):
    ticket = get_ticket(payment_hash)
    try:
        is_paid = not check_invoice_status(ticket.wallet, payment_hash).pending
    except Exception:
        return jsonify({"message": "Not paid."}), HTTPStatus.NOT_FOUND

    if is_paid:
        wallet = get_wallet(ticket.wallet)
        payment = wallet.get_payment(payment_hash)
        payment.set_pending(False)
        ticket = update_ticket(paid=True, payment_hash=payment_hash)
        return jsonify({"paid": True, "ticket_id": ticket.id}), HTTPStatus.OK

    return jsonify({"paid": False}), HTTPStatus.OK
Esempio n. 3
0
async def api_tpos_check_invoice(tpos_id, payment_hash):
    tpos = get_tpos(tpos_id)

    if not tpos:
        return jsonify({"message": "TPoS does not exist."}), HTTPStatus.NOT_FOUND

    try:
        is_paid = not check_invoice_status(tpos.wallet, payment_hash).pending
    except Exception as exc:
        print(exc)
        return jsonify({"paid": False}), HTTPStatus.OK

    if is_paid:
        wallet = get_wallet(tpos.wallet)
        payment = wallet.get_payment(payment_hash)
        payment.set_pending(False)

        return jsonify({"paid": True}), HTTPStatus.OK

    return jsonify({"paid": False}), HTTPStatus.OK
Esempio n. 4
0
async def api_amilkit(amilk_id):
    milk = get_amilk(amilk_id)
    memo = milk.id

    try:
        withdraw_res = handle_lnurl(milk.lnurl,
                                    response_class=LnurlWithdrawResponse)
    except LnurlException:
        abort(HTTPStatus.INTERNAL_SERVER_ERROR,
              "Could not process withdraw LNURL.")

    payment_hash, payment_request = create_invoice(
        wallet_id=milk.wallet,
        amount=withdraw_res.max_sats,
        memo=memo,
        extra={"tag": "amilk"})

    r = requests.get(
        withdraw_res.callback.base,
        params={
            **withdraw_res.callback.query_params,
            **{
                "k1": withdraw_res.k1,
                "pr": payment_request
            }
        },
    )

    if not r.ok:
        abort(HTTPStatus.INTERNAL_SERVER_ERROR,
              "Could not process withdraw LNURL.")

    for i in range(10):
        sleep(i)
        invoice_status = check_invoice_status(milk.wallet, payment_hash)
        if invoice_status.paid:
            return jsonify({"paid": True}), HTTPStatus.OK
        else:
            continue

    return jsonify({"paid": False}), HTTPStatus.OK