Example #1
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
Example #2
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
Example #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
Example #4
0
    def testGetPaymentInformations(self):
        """Get all payment methods (without parameter)
        """
        pm = IPaymentInformationManagement(self.customer)

        ids = [p.getId() for p in pm.getPaymentInformations()]
        self.assertEqual(["bank-account"], ids)
Example #5
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
Example #6
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
    def testGetSelectedPaymentMethod_1(self):
        """Customer has selected prepayment by default.
        """
        pm = IPaymentInformationManagement(self.customer)
        result = pm.getSelectedPaymentMethod().getId()

        self.assertEqual(result, "prepayment")
    def testGetPaymentInformations(self):
        """Get all payment methods (without parameter)
        """
        pm = IPaymentInformationManagement(self.customer)

        ids = [p.getId() for p in pm.getPaymentInformations()]
        self.assertEqual(["bank-account"], ids)
Example #9
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
Example #10
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")
Example #13
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
Example #14
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
Example #15
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
        }
Example #16
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
        }
Example #17
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
Example #18
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
Example #19
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
Example #20
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
Example #21
0
    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,
            }
Example #22
0
    def deletePaymentMethod(self):
        """
        """
        putils = getToolByName(self.context, "plone_utils")

        # delete address
        payment_method_id = self.context.request.get("id")
        pm = IPaymentInformationManagement(self.context)
        pm.deletePaymentInformation(payment_method_id)

        # If the selected payment information has been deleted set the payment
        # method to the default: atm prepayment.
        if payment_method_id == self.context.selected_payment_information:
            self.context.selected_payment_information = u""
            self.context.selected_payment_method = u"prepayment"

        # add message
        putils.addPortalMessage("The payment method has been deleted.")

        # Redirect to overview
        url = "%s/manage-payment-methods" % self.context.absolute_url()
        self.context.request.response.redirect(url)
    def deletePaymentMethod(self):
        """
        """
        putils = getToolByName(self.context, "plone_utils")

        # delete address
        payment_method_id = self.context.request.get("id")
        pm = IPaymentInformationManagement(self.context)
        pm.deletePaymentInformation(payment_method_id)

        # If the selected payment information has been deleted set the payment
        # method to the default: atm prepayment.
        if payment_method_id == self.context.selected_payment_information:
            self.context.selected_payment_information = u""
            self.context.selected_payment_method = u"prepayment"

        # add message
        putils.addPortalMessage("The payment method has been deleted.")

        # Redirect to overview
        url = "%s/manage-payment-methods" % self.context.absolute_url()
        self.context.request.response.redirect(url)
Example #24
0
    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,
            }
Example #25
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))
Example #26
0
    def testDeletePaymentInformations(self):
        """
        """
        pm = IPaymentInformationManagement(self.customer)

        ids = [p.getId() for p in pm.getPaymentInformations()]
        self.assertEqual(["bank-account"], ids)

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

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

        # still all there?
        ids = [p.getId() for p in pm.getPaymentInformations()]
        self.assertEqual(["bank-account"], ids)

        result = pm.deletePaymentInformation("bank-account")
        self.assertEqual(result, True)

        ids = [p.getId() for p in pm.getPaymentInformations()]
        self.assertEqual([], ids)
    def testDeletePaymentInformations(self):
        """
        """
        pm = IPaymentInformationManagement(self.customer)

        ids = [p.getId() for p in pm.getPaymentInformations()]
        self.assertEqual(["bank-account"], ids)

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

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

        # still all there?
        ids = [p.getId() for p in pm.getPaymentInformations()]
        self.assertEqual(["bank-account"], ids)

        result = pm.deletePaymentInformation("bank-account")
        self.assertEqual(result, True)

        ids = [p.getId() for p in pm.getPaymentInformations()]
        self.assertEqual([], ids)
 def testGetSelectedPaymentInformation(self):
     """
     """
     pm = IPaymentInformationManagement(self.customer)
     result = pm.getSelectedPaymentInformation()
     self.failUnless(result is None)
