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