Ejemplo n.º 1
0
def get_basket():
    basket = []
    for type_id in session.get("basket", []):
        basket.append(Ticket(type_id=type_id))

    total = sum(t.type.get_price(get_user_currency()) for t in basket)

    return basket, total
Ejemplo n.º 2
0
def add_payment_and_tickets(paymenttype):
    """
    Insert payment and tickets from session data into DB
    """

    infodata = session.get("ticketinfo")
    basket, total = get_basket()

    if not (basket and total):
        return None

    if paymenttype == GoogleCheckoutPayment:
        total *= Decimal("1.05")
        total = total.quantize(Decimal("0.01"), rounding=ROUND_UP)

    app.logger.info("Creating tickets for basket %s", basket)
    app.logger.info("Payment: %s for total %s GBP", paymenttype.name, total)
    app.logger.info("Ticket info: %s", infodata)

    if infodata:
        infolists = sum([infodata[i] for i in ticket_forms], [])
        for info in infolists:
            ticket_id = int(info.pop("ticket_id"))
            ticket = basket[ticket_id]
            for k, v in info.items():
                attrib = TicketAttrib(k, v)
                ticket.attribs.append(attrib)

    payment = paymenttype(total)
    current_user.payments.append(payment)

    for ticket in basket:
        name = get_form_name(ticket.type)
        if name and not ticket.attribs:
            app.logger.error("Ticket %s has no attribs", ticket)
            return None

        current_user.tickets.append(ticket)
        ticket.payment = payment
        if get_user_currency() == "GBP":
            ticket.expires = datetime.utcnow() + timedelta(days=app.config.get("EXPIRY_DAYS"))
        else:
            ticket.expires = datetime.utcnow() + timedelta(days=app.config.get("EXPIRY_DAYS_EURO"))

    db.session.add(current_user)
    db.session.commit()

    session.pop("basket", None)
    session.pop("ticketinfo", None)

    return payment
Ejemplo n.º 3
0
    try:
        payment = current_user.payments.filter_by(id=payment_id, user=current_user, state="new").one()
    except Exception, e:
        app.logger.error("google-checkout-tryagain: exception: %s for payment %s", e, payment.id)
        flash("An error occurred with your payment, please contact %s" % app.config.get("TICKETS_EMAIL")[1])
        return redirect(url_for("tickets"))

    if form.pay.data == True:
        if not app.config.get("GOOGLE_CHECKOUT"):
            app.logger.error("Unable to retry payment as Google Checkout is disabled")
            flash("Google Checkout is currently unavailable. Please try again later.")
            return redirect(url_for("tickets"))

        app.logger.info("User %s trying to pay again with Google Checkout payment %s", current_user.id, payment.id)
        total = sum(t.type.get_price(get_user_currency()) for t in payment.tickets)
        return googlecheckout_send(payment, total)

    if form.cancel.data == True:
        ynform = GoogleCheckoutTryAgainForm(payment=payment.id, yesno="yes", formdata=None)
        return render_template("google-checkout-discard-yesno.html", payment=payment, form=ynform)

    if form.yes.data == True:
        app.logger.info("User %s canceled new Google Checkout payment %s", current_user.id, payment.id)
        for t in payment.tickets.all():
            db.session.delete(t)
            app.logger.info("Cancelling Google Checkout ticket %s (u:%s p:%s)", t.id, current_user.id, payment.id)
        app.logger.info("Cancelling Google Checkout payment %s (u:%s)", payment.id, current_user.id)
        payment.state = "canceled"
        db.session.add(payment)
        db.session.commit()