Example #29
0
    def copyTo(self, target=None, new_id=None):
        """
        """
        if target is None:
            target = self.context.aq_inner.aq_parent

        if new_id is None:
            new_id = self.context.id

        wftool = getToolByName(self.context, "portal_workflow")

        new_customer = Customer(new_id)
        for field in ICustomer.names():
            setattr(new_customer, field, getattr(self.context, field))

        # Set object
        target._setObject(new_id, new_customer)
        new_customer = target[new_id]

        # NOTE: I know this is not really nice but it helps as there are some
        # permission problems with Zope's copy and paste, when it comes to
        # copying content as anonymous user, which is needed for anonymous
        # checkout -> copy the customer object to the new order.

        new_customer.firstname = self.context.firstname
        new_customer.lastname = self.context.lastname
        new_customer.email = self.context.email

        new_customer.selected_invoice_address = self.context.selected_invoice_address
        new_customer.selected_shipping_address = self.context.selected_shipping_address
        new_customer.selected_payment_method = self.context.selected_payment_method
        new_customer.selected_payment_information = self.context.selected_payment_information
        new_customer.selected_shipping_method = self.context.selected_shipping_method
        new_customer.selected_country = self.context.selected_country

        # Copy addresses
        session_addresses = IAddressManagement(self.context).getAddresses()
        for session_address in session_addresses:
            new_address = Address(session_address.id)
            for field in IAddress.names():
                setattr(new_address, field, getattr(session_address, field))
            new_customer._setObject(new_address.id, new_address)
            new_address = new_customer[new_address.id]
            wftool.notifyCreated(new_address)

        # Copy customer payment methods.
        pm = IPaymentInformationManagement(self.context)
        for session_direct_debit in pm.getPaymentInformations(IBankAccount):
            new_direct_debit = BankAccount(session_direct_debit.id)
            for field in IBankAccount.names():
                setattr(new_direct_debit, field,
                        getattr(session_direct_debit, field))
            new_customer._setObject(new_direct_debit.id, new_direct_debit)
            new_direct_debit = new_customer[new_direct_debit.id]
            wftool.notifyCreated(new_direct_debit)

        for session_credit_card in pm.getPaymentInformations(ICreditCard):
            new_credit_card = CreditCard(session_credit_card.id)
            for field in ICreditCard.names():
                setattr(new_credit_card, field,
                        getattr(session_credit_card, field))
            new_customer._setObject(new_credit_card.id, new_credit_card)
            new_credit_card = new_customer[new_credit_card.id]
            wftool.notifyCreated(new_credit_card)

        new_customer.reindexObject()
        wftool.notifyCreated(new_customer)

        return new_customer
 def getCreditCards(self):
     """
     """
     pm  = IPaymentInformationManagement(self.context)
     return pm.getPaymentInformations(ICreditCard)
 def getDirectDebitAccounts(self):
     """
     """
     pm  = IPaymentInformationManagement(self.context)
     return pm.getPaymentInformations(IBankAccount)
Example #32
0
 def getDirectDebitAccounts(self):
     """
     """
     pm = IPaymentInformationManagement(self.context)
     return pm.getPaymentInformations(IBankAccount)
Example #33
0
 def getCreditCards(self):
     """
     """
     pm = IPaymentInformationManagement(self.context)
     return pm.getPaymentInformations(ICreditCard)
Example #34
0
 def getSelectedPaymentInformation(self):
     """
     """
     customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
     pm = IPaymentInformationManagement(customer)
     return pm.getSelectedPaymentInformation()
