def perform_order(event: Event, payment_provider: BasePaymentProvider, positions: list, user: User=None, email: str=None, locale: str=None): dt = now() try: with event.lock(): check_positions(event, dt, positions) order = place_order(event, user, email if user is None else None, positions, dt, payment_provider, locale=locale) mail( order.email, _('Your order: %(code)s') % {'code': order.code}, 'pretixpresale/email/order_placed.txt', { 'order': order, 'event': event, 'url': build_absolute_uri('presale:event.order', kwargs={ 'event': event.slug, 'organizer': event.organizer.slug, 'order': order.code, }) + '?order_secret=' + order.secret, 'payment': payment_provider.order_pending_mail_render(order) }, event, locale=order.locale ) return order except EventLock.LockTimeoutException: # Is raised when there are too many threads asking for event locks and we were # unable to get one raise OrderError(error_messages['busy'])
def _create_order(event: Event, email: str, positions: list, dt: datetime, payment_provider: BasePaymentProvider, locale: str = None): total = sum([c.price for c in positions]) payment_fee = payment_provider.calculate_fee(total) total += payment_fee expires = [ dt + timedelta(days=event.settings.get('payment_term_days', as_type=int)) ] if event.settings.get('payment_term_last'): expires.append( event.settings.get('payment_term_last', as_type=datetime)) order = Order.objects.create(status=Order.STATUS_PENDING, event=event, email=email, datetime=dt, expires=min(expires), locale=locale, total=total, payment_fee=payment_fee, payment_provider=payment_provider.identifier) OrderPosition.transform_cart_positions(positions, order) order_placed.send(event, order=order) return order
def _create_order(event: Event, email: str, positions: List[CartPosition], now_dt: datetime, payment_provider: BasePaymentProvider, locale: str=None, address: int=None, meta_info: dict=None): from datetime import date, time total = sum([c.price for c in positions]) payment_fee = payment_provider.calculate_fee(total) total += payment_fee tz = pytz.timezone(event.settings.timezone) exp_by_date = now_dt.astimezone(tz) + timedelta(days=event.settings.get('payment_term_days', as_type=int)) exp_by_date = exp_by_date.astimezone(tz).replace(hour=23, minute=59, second=59, microsecond=0) if event.settings.get('payment_term_weekdays'): if exp_by_date.weekday() == 5: exp_by_date += timedelta(days=2) elif exp_by_date.weekday() == 6: exp_by_date += timedelta(days=1) expires = exp_by_date if event.settings.get('payment_term_last'): last_date = make_aware(datetime.combine( event.settings.get('payment_term_last', as_type=date), time(hour=23, minute=59, second=59) ), tz) if last_date < expires: expires = last_date with transaction.atomic(): order = Order.objects.create( status=Order.STATUS_PENDING, event=event, email=email, datetime=now_dt, expires=expires, locale=locale, total=total, payment_fee=payment_fee, payment_provider=payment_provider.identifier, meta_info=json.dumps(meta_info or {}), ) OrderPosition.transform_cart_positions(positions, order) if address is not None: try: addr = InvoiceAddress.objects.get( pk=address ) if addr.order is not None: addr.pk = None addr.order = order addr.save() except InvoiceAddress.DoesNotExist: pass order.log_action('pretix.event.order.placed') order_placed.send(event, order=order) return order
def _create_order(event: Event, email: str, positions: List[CartPosition], now_dt: datetime, payment_provider: BasePaymentProvider, locale: str=None, address: int=None, meta_info: dict=None): from datetime import date, time total = sum([c.price for c in positions]) payment_fee = payment_provider.calculate_fee(total) total += payment_fee tz = pytz.timezone(event.settings.timezone) exp_by_date = now_dt.astimezone(tz) + timedelta(days=event.settings.get('payment_term_days', as_type=int)) exp_by_date = exp_by_date.replace(hour=23, minute=59, second=59, microsecond=0) if event.settings.get('payment_term_weekdays'): if exp_by_date.weekday() == 5: exp_by_date += timedelta(days=2) elif exp_by_date.weekday() == 6: exp_by_date += timedelta(days=1) expires = exp_by_date if event.settings.get('payment_term_last'): last_date = make_aware(datetime.combine( event.settings.get('payment_term_last', as_type=date), time(hour=23, minute=59, second=59) ), tz) if last_date < expires: expires = last_date order = Order.objects.create( status=Order.STATUS_PENDING, event=event, email=email, datetime=now_dt, expires=expires, locale=locale, total=total, payment_fee=payment_fee, payment_provider=payment_provider.identifier, meta_info=json.dumps(meta_info or {}), ) OrderPosition.transform_cart_positions(positions, order) if address is not None: try: addr = InvoiceAddress.objects.get( pk=address ) if addr.order is not None: addr.pk = None addr.order = order addr.save() except InvoiceAddress.DoesNotExist: pass order.log_action('pretix.event.order.placed') order_placed.send(event, order=order) return order
def _get_fees(positions: List[CartPosition], payment_provider: BasePaymentProvider, address: InvoiceAddress, meta_info: dict, event: Event): fees = [] total = sum([c.price for c in positions]) payment_fee = payment_provider.calculate_fee(total) if payment_fee: fees.append(OrderFee(fee_type=OrderFee.FEE_TYPE_PAYMENT, value=payment_fee, internal_type=payment_provider.identifier)) for recv, resp in order_fee_calculation.send(sender=event, invoice_address=address, meta_info=meta_info, posiitons=positions): fees += resp return fees
def _create_order(event: Event, email: str, positions: List[CartPosition], now_dt: datetime, payment_provider: BasePaymentProvider, locale: str = None, address: int = None): total = sum([c.price for c in positions]) payment_fee = payment_provider.calculate_fee(total) total += payment_fee exp_by_date = now_dt + timedelta( days=event.settings.get('payment_term_days', as_type=int)) if event.settings.get('payment_term_weekdays'): if exp_by_date.weekday() == 5: exp_by_date += timedelta(days=2) elif exp_by_date.weekday() == 6: exp_by_date += timedelta(days=1) expires = [exp_by_date] if event.settings.get('payment_term_last'): expires.append( event.settings.get('payment_term_last', as_type=datetime)) order = Order.objects.create(status=Order.STATUS_PENDING, event=event, email=email, datetime=now_dt, expires=min(expires), locale=locale, total=total, payment_fee=payment_fee, payment_provider=payment_provider.identifier) OrderPosition.transform_cart_positions(positions, order) if address is not None: try: addr = InvoiceAddress.objects.get(pk=address) if addr.order is not None: addr.pk = None addr.order = order addr.save() except InvoiceAddress.DoesNotExist: pass order.log_action('pretix.event.order.placed') order_placed.send(event, order=order) return order
def _create_order(event: Event, email: str, positions: List[CartPosition], now_dt: datetime, payment_provider: BasePaymentProvider, locale: str=None, address: int=None): total = sum([c.price for c in positions]) payment_fee = payment_provider.calculate_fee(total) total += payment_fee exp_by_date = now_dt + timedelta(days=event.settings.get('payment_term_days', as_type=int)) if event.settings.get('payment_term_weekdays'): if exp_by_date.weekday() == 5: exp_by_date += timedelta(days=2) elif exp_by_date.weekday() == 6: exp_by_date += timedelta(days=1) expires = [exp_by_date] if event.settings.get('payment_term_last'): expires.append(event.settings.get('payment_term_last', as_type=datetime)) order = Order.objects.create( status=Order.STATUS_PENDING, event=event, email=email, datetime=now_dt, expires=min(expires), locale=locale, total=total, payment_fee=payment_fee, payment_provider=payment_provider.identifier ) OrderPosition.transform_cart_positions(positions, order) if address is not None: try: addr = InvoiceAddress.objects.get( pk=address ) if addr.order is not None: addr.pk = None addr.order = order addr.save() except InvoiceAddress.DoesNotExist: pass order.log_action('pretix.event.order.placed') order_placed.send(event, order=order) return order
def _create_order(event: Event, email: str, positions: list, dt: datetime, payment_provider: BasePaymentProvider, locale: str=None): total = sum([c.price for c in positions]) payment_fee = payment_provider.calculate_fee(total) total += payment_fee expires = [dt + timedelta(days=event.settings.get('payment_term_days', as_type=int))] if event.settings.get('payment_term_last'): expires.append(event.settings.get('payment_term_last', as_type=datetime)) order = Order.objects.create( status=Order.STATUS_PENDING, event=event, email=email, datetime=dt, expires=min(expires), locale=locale, total=total, payment_fee=payment_fee, payment_provider=payment_provider.identifier ) OrderPosition.transform_cart_positions(positions, order) order_placed.send(event, order=order) return order
def _create_order(event: Event, email: str, positions: List[CartPosition], now_dt: datetime, payment_provider: BasePaymentProvider, locale: str=None, address: int=None, meta_info: dict=None): from datetime import time total = sum([c.price for c in positions]) payment_fee = payment_provider.calculate_fee(total) total += payment_fee tz = pytz.timezone(event.settings.timezone) exp_by_date = now_dt.astimezone(tz) + timedelta(days=event.settings.get('payment_term_days', as_type=int)) exp_by_date = exp_by_date.astimezone(tz).replace(hour=23, minute=59, second=59, microsecond=0) if event.settings.get('payment_term_weekdays'): if exp_by_date.weekday() == 5: exp_by_date += timedelta(days=2) elif exp_by_date.weekday() == 6: exp_by_date += timedelta(days=1) expires = exp_by_date term_last = event.settings.get('payment_term_last', as_type=RelativeDateWrapper) if term_last: if event.has_subevents: term_last = min([ term_last.datetime(se).date() for se in event.subevents.filter(id__in=[p.subevent_id for p in positions]) ]) else: term_last = term_last.datetime(event).date() term_last = make_aware(datetime.combine( term_last, time(hour=23, minute=59, second=59) ), tz) if term_last < expires: expires = term_last with transaction.atomic(): order = Order.objects.create( status=Order.STATUS_PENDING, event=event, email=email, datetime=now_dt, expires=expires, locale=locale, total=total, payment_fee=payment_fee, payment_provider=payment_provider.identifier, meta_info=json.dumps(meta_info or {}), ) if address: if address.order is not None: address.pk = None address.order = order address.save() order._calculate_tax() # Might have changed due to new invoice address order.save() OrderPosition.transform_cart_positions(positions, order) order.log_action('pretix.event.order.placed') order_placed.send(event, order=order) return order