def payment_instructions_email_notification(sender, **kwargs):
    """
    Sends an email with payment instructions to the customer once and order is
    placed.
    """
    subject_template_name = 'shop_simplenotifications/payment_instructions_subject.txt'
    body_template_name = 'shop_simplenotifications/payment_instructions_body.txt'
    
    request = kwargs.get('request')
    order = kwargs.get('order')
    
    emails = []
    if order.user and order.user.email: 
        emails.append(order.user.email)
    if request and get_billing_address_from_request(request):
        address = get_billing_address_from_request(request)
        if hasattr(address, 'email'):
            emails.append(address.email)
        emails.append(address.email)
    
    emails = list(set(emails)) # removes duplicated entries
    if emails:
        subject = loader.render_to_string(
            subject_template_name,
            RequestContext(request, {'order': order})
        )
        subject = subject.join(subject.splitlines())
        body = loader.render_to_string(
            body_template_name,
            RequestContext(request, {'order': order})
        )
        from_email = getattr(settings, 'SN_FROM_EMAIL', settings.DEFAULT_FROM_EMAIL)
        send_mail(subject, body, from_email, emails, fail_silently=False)
Пример #2
0
    def get_billing_address_form(self):
        """
        Initializes and handles the form for the shipping address.
        AddressModel is a model of the type defined in
        ``settings.SHOP_ADDRESS_MODEL``.
        """
        # Try to get the cached version first.
        form = getattr(self, '_billing_form', None)
        if not form:
            # Create a dynamic Form class for the model specified as the
            # address model
            form_class = model_forms.modelform_factory(
                AddressModel, exclude=['user_shipping', 'user_billing'])

            # Try to get a shipping address instance from the request (user or
            # session))
            billing_address = get_billing_address_from_request(self.request)
            if self.request.method == "POST":
                form = form_class(self.request.POST, prefix="bill",
                    instance=billing_address)
            else:
                # We should either have an instance, or None
                if not billing_address:
                    # The user or guest doesn't already have a favorite
                    # address. Instansiate a blank one, and use this as the
                    # default value for the form.
                    billing_address = AddressModel()

                #Instanciate the form
                form = form_class(instance=billing_address, prefix="bill")
            setattr(self, '_billing_form', form)
        return form
Пример #3
0
    def get_billing_address_form(self):
        """
        Initializes and handles the form for the shipping address.
        AddressModel is a model of the type defined in
        ``settings.SHOP_ADDRESS_MODEL``.
        """
        # Try to get the cached version first.
        form = getattr(self, '_billing_form', None)
        if not form:
            # Create a dynamic Form class for the model specified as the
            # address model
            form_class = self.get_billing_form_class()

            # Try to get a shipping address instance from the request (user or
            # session))
            billing_address = get_billing_address_from_request(self.request)
            if self.request.method == "POST":
                form = form_class(self.request.POST, prefix="bill",
                    instance=billing_address)
            else:
                # We should either have an instance, or None
                if not billing_address:
                    # The user or guest doesn't already have a favorite
                    # address. Instansiate a blank one, and use this as the
                    # default value for the form.
                    billing_address = AddressModel()

                #Instanciate the form
                form = form_class(instance=billing_address, prefix="bill")
            setattr(self, '_billing_form', form)
        return form
Пример #4
0
 def get_form_dict(self, request):
     """
     From the current order, create a dictionary to initialize a hidden form.
     """
     order = self.shop.get_order(request)
     billing_address = get_billing_address_from_request(request)
     email = ''
     if request.user and not isinstance(request.user, AnonymousUser):
         email = request.user.email
     url_scheme = 'https://%s%s' if request.is_secure() else 'http://%s%s'
     domain = get_return_domain(request)
     return {
         'PSPID': settings.VIVEUM_PAYMENT.get('PSPID'),
         'CURRENCY': settings.VIVEUM_PAYMENT.get('CURRENCY'),
         'LANGUAGE': settings.VIVEUM_PAYMENT.get('LANGUAGE'),
         'TITLE': settings.VIVEUM_PAYMENT.get('TITLE'),
         'ORDERID': order.id,
         'AMOUNT': int(self.shop.get_order_total(order) * 100),
         'CN': getattr(billing_address, 'name', ''),
         'COM': settings.VIVEUM_PAYMENT.get('ORDER_DESCRIPTION', '') % order.id,
         'EMAIL': email,
         'TP': url_scheme % (domain, reverse('viveum_template')),
         'OWNERZIP': getattr(billing_address, 'zip_code', ''),
         'OWNERADDRESS': getattr(billing_address, 'address', ''),
         'OWNERADDRESS2': getattr(billing_address, 'address2', ''),
         'OWNERTOWN': getattr(billing_address, 'city', ''),
         'OWNERCTY': getattr(billing_address, 'country', '').__str__(),
         'ACCEPTURL': url_scheme % (domain, reverse('viveum_accept')),
         'DECLINEURL': url_scheme % (domain, reverse('viveum_decline')),
     }
