def testGetSelectedPaymentMethod_1(self):
        """Customer has selected prepayment by default.
        """
        pm = IPaymentInformationManagement(self.customer)
        result = pm.getSelectedPaymentMethod().getId()

        self.assertEqual(result, "prepayment")
示例#2
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
示例#3
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
示例#4
0
    def process(self):
        """
        """
        customer = self.context.getCustomer()
        pm = IPaymentInformationManagement(customer)
        payment_method = pm.getSelectedPaymentMethod()

        return IPaymentProcessing(payment_method).process(self.context)
    def testGetSelectedPaymentMethod_2(self):
        """Customer has selected paypal.
        """
        self.customer.selected_payment_method = "paypal"
        
        pm = IPaymentInformationManagement(self.customer)
        result = pm.getSelectedPaymentMethod().getId()

        self.assertEqual(result, "paypal")
    def testGetSelectedPaymentMethod_3(self):
        """Customer has selected a non existing. Returns default, which is 
        prepayment atm.
        """
        self.customer.selected_payment_method = "dummy"

        pm = IPaymentInformationManagement(self.customer)
        result = pm.getSelectedPaymentMethod().getId()

        self.assertEqual(result, "prepayment")
示例#7
0
    def getNote(self):
        """Returns the note from the selected payment method.
        """
        customer = self.context.getCustomer()
        pm = IPaymentInformationManagement(customer)

        selected_payment_method = pm.getSelectedPaymentMethod()

        note =  selected_payment_method.getNote()

        payment_url = self.context.absolute_url() + "/pay"
        note = note.replace("[payment-url]", payment_url)

        return note
示例#8
0
    def getSelectedPaymentData(self):
        """Returns selected payment method type and corresponding selected
        payment information.
        """
        customer = self.context.getCustomer()
        pm = IPaymentInformationManagement(customer)

        payment_information = pm.getSelectedPaymentInformation()
        selected_payment_method = pm.getSelectedPaymentMethod()

        return {
            "information": payment_information,
            "portal_type": selected_payment_method.portal_type,
            "payment_method": selected_payment_method
        }
示例#9
0
    def getSelectedPaymentData(self):
        """Returns selected payment method type and corresponding selected
        payment information.
        """
        customer = self.context.getCustomer()
        pm = IPaymentInformationManagement(customer)

        payment_information     = pm.getSelectedPaymentInformation()
        selected_payment_method = pm.getSelectedPaymentMethod()

        return {
            "information"    : payment_information,
            "portal_type"    : selected_payment_method.portal_type,
            "payment_method" : selected_payment_method
        }
示例#10
0
    def isPaymentAllowed(self):
        """
        """
        pm = IPaymentInformationManagement(self.context.getCustomer())
        m = pm.getSelectedPaymentMethod()

        if IType(m).getType() not in REDO_PAYMENT_PAYMENT_METHODS:
            return False

        wftool = getToolByName(self.context, "portal_workflow")
        state = wftool.getInfoFor(self.context, "review_state")

        if state not in REDO_PAYMENT_STATES:
            return False

        return True
示例#11
0
    def isPaymentAllowed(self):
        """
        """
        pm = IPaymentInformationManagement(self.context.getCustomer())
        m = pm.getSelectedPaymentMethod()

        if IType(m).getType() not in REDO_PAYMENT_PAYMENT_METHODS:
            return False

        wftool = getToolByName(self.context, "portal_workflow")
        state = wftool.getInfoFor(self.context, "review_state")

        if state not in REDO_PAYMENT_STATES:
            return False

        return True
示例#12
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 = IShopManagement(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
        pm = IPaymentInformationManagement(self.context)
        payment_method = pm.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, payment_method:
            if ICompleteness(toCheck).isComplete() == False:
                return False

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

        return True
示例#13
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 = IShopManagement(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
        pm = IPaymentInformationManagement(self.context)
        payment_method = pm.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, payment_method:
            if ICompleteness(toCheck).isComplete() == False:
                return False

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

        return True
示例#14
0
文件: cart.py 项目: viona/Easyshop
    def getPaymentInfo(self):
        """
        """
        pp = IPaymentPriceManagement(self.context)
        price = pp.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        price = cm.priceToString(price, suffix=None)

        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        pim = IPaymentInformationManagement(customer)
        selected_payment_method = pim.getSelectedPaymentMethod()

        if selected_payment_method is None:
            return {"display": False}
        else:
            return {
                "price": price,
                "title": selected_payment_method.Title(),
                "display": len(self.getCartItems()) > 0,
            }
示例#15
0
文件: cart.py 项目: Easyshop/Easyshop
    def getPaymentInfo(self):
        """
        """
        pp = IPaymentPriceManagement(self.context)
        price = pp.getPriceForCustomer()

        cm = ICurrencyManagement(self.context)
        price =  cm.priceToString(price, suffix=None)

        customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
        pim = IPaymentInformationManagement(customer)
        selected_payment_method = pim.getSelectedPaymentMethod()
        
        if selected_payment_method is None: 
            return {
                "display" : False
            }
        else:    
            return {
                "price"   : price,
                "title"   : selected_payment_method.Title(),
                "display" : len(self.getCartItems()) > 0,
            }