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")
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")
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")
def handle_save_action(self, action, data): """ """ if form.applyChanges(self.context, self.form_fields, data, self.adapters): notify(ObjectModifiedEvent(self.context)) notify(EditSavedEvent(self.context)) self.status = "Changes saved" else: notify(EditCancelledEvent(self.context)) self.status = "No changes" shop = IShopManagement(self.context).getShop() ICheckoutManagement(shop).redirectToNextURL("EDITED_ADDRESS")
def createAndAdd(self, data): """ """ username = data.get("username") username = username.encode( "utf-8") # rtool doesn't understand unicode. password = data.get("password_1") request = self.context.REQUEST rtool = getToolByName(self.context, "portal_registration") rtool.addMember(username, password) utool = getToolByName(self.context, "portal_url") portal_url = utool.getPortalObject().absolute_url() # Plone's logged_in script (see below) redirects to given came_from, # hence we just have to pass the next url to it to get to the next url # within the checkout process. came_from = ICheckoutManagement( self.context).getNextURL("AFTER_ADDED_USER") parameters = { "came_from": came_from, "__ac_name": username, "__ac_password": password, "form.submitted": "1", "js_enabled": "1", "cookies_enabled": "1", "login_name": username, "pwd_empty": "0", } temp = [] for key, value in parameters.items(): if value != "": temp.append("%s=%s" % (key, value)) url = "%s/logged_in?%s" % (portal_url, "&".join(temp)) request.RESPONSE.redirect(url)
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")
def checkout(self): """The start of the checkout process. """ mtool = getToolByName(self.context, "portal_membership") ICheckoutManagement(self.context).redirectToNextURL("AFTER_START")