Example #1
0
    def get(self, request, *args, **kwargs):
        cart = RequestContext(request).get('Cart')
        price = RequestContext(request).get('CartPrice')
        product_list = RequestContext(request).get('CartProducts')
        iva = Iva.objects.filter(is_active=True).get()
        transfer_data = ProjectSettings.objects.values('company', 'invoice_address', 'invoice_cp', 'invoice_town', 'invoice_country', 'bank_account', 'bank_iban').get()

        # Creates a PreOrder

        pre_order = PreOrder.objects.create(cart=cart, user=request.user, price=price, iva=Decimal(str(iva)), payed=False, deleted=False)

        # Mark the cart as checked out

        cart.checked_out = True
        cart.save()

        # Send a confirmation email with the transfer data

        subject = _("Dades d'INOXtags per tramitar comanda.")
        email = request.user.email
        html_content = render_to_string('email/bank_transfer.html', {'pre_order':pre_order, 'products':product_list, 'transfer_data':transfer_data})
        text_content = strip_tags(html_content)

        msg = EmailMultiAlternatives(subject, text_content, to=[email])
        msg.attach_alternative(html_content, "text/html")
        msg.send()

        return super(BankTransferView, self).get(request, *args, **kwargs)
Example #2
0
    def get(self, request, *args, **kwargs):
        cart = RequestContext(request).get('Cart')
        price = RequestContext(request).get('CartPrice')
        product_list = RequestContext(request).get('CartProducts')
        iva = Iva.objects.filter(is_active=True).get()
        user = request.user
        count_total = cart.get_count_total()
        management = False
        if user.is_professional:
            if not user.hand_delivery:
                management = True

        # Creates the Order
        order = Order.objects.create(
            cart=cart,
            user=user,
            to=user.name,
            address=user.shipping_address,
            postal_code=user.shipping_code,
            town=user.shipping_town,
            country=user.shipping_country.country,
            count=count_total,
            price=price,
            iva=Decimal(str(iva)),
            payed=False,
            hand_delivery=user.hand_delivery,
            management = management,
        )

        # Creates the order items
        for item in product_list:
            if user.is_professional:
                if user.hand_delivery:
                    price = item.price_in_hand
                else:
                    price = item.price_prof
            else:
                price = item.price_normal
            OrderItem.objects.create(
                order=order,
                quantity=item.quantity,
                product=item.product,
                color=item.color,
                front_main=item.front_main,
                front_tel=item.front_tel,
                back_1=item.back_1,
                back_2=item.back_2,
                back_3=item.back_3,
                price=price,
                made=item.made,
                repetition=item.repetition
            )

        # Mark the cart as checked out

        cart.checked_out = True
        cart.save()

        # Send a confirmation email
        subject = _("Comanda gestionada correctament a la web d'INOXtags.")
        email = user.email
        html_content = render_to_string('email/conf_order.html', {'order': order, 'products': product_list})
        text_content = strip_tags(html_content)

        msg = EmailMultiAlternatives(subject, text_content, to=[email])
        msg.attach_alternative(html_content, "text/html")
        msg.send()

        return super(UnpayedCheckoutView, self).get(request, *args, **kwargs)
Example #3
0
    def get(self, request, *args, **kwargs):
        cart = RequestContext(request).get("Cart")
        price = RequestContext(request).get("CartPrice")
        product_list = RequestContext(request).get("CartProducts")
        query_string = (
            "http_status="
            + request.GET.get("http_status")
            + "&id="
            + request.GET.get("id", "")
            + "&kind="
            + request.GET.get("kind")
            + "&hash="
            + request.GET.get("hash")
        )
        raw_log = BraintreeRawLog.objects.create(user=request.user, queryset=query_string)
        result = braintree.TransparentRedirect.confirm(query_string)
        if result.is_success:
            self.status = None
            PaymentLog.objects.create(
                rawlog=raw_log, user=request.user, amount=price, transaction_id=result.transaction.id
            )
            iva = Iva.objects.filter(is_active=True).get()
            count_total = cart.get_count_total()

            # Creates the order

            order = Order.objects.create(
                cart=cart,
                user=request.user,
                to=request.user.name,
                address=request.user.shipping_address,
                postal_code=request.user.shipping_code,
                town=request.user.shipping_town,
                country=request.user.shipping_country.country,
                count=count_total,
                price=price,
                iva=Decimal(str(iva)),
                payed=True,
            )

            # Creates the order items

            for item in product_list:
                OrderItem.objects.create(
                    order=order,
                    quantity=item.quantity,
                    product=item.product,
                    color=item.color,
                    front_main=item.front_main,
                    front_tel=item.front_tel,
                    back_1=item.back_1,
                    back_2=item.back_2,
                    back_3=item.back_3,
                    price=item.price,
                    price_special_1=item.price_special_1,
                    price_special_2=item.price_special_2,
                    price_special_3=item.price_special_3,
                    price_special_4=item.price_special_4,
                    price_in_hand=item.price_in_hand,
                    made=item.made,
                    repetition=item.repetition,
                )

            # Send a confirmation email

            subject = _("Comanda gestionada correctament a la web d'INOXtags.")
            email = request.user.email
            html_content = render_to_string("email/conf_order.html", {"order": order, "products": product_list})
            text_content = strip_tags(html_content)

            msg = EmailMultiAlternatives(subject, text_content, to=[email])
            msg.attach_alternative(html_content, "text/html")
            msg.send()

            # Mark the cart as checked out

            cart.checked_out = True
            cart.save()

        else:
            self.status = result.message
            PaymentErrorLog.objects.create(
                rawlog=raw_log, user=request.user, amount=price, cart=cart, error=self.status
            )

        return super(PaymentResultView, self).get(request, *args, **kwargs)
