source: WAeUP_SRP/branches/uli/skins/waeup_epayment/pay_online.py @ 3790

Last change on this file since 3790 was 1653, checked in by uli, 18 years ago

Incorporated changeset 1593:1652 of trunk into uli-branch.

  • Property svn:keywords set to Id
File size: 3.6 KB
RevLine 
[1147]1## Script (Python) "pay_online"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: pay_online.py 1653 2007-03-28 02:35:25Z uli $
11"""
[1158]12pay online
[1147]13"""
[1311]14from urllib import urlencode
[1147]15import logging
[1593]16logger = logging.getLogger('Skins.pay_online')
[1147]17import DateTime
[1365]18
19if context.portal_membership.isAnonymousUser():
20    return None
21
[1147]22request = context.REQUEST
[1303]23wftool = context.portal_workflow
[1147]24students = context.portal_url.getPortalObject().campus.students
25
26student_id = context.getStudentId()
[1365]27student = getattr(students,student_id)
[1147]28
[1158]29sbrain = context.students_catalog(id=student_id)[0]
[1243]30amount,description = context.getSchoolFee(sbrain.faculty)
31##res = context.portal_catalog(portal_type="Certificate",
32##                                     id = sbrain.course)
33##
34##if not res:
35##    logger.info('"%s","certificate not found", "%s"' % (student_id,course))
36##    sfc = "ART"
[1304]37##else:
[1243]38##    sfc = res[0].getPath().split('/')[-4]
[1147]39info = {}
[1311]40info['site_id'] = '300100100'
[1257]41info['currency_id'] = '566'
[1243]42info['amount'] = amount
43info['type_code'] = sbrain.faculty
44info['type_description'] = description
[1224]45info['pay_bill_to'] = sbrain.name
46info['pay_ship_to'] = "University of Benin"
[1158]47info['student_id'] = student_id
48info['student_name'] = sbrain.name
49info['student_email'] = sbrain.email
[1226]50now = DateTime.DateTime()
[1243]51info['date'] = now
[1226]52order_id = info['order_id'] = "%d" % int(now.timeTime()*1000)
[1224]53info['order_id'] = "%s%s" % (student_id[1:],order_id)
[1355]54p_id = "p%s" % order_id
55
[1362]56#from Products.zdb import set_trace;set_trace()
[1355]57if student_id is None:
58    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
[1365]59
[1355]60if context.portal_url().find('uniben-demo.waeup.org') >-1 or\
61   context.portal_url().find('uniben.waeup.org') >-1:
62    info['action'] = "http://www.wemaonlinepayments.biz/payment.aspx"
63else:
[1362]64    #pass
65    #return None
[1365]66    info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id)
[1355]67
68
[1224]69if "payments" not in student.objectIds():
[1226]70    student.invokeFactory('PaymentsFolder','payments')
[1224]71    payments = getattr(student,'payments')
72    d = {}
[1243]73    d['Title'] = 'Payments'
[1226]74    payments.getContent().edit(mapping=d)
[1243]75    wftool.doActionFor(payments,'open')
[1224]76else:
77    payments = getattr(student,'payments')
[1257]78if request.has_key('epayment'):
79    return context.wema_form(info=info)
80
[1355]81
[1224]82payments.invokeFactory('Payment', p_id)
83payment = getattr(payments,p_id)
[1303]84wftool.doActionFor(payment,'open')
[1224]85d = {}
86d.update(info)
[1243]87#from Products.zdb import set_trace;set_trace()
[1224]88payment.getContent().edit(mapping=d)
[1308]89#wftool.doActionFor(payment,'close')
[1304]90#wftool.doActionFor(student,'pay_school_fee')
[1224]91info['callback_url'] = "%s/payments/%s/epayment_cb" % (student.absolute_url(),p_id)
[1355]92
[1653]93logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
[1257]94payment_fields = (('x_SiteID','site_id'),
95                  ('x_Redirect_url','callback_url'),
96                  ('x_CurrencyID','currency_id'),
97                  ('x_PaymentCode','type_code'),
98                  ('x_PayDesc','type_description'),
99                  ('x_Billto','pay_bill_to'),
100                  ('x_Shipto','pay_ship_to'),
101                  ('x_PayerID','student_id'),
102                  ('x_PayerNames','student_name'),
103                  ('x_PayerEmail','student_email'),
104                  ('x_OrderID','order_id'),
105                  ('x_amt','amount'),
106                  )
107args = {}
108for arg,field in payment_fields:
109    args[arg] = info[field]
[1362]110info['args'] = args
111return context.goto_wema_form(info=info)
[1257]112url = info['action'] + "?" + urlencode(args)
113request.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.