Ejemplo n.º 1
0
    def isComplete(self):
        """Checks weather the customer is complete to checkout.
        
           Customer completeness means the customer is ready to check out:
             1. Invoice address is complete
             2. Shipping address is complete
             3. Selected payment method is complete
             4. There a items in the cart            
        """
        # Get shop
        shop = self.context.getShop()

        # Get shipping and invoice address
        adressman = IAddressManagement(self.context)

        s_addr = adressman.getShippingAddress()
        if s_addr is None: return False

        i_addr = adressman.getInvoiceAddress()
        if i_addr is None: return False

        # Get payment method
        payman = IPaymentManagement(self.context)
        paymeth = payman.getSelectedPaymentMethod()

        # Get cart of the customer
        cart = ICartManagement(shop).getCart()

        # If there is no cart, the customer hasn't selected a product, hence
        # he is not complete
        if cart is None:
            return False

        im = IItemManagement(cart)

        # Check all for completeness
        # if at least one is False customer is not complete, too.
        for toCheck in s_addr, i_addr, paymeth:
            if ICompleteness(toCheck).isComplete() == False:
                return False

        # check items in cart
        if im.hasItems() == False:
            return False

        return True
Ejemplo n.º 2
0
    def isValid(self, product=None):
        """Returns true if the corresponding payment validator is not False and
        all contained criteria are True.
        """
        # First we check the general validity. For that we try to get the
        # corresponding payment validator.
        type = IType(self.context).getType()
        pm = IPaymentManagement(IShopManagement(self.context).getShop())
        method = pm.getPaymentMethod(type)

        # Only if we find one, we check validity. If we didn't find one, we
        # consider the general validity as fulfilled.
        if method and IValidity(method).isValid() == False:
            return False

        # If the non-validity isn't proved we check the criteria of context
        # (a customer payment method)
        return super(CustomerPaymentValidityManagement, self).isValid(product)
Ejemplo n.º 3
0
    def testDeletePaymentMethod(self):
        """
        """
        pm = IPaymentManagement(self.customer)

        ids = [p.getId() for p in pm.getPaymentMethods()]
        self.assertEqual(["directdebit"], ids)

        # Shop level payment methods shouldn't be deletable here.
        result = pm.deletePaymentMethod("paypal")
        self.assertEqual(result, False)

        result = pm.deletePaymentMethod("prepayment")
        self.assertEqual(result, False)

        # still all there?
        ids = [p.getId() for p in pm.getPaymentMethods()]
        self.assertEqual(["directdebit"], ids)

        result = pm.deletePaymentMethod("directdebit")
        self.assertEqual(result, True)

        ids = [p.getId() for p in pm.getPaymentMethods()]
        self.assertEqual([], ids)
Ejemplo n.º 4
0
 def testGetSelectedPaymentMethod_1(self):
     """Customer has selected prepayment
     """
     pm = IPaymentManagement(self.shop)
     result = pm.getSelectedPaymentMethod().getId()
     self.assertEqual(result, "prepayment")