def is_completed(self, request, warn=False): if request.event.has_subevents and cart_session(request).get( 'clique_mode') == 'join' and 'clique_join' in cart_session( request): try: clique = Clique.objects.get( event=self.event, pk=cart_session(request)['clique_join']) clique_subevents = set( c['order__all_positions__subevent'] for c in clique.ordercliques.filter( order__all_positions__canceled=False).values( 'order__all_positions__subevent').distinct()) if clique_subevents: cart_subevents = set(c['subevent'] for c in get_cart( request).values('subevent').distinct()) if any(c not in clique_subevents for c in cart_subevents): if warn: messages.warning( request, _('You requested to join a clique that participates in "{subevent_clique}", while you chose to participate in "{subevent_cart}". Please choose a different clique.' ).format( subevent_clique=SubEvent.objects.get( pk=list(clique_subevents)[0]).name, subevent_cart=SubEvent.objects.get( pk=list(cart_subevents)[0]).name, )) return False except Clique.DoesNotExist: pass return 'clique_mode' in cart_session(request)
def order_meta_signal(sender: Event, request: HttpRequest, **kwargs): cs = cart_session(request) return { 'clique_mode': cs.get('clique_mode'), 'clique_join': cs.get('clique_join'), 'clique_create': cs.get('clique_create'), }
def cart_fee(sender: Event, request: HttpRequest, total: Decimal, invoice_address, **kwargs): cs = cart_session(request) if cs.get('payment') == 'stripe_cc_reluctant' and total > 0: if request.session.get('payment_%s_%s' % ('stripe_cc_reluctant', 'pay_fees')) == 'yes': return [get_fee(sender, total, invoice_address)] return []
def order_meta_signal(sender: Event, request: HttpRequest, **kwargs): cs = cart_session(request) if cs.get('payment') == 'stripe_cc_reluctant': return { 'pretix_stripe_reluctant_pay_fee': request.session.get('payment_%s_%s' % ('stripe_cc_reluctant', 'pay_fees')) == 'yes' } return {}
def get_cart_is_free(request): from pretix.presale.views.cart import cart_session if not hasattr(request, '_cart_free_cache'): cs = cart_session(request) ia = get_cart_invoice_address(request) total = get_cart_total(request) fees = get_fees(request.event, request, total, ia, cs.get('payment')) request._cart_free_cache = total + sum(f.value for f in fees) == Decimal('0.00') return request._cart_free_cache
def get_invoice_address(): if not hasattr(request, '_checkout_flow_invoice_address'): cs = cart_session(request) iapk = cs.get('invoice_address') if not iapk: request._checkout_flow_invoice_address = InvoiceAddress() else: try: request._checkout_flow_invoice_address = InvoiceAddress.objects.get(pk=iapk, order__isnull=True) except InvoiceAddress.DoesNotExist: request._checkout_flow_invoice_address = InvoiceAddress() return request._checkout_flow_invoice_address
def get_cart_invoice_address(request): from pretix.presale.views.cart import cart_session if not hasattr(request, '_checkout_flow_invoice_address'): cs = cart_session(request) iapk = cs.get('invoice_address') if not iapk: request._checkout_flow_invoice_address = InvoiceAddress() else: try: with scopes_disabled(): request._checkout_flow_invoice_address = InvoiceAddress.objects.get(pk=iapk, order__isnull=True) except InvoiceAddress.DoesNotExist: request._checkout_flow_invoice_address = InvoiceAddress() return request._checkout_flow_invoice_address
def confirm_page(sender: Event, request: HttpRequest, **kwargs): cs = cart_session(request) template = get_template('pretix_cliques/checkout_confirm.html') ctx = { 'mode': cs.get('clique_mode'), 'request': request, } if cs.get('clique_mode') == 'join': try: ctx['clique'] = sender.cliques.get(pk=cs.get('clique_join')) except Clique.DoesNotExist: return elif cs.get('clique_mode') == 'create': try: ctx['clique'] = sender.cliques.get(pk=cs.get('clique_create')) except Clique.DoesNotExist: return return template.render(ctx)
def register_onpremise_contact_confirmpage_content(sender, request, **kwargs): session = cart_session(request) if not (sender.settings.get('onpremise_contact_availability', as_type=str) == 'always' \ or session.get('contact_form_data', {}).get('has_onpremise_contact', False)): return "" from .checkoutflow import ContactForm session_info = session.get('onpremise_contact', {}) contact_info = [] if session_info: contact_info = ContactForm.label_formdata(session_info, sender).values() template = get_template('pretix_purpletweaks/onpremise_contact_card.html') return template.render({ 'message': '', 'contact_info': contact_info, 'panelclass': 'panel-contact panel-primary', 'event': sender, })
def cached_invoice_address(request): from .cart import cart_session if not hasattr(request, '_checkout_flow_invoice_address'): if not request.session.session_key: # do not create a session, if we don't have a session we also don't have an invoice address ;) request._checkout_flow_invoice_address = InvoiceAddress() return request._checkout_flow_invoice_address cs = cart_session(request) iapk = cs.get('invoice_address') if not iapk: request._checkout_flow_invoice_address = InvoiceAddress() else: try: with scopes_disabled(): request._checkout_flow_invoice_address = InvoiceAddress.objects.get( pk=iapk, order__isnull=True) except InvoiceAddress.DoesNotExist: request._checkout_flow_invoice_address = InvoiceAddress() return request._checkout_flow_invoice_address
def checkout_prepare(self, request: HttpRequest, cart: Dict[str, Any]) -> Union[bool, str, None]: for p in get_cart(request): if p.item.issue_giftcard: messages.error( request, _("You cannot pay with gift cards when buying a gift card." )) return cs = cart_session(request) try: gc = self.event.organizer.accepted_gift_cards.get( secret=request.POST.get("giftcard")) if gc.currency != self.event.currency: messages.error( request, _("This gift card does not support this currency.")) return if gc.testmode and not self.event.testmode: messages.error( request, _("This gift card can only be used in test mode.")) return if not gc.testmode and self.event.testmode: messages.error( request, _("Only test gift cards can be used in test mode.")) return if gc.value <= Decimal("0.00"): messages.error( request, _("All credit on this gift card has been used.")) return if 'gift_cards' not in cs: cs['gift_cards'] = [] elif gc.pk in cs['gift_cards']: messages.error( request, _("This gift card is already used for your payment.")) return cs['gift_cards'] = cs['gift_cards'] + [gc.pk] remainder = cart['total'] - gc.value if remainder >= Decimal('0.00'): del cs['payment'] messages.success( request, _("Your gift card has been applied, but {} still need to be paid. Please select a payment method." ).format(money_filter(remainder, self.event.currency))) else: messages.success(request, _("Your gift card has been applied.")) kwargs = {'step': 'payment'} if request.resolver_match and 'cart_namespace' in request.resolver_match.kwargs: kwargs['cart_namespace'] = request.resolver_match.kwargs[ 'cart_namespace'] return eventreverse(self.event, 'presale:event.checkout', kwargs=kwargs) except GiftCard.DoesNotExist: if self.event.vouchers.filter( code__iexact=request.POST.get("giftcard")).exists(): messages.warning( request, _("You entered a voucher instead of a gift card. Vouchers can only be entered on the first page of the shop below " "the product selection.")) else: messages.error(request, _("This gift card is not known.")) except GiftCard.MultipleObjectsReturned: messages.error( request, _("This gift card can not be redeemed since its code is not unique. Please contact the organizer of this event." ))
def cart_session(self): from pretix.presale.views.cart import cart_session return cart_session(self.request)
def cart_session(self): return cart_session(self.request)
def get_fees(event, total, invoice_address, mod='', request=None, positions=[], gift_cards=None): if request is not None and not positions: positions = get_cart(request) skip_free = event.settings.get('service_fee_skip_free', as_type=bool) if skip_free: positions = [pos for pos in positions if pos.price != Decimal('0.00')] skip_addons = event.settings.get('service_fee_skip_addons', as_type=bool) if skip_addons: positions = [pos for pos in positions if not pos.addon_to_id] skip_non_admission = event.settings.get('service_fee_skip_non_admission', as_type=bool) if skip_non_admission: positions = [pos for pos in positions if pos.item.admission] fee_per_ticket = event.settings.get('service_fee_per_ticket' + mod, as_type=Decimal) if mod and fee_per_ticket is None: fee_per_ticket = event.settings.get('service_fee_per_ticket', as_type=Decimal) fee_abs = event.settings.get('service_fee_abs' + mod, as_type=Decimal) if mod and fee_abs is None: fee_abs = event.settings.get('service_fee_abs', as_type=Decimal) fee_percent = event.settings.get('service_fee_percent' + mod, as_type=Decimal) if mod and fee_percent is None: fee_percent = event.settings.get('service_fee_percent', as_type=Decimal) fee_per_ticket = Decimal("0") if fee_per_ticket is None else fee_per_ticket fee_abs = Decimal("0") if fee_abs is None else fee_abs fee_percent = Decimal("0") if fee_percent is None else fee_percent if event.settings.get('service_fee_skip_if_gift_card', as_type=bool): gift_cards = gift_cards or [] if request: cs = cart_session(request) if cs.get('gift_cards'): gift_cards = event.organizer.accepted_gift_cards.filter( pk__in=cs.get('gift_cards'), currency=event.currency) summed = 0 for gc in gift_cards: fval = Decimal(gc.value) # TODO: don't require an extra query fval = min(fval, total - summed) if fval > 0: total -= fval summed += fval if (fee_per_ticket or fee_abs or fee_percent) and total != Decimal('0.00'): fee = round_decimal( fee_abs + total * (fee_percent / 100) + len(positions) * fee_per_ticket, event.currency) tax_rule = event.settings.tax_rate_default or TaxRule.zero() tax = tax_rule.tax(fee, invoice_address=invoice_address, base_price_is='gross') return [ OrderFee(fee_type=OrderFee.FEE_TYPE_SERVICE, internal_type='', value=fee, tax_rate=tax.rate, tax_value=tax.tax, tax_rule=tax_rule) ] return []
def register_order_meta_for_contact_step(sender, request, **kwargs): session = cart_session(request) if not (sender.settings.get('onpremise_contact_availability', as_type=str) == 'always' \ or session.get('contact_form_data', {}).get('has_onpremise_contact', False)): return {} return {'onpremise_contact': session.get('onpremise_contact', {})}