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

Last change on this file since 17935 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
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 1653 2007-03-28 02:35:25Z uli $
11"""
12pay online
13"""
14from urllib import urlencode
15import logging
16logger = logging.getLogger('Skins.pay_online')
17import DateTime
18
19if context.portal_membership.isAnonymousUser():
20    return None
21
22request = context.REQUEST
23wftool = context.portal_workflow
24students = context.portal_url.getPortalObject().campus.students
25
26student_id = context.getStudentId()
27student = getattr(students,student_id)
28
29sbrain = context.students_catalog(id=student_id)[0]
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"
37##else:
38##    sfc = res[0].getPath().split('/')[-4]
39info = {}
40info['site_id'] = '300100100'
41info['currency_id'] = '566'
42info['amount'] = amount
43info['type_code'] = sbrain.faculty
44info['type_description'] = description
45info['pay_bill_to'] = sbrain.name
46info['pay_ship_to'] = "University of Benin"
47info['student_id'] = student_id
48info['student_name'] = sbrain.name
49info['student_email'] = sbrain.email
50now = DateTime.DateTime()
51info['date'] = now
52order_id = info['order_id'] = "%d" % int(now.timeTime()*1000)
53info['order_id'] = "%s%s" % (student_id[1:],order_id)
54p_id = "p%s" % order_id
55
56#from Products.zdb import set_trace;set_trace()
57if student_id is None:
58    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
59
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:
64    #pass
65    #return None
66    info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id)
67
68
69if "payments" not in student.objectIds():
70    student.invokeFactory('PaymentsFolder','payments')
71    payments = getattr(student,'payments')
72    d = {}
73    d['Title'] = 'Payments'
74    payments.getContent().edit(mapping=d)
75    wftool.doActionFor(payments,'open')
76else:
77    payments = getattr(student,'payments')
78if request.has_key('epayment'):
79    return context.wema_form(info=info)
80
81
82payments.invokeFactory('Payment', p_id)
83payment = getattr(payments,p_id)
84wftool.doActionFor(payment,'open')
85d = {}
86d.update(info)
87#from Products.zdb import set_trace;set_trace()
88payment.getContent().edit(mapping=d)
89#wftool.doActionFor(payment,'close')
90#wftool.doActionFor(student,'pay_school_fee')
91info['callback_url'] = "%s/payments/%s/epayment_cb" % (student.absolute_url(),p_id)
92
93logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
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]
110info['args'] = args
111return context.goto_wema_form(info=info)
112url = info['action'] + "?" + urlencode(args)
113request.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.