[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 1311 2007-01-16 18:03:26Z joachim $ |
---|
| 11 | """ |
---|
[1158] | 12 | pay online |
---|
[1147] | 13 | """ |
---|
[1311] | 14 | from urllib import urlencode |
---|
[1147] | 15 | import logging |
---|
| 16 | logger = logging.getLogger('EPayment.') |
---|
| 17 | import DateTime |
---|
| 18 | request = context.REQUEST |
---|
[1303] | 19 | wftool = context.portal_workflow |
---|
[1147] | 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) |
---|
[1158] | 27 | sbrain = context.students_catalog(id=student_id)[0] |
---|
[1243] | 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" |
---|
[1304] | 35 | ##else: |
---|
[1243] | 36 | ## sfc = res[0].getPath().split('/')[-4] |
---|
[1147] | 37 | info = {} |
---|
[1311] | 38 | info['site_id'] = '300100100' |
---|
[1257] | 39 | info['currency_id'] = '566' |
---|
[1243] | 40 | info['amount'] = amount |
---|
| 41 | info['type_code'] = sbrain.faculty |
---|
| 42 | info['type_description'] = description |
---|
[1224] | 43 | info['pay_bill_to'] = sbrain.name |
---|
| 44 | info['pay_ship_to'] = "University of Benin" |
---|
[1158] | 45 | info['student_id'] = student_id |
---|
| 46 | info['student_name'] = sbrain.name |
---|
| 47 | info['student_email'] = sbrain.email |
---|
[1226] | 48 | now = DateTime.DateTime() |
---|
[1243] | 49 | info['date'] = now |
---|
[1226] | 50 | order_id = info['order_id'] = "%d" % int(now.timeTime()*1000) |
---|
[1224] | 51 | info['order_id'] = "%s%s" % (student_id[1:],order_id) |
---|
| 52 | if "payments" not in student.objectIds(): |
---|
[1226] | 53 | student.invokeFactory('PaymentsFolder','payments') |
---|
[1224] | 54 | payments = getattr(student,'payments') |
---|
| 55 | d = {} |
---|
[1243] | 56 | d['Title'] = 'Payments' |
---|
[1226] | 57 | payments.getContent().edit(mapping=d) |
---|
[1243] | 58 | wftool.doActionFor(payments,'open') |
---|
[1224] | 59 | else: |
---|
| 60 | payments = getattr(student,'payments') |
---|
[1257] | 61 | if request.has_key('epayment'): |
---|
| 62 | return context.wema_form(info=info) |
---|
| 63 | |
---|
[1224] | 64 | p_id = "p%s" % order_id |
---|
| 65 | payments.invokeFactory('Payment', p_id) |
---|
| 66 | payment = getattr(payments,p_id) |
---|
[1303] | 67 | wftool.doActionFor(payment,'open') |
---|
[1224] | 68 | d = {} |
---|
| 69 | d.update(info) |
---|
[1243] | 70 | #from Products.zdb import set_trace;set_trace() |
---|
[1224] | 71 | payment.getContent().edit(mapping=d) |
---|
[1308] | 72 | #wftool.doActionFor(payment,'close') |
---|
[1304] | 73 | #wftool.doActionFor(student,'pay_school_fee') |
---|
[1224] | 74 | info['callback_url'] = "%s/payments/%s/epayment_cb" % (student.absolute_url(),p_id) |
---|
[1243] | 75 | if context.portal_url().find('uniben-demo.waeup.org') >-1 or\ |
---|
| 76 | context.portal_url().find('uniben.waeup.org') >-1: |
---|
[1235] | 77 | info['action'] = "http://www.wemaonlinepayments.biz/payment.aspx" |
---|
| 78 | else: |
---|
| 79 | info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id) |
---|
[1226] | 80 | logger.info('"%(student_id)s","%(type_description)s", "%(amount)s N"' % info) |
---|
[1257] | 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) |
---|