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