Esempio n. 1
0
    def addOrder(self, customer=None, cart=None):
        """
        """
        cartmanager = ICartManagement(self.context)
        if customer is None:
            cm = ICustomerManagement(self.context)
            customer = cm.getAuthenticatedCustomer()

        if cart is None:
            cart = cartmanager.getCart()

        portal = getToolByName(self.context, 'portal_url').getPortalObject()

        ## The current user may not be allowed to create an order, so we
        ## temporarily change the security context to use a temporary
        ## user with manager role.
        old_sm = getSecurityManager()
        tmp_user = UnrestrictedUser(old_sm.getUser().getId(), '', ['Manager'],
                                    '')

        tmp_user = tmp_user.__of__(portal.acl_users)
        newSecurityManager(None, tmp_user)

        # Add a new order
        new_id = self._createOrderId()
        self.orders.invokeFactory("Order", id=new_id)
        new_order = getattr(self.orders, new_id)

        # Copy Customer to Order
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        cm = ICopyManagement(customer)
        cm.copyTo(new_order)

        # Add cart items to order
        IItemManagement(new_order).addItemsFromCart(cart)

        # Add total tax
        new_order.setTax(ITaxes(cart).getTaxForCustomer())

        # Add shipping values to order
        sm = IShippingPriceManagement(self.context)
        new_order.setShippingPriceNet(sm.getPriceNet())
        new_order.setShippingPriceGross(sm.getPriceForCustomer())
        new_order.setShippingTax(sm.getTaxForCustomer())
        new_order.setShippingTaxRate(sm.getTaxRateForCustomer())

        # Add payment price values to order
        pp = IPaymentPriceManagement(self.context)
        new_order.setPaymentPriceGross(pp.getPriceForCustomer())
        new_order.setPaymentPriceNet(pp.getPriceNet())
        new_order.setPaymentTax(pp.getTaxForCustomer())
        new_order.setPaymentTaxRate(pp.getTaxRateForCustomer())

        ## Reset security manager
        setSecurityManager(old_sm)

        # Index with customer again
        new_order.reindexObject()

        return new_order
