Example #1
0
def stripe_payment_paid(payment: StripePayment):
    if payment.state == "paid":
        logger.info("Payment is already paid, ignoring")
        return

    if payment.state == "partrefunded":
        logger.info("Payment is already partially refunded, ignoring")
        return

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

    msg = Message(
        "Your EMF payment has been confirmed",
        sender=app.config.get("TICKETS_EMAIL"),
        recipients=[payment.user.email],
    )

    already_emailed = set_tickets_emailed(payment.user)
    msg.body = render_template(
        "emails/tickets-paid-email-stripe.txt",
        user=payment.user,
        payment=payment,
        already_emailed=already_emailed,
    )

    if feature_enabled("ISSUE_TICKETS"):
        attach_tickets(msg, payment.user)

    mail.send(msg)
    db.session.commit()
Example #2
0
def stripe_update_payment(payment: StripePayment,
                          intent: stripe.PaymentIntent = None):
    """ Update a Stripe payment.
        If a PaymentIntent object is not passed in, this will fetch the payment details from the Stripe API.
    """
    if intent is None:
        intent = stripe.PaymentIntent.retrieve(payment.intent_id)

    if len(intent.charges) == 0:
        # Intent does not have a charge (yet?), do nothing
        return
    elif len(intent.charges) > 1:
        raise StripeUpdateUnexpected(
            f"Payment intent #{intent['id']} has more than one charge")

    charge = intent.charges.data[0]

    if payment.charge_id is not None and payment.charge_id != charge["id"]:
        logging.warn(
            f"Charge ID for intent {intent['id']} has changed from {payment.charge_id} to {charge['id']}"
        )

    payment.charge_id = charge["id"]

    if charge.refunded:
        return stripe_payment_refunded(payment)
    elif charge.status == "succeeded":
        return stripe_payment_paid(payment)
    elif charge.status == "failed":
        return stripe_payment_failed(payment)

    raise StripeUpdateUnexpected(
        "Charge object is not paid, refunded or failed")
Example #3
0
def stripe_payment_refunded(payment: StripePayment):
    if payment.state == "refunded":
        logger.info("Payment is already refunded, ignoring")
        return

    logger.info("Setting payment %s to refunded", payment.id)

    # Payment is already locked by the caller of stripe_update_payment
    with db.session.no_autoflush:
        for purchase in payment.purchases:
            purchase.refund_purchase()

    payment.state = "refunded"
    db.session.commit()

    if not app.config.get("TICKETS_NOTICE_EMAIL"):
        app.logger.warning("No tickets notice email configured, not sending")
        return

    msg = Message(
        "An EMF payment has been refunded",
        sender=app.config.get("TICKETS_EMAIL"),
        recipients=[app.config.get("TICKETS_NOTICE_EMAIL")[1]],
    )
    msg.body = render_template("emails/notice-payment-refunded.txt",
                               payment=payment)
    mail.send(msg)
Example #4
0
def stripe_payment_refunded(payment: StripePayment):
    # Email user
    msg = Message(
        "You have received a refund from EMF",
        sender=app.config.get("TICKETS_EMAIL"),
        recipients=[payment.user.email],
    )
    msg.body = render_template("emails/stripe-refund-sent.txt",
                               user=payment.user,
                               payment=payment)
    mail.send(msg)

    if payment.state == "refunded":
        logger.info("Payment is already refunded, ignoring")
        return

    logger.info("Setting payment %s to refunded", payment.id)

    # Payment is already locked by the caller of stripe_update_payment
    with db.session.no_autoflush:
        for purchase in payment.purchases:
            purchase.refund_purchase()

    payment.state = "refunded"
    db.session.commit()

    ticket_admin_email(
        "Unexpected Stripe refund received",
        "emails/notice-payment-refunded.txt",
        payment=payment,
    )
Example #5
0
def main():
    if app.config.get('ARRIVALS_SITE'):
        return redirect(url_for('arrivals'))

    full_price = TicketType.query.get('full').get_price('GBP')
    if not (app.config.get('BANK_TRANSFER') or app.config.get('GOCARDLESS')):
        # Only card payment left
        full_price += StripePayment.premium('GBP', full_price)
    return render_template('splash.html',
        ticket_sales=app.config.get('TICKET_SALES', False),
        full_price=full_price)
Example #6
0
def main():
    if app.config.get('ARRIVALS_SITE'):
        return redirect(url_for('arrivals'))

    full_price = TicketType.query.get('full').get_price('GBP')
    if not (app.config.get('BANK_TRANSFER') or app.config.get('GOCARDLESS')):
        # Only card payment left
        full_price += StripePayment.premium('GBP', full_price)
    return render_template('splash.html',
                           ticket_sales=app.config.get('TICKET_SALES', False),
                           full_price=full_price)
Example #7
0
def main():
    full_price = TicketType.get_price_cheapest_full()
    if not (feature_enabled('BANK_TRANSFER')
            or feature_enabled('GOCARDLESS')) and full_price is not None:
        # Only card payment left
        full_price += StripePayment.premium('GBP', full_price)

    state = get_site_state()
    if app.config.get('DEBUG'):
        state = request.args.get("site_state", state)

    return render_template('home/%s.html' % state, full_price=full_price)
Example #8
0
def main():
    full_price = TicketType.get_price_cheapest_full()
    if not (feature_enabled('BANK_TRANSFER') or feature_enabled('GOCARDLESS')) and full_price is not None:
        # Only card payment left
        full_price += StripePayment.premium('GBP', full_price)

    state = get_site_state()
    if app.config.get('DEBUG'):
        state = request.args.get("site_state", state)

    return render_template('home/%s.html' % state,
                           full_price=full_price)
Example #9
0
def stripe_payment_refunded(payment: StripePayment):
    if payment.state in ("refunded", "refunding"):
        logger.info(
            f"Payment {payment.id} is {payment.state}, ignoring refund webhook"
        )
        return

    logger.info("Setting payment %s to refunded", payment.id)

    # Payment is already locked by the caller of stripe_update_payment
    with db.session.no_autoflush:
        for purchase in payment.purchases:
            purchase.refund_purchase()

    payment.state = "refunded"
    db.session.commit()

    ticket_admin_email(
        "Unexpected Stripe refund received",
        "emails/notice-payment-refunded.txt",
        payment=payment,
    )