Пример #5
0
 def get_form_dict(self, request):
     """
     From the current order, create a dictionary to initialize a hidden form.
     """
     order = self.shop.get_order(request)
     billing_address = get_billing_address_from_request(request)
     email = ''
     if request.user and not isinstance(request.user, AnonymousUser):
         email = request.user.email
     url_scheme = 'https://%s%s' if request.is_secure() else 'http://%s%s'
     domain = get_return_domain(request)
     return {
         'PSPID': settings.VIVEUM_PAYMENT.get('PSPID'),
         'CURRENCY': settings.VIVEUM_PAYMENT.get('CURRENCY'),
         'LANGUAGE': settings.VIVEUM_PAYMENT.get('LANGUAGE'),
         'TITLE': settings.VIVEUM_PAYMENT.get('TITLE'),
         'ORDERID': order.id,
         'AMOUNT': int(self.shop.get_order_total(order) * 100),
         'CN': getattr(billing_address, 'name', ''),
         'COM':
         settings.VIVEUM_PAYMENT.get('ORDER_DESCRIPTION', '') % order.id,
         'EMAIL': email,
         'TP': url_scheme % (domain, reverse('viveum_template')),
         'OWNERZIP': getattr(billing_address, 'zip_code', ''),
         'OWNERADDRESS': getattr(billing_address, 'address', ''),
         'OWNERADDRESS2': getattr(billing_address, 'address2', ''),
         'OWNERTOWN': getattr(billing_address, 'city', ''),
         'OWNERCTY': getattr(billing_address, 'country', '').__str__(),
         'ACCEPTURL': url_scheme % (domain, reverse('viveum_accept')),
         'DECLINEURL': url_scheme % (domain, reverse('viveum_decline')),
     }
Пример #6
0
    def addresses_form(self):
        """Create an form which handles selecting the two addresses."""
        data = None
        if self.request.method == "POST":
            data = self.request.POST

        return AddressesForm(
            data,
            billing=get_billing_address_from_request(self.request),
            shipping=get_shipping_address_from_request(self.request),
            billing_form_class=self.get_billing_form_class(),
            shipping_form_class=self.get_shipping_form_class(),
        )
def payment_instructions_email_notification(sender, **kwargs):
    """
    Sends an email with payment instructions to the customer once and order is
    placed.
    """
    subject_template_name = "shop_simplenotifications/payment_instructions_subject.txt"
    body_text_template_name = "shop_simplenotifications/payment_instructions_body.txt"
    body_html_template_name = "shop_simplenotifications/payment_instructions_body.html"

    request = kwargs.get("request")
    order = kwargs.get("order")

    emails = []
    if order.user and order.user.email:
        emails.append(order.user.email)
    if request and get_billing_address_from_request(request):
        address = get_billing_address_from_request(request)
        if hasattr(address, "email"):
            emails.append(address.email)
    emails = list(set(emails))  # removes duplicated entries
    if emails:
        subject = loader.render_to_string(subject_template_name, RequestContext(request, {"order": order}))
        subject = subject.join(subject.splitlines())

        text_content = loader.render_to_string(body_text_template_name, RequestContext(request, {"order": order}))

        try:
            html_content = loader.render_to_string(body_html_template_name, RequestContext(request, {"order": order}))
        except TemplateDoesNotExist:
            html_content = None

        from_email = getattr(settings, "SN_FROM_EMAIL", settings.DEFAULT_FROM_EMAIL)

        message = EmailMultiAlternatives(subject, text_content, from_email, emails)
        if html_content:
            message.attach_alternative(html_content, "text/html")
        message.send()
Пример #8
0
 def test_get_billing_address_from_request_with_preset_and_session(self):
     assign_address_to_request(self.request, self.address, shipping=False)
     res = get_billing_address_from_request(self.request)
     self.assertEqual(res, self.address)
Пример #9
0
 def test_get_billing_address_from_request_with_preset_and_user(self):
     setattr(self.request, 'user', self.user)
     assign_address_to_request(self.request, self.address, shipping=False)
     res = get_billing_address_from_request(self.request)
     self.assertEqual(res, self.address)
Пример #10
0
 def test_get_billing_address_from_request_no_preset(self):
     # Set the user
     setattr(self.request, 'user', self.user)
     res = get_billing_address_from_request(self.request)
     self.assertEqual(res, None)
Пример #11
0
 def test_get_billing_address_from_request_with_preset_and_session(self):
     assign_address_to_request(self.request, self.address, shipping=False)
     res = get_billing_address_from_request(self.request)
     self.assertEqual(res, self.address)
Пример #12
0
 def test_get_billing_address_from_request_with_preset_and_user(self):
     setattr(self.request, 'user', self.user)
     assign_address_to_request(self.request, self.address, shipping=False)
     res = get_billing_address_from_request(self.request)
     self.assertEqual(res, self.address)
Пример #13
0
 def test_get_billing_address_from_request_no_preset(self):
     # Set the user
     setattr(self.request, 'user', self.user)
     res = get_billing_address_from_request(self.request)
     self.assertEqual(res, None)