Пример #1
0
    def update(self):
        """ Handle the mxit response
        """
        context = self.context
        request = self.request
        self.pps = self.context.restrictedTraverse('@@plone_portal_state')
        self.portal = self.pps.portal()
        self.products_and_services = self.portal._getOb('products_and_services')
        self.memberservices = self.portal._getOb('memberservices')
        self.navroot = self.pps.navigation_root()

        self.orders = self.portal._getOb('orders')
        order_number = self.request['order_number']
        self.order = self.orders._getOb(order_number)

        self.base_url = context.absolute_url()
        self.response_code = request.get('mxit_transaction_res', None)
        # we try to interpret the response, if that fails we use the response
        # code itself as the message. That way we can at least see what we did
        # not understand :)
        self.message = MXIT_MESSAGES.get(self.response_code, self.response_code)

        # check response code
        if not self.response_code:
            return
       
        # Transaction completed successfully.
        if self.response_code == '0':
            self.productid = request['productId']
            self.service = self.products_and_services._getOb(self.productid)

            memberid = member_id(
                self.request.get(USER_ID_TOKEN.lower(),
                                 self.request.get(USER_ID_TOKEN)
                                )
            )
            password = password_hash(context, memberid)
            pmt = getToolByName(context, 'portal_membership')
            member = pmt.getMemberById(memberid)
            if not member:
                pmt.addMember(memberid, password, 'Member', '')
                member = pmt.getMemberById(memberid)
            
            # login as member
            newSecurityManager(self.request, member)
            # now transition the order to paid
            wf = getToolByName(self.context, 'portal_workflow')
            status = wf.getStatusOf('order_workflow', self.order)
            if status['review_state'] != 'paid':
                wf.doActionFor(self.order, 'pay')
                self.order.reindexObject()
Пример #2
0
    def update(self):
        pps = self.context.restrictedTraverse('@@plone_portal_state')
        self.products_and_services = pps.portal()._getOb('products_and_services')
        self.navroot = pps.navigation_root()
        self.base_url = 'http://billing.internal.mxit.com/Transaction/PaymentRequest'
        self.action = self.context.absolute_url() + '/@@mxitpaymentrequest'

        pmt = getToolByName(self.context, 'portal_membership')
        memberid = member_id(
            self.request.get(USER_ID_TOKEN.lower(),
                             self.request.get(USER_ID_TOKEN)
                            )
        )
        if not memberid:
            raise ValueError('No member id supplied.')
        member = pmt.getMemberById(memberid)
        if not member:
            password = password_hash(self.context, memberid)
            pmt.addMember(memberid, password, 'Member', '')
            member = pmt.getMemberById(memberid)
            # login as new member
            newSecurityManager(self.request, member)

        registry = queryUtility(IRegistry)
        self.emas_settings = registry.forInterface(IEmasSettings)
        self.transaction_reference = self.emas_settings.order_sequence_number +1
        self.emas_settings.order_sequence_number = self.transaction_reference
        self.transaction_reference = '%04d' % self.transaction_reference

        self.product_id = self.request.get('productId')
        try:
            self.product = self.products_and_services._getOb(self.product_id)
        except AttributeError:
            raise AttributeError(
                'Product with id %s not found' % self.product_id
                )
            
        self.product_name = self.product.title
        self.product_description = self.product.description
        
        # create an order for this member : product combination
        if self.product:
            portal = pps.portal()
            member_orders = portal['orders']

            props = {'id'            : self.transaction_reference, 
                     'title'         : self.transaction_reference,
                     'userid'        : memberid,
                     'payment_method': MOOLA,
                     }
            self.order= createContentInContainer(
                member_orders,
                'emas.app.order',
                False,
                **props
            )
            self.order = member_orders._getOb(self.transaction_reference)
            self.order.verification_code = generate_verification_code(self.order)
            self.order.manage_setLocalRoles(self.order.userid, ('Owner',))
                
            relation = create_relation(self.product.getPhysicalPath())
            item_id = self.order.generateUniqueId(type_name='orderitem')
            props = {'id'           : item_id,
                     'title'        : item_id,
                     'related_item' : relation,
                     'quantity'     : 1}
            order_item = createContentInContainer(
                self.order,
                'emas.app.orderitem',
                False,
                **props
            )
            order_item.manage_setLocalRoles(self.order.userid, ('Owner',))

            self.callback_url = \
                '%s/mxitpaymentresponse?productId=%s&order_number=%s&verification_code=%s' %(
                    self.context.absolute_url(),
                    self.product_id,
                    self.order.getId(),
                    self.order.verification_code
            )

        self.cost_settings = registry.forInterface(IEmasServiceCost)
        self.vendor_id = self.cost_settings.MXitVendorId
        self.moola_amount = self.product.amount_of_moola
        self.currency_amount = self.product.price
        url = '%s/%s' %(self.navroot.absolute_url(), self.product.access_path)
        
        # get all active services for this user
        service_intids = practice_service_intids(self.context)
        dao = MemberServicesDataAccess(self.context)
        memberservices = dao.get_memberservices(service_intids, memberid)
        active_services = [m.related_service(self.context) for m in memberservices]

        # check if the currently requested one is in the list
        if self.product in active_services:
            return self.request.response.redirect(url)
        else:
            return self.render()