Example #4
0
    def form_valid(self, form):
        # Get the CartPrice
        context_price = RequestContext(self.request).get('CartPrice')
        price_cents = int(context_price * 100)

        # Creates the description
        count_items = RequestContext(self.request).get('CountCartItems')
        cart = RequestContext(self.request).get('Cart')
        description = str(count_items) + ' items(' + str(context_price) + '€) from cart #' + str(cart)

        # Get the products in the current cart
        product_list = RequestContext(self.request).get('CartProducts')

        # Get the credit card details submitted by the form
        token = form.cleaned_data['stripeToken']

        # Create the charge on Stripe's servers - this will charge the user's
        # card
        try:
            charge = stripe.Charge.create(
                amount=price_cents,  # amount in cents, again
                currency="eur",
                card=token,
                description=description
            )

            # Once the charge is made, creates the order, the order items,
            # sends the confirmation email and marks the cart as checked out.
            iva = Iva.objects.filter(is_active=True).get()
            count_total = cart.get_count_total()
            user = self.request.user
            management = False
            if user.is_professional:
                if not user.hand_delivery:
                    management = True

            # Creates the order
            order = Order.objects.create(
                cart=cart,
                user=user,
                to=user.name,
                address=user.shipping_address,
                postal_code=user.shipping_code,
                town=user.shipping_town,
                country=user.shipping_country.country,
                count=count_total,
                price=context_price,
                iva=Decimal(str(iva)),
                payed=True,
                management=management,
            )

            # Creates the order items
            for item in product_list:
                if user.is_professional:
                    if user.hand_delivery:
                        price = item.price_in_hand
                    else:
                        price = item.price_prof
                else:
                    price = item.price_normal
                OrderItem.objects.create(
                    order=order,
                    quantity=item.quantity,
                    product=item.product,
                    color=item.color,
                    front_main=item.front_main,
                    front_tel=item.front_tel,
                    back_1=item.back_1,
                    back_2=item.back_2,
                    back_3=item.back_3,
                    price=price,
                    made=item.made,
                    repetition=item.repetition
                )

            # Send a confirmation email
            subject = _("Comanda gestionada correctament a la web d'INOXtags.")
            email = user.email
            html_content = render_to_string('email/conf_order.html', {'order': order, 'products': product_list})
            text_content = strip_tags(html_content)

            msg = EmailMultiAlternatives(subject, text_content, to=[email])
            msg.attach_alternative(html_content, "text/html")
            msg.send()

            # Mark the cart as checked out
            cart.checked_out = True
            cart.save()

        except stripe.CardError:
              # The card has been declined
            pass

        return super(ChargeView, self).form_valid(form)
Example #5
0
    def form_valid(self, form):
        cart = RequestContext(self.request).get("Cart")
        product_list = RequestContext(self.request).get("CartProducts")

        iva = Iva.objects.filter(is_active=True).get()

        # Creates the order from the form data

        order = form.save(commit=False)
        order.cart = cart
        order.to = order.user.name
        order.address = order.user.shipping_address
        order.postal_code = order.user.shipping_code
        order.town = order.user.shipping_town
        order.country = order.user.shipping_country.name
        order.count = cart.get_count_total()
        order.price = cart.get_price(order.user)
        order.iva = Decimal(str(iva))
        order.payed = False
        order.hand_delivery = order.user.hand_delivery
        if order.user.is_professional:
            if not order.user.hand_delivery:
                order.management = True
        order.save()

        # Creates the order items from the customized products

        for product in product_list:
            if not product.repetition:
                if order.user.is_professional:
                    if order.user.hand_delivery:
                        price = product.price_in_hand
                    else:
                        price = product.price_prof
                else:
                    price = product.price_normal
            else:
                price = 0
            OrderItem.objects.create(
                order=order,
                quantity=product.quantity,
                product=product.product,
                color=product.color,
                front_main=product.front_main,
                front_tel=product.front_tel,
                back_1=product.back_1,
                back_2=product.back_2,
                back_3=product.back_3,
                price=price,
                made=product.made,
                repetition=product.repetition,
            )

        # Mark the cart as checked out

        cart.checked_out = True
        cart.save()

        # Send the confirmation email

        mail = order.user.email
        try:
            if order.user.lang == "ca":
                subject = _("Nova comanda a INOXtags.com")
                html_content = render_to_string(
                    "email/conf_order_ca.html", {"order": order, "product_list": product_list}
                )
            elif order.user.lang == "es":
                subject = _("Nuevo pedido en INOXtags.com")
                html_content = render_to_string(
                    "email/conf_order_es.html", {"order": order, "product_list": product_list}
                )
            else:
                subject = _("Your new order from INOXtags.com")
                html_content = render_to_string(
                    "email/conf_order_en.html", {"order": order, "product_list": product_list}
                )
        except:
            subject = _("Your new order from INOXtags.com")
            html_content = render_to_string("email/conf_order_en.html", {"order": order, "product_list": product_list})
        text_content = strip_tags(html_content)

        msg = EmailMultiAlternatives(subject, text_content, to=[mail])
        msg.attach_alternative(html_content, "text/html")
        msg.send()

        return HttpResponseRedirect(self.get_success_url())