def render(self): session = ISession(self.request, None) if session is None: return None utils = getToolByName(self, "plone_utils") url = self.context.absolute_url() + '/' + MEGABANKVIEW_URL responseCode = self.request['responseCode'] transactionId = self.request['transactionId'] bank = Bank() if responseCode == 'Cancel': # the person pressed Cacel or error occured # TODO: Kontrollera att Megabank lyckas med cancel, lägg till i meddeelande result = bank.cancelOnlineTransaction(transactionId) utils.addPortalMessage(_(u'Betalningen avbröts'), 'info') return self.request.response.redirect(url) if responseCode == 'OK': # The PSP performed payment # TODO: Kontrollera att Megabank lyckas med commit, lägg till i meddeelande # Remove payed invoices from session's selected_invoices session[SessionKeys.selected_invoices] = [] result = bank.commitOnlineTransaction(transactionId) utils.addPortalMessage(_(u'Betalningen genomfördes'), 'info') return self.request.response.redirect(url)
def setupMyAccountFolder(portal, logger=None): if logger: logger.info("") # _createObjects(portal, _my_account()) folder_id = "my-account" folder_title = u"Mitt konto" object_type = "Folder" view = "@@list-transactions" # Check if hejasverige.policy is applied. If not, place my-account in root folder, otherwise in my-pages parent = "my-pages" mypages = portal.get(parent, None) if mypages: rootfolder = mypages else: rootfolder = portal existing_objects = rootfolder.objectIds() if folder_id in existing_objects: logger.info("Object exists in folder") else: _createObjectByType(object_type, rootfolder, id=folder_id, title=_(folder_title)) obj = rootfolder.get(folder_id, None) if obj: if obj.Type() == object_type: try: alsoProvides(obj, IMyAccountFolder) except: logger.info("Could not apply marker interface...") try: obj.setLayout(view) except: logger.info("Could not apply marker interface...") try: workflowTool = getToolByName(portal, "portal_workflow") workflowTool.doActionFor(obj, "publish_internally") except WorkflowException: logger.info("Could not apply workflow publish_internally transition. Trying publish...") try: workflowTool.doActionFor(obj, "publish") except WorkflowException: logger.info("Workflow transition 'publish' failed...")
def update(self): """ Renders the view """ session = ISession(self.request, None) if session is None: return None if 'form.button.Submit' in self.request: #import pdb; pdb.set_trace() authenticator = getMultiAdapter((self.context, self.request), name=u"authenticator") if not authenticator.verify(): raise Forbidden() utils = getToolByName(self, "plone_utils") url = self.url() if float(self.request['points_amount']) > float(self.myinfo().get('balance')): utils.addPortalMessage(_('Angivna poäng är fler än du har.'), 'error') return self.request.response.redirect(url) if float(self.request['points_amount']) + float(self.request['card_amount']) != float(self.myinfo().get('amount_to_pay')): utils.addPortalMessage(_('Totalbeloppet är inte korrekt.'), 'error') return self.request.response.redirect(url) if float(self.request['points_amount']) < 0: utils.addPortalMessage(_('Antalet poäng får ej vara mindre än 0'), 'error') return self.request.response.redirect(url) if float(self.request['card_amount']) < 0: utils.addPortalMessage(_('Kortbelopp får ej vara mindre än 0'), 'error') return self.request.response.redirect(url) bank = Bank() obj = dict() obj['amount'] = float(self.request['card_amount']) if len(session[SessionKeys.selected_invoices]) > 1: invoiceword = 'fakturor' else: invoiceword = 'faktura' obj['description'] = "Onlinebetalning av %s (%s) " % (invoiceword, ", ".join([x.get('invoiceno') for x in session[SessionKeys.selected_invoices]])) obj['invoices'] = [int(x.get('id')) for x in session[SessionKeys.selected_invoices]] obj['url'] = self.context.absolute_url() + '/@@psplandingpage' pid = self.myinfo().get('pid') try: result = bank.registerOnlineTransaction(obj, pid) #import pdb; pdb.set_trace() except Exception, ex: error_message = u'Kunde inte kontakta banken. Betalningen kunde inte registreras.' logger.error(error_message + ' Ex: %s' % (str(ex))) utils.addPortalMessage(_(result.get(error_message)), 'error') return self.request.response.redirect(url) pass else: if result: try: redir_url = result.get('Url', None) if redir_url: return self.request.response.redirect(redir_url) except: pass utils.addPortalMessage(_(u'Banken svarade dåligt. Ingen betalning kan genomföras.'), 'error') return self.request.response.redirect(url)