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 | """ |
---|
12 | pay online |
---|
13 | """ |
---|
14 | from urllib import urlencode |
---|
15 | import logging |
---|
16 | logger = logging.getLogger('Skins.pay_online') |
---|
17 | import DateTime |
---|
18 | |
---|
19 | if context.portal_membership.isAnonymousUser(): |
---|
20 | return None |
---|
21 | |
---|
22 | request = context.REQUEST |
---|
23 | wftool = context.portal_workflow |
---|
24 | students = context.portal_url.getPortalObject().campus.students |
---|
25 | |
---|
26 | student_id = context.getStudentId() |
---|
27 | student = getattr(students,student_id) |
---|
28 | |
---|
29 | sbrain = context.students_catalog(id=student_id)[0] |
---|
30 | amount,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] |
---|
39 | info = {} |
---|
40 | info['site_id'] = '300100100' |
---|
41 | info['currency_id'] = '566' |
---|
42 | info['amount'] = amount |
---|
43 | info['type_code'] = sbrain.faculty |
---|
44 | info['type_description'] = description |
---|
45 | info['pay_bill_to'] = sbrain.name |
---|
46 | info['pay_ship_to'] = "University of Benin" |
---|
47 | info['student_id'] = student_id |
---|
48 | info['student_name'] = sbrain.name |
---|
49 | info['student_email'] = sbrain.email |
---|
50 | now = DateTime.DateTime() |
---|
51 | info['date'] = now |
---|
52 | order_id = info['order_id'] = "%d" % int(now.timeTime()*1000) |
---|
53 | info['order_id'] = "%s%s" % (student_id[1:],order_id) |
---|
54 | p_id = "p%s" % order_id |
---|
55 | |
---|
56 | #from Products.zdb import set_trace;set_trace() |
---|
57 | if student_id is None: |
---|
58 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
59 | |
---|
60 | if 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" |
---|
63 | else: |
---|
64 | #pass |
---|
65 | #return None |
---|
66 | info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id) |
---|
67 | |
---|
68 | |
---|
69 | if "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') |
---|
76 | else: |
---|
77 | payments = getattr(student,'payments') |
---|
78 | if request.has_key('epayment'): |
---|
79 | return context.wema_form(info=info) |
---|
80 | |
---|
81 | |
---|
82 | payments.invokeFactory('Payment', p_id) |
---|
83 | payment = getattr(payments,p_id) |
---|
84 | wftool.doActionFor(payment,'open') |
---|
85 | d = {} |
---|
86 | d.update(info) |
---|
87 | #from Products.zdb import set_trace;set_trace() |
---|
88 | payment.getContent().edit(mapping=d) |
---|
89 | #wftool.doActionFor(payment,'close') |
---|
90 | #wftool.doActionFor(student,'pay_school_fee') |
---|
91 | info['callback_url'] = "%s/payments/%s/epayment_cb" % (student.absolute_url(),p_id) |
---|
92 | |
---|
93 | logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info) |
---|
94 | payment_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 | ) |
---|
107 | args = {} |
---|
108 | for arg,field in payment_fields: |
---|
109 | args[arg] = info[field] |
---|
110 | info['args'] = args |
---|
111 | return context.goto_wema_form(info=info) |
---|
112 | url = info['action'] + "?" + urlencode(args) |
---|
113 | request.RESPONSE.redirect(url) |
---|