Example #35
0
    def handle_buy_action(self, action, data):
        """Buys a cart.
        """
        putils = getToolByName(self.context, "plone_utils")

        # add order
        om = IOrderManagement(self.context)
        new_order = om.addOrder()

        # Set message to shop owner
        new_order.setMessage(self.context.request.get("form.message", ""))

        # process payment
        result = IPaymentProcessing(new_order).process()

        # Need error for payment methods for which the customer has to pay at
        # any case The order process should not go on if the customer is not
        # able to pay.
        if result.code == ERROR:
            om.deleteOrder(new_order.id)
            putils.addPortalMessage(result.message, type=u"error")
            ICheckoutManagement(
                self.context).redirectToNextURL("ERROR_PAYMENT")
            return ""
        else:
            cm = ICartManagement(self.context)

            # Decrease stock
            IStockManagement(self.context).removeCart(cm.getCart())

            # Delete cart
            cm.deleteCart()

            # Set order to pending (Mails will be sent)
            wftool = getToolByName(self.context, "portal_workflow")
            wftool.doActionFor(new_order, "submit")

            putils.addPortalMessage(MESSAGES["ORDER_RECEIVED"])

        if result.code == PAYED:

            # Set order to payed (Mails will be sent)
            wftool = getToolByName(self.context, "portal_workflow")

            # We need a new security manager here, because this transaction
            # should usually just be allowed by a Manager except here.
            old_sm = getSecurityManager()
            tmp_user = UnrestrictedUser(old_sm.getUser().getId(), '',
                                        ['Manager'], '')

            portal = getToolByName(self.context,
                                   'portal_url').getPortalObject()
            tmp_user = tmp_user.__of__(portal.acl_users)
            newSecurityManager(None, tmp_user)

            wftool.doActionFor(new_order, "pay_not_sent")

            ## Reset security manager
            setSecurityManager(old_sm)

        # Redirect
        customer = \
            ICustomerManagement(self.context).getAuthenticatedCustomer()
        selected_payment_method = \
            IPaymentInformationManagement(customer).getSelectedPaymentMethod()

        if not IAsynchronPaymentMethod.providedBy(selected_payment_method):
            ICheckoutManagement(self.context).redirectToNextURL("BUYED_ORDER")
Example #36
0
 def getSelectedPaymentInformation(self):
     """
     """
     customer = ICustomerManagement(self.context).getAuthenticatedCustomer()
     pm = IPaymentInformationManagement(customer)
     return pm.getSelectedPaymentInformation()
Example #37
0
 def testGetSelectedPaymentInformation(self):
     """
     """
     pm = IPaymentInformationManagement(self.customer)
     result = pm.getSelectedPaymentInformation()
     self.failUnless(result is None)
Example #38
0
    def copyTo(self, target=None, new_id=None):
        """
        """
        if target is None:
            target = self.context.aq_inner.aq_parent

        if new_id is None:
            new_id = self.context.id

        wftool = getToolByName(self.context, "portal_workflow")
        
        new_customer = Customer(new_id)
        for field in ICustomer.names():
            setattr(new_customer, field, getattr(self.context, field))

        # Set object
        target._setObject(new_id, new_customer)
        new_customer = target[new_id]
        
        # NOTE: I know this is not really nice but it helps as there are some
        # permission problems with Zope's copy and paste, when it comes to 
        # copying content as anonymous user, which is needed for anonymous 
        # checkout -> copy the customer object to the new order.

        new_customer.firstname = self.context.firstname
        new_customer.lastname  = self.context.lastname
        new_customer.email     = self.context.email
    
        new_customer.selected_invoice_address     = self.context.selected_invoice_address
        new_customer.selected_shipping_address    = self.context.selected_shipping_address
        new_customer.selected_payment_method      = self.context.selected_payment_method
        new_customer.selected_payment_information = self.context.selected_payment_information
        new_customer.selected_shipping_method     = self.context.selected_shipping_method
        new_customer.selected_country             = self.context.selected_country
        
        # Copy addresses    
        session_addresses = IAddressManagement(self.context).getAddresses()
        for session_address in session_addresses:
            new_address = Address(session_address.id)
            for field in IAddress.names():
                setattr(new_address, field, getattr(session_address, field))
            new_customer._setObject(new_address.id, new_address)
            new_address = new_customer[new_address.id]
            wftool.notifyCreated(new_address)

        # Copy customer payment methods.
        pm = IPaymentInformationManagement(self.context)
        for session_direct_debit in pm.getPaymentInformations(IBankAccount):
            new_direct_debit = BankAccount(session_direct_debit.id)
            for field in IBankAccount.names():
                setattr(new_direct_debit, field, getattr(session_direct_debit, field))
            new_customer._setObject(new_direct_debit.id, new_direct_debit)
            new_direct_debit = new_customer[new_direct_debit.id]
            wftool.notifyCreated(new_direct_debit)

        for session_credit_card in pm.getPaymentInformations(ICreditCard):
            new_credit_card = CreditCard(session_credit_card.id)
            for field in ICreditCard.names():
                setattr(new_credit_card, field, getattr(session_credit_card, field))
            new_customer._setObject(new_credit_card.id, new_credit_card)
            new_credit_card = new_customer[new_credit_card.id]
            wftool.notifyCreated(new_credit_card)
        
        new_customer.reindexObject()
        wftool.notifyCreated(new_customer)
        
        return new_customer