Ejemplo n.º 1
0
def notify_incomplete_payment(o: Order):
    with language(o.locale):
        tz = pytz.timezone(o.event.settings.get('timezone', settings.TIME_ZONE))
        try:
            invoice_name = o.invoice_address.name
            invoice_company = o.invoice_address.company
        except InvoiceAddress.DoesNotExist:
            invoice_name = ""
            invoice_company = ""
        email_template = o.event.settings.mail_text_order_expire_warning
        email_context = {
            'event': o.event.name,
            'url': build_absolute_uri(o.event, 'presale:event.order', kwargs={
                'order': o.code,
                'secret': o.secret
            }),
            'expire_date': date_format(o.expires.astimezone(tz), 'SHORT_DATE_FORMAT'),
            'invoice_name': invoice_name,
            'invoice_company': invoice_company,
        }
        email_subject = ugettext('Your order received an incomplete payment: %(code)s') % {'code': o.code}

        try:
            o.send_mail(
                email_subject, email_template, email_context,
                'pretix.event.order.email.expire_warning_sent'
            )
        except SendMailException:
            logger.exception('Reminder email could not be sent')
Ejemplo n.º 2
0
def notify_incomplete_payment(o: Order):
    with language(o.locale):
        tz = pytz.timezone(o.event.settings.get('timezone', settings.TIME_ZONE))
        try:
            invoice_name = o.invoice_address.name
            invoice_company = o.invoice_address.company
        except InvoiceAddress.DoesNotExist:
            invoice_name = ""
            invoice_company = ""
        email_template = o.event.settings.mail_text_order_expire_warning
        email_context = {
            'event': o.event.name,
            'url': build_absolute_uri(o.event, 'presale:event.order.open', kwargs={
                'order': o.code,
                'secret': o.secret,
                'hash': o.email_confirm_hash()
            }),
            'expire_date': date_format(o.expires.astimezone(tz), 'SHORT_DATE_FORMAT'),
            'invoice_name': invoice_name,
            'invoice_company': invoice_company,
        }
        email_subject = ugettext('Your order received an incomplete payment: %(code)s') % {'code': o.code}

        try:
            o.send_mail(
                email_subject, email_template, email_context,
                'pretix.event.order.email.expire_warning_sent'
            )
        except SendMailException:
            logger.exception('Reminder email could not be sent')
Ejemplo n.º 3
0
def notify_incomplete_payment(o: Order):
    with language(o.locale, o.event.settings.region):
        email_template = o.event.settings.mail_text_order_expire_warning
        email_context = get_email_context(event=o.event, order=o)
        email_subject = gettext('Your order received an incomplete payment: %(code)s') % {'code': o.code}

        try:
            o.send_mail(
                email_subject, email_template, email_context,
                'pretix.event.order.email.expire_warning_sent'
            )
        except SendMailException:
            logger.exception('Reminder email could not be sent')
Ejemplo n.º 4
0
def _send_mail(order: Order, subject: LazyI18nString, message: LazyI18nString,
               subevent: SubEvent, refund_amount: Decimal, user: User,
               positions: list):
    with language(order.locale, order.event.settings.region):
        try:
            ia = order.invoice_address
        except InvoiceAddress.DoesNotExist:
            ia = InvoiceAddress(order=order)

        email_context = get_email_context(event_or_subevent=subevent
                                          or order.event,
                                          refund_amount=refund_amount,
                                          order=order,
                                          position_or_address=ia,
                                          event=order.event)
        real_subject = str(subject).format_map(TolerantDict(email_context))
        try:
            order.send_mail(
                real_subject,
                message,
                email_context,
                'pretix.event.order.email.event_canceled',
                user,
            )
        except SendMailException:
            logger.exception('Order canceled email could not be sent')

        for p in positions:
            if subevent and p.subevent_id != subevent.id:
                continue

            if p.addon_to_id is None and p.attendee_email and p.attendee_email != order.email:
                real_subject = str(subject).format_map(
                    TolerantDict(email_context))
                email_context = get_email_context(event_or_subevent=p.subevent
                                                  or order.event,
                                                  event=order.event,
                                                  refund_amount=refund_amount,
                                                  position_or_address=p,
                                                  order=order,
                                                  position=p)
                try:
                    order.send_mail(real_subject,
                                    message,
                                    email_context,
                                    'pretix.event.order.email.event_canceled',
                                    position=p,
                                    user=user)
                except SendMailException:
                    logger.exception(
                        'Order canceled email could not be sent to attendee')
Ejemplo n.º 5
0
def mark_order_paid(order: Order, provider: str=None, info: str=None, date: datetime=None, manual: bool=None,
                    force: bool=False, send_mail: bool=True, user: User=None, mail_text='') -> Order:
    """
    Marks an order as paid. This sets the payment provider, info and date and returns
    the order object.

    :param provider: The payment provider that marked this as paid
    :type provider: str
    :param info: The information to store in order.payment_info
    :type info: str
    :param date: The date the payment was received (if you pass ``None``, the current
                 time will be used).
    :type date: datetime
    :param force: Whether this payment should be marked as paid even if no remaining
                  quota is available (default: ``False``).
    :type force: boolean
    :param send_mail: Whether an email should be sent to the user about this event (default: ``True``).
    :type send_mail: boolean
    :param user: The user that performed the change
    :param mail_text: Additional text to be included in the email
    :type mail_text: str
    :raises Quota.QuotaExceededException: if the quota is exceeded and ``force`` is ``False``
    """
    if order.status == Order.STATUS_PAID:
        return order

    with order.event.lock() as now_dt:
        can_be_paid = order._can_be_paid()
        if not force and can_be_paid is not True:
            raise Quota.QuotaExceededException(can_be_paid)
        order.payment_provider = provider or order.payment_provider
        order.payment_info = info or order.payment_info
        order.payment_date = date or now_dt
        if manual is not None:
            order.payment_manual = manual
        order.status = Order.STATUS_PAID
        order.save()

    order.log_action('pretix.event.order.paid', {
        'provider': provider,
        'info': info,
        'date': date or now_dt,
        'manual': manual,
        'force': force
    }, user=user)
    order_paid.send(order.event, order=order)

    if order.event.settings.get('invoice_generate') in ('True', 'paid') and invoice_qualified(order):
        if not order.invoices.exists():
            generate_invoice(order)

    if send_mail:
        with language(order.locale):
            try:
                invoice_name = order.invoice_address.name
                invoice_company = order.invoice_address.company
            except InvoiceAddress.DoesNotExist:
                invoice_name = ""
                invoice_company = ""
            email_template = order.event.settings.mail_text_order_paid
            email_context = {
                'event': order.event.name,
                'url': build_absolute_uri(order.event, 'presale:event.order', kwargs={
                    'order': order.code,
                    'secret': order.secret
                }),
                'downloads': order.event.settings.get('ticket_download', as_type=bool),
                'invoice_name': invoice_name,
                'invoice_company': invoice_company,
                'payment_info': mail_text
            }
            email_subject = _('Payment received for your order: %(code)s') % {'code': order.code}
            try:
                order.send_mail(
                    email_subject, email_template, email_context,
                    'pretix.event.order.email.order_paid', user
                )
            except SendMailException:
                logger.exception('Order paid email could not be sent')

    return order