Esempio n. 1
0
def stripe_payment_paid(payment):
    if payment.state == 'paid':
        logger.info('Payment is already paid, ignoring')
        return

    if payment.state != 'charged':
        logger.error('Current payment state is %s (should be charged)', payment.state)
        raise StripeUpdateConflict()

    logger.info('Setting payment %s to paid', payment.id)
    payment.paid()
    db.session.commit()

    msg = Message('Your EMF ticket payment has been confirmed',
        sender=app.config.get('TICKETS_EMAIL'),
        recipients=[payment.user.email])
    msg.body = render_template('tickets-paid-email-stripe.txt',
        user=payment.user, payment=payment)

    if app.config.get('RECEIPTS'):
        page = render_receipt(payment.tickets, pdf=True)
        pdf = render_pdf(page)
        msg.attach('Receipt.pdf', 'application/pdf', pdf.read())

    mail.send(msg)
Esempio n. 2
0
def stripe_payment_paid(payment):
    if payment.state == 'paid':
        logger.info('Payment is already paid, ignoring')
        return

    if payment.state != 'charged':
        logger.error('Current payment state is %s (should be charged)',
                     payment.state)
        raise StripeUpdateConflict()

    logger.info('Setting payment %s to paid', payment.id)
    payment.paid()
    db.session.commit()

    msg = Message('Your EMF ticket payment has been confirmed',
                  sender=app.config.get('TICKETS_EMAIL'),
                  recipients=[payment.user.email])
    msg.body = render_template('tickets-paid-email-stripe.txt',
                               user=payment.user,
                               payment=payment)

    if app.config.get('RECEIPTS'):
        page = render_receipt(payment.tickets, pdf=True)
        pdf = render_pdf(page)
        msg.attach('Receipt.pdf', 'application/pdf', pdf.read())

    mail.send(msg)
Esempio n. 3
0
    def run(self):
        all_tickets = Ticket.query.filter_by(paid=True, emailed=False)
        users = all_tickets.join(User).group_by(User).with_entities(
            User).order_by(User.id)

        for user in users:
            tickets = all_tickets.filter_by(user_id=user.id)
            page = render_receipt(tickets, pdf=True)
            pdf = render_pdf(page, url_root=app.config.get('BASE_URL'))
            plural = (tickets.count() != 1 and 's' or '')

            msg = Message("Your Electromagnetic Field Ticket%s" % plural,
                          sender=app.config['TICKETS_EMAIL'],
                          recipients=[user.email])

            msg.body = render_template("receipt.txt", user=user)
            msg.attach('Receipt.pdf', 'application/pdf', pdf.read())

            app.logger.info('Emailing %s receipt for %s tickets', user.email,
                            tickets.count())
            mail.send(msg)

            for ticket in tickets:
                ticket.emailed = True
            db.session.commit()
Esempio n. 4
0
    def run(self):
        all_tickets = Ticket.query.filter_by(paid=True, emailed=False)
        users = all_tickets.join(User).group_by(User).with_entities(User).order_by(User.id)

        for user in users:
            tickets = all_tickets.filter_by(user_id=user.id)
            page = render_receipt(tickets, pdf=True)
            pdf = render_pdf(page, url_root=app.config.get('BASE_URL'))
            plural = (tickets.count() != 1 and 's' or '')

            msg = Message("Your Electromagnetic Field Ticket%s" % plural,
                          sender=app.config['TICKETS_EMAIL'],
                          recipients=[user.email])

            msg.body = render_template("receipt.txt", user=user)
            msg.attach('Receipt.pdf', 'application/pdf', pdf.read())

            app.logger.info('Emailing %s receipt for %s tickets', user.email, tickets.count())
            mail.send(msg)

            for ticket in tickets:
                ticket.emailed = True
            db.session.commit()
Esempio n. 5
0
        for t in payment.tickets:
            t.expires = datetime.utcnow() + timedelta(days=app.config['EXPIRY_DAYS_STRIPE'])
            logger.info("Set expiry for ticket %s", t.id)

    db.session.commit()

    logger.info('Payment %s completed OK (state %s)', payment.id, payment.state)

    msg = Message("Your EMF ticket purchase",
        sender=app.config.get('TICKETS_EMAIL'),
        recipients=[payment.user.email])
    msg.body = render_template("tickets-purchased-email-stripe.txt",
        user=payment.user, payment=payment)

    if app.config.get('RECEIPTS'):
        page = render_receipt(payment.tickets, pdf=True)
        pdf = render_pdf(page)
        msg.attach('Receipt.pdf', 'application/pdf', pdf.read())

        for t in payment.tickets:
            t.emailed = True
        db.session.commit()

    mail.send(msg)

    return redirect(url_for('stripe_waiting', payment_id=payment.id))


class StripeAuthorizeForm(Form):
    token = HiddenField('Stripe token')
    forward = SubmitField('Continue')
Esempio n. 6
0
            logger.info("Set expiry for ticket %s", t.id)

    db.session.commit()

    logger.info('Payment %s completed OK (state %s)', payment.id,
                payment.state)

    msg = Message("Your EMF ticket purchase",
                  sender=app.config.get('TICKETS_EMAIL'),
                  recipients=[payment.user.email])
    msg.body = render_template("tickets-purchased-email-stripe.txt",
                               user=payment.user,
                               payment=payment)

    if app.config.get('RECEIPTS'):
        page = render_receipt(payment.tickets, pdf=True)
        pdf = render_pdf(page)
        msg.attach('Receipt.pdf', 'application/pdf', pdf.read())

        for t in payment.tickets:
            t.emailed = True
        db.session.commit()

    mail.send(msg)

    return redirect(url_for('stripe_waiting', payment_id=payment.id))


class StripeAuthorizeForm(Form):
    token = HiddenField('Stripe token')
    forward = SubmitField('Continue')