source: WAeUP_SRP/trunk/skins/waeup_epayment/pay_online.py @ 1338

Last change on this file since 1338 was 1311, checked in by joachim, 18 years ago

New Site ID

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
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 1311 2007-01-16 18:03:26Z joachim $
11"""
12pay online
13"""
14from urllib import urlencode
15import logging
16logger = logging.getLogger('EPayment.')
17import DateTime
18request = context.REQUEST
19wftool = context.portal_workflow
20students = context.portal_url.getPortalObject().campus.students
21
22student_id = context.getStudentId()
23if student_id is None:
24    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
25
26student = getattr(students,student_id)
27sbrain = context.students_catalog(id=student_id)[0]
28amount,description = context.getSchoolFee(sbrain.faculty)
29##res = context.portal_catalog(portal_type="Certificate",
30##                                     id = sbrain.course)
31##
32##if not res:
33##    logger.info('"%s","certificate not found", "%s"' % (student_id,course))
34##    sfc = "ART"
35##else:
36##    sfc = res[0].getPath().split('/')[-4]
37info = {}
38info['site_id'] = '300100100'
39info['currency_id'] = '566'
40info['amount'] = amount
41info['type_code'] = sbrain.faculty
42info['type_description'] = description
43info['pay_bill_to'] = sbrain.name
44info['pay_ship_to'] = "University of Benin"
45info['student_id'] = student_id
46info['student_name'] = sbrain.name
47info['student_email'] = sbrain.email
48now = DateTime.DateTime()
49info['date'] = now
50order_id = info['order_id'] = "%d" % int(now.timeTime()*1000)
51info['order_id'] = "%s%s" % (student_id[1:],order_id)
52if "payments" not in student.objectIds():
53    student.invokeFactory('PaymentsFolder','payments')
54    payments = getattr(student,'payments')
55    d = {}
56    d['Title'] = 'Payments'
57    payments.getContent().edit(mapping=d)
58    wftool.doActionFor(payments,'open')
59else:
60    payments = getattr(student,'payments')
61if request.has_key('epayment'):
62    return context.wema_form(info=info)
63
64p_id = "p%s" % order_id
65payments.invokeFactory('Payment', p_id)
66payment = getattr(payments,p_id)
67wftool.doActionFor(payment,'open')
68d = {}
69d.update(info)
70#from Products.zdb import set_trace;set_trace()
71payment.getContent().edit(mapping=d)
72#wftool.doActionFor(payment,'close')
73#wftool.doActionFor(student,'pay_school_fee')
74info['callback_url'] = "%s/payments/%s/epayment_cb" % (student.absolute_url(),p_id)
75if context.portal_url().find('uniben-demo.waeup.org') >-1 or\
76   context.portal_url().find('uniben.waeup.org') >-1:
77    info['action'] = "http://www.wemaonlinepayments.biz/payment.aspx"
78else:
79    info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id)
80logger.info('"%(student_id)s","%(type_description)s", "%(amount)s N"' % info)
81payment_fields = (('x_SiteID','site_id'),
82                  ('x_Redirect_url','callback_url'),
83                  ('x_CurrencyID','currency_id'),
84                  ('x_PaymentCode','type_code'),
85                  ('x_PayDesc','type_description'),
86                  ('x_Billto','pay_bill_to'),
87                  ('x_Shipto','pay_ship_to'),
88                  ('x_PayerID','student_id'),
89                  ('x_PayerNames','student_name'),
90                  ('x_PayerEmail','student_email'),
91                  ('x_OrderID','order_id'),
92                  ('x_amt','amount'),
93                  )
94args = {}
95for arg,field in payment_fields:
96    args[arg] = info[field]
97url = info['action'] + "?" + urlencode(args)
98request.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.