[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 1365 2007-01-26 22:05:40Z 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 |
---|
[1365] | 18 | |
---|
| 19 | if context.portal_membership.isAnonymousUser(): |
---|
| 20 | return None |
---|
| 21 | |
---|
[1147] | 22 | request = context.REQUEST |
---|
[1303] | 23 | wftool = context.portal_workflow |
---|
[1147] | 24 | students = context.portal_url.getPortalObject().campus.students |
---|
| 25 | |
---|
| 26 | student_id = context.getStudentId() |
---|
[1365] | 27 | student = getattr(students,student_id) |
---|
[1147] | 28 | |
---|
[1158] | 29 | sbrain = context.students_catalog(id=student_id)[0] |
---|
[1243] | 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" |
---|
[1304] | 37 | ##else: |
---|
[1243] | 38 | ## sfc = res[0].getPath().split('/')[-4] |
---|
[1147] | 39 | info = {} |
---|
[1311] | 40 | info['site_id'] = '300100100' |
---|
[1257] | 41 | info['currency_id'] = '566' |
---|
[1243] | 42 | info['amount'] = amount |
---|
| 43 | info['type_code'] = sbrain.faculty |
---|
| 44 | info['type_description'] = description |
---|
[1224] | 45 | info['pay_bill_to'] = sbrain.name |
---|
| 46 | info['pay_ship_to'] = "University of Benin" |
---|
[1158] | 47 | info['student_id'] = student_id |
---|
| 48 | info['student_name'] = sbrain.name |
---|
| 49 | info['student_email'] = sbrain.email |
---|
[1226] | 50 | now = DateTime.DateTime() |
---|
[1243] | 51 | info['date'] = now |
---|
[1226] | 52 | order_id = info['order_id'] = "%d" % int(now.timeTime()*1000) |
---|
[1224] | 53 | info['order_id'] = "%s%s" % (student_id[1:],order_id) |
---|
[1355] | 54 | p_id = "p%s" % order_id |
---|
| 55 | |
---|
[1362] | 56 | #from Products.zdb import set_trace;set_trace() |
---|
[1355] | 57 | if student_id is None: |
---|
| 58 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
[1365] | 59 | |
---|
[1355] | 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: |
---|
[1362] | 64 | #pass |
---|
| 65 | #return None |
---|
[1365] | 66 | info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id) |
---|
[1355] | 67 | |
---|
| 68 | |
---|
[1224] | 69 | if "payments" not in student.objectIds(): |
---|
[1226] | 70 | student.invokeFactory('PaymentsFolder','payments') |
---|
[1224] | 71 | payments = getattr(student,'payments') |
---|
| 72 | d = {} |
---|
[1243] | 73 | d['Title'] = 'Payments' |
---|
[1226] | 74 | payments.getContent().edit(mapping=d) |
---|
[1243] | 75 | wftool.doActionFor(payments,'open') |
---|
[1224] | 76 | else: |
---|
| 77 | payments = getattr(student,'payments') |
---|
[1257] | 78 | if request.has_key('epayment'): |
---|
| 79 | return context.wema_form(info=info) |
---|
| 80 | |
---|
[1355] | 81 | |
---|
[1224] | 82 | payments.invokeFactory('Payment', p_id) |
---|
| 83 | payment = getattr(payments,p_id) |
---|
[1303] | 84 | wftool.doActionFor(payment,'open') |
---|
[1224] | 85 | d = {} |
---|
| 86 | d.update(info) |
---|
[1243] | 87 | #from Products.zdb import set_trace;set_trace() |
---|
[1224] | 88 | payment.getContent().edit(mapping=d) |
---|
[1308] | 89 | #wftool.doActionFor(payment,'close') |
---|
[1304] | 90 | #wftool.doActionFor(student,'pay_school_fee') |
---|
[1224] | 91 | info['callback_url'] = "%s/payments/%s/epayment_cb" % (student.absolute_url(),p_id) |
---|
[1355] | 92 | |
---|
[1226] | 93 | logger.info('"%(student_id)s","%(type_description)s", "%(amount)s N"' % info) |
---|
[1257] | 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] |
---|
[1362] | 110 | info['args'] = args |
---|
| 111 | return context.goto_wema_form(info=info) |
---|
[1257] | 112 | url = info['action'] + "?" + urlencode(args) |
---|
| 113 | request.RESPONSE.redirect(url) |
---|