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 1304 2007-01-15 22:46:27Z henrik $ |
---|
11 | """ |
---|
12 | pay online |
---|
13 | """ |
---|
14 | import logging |
---|
15 | from urllib import urlencode |
---|
16 | logger = logging.getLogger('EPayment.') |
---|
17 | import DateTime |
---|
18 | request = context.REQUEST |
---|
19 | wftool = context.portal_workflow |
---|
20 | students = context.portal_url.getPortalObject().campus.students |
---|
21 | |
---|
22 | student_id = context.getStudentId() |
---|
23 | if student_id is None: |
---|
24 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
25 | |
---|
26 | student = getattr(students,student_id) |
---|
27 | sbrain = context.students_catalog(id=student_id)[0] |
---|
28 | amount,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] |
---|
37 | info = {} |
---|
38 | info['site_id'] = '8000' |
---|
39 | info['currency_id'] = '566' |
---|
40 | info['amount'] = amount |
---|
41 | info['type_code'] = sbrain.faculty |
---|
42 | info['type_description'] = description |
---|
43 | info['pay_bill_to'] = sbrain.name |
---|
44 | info['pay_ship_to'] = "University of Benin" |
---|
45 | info['student_id'] = student_id |
---|
46 | info['student_name'] = sbrain.name |
---|
47 | info['student_email'] = sbrain.email |
---|
48 | now = DateTime.DateTime() |
---|
49 | info['date'] = now |
---|
50 | order_id = info['order_id'] = "%d" % int(now.timeTime()*1000) |
---|
51 | info['order_id'] = "%s%s" % (student_id[1:],order_id) |
---|
52 | if "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') |
---|
59 | else: |
---|
60 | payments = getattr(student,'payments') |
---|
61 | if request.has_key('epayment'): |
---|
62 | return context.wema_form(info=info) |
---|
63 | |
---|
64 | p_id = "p%s" % order_id |
---|
65 | payments.invokeFactory('Payment', p_id) |
---|
66 | payment = getattr(payments,p_id) |
---|
67 | wftool.doActionFor(payment,'open') |
---|
68 | d = {} |
---|
69 | d.update(info) |
---|
70 | #from Products.zdb import set_trace;set_trace() |
---|
71 | payment.getContent().edit(mapping=d) |
---|
72 | wftool.doActionFor(payment,'close') |
---|
73 | #wftool.doActionFor(student,'pay_school_fee') |
---|
74 | info['callback_url'] = "%s/payments/%s/epayment_cb" % (student.absolute_url(),p_id) |
---|
75 | if 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" |
---|
78 | else: |
---|
79 | info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id) |
---|
80 | logger.info('"%(student_id)s","%(type_description)s", "%(amount)s N"' % info) |
---|
81 | payment_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 | ) |
---|
94 | args = {} |
---|
95 | for arg,field in payment_fields: |
---|
96 | args[arg] = info[field] |
---|
97 | url = info['action'] + "?" + urlencode(args) |
---|
98 | request.RESPONSE.redirect(url) |
---|