Example #1
0
def root():
    price_in_btc = to_btc('USD', PRICE_IN_USD)
    run_db("""INSERT OR IGNORE INTO invoices
              (invoice_id, price_in_usd, price_in_btc, product_url)
              VALUES(?,?,?,?)""",
           [INVOICE_ID, PRICE_IN_USD, price_in_btc, PRODUCT_URL])
    return render_template('invoice.html',
                           blockchain_root=app.config['BLOCKCHAIN_ROOT'],
                           invoice_id=INVOICE_ID,
                           price_in_btc=price_in_btc)
Example #2
0
def create_handler(invoice_id):
    callback_url = url_for('payment_handler',
                           invoice_id=invoice_id,
                           secret=app.config['SECRET_KEY'],
                           _external=True)
    recv = receive(app.config['XPUB'], callback_url, app.config['API_KEY'])
    run_db("""UPDATE invoices
              SET address = ?
              WHERE invoice_id = ?""",
           [recv.address, invoice_id])
    return json.dumps({'input_address': recv.address})
Example #3
0
def create_handler(invoice_id):
    callback_url = url_for('payment_handler',
                           invoice_id=invoice_id,
                           secret=app.config['SECRET_KEY'],
                           _external=True)
    recv = receive(app.config['XPUB'], callback_url, app.config['API_KEY'])
    run_db(
        """UPDATE invoices
              SET address = ?
              WHERE invoice_id = ?""", [recv.address, invoice_id])
    return json.dumps({'input_address': recv.address})
Example #4
0
def root():
    price_in_btc = to_btc('USD', PRICE_IN_USD)
    run_db(
        """INSERT OR IGNORE INTO invoices
              (invoice_id, price_in_usd, price_in_btc, product_url)
              VALUES(?,?,?,?)""",
        [INVOICE_ID, PRICE_IN_USD, price_in_btc, PRODUCT_URL])
    return render_template('invoice.html',
                           blockchain_root=app.config['BLOCKCHAIN_ROOT'],
                           invoice_id=INVOICE_ID,
                           price_in_btc=price_in_btc)
Example #5
0
def payment_handler(invoice_id):
    address = request.args.get('address')
    secret = request.args.get('secret')
    confirmations = request.args.get('confirmations')
    tx_hash = request.args.get('transaction_hash')
    value = float(request.args.get('value')) / 100000000
    order = query_db("""SELECT address
                        FROM invoices
                        WHERE invoice_id = ?""",
                     [invoice_id],
                     one=True)
    if address != order['address']:
        return 'Incorrect Receiving Address', 400
    if secret != app.config['SECRET_KEY']:
        return 'invalid secret', 400
    if confirmations >= 4:
        run_db("""INSERT INTO invoice_payments
                  (invoice_id, transaction_hash, value)
                  VALUES (?, ?, ?)""",
               [invoice_id, tx_hash, value])
        run_db("""DELETE FROM pending_invoice_payments
                  WHERE invoice_id = ?""",
               [invoice_id])
        return '*ok*'
    else:
        run_db("""INSERT INTO pending_invoice_payments
                  (invoice_id, transaction_hash, value)
                VALUES (?, ?, ?)""",
               [invoice_id, tx_hash, value])
        return 'Waiting for confirmations'
    # should never reach here!
    return 'something went wrong', 500
Example #6
0
def payment_handler(invoice_id):
    address = request.args.get('address')
    secret = request.args.get('secret')
    confirmations = request.args.get('confirmations')
    tx_hash = request.args.get('transaction_hash')
    value = float(request.args.get('value')) / 100000000
    order = query_db("""SELECT address
                        FROM invoices
                        WHERE invoice_id = ?""", [invoice_id],
                     one=True)
    if address != order['address']:
        return 'Incorrect Receiving Address', 400
    if secret != app.config['SECRET_KEY']:
        return 'invalid secret', 400
    if confirmations >= 4:
        run_db(
            """INSERT INTO invoice_payments
                  (invoice_id, transaction_hash, value)
                  VALUES (?, ?, ?)""", [invoice_id, tx_hash, value])
        run_db(
            """DELETE FROM pending_invoice_payments
                  WHERE invoice_id = ?""", [invoice_id])
        return '*ok*'
    else:
        run_db(
            """INSERT INTO pending_invoice_payments
                  (invoice_id, transaction_hash, value)
                VALUES (?, ?, ?)""", [invoice_id, tx_hash, value])
        return 'Waiting for confirmations'
    # should never reach here!
    return 'something went wrong', 500