def pay_ship_info(request): template = 'satchmo_stripe/pay_ship.html' payment_module = stripe_config form_handler = stripe_pay_ship_process_form result = payship.pay_ship_info_verify(request, payment_module) if not result[0]: return result[1] contact = result[1] working_cart = result[2] success, form = form_handler(request, contact, working_cart, payment_module) if success: return form template = lookup_template(payment_module, template) live = gateway_live(payment_module) last4='' cc_type='' user = threadlocals.get_current_user() if user and user.is_authenticated: stripe_id = utils.check_stripe_customer(threadlocals.get_current_user()) if stripe_id: customer = utils.get_customer(stripe_id) if customer: last4 = customer.active_card.last4 cc_type = customer.active_card.type if utils.card_is_about_to_expire(customer.active_card): #Raise message telling user that the card is about to expire message = "The %s card ending in %s will expire in less than %d days, please enter a new card" % (cc_type,last4,payment_module.MIN_DAYS.value) messages.add_message(request, messages.WARNING, message) cc_type = '' last4='' ctx = RequestContext(request, { 'form': form, 'PAYMENT_LIVE': live, 'saved_card' : last4, 'cc_type' : cc_type, 'show_save_option' : payment_module.CAPTURE.value, }) return render_to_response(template, context_instance=ctx)
def tiered_price_listener(signal, adjustment=None, **kwargs): """Listens for satchmo_price_query signals, and returns a tiered price instead of the default price. Requires threaded_multihost.ThreadLocalMiddleware to be installed so that it can determine the current user.""" if kwargs.has_key('discountable'): discountable = kwargs['discountable'] else: discountable = adjustment.product.is_discountable if discountable: product = adjustment.product user = threadlocals.get_current_user() if user and not user.is_anonymous(): try: tiers = PricingTier.objects.by_user(user) log.debug('got tiers: %s', tiers) best = None besttier = None currentprice = adjustment.final_price() qty = adjustment.price.quantity for tier in tiers: candidate = None try: tp = TieredPrice.objects.by_product_qty( tier, product, qty) log.debug("Found a Tiered Price for %s qty %d = %s", product.slug, qty, tp.price) candidate = tp.price except TieredPrice.DoesNotExist: pcnt = tier.discount_percent if pcnt is not None and pcnt != 0: candidate = currentprice * (100 - pcnt) / 100 if best is None or (candidate and candidate < best): best = candidate besttier = tier log.debug('best = %s', best) if best is not None: delta = currentprice - best adjustment += PriceAdjustment( 'tieredpricing', _('Tiered Pricing for %(tier)s' % {'tier': besttier.group.name}), delta) except PricingTier.DoesNotExist: pass
def add_toolbar_context(sender, context={}, **kwargs): user = threadlocals.get_current_user() if user and user.is_staff: request_path = context['request'].META['PATH_INFO'] slug = request_path.split('/')[-2] total_sales = 0 show_sales = False variation_items = [] try: product = Product.objects.get(slug=slug) show_sales = True subtypes = product.get_subtypes() if 'ConfigurableProduct' in subtypes: variation_items, total_sales = _get_all_variations(product) else: total_sales = product.total_sold except: pass st = {} st['st_satchmo_version'] = get_version() newq = Order.objects.filter(status__exact='New') st['st_new_order_ct'] = newq.count() amounts = newq.values_list('total', flat=True) if amounts: newtotal = reduce(operator.add, filter(None, amounts), 0) else: newtotal = 0 st['st_new_order_total'] = newtotal st['st_total_sold'] = total_sales st['st_show_sales'] = show_sales st['st_variations'] = variation_items week = datetime.datetime.today() - datetime.timedelta(days=7) day = datetime.datetime.today() - datetime.timedelta(days=1) hours = datetime.datetime.today() - datetime.timedelta(hours=1) cartweekq = Cart.objects.filter(date_time_created__gte=week) cartdayq = Cart.objects.filter(date_time_created__gte=day) carthourq = Cart.objects.filter(date_time_created__gte=hours) st['st_cart_7d_ct'] = cartweekq.count() st['st_cart_1d_ct'] = cartdayq.count() st['st_cart_1h_ct'] = carthourq.count() st['st_contacts_ct'] = Contact.objects.all().count() st['st_contacts_7d_ct'] = Contact.objects.filter( create_date__gte=week).count() # edits = [] # st['st_edits'] = edits context.update(st)
def tiered_price_listener(signal, adjustment=None, **kwargs): """Listens for satchmo_price_query signals, and returns a tiered price instead of the default price. Requires threaded_multihost.ThreadLocalMiddleware to be installed so that it can determine the current user.""" if kwargs.has_key('discountable'): discountable = kwargs['discountable'] else: discountable = adjustment.product.is_discountable if discountable: product = adjustment.product user = threadlocals.get_current_user() if user and not user.is_anonymous(): try: tiers = PricingTier.objects.by_user(user) log.debug('got tiers: %s', tiers) best = None besttier = None currentprice = adjustment.final_price() qty = adjustment.price.quantity for tier in tiers: candidate = None try: tp = TieredPrice.objects.by_product_qty(tier, product, qty) log.debug("Found a Tiered Price for %s qty %d = %s", product.slug, qty, tp.price) candidate = tp.price except TieredPrice.DoesNotExist: pcnt = tier.discount_percent if pcnt is not None and pcnt != 0: candidate = currentprice * (100-pcnt)/100 if best is None or (candidate and candidate < best): best = candidate besttier = tier log.debug('best = %s', best) if best is not None: delta = currentprice - best adjustment += PriceAdjustment( 'tieredpricing', _('Tiered Pricing for %(tier)s' % { 'tier': besttier.group.name}), delta) except PricingTier.DoesNotExist: pass
def add_toolbar_context(sender, context={}, **kwargs): user = threadlocals.get_current_user() if user and user.is_staff: request_path = context["request"].META["PATH_INFO"] slug = request_path.split("/")[-2] total_sales = 0 show_sales = False variation_items = [] try: product = Product.objects.get(slug=slug) show_sales = True subtypes = product.get_subtypes() if "ConfigurableProduct" in subtypes: variation_items, total_sales = _get_all_variations(product) else: total_sales = product.total_sold except: pass st = {} st["st_satchmo_version"] = get_version() newq = Order.objects.filter(status__exact="New") st["st_new_order_ct"] = newq.count() amounts = newq.values_list("total", flat=True) if amounts: newtotal = reduce(operator.add, filter(None, amounts), 0) else: newtotal = 0 st["st_new_order_total"] = newtotal st["st_total_sold"] = total_sales st["st_show_sales"] = show_sales st["st_variations"] = variation_items week = datetime.datetime.today() - datetime.timedelta(days=7) day = datetime.datetime.today() - datetime.timedelta(days=1) hours = datetime.datetime.today() - datetime.timedelta(hours=1) cartweekq = Cart.objects.filter(date_time_created__gte=week) cartdayq = Cart.objects.filter(date_time_created__gte=day) carthourq = Cart.objects.filter(date_time_created__gte=hours) st["st_cart_7d_ct"] = cartweekq.count() st["st_cart_1d_ct"] = cartdayq.count() st["st_cart_1h_ct"] = carthourq.count() st["st_contacts_ct"] = Contact.objects.all().count() st["st_contacts_7d_ct"] = Contact.objects.filter(create_date__gte=week).count() # edits = [] # st['st_edits'] = edits context.update(st)
def _get_taxprocessor(request=None): taxprocessor = get_thread_variable("taxer", None) if not taxprocessor: if request: user = request.user if user.is_authenticated(): user = user else: user = None else: user = get_current_user() taxprocessor = get_tax_processor(user=user) set_thread_variable("taxer", taxprocessor) return taxprocessor
def _get_taxprocessor(request=None): taxprocessor = get_thread_variable('taxer', None) if not taxprocessor: if request: user = request.user if user.is_authenticated(): user = user else: user = None else: user = get_current_user() taxprocessor = get_tax_processor(user=user) set_thread_variable('taxer', taxprocessor) return taxprocessor
def _get_taxprocessor(request=None): if request: user = request.user if user.is_authenticated: user_id = user.id else: user = None user_id = "None" else: user = get_current_user() user_id = user and user.id thread_key = "taxer-%s" % user_id taxprocessor = get_thread_variable(thread_key, None) if not taxprocessor: taxprocessor = get_tax_processor(user=user) set_thread_variable(thread_key, taxprocessor) return taxprocessor
def _get_taxprocessor(request=None): if request: user = request.user if user.is_authenticated(): user_id = user.id else: user = None user_id = "None" else: user = get_current_user() user_id = user and user.id thread_key = "taxer-%s" % user_id taxprocessor = get_thread_variable(thread_key, None) if not taxprocessor: taxprocessor = get_tax_processor(user=user) set_thread_variable(thread_key, taxprocessor) return taxprocessor
def stripe_pay_ship_process_form(request, contact, working_cart, payment_module, allow_skip=True, *args, **kwargs): def _get_form(request, payment_module, *args, **kwargs): return StripePayShipForm(request, payment_module, *args, **kwargs) if request.method == "POST": new_data = request.POST.copy() #if using saved card, fill in the stripe token field with the customer_id if not new_data['stripe_token'] and new_data['use_saved_cc']: new_data['stripe_token'] = utils.check_stripe_customer(threadlocals.get_current_user()) form = _get_form(request, payment_module, new_data, *args, **kwargs) if form.is_valid(): data = form.cleaned_data form.save(request, working_cart, contact, payment_module, data=data) url = lookup_url(payment_module, 'satchmo_checkout-step3') return (True, http.HttpResponseRedirect(url)) else: log.info('Form didn\'t pass!!!!') for error in form.errors: log.info(error) pass else: order_data = {} try: order = Order.objects.from_request(request) if order.shipping_model: order_data['shipping'] = order.shipping_model kwargs['initial'] = order_data ordershippable = order.is_shippable except Order.DoesNotExist: pass form = _get_form(request, payment_module, *args, **kwargs) if not form.is_needed(): form.save(request, working_cart, contact, None, data={'shipping': form.shipping_dict.keys()[0]}) url = lookup_url(payment_module, 'satchmo_checkout-step3') return (True, http.HttpResponseRedirect(url)) return (False, form)
def setUp(self): self.original_user = get_current_user() self.user = User.objects.create(username='******') set_current_user(self.user) self.test_instance = TestCustomRelatedName.objects.create(name='foo')
def setUp(self): self.original_user = get_current_user() self.user = User.objects.create(username='******') set_current_user(self.user) self.test_instance = TestDefaultAuditedModel.objects.create(name='foo')