Esempio n. 2
0
    def getMyAccountURL(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        customer = ICustomerManagement(shop).getAuthenticatedCustomer()

        return customer.absolute_url() + "/" + "my-account"
Esempio n. 3
0
    def _calcTaxRateForCustomer(self):
        """Calculates the special tax for a given product and customer.
        """

        # If the customer has a VAT registration and the shop has a VAT
        # registration, and his country ID is different to the shop's
        # country ID, then don't apply customer taxes (default taxes
        # still apply)
        customer = ICustomerManagement(
            self.shop).getAuthenticatedCustomer(createIfNotExist=False)
        if customer is not None:
            vatreg = customer.getVATRegistration()
        else:
            vatreg = None
        if not self.shop.__dict__.has_key(
                'VATCountry'
        ) or self.shop.VATCountry == "None" or not vatreg or vatreg[:
                                                                    2] == self.shop.VATCountry:

            # 1. Try to find a Tax for actual Customer
            tm = ITaxManagement(self.shop)
            for tax in tm.getCustomerTaxes():
                if IValidity(tax).isValid(self.context) == True:
                    return tax.getRate()

        # 2. If nothing is found, returns the default tax for the product.
        return self._calcTaxRateForProduct()
Esempio n. 4
0
    def addAddress(self, form):
        """
        """
        shop = IShopManagement(self.context).getShop()
        customer = ICustomerManagement(shop).getAuthenticatedCustomer()

        id = self.context.generateUniqueId("Address")

        customer.invokeFactory("Address", id=id, title=form.get("address1"))
        address = getattr(customer, id)

        # set data
        address.setFirstname(form.get("firstname", ""))
        address.setLastname(form.get("lastname", ""))
        address.setLastname(form.get("companyName", ""))
        address.setAddress1(form.get("address1", ""))
        address.setAddress2(form.get("address2", ""))
        address.setZipCode(form.get("zipCode", ""))
        address.setCity(form.get("city", ""))
        address.setCountry(form.get("country", ""))
        address.setPhone(form.get("phone", ""))

        # Refresh addresses
        kss_core = self.getCommandSet("core")
        kss_zope = self.getCommandSet("zope")

        selector = kss_core.getHtmlIdSelector("manage-address-book")
        kss_zope.refreshViewlet(selector,
                                manager="easyshop.manager.addresses",
                                name="easyshop.addresses")
Esempio n. 5
0
    def getSelectablePaymentMethods(self):
        """Returns selectable payment methods.
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        pm = IPaymentInformationManagement(customer)

        selected_payment_method = \
            pm.getSelectedPaymentMethod(check_validity=True)

        result = []
        pm = IPaymentMethodManagement(self.context)
        for payment in pm.getSelectablePaymentMethods(check_validity=True):

            # Todo: Make default payment method editable. ATM it is prepayment.
            # So if nothing is selected checked is true for prepayment.

            # If id is bank_account_new (this happens when customer wants to
            # add a new direct debit and is due to validation errors redirected to
            # the form).

            checked = False
            if (self.request.get("form.id", "") not in ("bank_account_new", "credit_card_new")) and \
               (selected_payment_method.getId() == safe_unicode(payment.getId())):
                checked = True

            result.append({
                "id": payment.getId(),
                "title": payment.Title(),
                "description": payment.Description(),
                "checked": checked,
            })

        return result
Esempio n. 6
0
    def testPaymentMethod(self):
        """
        """
        self.shop.manage_addProduct["easyshop.core"].addPaymentMethodCriteria(
            "c")
        v = IValidity(self.shop.c)

        self.login("newmember")

        cm = ICustomerManagement(self.shop)
        customer = cm.getAuthenticatedCustomer()

        customer.selected_payment_method = u"cash-on-delivery"
        self.assertEqual(v.isValid(), False)

        customer.selected_payment_method = u"prepayment"
        self.assertEqual(v.isValid(), False)

        self.shop.c.setPaymentMethods(["direct-debit"])
        self.assertEqual(v.isValid(), False)

        self.shop.c.setPaymentMethods(["prepayment"])
        self.assertEqual(v.isValid(), True)

        self.shop.c.setPaymentMethods(["prepayment", "direct-debit"])
        self.assertEqual(v.isValid(), True)
Esempio n. 7
0
    def getCreditCards(self):
        """
        """
        if self._isValid("credit-card") == False:
            return []

        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()

        result = []
        pm = IPaymentInformationManagement(customer)
        for credit_card in pm.getPaymentInformations(interface=ICreditCard,
                                                     check_validity=True):

            selected_payment_information = \
                pm.getSelectedPaymentInformation(check_validity=True)

            if selected_payment_information and \
               selected_payment_information.getId() == credit_card.getId():
                checked = True
            else:
                checked = False

            exp_date = "%s/%s" % (credit_card.card_expiration_date_month,
                                  credit_card.card_expiration_date_year)
            result.append({
                "id": credit_card.getId(),
                "type": credit_card.card_type,
                "owner": credit_card.card_owner,
                "number": credit_card.card_number,
                "expiration_date": exp_date,
                "checked": checked,
            })

        return result
Esempio n. 8
0
    def getBankAccounts(self):
        """
        """
        if self._isValid("direct-debit") == False:
            return []

        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()

        result = []
        pm = IPaymentInformationManagement(customer)

        for bank_account in pm.getPaymentInformations(interface=IBankAccount,
                                                      check_validity=True):

            selected_payment_information = \
                pm.getSelectedPaymentInformation(check_validity=True)

            if selected_payment_information and \
               selected_payment_information.getId() == bank_account.getId():
                checked = True
            else:
                checked = False

            result.append({
                "id": bank_account.getId(),
                "bic": bank_account.bank_identification_code,
                "account_no": bank_account.account_number,
                "depositor": bank_account.depositor,
                "bank_name": bank_account.bank_name,
                "checked": checked,
            })

        return result
Esempio n. 9
0
    def getShippingAddresses(self):
        """Returns all addresses with the currently selected invoice address
        checked.
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        am = IAddressManagement(customer)

        found_selected_address = False
        result = []
        line = []

        for index, address in enumerate(am.getAddresses()):

            checked = False
            if safe_unicode(
                    address.getId()) == customer.selected_shipping_address:
                checked = "checked"
                found_selected_address = True

            address_as_dict = self._getAddressAsDict(address)
            address_as_dict["checked"] = checked

            line.append(address_as_dict)

            if (index + 1) % 3 == 0:
                result.append(line)
                line = []

        result.append(line)

        if len(result) > 0 and found_selected_address == False:
            result[0][0]["checked"] = True

        return result
Esempio n. 10
0
    def isCustomerComplete(self):
        """
        """
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()

        return ICompleteness(customer).isComplete()
Esempio n. 11
0
    def getShippingMethods(self):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        selected_shipping_id = customer.selected_shipping_method

        sm = IShippingMethodManagement(self.context)

        shipping_methods = []
        for shipping in sm.getShippingMethods(check_validity=True):

            if selected_shipping_id == safe_unicode(shipping.getId()):
                checked = True
            elif selected_shipping_id == u"" and shipping.getId() == "default":
                checked = True
            else:
                checked = False

            shipping_methods.append({
                "id": shipping.getId(),
                "title": shipping.Title,
                "description": shipping.Description,
                "checked": checked,
            })

        return shipping_methods
Esempio n. 12
0
    def getAddressInfo(self):
        """
        """
        id = self.request.get("id")
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()
        
        am = IAddressManagement(customer)
        address = am.getAddress(id)
        
        result = {}
        result["id"] = id
         
        if self.request.get("firstname", "") != "":
            result["firstname"] = self.request.get("firstname")
        else:
            result["firstname"] = address.getFirstname()

        if self.request.get("lastname", "") != "":
            result["lastname"] = self.request.get("lastname")
        else:
            result["lastname"] = address.getLastname()

        if self.request.get("companyname", "") != "":
            result["companyname"] = self.request.get("companyname")
        else:
            result["companyname"] = address.getCompanyName()

        if self.request.get("address1", "") != "":
            result["address1"] = self.request.get("address1")
        else:
            result["address1"] = address.getAddress1()

        if self.request.get("address2", "") != "":
            result["address2"] = self.request.get("address2")
        else:
            result["address2"] = address.getAddress2()

        if self.request.get("zipcode", "") != "":
            result["zipcode"] = self.request.get("zipcode")
        else:
            result["zipcode"] = address.getZipCode()

        if self.request.get("city", "") != "":
            result["city"] = self.request.get("city")
        else:
            result["city"] = address.getCity()

        if self.request.get("country", "") != "":
            result["country"] = self.request.get("country")
        else:
            result["country"] = address.getCountry()

        if self.request.get("phone", "") != "":
            result["phone"] = self.request.get("phone")
        else:
            result["phone"] = address.getPhone()
            
        return result
Esempio n. 13
0
    def getSelectedShippingMethod(self):
        """
        """
        cm = ICustomerManagement(IShopManagement(self.context).getShop())
        customer = cm.getAuthenticatedCustomer()
        shipping_method_id = customer.selected_shipping_method

        return self.getShippingMethod(shipping_method_id)
Esempio n. 14
0
    def handle_next_action(self, action, data):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        customer.selected_shipping_method = data.get("shipping_method", "")

        ICheckoutManagement(
            self.context).redirectToNextURL("SELECTED_SHIPPING_METHOD")
Esempio n. 15
0
    def handle_next_action(self, action, data):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        id = self.request.get("form.id")

        # figure out payment method type
        if id.startswith("bank_account"):
            payment_method = "direct-debit"
        elif id.startswith("credit_card"):
            payment_method = "credit-card"
        else:
            payment_method = id

        if id == "bank_account_new":
            depositor = self.request.get("form.depositor", u"")
            account_number = self.request.get("form.account_number", u"")
            bank_identification_code = self.request.get(
                "form.bank_identification_code", u"")
            bank_name = self.request.get("form.bank_name", u"")

            id = self.context.generateUniqueId("BankAccount")
            bank_account = BankAccount(id)
            bank_account.account_number = account_number
            bank_account.bank_identification_code = bank_identification_code
            bank_account.bank_name = bank_name
            bank_account.depositor = depositor

            customer._setObject(id, bank_account)

        if id == "credit_card_new":
            card_type = self.request.get("form.card_type", u"")
            card_number = self.request.get("form.card_number", u"")
            card_owner = self.request.get("form.card_owner", u"")
            card_expiration_date_month = self.request.get(
                "form.card_expiration_date_month", u"")
            card_expiration_date_year = self.request.get(
                "form.card_expiration_date_year", u"")

            id = self.context.generateUniqueId("CreditCard")
            credit_card = CreditCard(id)
            credit_card.card_type = card_type
            credit_card.card_number = card_number
            credit_card.card_owner = card_owner
            credit_card.card_expiration_date_month = card_expiration_date_month
            credit_card.card_expiration_date_year = card_expiration_date_year

            customer._setObject(id, credit_card)

        elif id.startswith("bank_account_existing") or \
             id.startswith("credit_card_existing"):
            id = id.split(":")[1]

        customer.selected_payment_method = payment_method
        customer.selected_payment_information = id

        ICheckoutManagement(
            self.context).redirectToNextURL("SELECTED_PAYMENT_METHOD")
Esempio n. 16
0
    def handle_next_action(self, action, data):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        customer.selected_invoice_address = data.get("invoice_address", "")
        customer.selected_shipping_address = data.get("shipping_address", "")

        ICheckoutManagement(
            self.context).redirectToNextURL("SELECTED_ADDRESSES")
Esempio n. 17
0
    def getShippingAddress(self):
        """
        """
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()

        am = IAddressManagement(customer)
        address = am.getShippingAddress()

        return addressToDict(address)
Esempio n. 18
0
    def getInvoiceAddress(self):
        """Returns invoice address of the current customer.
        """
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()

        am = IAddressManagement(customer)
        address = am.getInvoiceAddress()

        return addressToDict(address)
Esempio n. 19
0
    def getOrdersForAuthenticatedCustomer(self):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        orders = []
        for order in self.getOrders():
            if order.getCustomer().getId() == customer.getId():
                orders.append(order)

        return orders
Esempio n. 20
0
    def handle_add_address_action(self, action, data):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        customer_url = customer.absolute_url()
        template_url = self.context.absolute_url(
        ) + "/checkout-select-addresses"

        url = customer_url + "/add-address?goto=" + template_url
        self.request.response.redirect(url)
Esempio n. 21
0
 def isComplete(self):
     """
     """
     shop         = IShopManagement(self.context).getShop()
     customer     = ICustomerManagement(shop).getAuthenticatedCustomer()        
     pim          = IPaymentInformationManagement(customer)
     bank_account = pim.getSelectedPaymentInformation()
     
     if IBankAccount.providedBy(bank_account) == False or \
        ICompleteness(bank_account) == False:
         return False
     else:        
         return True
Esempio n. 22
0
    def isValid(self, product=None):
        """Returns True if the selected payment method of the current customer 
        is within the selected payment methods of the criterion.
        """
        shop = IShopManagement(self.context).getShop()

        customer = ICustomerManagement(shop).getAuthenticatedCustomer()
        customer_payment_method = customer.selected_payment_method

        if customer_payment_method in self.context.getPaymentMethods():
            return True
        else:
            return False
 def afterSetUp(self):
     """
     """
     super(TestDirectDebit, self).afterSetUp()
     
     self.login("newmember")
     cm = ICustomerManagement(self.shop)
     self.customer = cm.getAuthenticatedCustomer()
     
     self.customer.invokeFactory(
         "BankAccount",
         id = "bank-account",
         )
Esempio n. 24
0
    def getCountries(self):
        """Returns available countries.
        """
        result = []
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        shop = IShopManagement(self.context).getShop()
        for country in shop.getCountries():
            result.append({
                "title":
                country,
                "selected":
                safe_unicode(country) == customer.selected_country
            })

        return result
Esempio n. 25
0
    def _editedAddress(self):
        """
        """
        if self.context.REQUEST.get("also_invoice_address", "yes") == "yes":
            url = self.context.absolute_url() + "/checkout-shipping"
        else:
            customer = ICustomerManagement(
                self.context).getAuthenticatedCustomer()
            invoice_address = IAddressManagement(customer).getInvoiceAddress()
            if invoice_address is None:
                url = self.context.absolute_url(
                ) + "/checkout-add-address?address_type=invoice"
            else:
                url = invoice_address.absolute_url() + "/checkout-edit-address"

        return url
Esempio n. 26
0
    def getMailInfo(self):
        """
        """
        cm = ICustomerManagement(self.context)
        customer = cm.getAuthenticatedCustomer()
        am = IAddressManagement(customer)
        shipping_address = am.getShippingAddress()

        mtool = getToolByName(self.context, "portal_membership")        
        member = mtool.getAuthenticatedMember()
        
        name  = shipping_address.getFirstname() + " "
        name += shipping_address.getLastname()
                
        return {
            "email" : member.getProperty("email"),
            "name"  : name,
        }
Esempio n. 27
0
    def _gotoAddresses(self):
        """
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        shipping_address = IAddressManagement(customer).getShippingAddress()

        mtool = getToolByName(self.context, "portal_membership")
        if mtool.isAnonymousUser():
            if shipping_address is None:
                return self.context.absolute_url() + "/checkout-add-address"
            else:
                return shipping_address.absolute_url(
                ) + "/checkout-edit-address"
        else:
            if shipping_address is None:
                return self.context.absolute_url() + "/checkout-add-address"
            else:
                return self.context.absolute_url(
                ) + "/checkout-select-addresses"
Esempio n. 28
0
    def getPaymentMethodTypes(self):
        """Returns all *types* of payment methods of the current customer.
        """
        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        pm = IPaymentMethodManagement(self.context)

        result = []
        for payment_method in pm.getPaymentMethods(check_validity=True):

            id = payment_method.getId()
            selected = (id == customer.selected_payment_method)

            result.append({
                "id": payment_method.getId(),
                "title": payment_method.Title(),
                "selected": selected,
            })

        return result
Esempio n. 29
0
    def testCountry(self):
        """
        """
        self.shop.manage_addProduct["easyshop.core"].addCountryCriteria("c")
        self.shop.c.setCountries((u"USA", ))
        v = IValidity(self.shop.c)

        self.login("newmember")

        cm = ICustomerManagement(self.shop)
        customer = cm.getAuthenticatedCustomer()

        customer.invokeFactory("Address", "address_1")

        customer.address_1.country = u"USA"
        self.assertEqual(v.isValid(), True)

        customer.address_1.country = u"Germany"
        self.assertEqual(v.isValid(), False)
Esempio n. 30
0
    def process(self, order=None):
        """
        """
        shop        = IShopManagement(self.context).getShop()
        customer    = ICustomerManagement(shop).getAuthenticatedCustomer()
        credit_card = IPaymentInformationManagement(customer).getSelectedPaymentInformation()

        card_num = credit_card.card_number
        exp_date = "%s/%s" % (credit_card.card_expiration_date_month,
                              credit_card.card_expiration_date_year)

        line_items = []
        for i, item in enumerate(IItemManagement(order).getItems()):
            if item.getProductTax() > 0:
                tax = "Y"
            else:
                tax = "N"

            line_items.append((
                str(i+1),
                item.getProduct().Title(),
                str(item.getProductQuantity()),
                str(item.getProductPriceGross()),
                tax,
            ))

        amount = "%.2f" % IPrices(order).getPriceForCustomer()

        cc = EasyShopCcProcessor(
            server="test.authorize.net",
            login="******",
            key="9ME22bvLnu87P4FY")

        # Used for authorizeAndCapture
        result = cc.authorizeAndCapture(
            amount = amount,
            card_num = card_num,
            exp_date = exp_date)
        if result.response == "approved":
            return PaymentResult(PAYED, _(u"Your order has been payed."))
        else:
            return PaymentResult(ERROR, _(result.response_reason))