def complete_payment(): if flask.request.method == 'POST': flashes = [] tickets = models.Ticket.query.filter( models.Ticket.object_id.in_( flask.request.form.getlist('tickets[]'))).filter( models.Ticket.owner_id == login.current_user.object_id ).filter(models.Ticket.paid == False).all() if not tickets: flashes.append('You have not selected any tickets to pay for.') method, term = purchase_logic.check_payment_method(flashes) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash(('There were errors in your order. Please fix ' 'these and try again'), 'error') for msg in flashes: flask.flash(msg, 'warning') return flask.render_template('purchase/complete_payment.html', form=flask.request.form) return payment_logic.do_payment(tickets, postage, method, term, address) else: return flask.render_template('purchase/complete_payment.html')
def pay_admin_fee(admin_fee_id): """Allow the user to pay an admin fee.""" admin_fee = models.AdminFee.query.get_or_404(admin_fee_id) if not admin_fee: flask.flash('Admin Fee not found', 'warning') elif admin_fee.charged_to != login.current_user: flask.flash('That is not your admin fee to pay.', 'warning') elif admin_fee.paid: flask.flash('That admin fee has been paid.', 'warning') else: if flask.request.method == 'POST': flashes = [] payment_method, payment_term = purchase_logic.check_payment_method( flashes) if flashes: flask.flash(('There were errors in your input. Please fix ' 'these and try again'), 'error') for msg in flashes: flask.flash(msg, 'warning') return flask.render_template('purchase/pay_admin_fee.html', fee=admin_fee) return payment_logic.pay_admin_fee(admin_fee, payment_method, payment_term) else: return flask.render_template('purchase/pay_admin_fee.html', fee=admin_fee) return flask.redirect(flask.request.referrer or flask.url_for('dashboard.dashboard_home'))
def buy_postage(): """Allow the user to buy postage for tickets.""" if flask.request.method == 'POST': flashes = [] tickets = models.Ticket.query.filter( models.Ticket.object_id.in_( flask.request.form.getlist('tickets[]'))).filter( models.Ticket.cancelled == False # pylint: disable=singleton-comparison ).filter( or_(models.Ticket.owner == login.current_user, models.Ticket.holder == login.current_user)).all() if not tickets: flashes.append( 'You have not selected any tickets to buy postage for.') method, term = purchase_logic.check_payment_method(flashes) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash(('There were errors in your order. Please fix ' 'these and try again'), 'error') for msg in flashes: flask.flash(msg, 'warning') return flask.render_template('purchase/buy_postage.html', form=flask.request.form) return payment_logic.buy_postage(tickets, postage, method, term, address) return flask.render_template('purchase/buy_postage.html')
def complete_payment(): """Allow the user to complete payment for tickets. Used if card payment fails, or for manually allocated tickets. """ if flask.request.method == 'POST': flashes = [] tickets = models.Ticket.query.filter( models.Ticket.object_id.in_(flask.request.form.getlist('tickets[]')) ).filter( models.Ticket.owner_id == login.current_user.object_id ).filter( models.Ticket.paid == False # pylint: disable=singleton-comparison ).all() if not tickets: flashes.append('You have not selected any tickets to pay for.') method, term = purchase_logic.check_payment_method(flashes) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash( ( 'There were errors in your order. Please fix ' 'these and try again' ), 'error' ) for msg in flashes: flask.flash(msg, 'warning') return flask.render_template( 'purchase/complete_payment.html', form=flask.request.form ) return payment_logic.do_payment( tickets, postage, method, term, address ) else: return flask.render_template( 'purchase/complete_payment.html' )
def buy_postage(): """Allow the user to buy postage for tickets.""" if flask.request.method == 'POST': flashes = [] tickets = models.Ticket.query.filter( models.Ticket.object_id.in_(flask.request.form.getlist('tickets[]')) ).filter( models.Ticket.cancelled == False # pylint: disable=singleton-comparison ).filter(or_( models.Ticket.owner == login.current_user, models.Ticket.holder == login.current_user )).all() if not tickets: flashes.append( 'You have not selected any tickets to buy postage for.' ) method, term = purchase_logic.check_payment_method(flashes) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash( ( 'There were errors in your order. Please fix ' 'these and try again' ), 'error' ) for msg in flashes: flask.flash(msg, 'warning') return flask.render_template( 'purchase/buy_postage.html', form=flask.request.form ) return payment_logic.buy_postage( tickets, postage, method, term, address ) return flask.render_template('purchase/buy_postage.html')
def pay_admin_fee(admin_fee_id): """Allow the user to pay an admin fee.""" admin_fee = models.AdminFee.get_by_id(admin_fee_id) if not admin_fee: flask.flash('Admin Fee not found', 'warning') elif admin_fee.charged_to != login.current_user: flask.flash('That is not your admin fee to pay.', 'warning') elif admin_fee.paid: flask.flash('That admin fee has been paid.', 'warning') else: if flask.request.method == 'POST': flashes = [] payment_method, payment_term = purchase_logic.check_payment_method( flashes ) if flashes: flask.flash( ( 'There were errors in your input. Please fix ' 'these and try again' ), 'error' ) for msg in flashes: flask.flash(msg, 'warning') return flask.render_template( 'purchase/pay_admin_fee.html', fee=admin_fee ) return payment_logic.pay_admin_fee(admin_fee, payment_method, payment_term) else: return flask.render_template( 'purchase/pay_admin_fee.html', fee=admin_fee ) return flask.redirect(flask.request.referrer or flask.url_for('dashboard.dashboard_home'))
def complete_payment(): """Allow the user to complete payment for tickets. Used if card payment fails, or for manually allocated tickets. """ if flask.request.method == "POST": flashes = [] tickets = ( models.Ticket.query.filter( models.Ticket.object_id.in_( flask.request.form.getlist("tickets[]"))).filter( models.Ticket.owner_id == login.current_user.object_id).filter( models.Ticket.paid == False) # pylint: disable=singleton-comparison .all()) if not tickets: flashes.append("You have not selected any tickets to pay for.") method, term = purchase_logic.check_payment_method(flashes) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash( ("There were errors in your order. Please fix " "these and try again"), "error", ) for msg in flashes: flask.flash(msg, "warning") return flask.render_template("purchase/complete_payment.html", form=flask.request.form) return payment_logic.do_payment(tickets, postage, method, term, address) else: return flask.render_template("purchase/complete_payment.html")
def pay_admin_fee(admin_fee_id): """Allow the user to pay an admin fee.""" admin_fee = models.AdminFee.get_by_id(admin_fee_id) if not admin_fee: flask.flash("Admin Fee not found", "warning") elif admin_fee.charged_to != login.current_user: flask.flash("That is not your admin fee to pay.", "warning") elif admin_fee.paid: flask.flash("That admin fee has been paid.", "warning") else: if flask.request.method == "POST": flashes = [] payment_method, payment_term = purchase_logic.check_payment_method( flashes) if flashes: flask.flash( ("There were errors in your input. Please fix " "these and try again"), "error", ) for msg in flashes: flask.flash(msg, "warning") return flask.render_template("purchase/pay_admin_fee.html", fee=admin_fee) return payment_logic.pay_admin_fee(admin_fee, payment_method, payment_term) else: return flask.render_template("purchase/pay_admin_fee.html", fee=admin_fee) return flask.redirect(flask.request.referrer or flask.url_for("dashboard.dashboard_home"))
def purchase_home(): """First step of the purchasing flow. Checks if the user can purchase tickets, and processes the purchase form. """ if login.current_user.purchase_group: if login.current_user == login.current_user.purchase_group.leader: if APP.config['TICKETS_ON_SALE']: return flask.redirect(flask.url_for('group_purchase.checkout')) else: flask.flash( ( 'You cannot currently purchase tickets because you are ' 'leading a purchase group. You will be able to ' 'purchase tickets on behalf of your group when general ' 'release starts.' ), 'info' ) return flask.redirect(flask.url_for('dashboard.dashboard_home')) else: flask.flash( ( 'You cannot currently purchase tickets because you are a ' 'member of a purchase group. Your group leader {0} will be ' 'able to purchase tickets on behalf of your group when ' 'general release starts.' ).format(login.current_user.purchase_group.leader.full_name), 'info' ) return flask.redirect(flask.url_for('dashboard.dashboard_home')) ticket_info = purchase_logic.get_ticket_info( login.current_user ) if models.Waiting.query.count() > 0 or not ticket_info.ticket_types: flask.flash( 'You are not able to purchase tickets at this time.', 'info' ) if purchase_logic.wait_available(login.current_user): flask.flash( ( 'Please join the waiting list, and you will be allocated ' 'tickets as they become available' ), 'info' ) return flask.redirect(flask.url_for('purchase.wait')) else: return flask.redirect(flask.url_for('dashboard.dashboard_home')) num_tickets = { ticket_type.slug: 0 for ticket_type, _ in ticket_info.ticket_types } if flask.request.method == 'POST': for ticket_type, _ in ticket_info.ticket_types: num_tickets[ticket_type.slug] = int( flask.request.form['num_tickets_{0}'.format(ticket_type.slug)] ) flashes = purchase_logic.validate_tickets( ticket_info, num_tickets ) payment_method, payment_term = purchase_logic.check_payment_method( flashes ) voucher = None if ( 'voucher_code' in flask.request.form and flask.request.form['voucher_code'] != '' ): (result, response, voucher) = validators.validate_voucher( flask.request.form['voucher_code']) if not result: flashes.append( ( '{} Please clear the discount code field to continue ' 'without using a voucher.' ).format(response['message']) ) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash( ( 'There were errors in your order. Please fix ' 'these and try again' ), 'error' ) for msg in flashes: flask.flash(msg, 'warning') return flask.render_template( 'purchase/purchase_home.html', form=flask.request.form, num_tickets=num_tickets, ticket_info=ticket_info ) tickets = purchase_logic.create_tickets( login.current_user, ticket_info, num_tickets ) if voucher is not None: (success, tickets, error) = voucher.apply(tickets, login.current_user) if not success: flask.flash('Could not use voucher - ' + error, 'error') roundup_price = purchase_logic.check_roundup_donation(flashes) if roundup_price is not 0: roundup_donation = None roundup_donation = models.RoundupDonation( roundup_price, login.current_user, ) if roundup_donation is not None: # Tack on the roundup donation fee to their ticket(s) # Entry tickets = roundup_donation.apply(tickets) DB.session.add(roundup_donation); DB.session.add_all(tickets) DB.session.commit() APP.log_manager.log_event( 'Purchased Tickets', tickets=tickets, user=login.current_user ) # return flask.render_template( # 'purchase/purchase_home.html', # num_tickets=num_tickets, # ticket_info=ticket_info # ) return payment_logic.do_payment( tickets, postage, payment_method, payment_term, address ) else: return flask.render_template( 'purchase/purchase_home.html', num_tickets=num_tickets, ticket_info=ticket_info )
def purchase_home(): """First step of the purchasing flow. Checks if the user can purchase tickets, and processes the purchase form. """ ticket_info = purchase_logic.get_ticket_info(login.current_user) if not ticket_info.ticket_types: flask.flash('You are not able to purchase tickets at this time.', 'info') (waiting_permitted, _, _) = login.current_user.can_wait() if waiting_permitted: flask.flash( ('Please join the waiting list, and you will be allocated ' 'tickets as they become available'), 'info') return flask.redirect(flask.url_for('purchase.wait')) else: return flask.redirect(flask.url_for('dashboard.dashboard_home')) num_tickets = { ticket_type.slug: 0 for ticket_type, _ in ticket_info.ticket_types } ticket_names = [] if flask.request.method == 'POST': for ticket_type, _ in ticket_info.ticket_types: num_tickets[ticket_type.slug] = int( flask.request.form['num_tickets_{0}'.format(ticket_type.slug)]) ticket_names = [ name for name in flask.request.form.getlist('ticket_name[]') if name ] flashes = purchase_logic.validate_tickets(ticket_info, num_tickets, ticket_names) payment_method, payment_term = purchase_logic.check_payment_method( flashes) voucher = None if ('voucher_code' in flask.request.form and flask.request.form['voucher_code'] != ''): (result, response, voucher) = validators.validate_voucher( flask.request.form['voucher_code']) if not result: flashes.append( ('{} Please clear the discount code field to continue ' 'without using a voucher.').format(response['message'])) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash(('There were errors in your order. Please fix ' 'these and try again'), 'error') for msg in flashes: flask.flash(msg, 'warning') return flask.render_template('purchase/purchase_home.html', form=flask.request.form, ticket_names=ticket_names, num_tickets=num_tickets, ticket_info=ticket_info) tickets = purchase_logic.create_tickets(login.current_user, ticket_info, num_tickets, ticket_names) if voucher is not None: (success, tickets, error) = voucher.apply(tickets, login.current_user) if not success: flask.flash('Could not use voucher - ' + error, 'error') DB.session.add_all(tickets) DB.session.commit() APP.log_manager.log_event('Purchased Tickets', tickets, login.current_user) return payment_logic.do_payment(tickets, postage, payment_method, payment_term, address) else: return flask.render_template('purchase/purchase_home.html', num_tickets=num_tickets, ticket_names=ticket_names, ticket_info=ticket_info)
def purchase_home(): """First step of the purchasing flow. Checks if the user can purchase tickets, and processes the purchase form. """ ticket_info = purchase_logic.get_ticket_info( login.current_user ) if not ticket_info.ticket_types: flask.flash( 'You are not able to purchase tickets at this time.', 'info' ) (waiting_permitted, _, _) = login.current_user.can_wait() if waiting_permitted: flask.flash( ( 'Please join the waiting list, and you will be allocated ' 'tickets as they become available' ), 'info' ) return flask.redirect(flask.url_for('purchase.wait')) else: return flask.redirect(flask.url_for('dashboard.dashboard_home')) num_tickets = { ticket_type.slug: 0 for ticket_type, _ in ticket_info.ticket_types } ticket_names = [] if flask.request.method == 'POST': for ticket_type, _ in ticket_info.ticket_types: num_tickets[ticket_type.slug] = int( flask.request.form['num_tickets_{0}'.format(ticket_type.slug)] ) ticket_names = [ name for name in flask.request.form.getlist('ticket_name[]') if name ] flashes = purchase_logic.validate_tickets( ticket_info, num_tickets, ticket_names ) payment_method, payment_term = purchase_logic.check_payment_method( flashes ) voucher = None if ( 'voucher_code' in flask.request.form and flask.request.form['voucher_code'] != '' ): (result, response, voucher) = validators.validate_voucher( flask.request.form['voucher_code']) if not result: flashes.append( ( '{} Please clear the discount code field to continue ' 'without using a voucher.' ).format(response['message']) ) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash( ( 'There were errors in your order. Please fix ' 'these and try again' ), 'error' ) for msg in flashes: flask.flash(msg, 'warning') return flask.render_template( 'purchase/purchase_home.html', form=flask.request.form, ticket_names=ticket_names, num_tickets=num_tickets, ticket_info=ticket_info ) tickets = purchase_logic.create_tickets( login.current_user, ticket_info, num_tickets, ticket_names ) if voucher is not None: (success, tickets, error) = voucher.apply(tickets, login.current_user) if not success: flask.flash('Could not use voucher - ' + error, 'error') DB.session.add_all(tickets) DB.session.commit() APP.log_manager.log_event( 'Purchased Tickets', tickets, login.current_user ) return payment_logic.do_payment( tickets, postage, payment_method, payment_term, address ) else: return flask.render_template( 'purchase/purchase_home.html', num_tickets=num_tickets, ticket_names=ticket_names, ticket_info=ticket_info )
def purchase_home(): """First step of the purchasing flow. Checks if the user can purchase tickets, and processes the purchase form. """ if login.current_user.purchase_group: if login.current_user == login.current_user.purchase_group.leader: if APP.config['TICKETS_ON_SALE']: return flask.redirect(flask.url_for('group_purchase.checkout')) else: flask.flash( ('You cannot currently purchase tickets because you are ' 'leading a purchase group. You will be able to ' 'purchase tickets on behalf of your group when general ' 'release starts.'), 'info') return flask.redirect( flask.url_for('dashboard.dashboard_home')) else: flask.flash( ('You cannot currently purchase tickets because you are a ' 'member of a purchase group. Your group leader {0} will be ' 'able to purchase tickets on behalf of your group when ' 'general release starts.').format( login.current_user.purchase_group.leader.full_name), 'info') return flask.redirect(flask.url_for('dashboard.dashboard_home')) ticket_info = purchase_logic.get_ticket_info(login.current_user) if models.Waiting.query.count() > 0 or not ticket_info.ticket_types: flask.flash('You are not able to purchase tickets at this time.', 'info') if purchase_logic.wait_available(login.current_user): flask.flash( ('Please join the waiting list, and you will be allocated ' 'tickets as they become available'), 'info') return flask.redirect(flask.url_for('purchase.wait')) else: return flask.redirect(flask.url_for('dashboard.dashboard_home')) num_tickets = { ticket_type.slug: 0 for ticket_type, _ in ticket_info.ticket_types } if flask.request.method == 'POST': for ticket_type, _ in ticket_info.ticket_types: num_tickets[ticket_type.slug] = int( flask.request.form['num_tickets_{0}'.format(ticket_type.slug)]) flashes = purchase_logic.validate_tickets(ticket_info, num_tickets) payment_method, payment_term = purchase_logic.check_payment_method( flashes) voucher = None if ('voucher_code' in flask.request.form and flask.request.form['voucher_code'] != ''): (result, response, voucher) = validators.validate_voucher( flask.request.form['voucher_code']) if not result: flashes.append( ('{} Please clear the discount code field to continue ' 'without using a voucher.').format(response['message'])) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash(('There were errors in your order. Please fix ' 'these and try again'), 'error') for msg in flashes: flask.flash(msg, 'warning') return flask.render_template('purchase/purchase_home.html', form=flask.request.form, num_tickets=num_tickets, ticket_info=ticket_info) tickets = purchase_logic.create_tickets(login.current_user, ticket_info, num_tickets) if voucher is not None: (success, tickets, error) = voucher.apply(tickets, login.current_user) if not success: flask.flash('Could not use voucher - ' + error, 'error') roundup_price = purchase_logic.check_roundup_donation(flashes) if roundup_price is not 0: roundup_donation = None roundup_donation = models.RoundupDonation( roundup_price, login.current_user, ) if roundup_donation is not None: # Tack on the roundup donation fee to their ticket(s) # Entry tickets = roundup_donation.apply(tickets) DB.session.add(roundup_donation) DB.session.add_all(tickets) DB.session.commit() APP.log_manager.log_event('Purchased Tickets', tickets=tickets, user=login.current_user) # return flask.render_template( # 'purchase/purchase_home.html', # num_tickets=num_tickets, # ticket_info=ticket_info # ) return payment_logic.do_payment(tickets, postage, payment_method, payment_term, address) else: return flask.render_template('purchase/purchase_home.html', num_tickets=num_tickets, ticket_info=ticket_info)
def purchase_home(): """First step of the purchasing flow. Checks if the user can purchase tickets, and processes the purchase form. """ if login.current_user.purchase_group: if login.current_user == login.current_user.purchase_group.leader: if APP.config["TICKETS_ON_SALE"]: return flask.redirect(flask.url_for("group_purchase.checkout")) else: flask.flash( ("You cannot currently purchase tickets because you are " "leading a purchase group. You will be able to " "purchase tickets on behalf of your group when general " "release starts."), "info", ) return flask.redirect( flask.url_for("dashboard.dashboard_home")) else: flask.flash( ("You cannot currently purchase tickets because you are a " "member of a purchase group. Your group leader {0} will be " "able to purchase tickets on behalf of your group when " "general release starts.").format( login.current_user.purchase_group.leader.full_name), "info", ) return flask.redirect(flask.url_for("dashboard.dashboard_home")) ticket_info = purchase_logic.get_ticket_info(login.current_user) if models.Waiting.query.count() > 0 or not ticket_info.ticket_types: flask.flash("You are not able to purchase tickets at this time.", "info") if purchase_logic.wait_available(login.current_user): flask.flash( ("Please join the waiting list, and you will be allocated " "tickets as they become available"), "info", ) return flask.redirect(flask.url_for("purchase.wait")) else: return flask.redirect(flask.url_for("dashboard.dashboard_home")) num_tickets = { ticket_type.slug: 0 for ticket_type, _ in ticket_info.ticket_types } addons_selected = {addon.slug: False for addon, _ in ticket_info.addons} if flask.request.method == "POST": for ticket_type, _ in ticket_info.ticket_types: num_tickets[ticket_type.slug] = int( flask.request.form["num_tickets_{0}".format(ticket_type.slug)]) for addon, _ in ticket_info.addons: try: addons_selected[addon.slug] = ( flask.request.form["addon_{0}".format( addon.slug)] == "Yes") except KeyError: pass flashes = purchase_logic.validate_tickets(ticket_info, num_tickets, addons_selected) payment_method, payment_term = purchase_logic.check_payment_method( flashes) voucher = None if ("voucher_code" in flask.request.form and flask.request.form["voucher_code"] != ""): (result, response, voucher) = validators.validate_voucher( flask.request.form["voucher_code"]) if not result: flashes.append( ("{} Please clear the discount code field to continue " "without using a voucher.").format(response["message"])) postage, address = purchase_logic.check_postage(flashes) if flashes: flask.flash( ("There were errors in your order. Please fix " "these and try again"), "error", ) for msg in flashes: flask.flash(msg, "warning") return flask.render_template( "purchase/purchase_home.html", form=flask.request.form, num_tickets=num_tickets, addons_selected=addons_selected, ticket_info=ticket_info, ) tickets, addons = purchase_logic.create_tickets( login.current_user, ticket_info, num_tickets, addons_selected) if voucher is not None: (success, tickets, error) = voucher.apply(tickets, login.current_user) if not success: flask.flash("Could not use voucher - " + error, "error") roundup_price = purchase_logic.check_roundup_donation(flashes) if roundup_price is not 0: roundup_donation = None roundup_donation = models.RoundupDonation(roundup_price, login.current_user) if roundup_donation is not None: # Tack on the roundup donation fee to their ticket(s) # Entry tickets = roundup_donation.apply(tickets) DB.session.add(roundup_donation) DB.session.add_all(tickets) DB.session.add_all(addons) DB.session.commit() APP.log_manager.log_event("Purchased Tickets", tickets=tickets, user=login.current_user) # return flask.render_template( # 'purchase/purchase_home.html', # num_tickets=num_tickets, # ticket_info=ticket_info # ) return payment_logic.do_payment(tickets, postage, payment_method, payment_term, address) else: return flask.render_template( "purchase/purchase_home.html", num_tickets=num_tickets, ticket_info=ticket_info, )