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

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

use form for submit

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