Ejemplo n.º 1
0
def index():
    time_valid_until = datetime.now() - timedelta(hours=1)
    phone = session.get(PHONE_SESSION_KEY)

    tickets = []
    if phone is not None:
        tickets = Ticket.query.filter(Ticket.phone == phone)\
            .filter(or_(and_(Ticket.status == 'confirmed', Ticket.valid_until > time_valid_until), Ticket.status == 'received'))

    return render_template('index.html', phone=phone, tariffs=get_tariffs(), tickets=tickets)
Ejemplo n.º 2
0
def ticket_buy(tariff_id):
    if request.method == 'POST' and int(tariff_id) in [20, 29]:
        # HOTFIX - umoznuje to volat i GETem
        # if int(tariff_id) in [20, 29]:
        phone = request.form['phone']

        ticket = Ticket(tariff=tariff_id, phone=phone)

        d = {}
        d["settled_currency"] = "CZK"
        d["return_url"] = "http://%s/notification" % request.host
        d["notify_url"] = "http://%s/notification" % request.host
        d["notify_email"] = "%s" % settings.bitcoinPayOwnerEmail
        d["price"] = tariff_id
        d["currency"] = "CZK"

        ref = {}
        ref["phone_number"] = phone
        ref["tariff"] = tariff_id
        d["reference"] = ref

        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Token %s' % settings.bitcoinPayAuthToken
        }
        request_payment = Request(
            'https://www.bitcoinpay.com/api/v1/payment/btc',
            data=json.dumps(d),
            headers=headers)

        response_body = urlopen(request_payment).read()

        data = json.loads(response_body)["data"]

        ticket.payment_id = data["payment_id"]
        ticket.status = data["status"]
        ticket.settled_amount = data["settled_amount"]
        ticket.settled_currency = data["settled_currency"]
        ticket.payment_response = json.dumps(data)

        db_session.add(ticket)
        db_session.commit()

        # ulozime payment id v session
        session["last_payment_id"] = ticket.payment_id
        # saving user's phone to be able to retrieve tickets overview
        session[PHONE_SESSION_KEY] = int(phone)

        return redirect(data["payment_url"], code=302)

    phone = session.get(PHONE_SESSION_KEY)
    tariff = get_tariffs(tariff_id)

    # return redirect(url_for('index'))
    return render_template('ticket_buy.html', tariff=tariff, phone=phone)
Ejemplo n.º 3
0
def ticket_buy(tariff_id):
    if request.method == 'POST' and int(tariff_id) in [20, 29]:
    # HOTFIX - umoznuje to volat i GETem
    # if int(tariff_id) in [20, 29]:
        phone = request.form['phone']

        ticket = Ticket(tariff=tariff_id, phone=phone)

        d = {}
        d["settled_currency"] = "CZK"
        d["return_url"] = "http://%s/notification" % request.host
        d["notify_url"] = "http://%s/notification" % request.host
        d["notify_email"] = "%s" % settings.bitcoinPayOwnerEmail
        d["price"] = tariff_id
        d["currency"] = "CZK"

        ref = {}
        ref["phone_number"] = phone
        ref["tariff"] = tariff_id
        d["reference"] = ref

        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Token %s' % settings.bitcoinPayAuthToken
        }
        request_payment = Request('https://www.bitcoinpay.com/api/v1/payment/btc', data=json.dumps(d), headers=headers)

        response_body = urlopen(request_payment).read()

        data = json.loads(response_body)["data"]

        ticket.payment_id = data["payment_id"]
        ticket.status = data["status"]
        ticket.settled_amount = data["settled_amount"]
        ticket.settled_currency = data["settled_currency"]
        ticket.payment_response = json.dumps(data)

        db_session.add(ticket)
        db_session.commit()

        # ulozime payment id v session
        session["last_payment_id"] = ticket.payment_id
        # saving user's phone to be able to retrieve tickets overview
        session[PHONE_SESSION_KEY] = int(phone)

        return redirect(data["payment_url"], code=302)

    phone = session.get(PHONE_SESSION_KEY)
    tariff = get_tariffs(tariff_id)

    # return redirect(url_for('index'))
    return render_template('ticket_buy.html', tariff=tariff, phone=phone)
Ejemplo n.º 4
0
def index():
    time_valid_until = datetime.now() - timedelta(hours=1)
    phone = session.get(PHONE_SESSION_KEY)

    tickets = []
    if phone is not None:
        tickets = Ticket.query.filter(Ticket.phone == phone)\
            .filter(or_(and_(Ticket.status == 'confirmed', Ticket.valid_until > time_valid_until), Ticket.status == 'received'))

    return render_template('index.html',
                           phone=phone,
                           tariffs=get_tariffs(),
                           tickets=tickets)