[2857] | 1 | ## Script (Python) "pay_interswitch_acco" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=paytype=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: pay_interswitch_acco.py 3778 2008-11-20 06:37:12Z henrik $ |
---|
| 11 | """ |
---|
| 12 | pay online |
---|
| 13 | """ |
---|
| 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
| 19 | from urllib import urlencode |
---|
| 20 | import logging |
---|
[2891] | 21 | logger = logging.getLogger('Skins.pay_interswitch_acco') |
---|
[2857] | 22 | import DateTime |
---|
| 23 | |
---|
| 24 | if context.portal_membership.isAnonymousUser(): |
---|
| 25 | return None |
---|
| 26 | |
---|
| 27 | request = context.REQUEST |
---|
| 28 | wftool = context.portal_workflow |
---|
| 29 | students = context.portal_url.getPortalObject().campus.students |
---|
| 30 | |
---|
| 31 | student_id = context.getStudentId() |
---|
| 32 | if student_id is None: |
---|
| 33 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 34 | student = getattr(students,student_id) |
---|
| 35 | |
---|
| 36 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 37 | #amount,description = context.getSchoolFee(student_record.faculty,student_record.session,student_record.course) |
---|
| 38 | now = DateTime.DateTime() |
---|
| 39 | timestamp = "%d" % int(now.timeTime()*1000) |
---|
| 40 | payment_id = "p%s" % timestamp |
---|
| 41 | hostel = paytype == "HOM" |
---|
| 42 | if hostel: |
---|
[3625] | 43 | info = context.getInterswitchParams(paytype,student,payment_id,student_record) |
---|
[2857] | 44 | info['student'] = student_record |
---|
[2967] | 45 | |
---|
[2857] | 46 | info['pay_bill_to'] = student_record.name |
---|
| 47 | info['student_id'] = student_id |
---|
| 48 | info['student_name'] = student_record.name |
---|
[2891] | 49 | info['session_id'] = student_record.session |
---|
[2857] | 50 | info['student_email'] = student_record.email |
---|
| 51 | info['date'] = now |
---|
| 52 | info['order_id'] = "%s%s" % (student_id[1:],timestamp) |
---|
| 53 | |
---|
| 54 | if "payments" not in student.objectIds(): |
---|
| 55 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 56 | payments = getattr(student,'payments') |
---|
| 57 | d = {} |
---|
| 58 | d['Title'] = 'Payments' |
---|
| 59 | payments.getContent().edit(mapping=d) |
---|
| 60 | wftool.doActionFor(payments,'open') |
---|
| 61 | else: |
---|
| 62 | payments = getattr(student,'payments') |
---|
| 63 | if request.has_key('epayment'): |
---|
| 64 | return context.interswitch_form(info=info) |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | payments.invokeFactory('Payment', payment_id) |
---|
| 68 | payment = getattr(payments,payment_id) |
---|
| 69 | wftool.doActionFor(payment,'open') |
---|
| 70 | d = {} |
---|
| 71 | d.update(info) |
---|
| 72 | payment.getContent().edit(mapping=d) |
---|
| 73 | #wftool.doActionFor(payment,'close') |
---|
| 74 | #wftool.doActionFor(student,'pay_school_fee') |
---|
| 75 | info['callback_url'] = "%s/payments/%s/%s?echo=%s" % (student.absolute_url(), |
---|
| 76 | payment_id, |
---|
| 77 | info['callback_function'], |
---|
| 78 | payment_id) |
---|
| 79 | |
---|
[2891] | 80 | logger.info('%(student_id)s initiated %(type_description)s payment with order_id %(order_id)s and callback url %(callback_url)s' % info) |
---|
[2857] | 81 | payment_fields = (('product_id','site_id'), |
---|
| 82 | ('site_name','site_name'), |
---|
| 83 | ('site_redirect_url','callback_url'), |
---|
| 84 | ('Currency','currency_id'), |
---|
| 85 | ('cust_id','student_id'), |
---|
| 86 | ('cust_id_desc','type_description'), |
---|
| 87 | ('cust_name','student_name'), |
---|
| 88 | ('txn_ref','order_id'), |
---|
| 89 | ('Amount','amount'), |
---|
| 90 | ('pay_item_id','pay_item_id'), |
---|
| 91 | ('pay_item_name','pay_item_name'), |
---|
| 92 | ('payment_params','payment_params'), |
---|
| 93 | ) |
---|
| 94 | args = {} |
---|
| 95 | for arg,field in payment_fields: |
---|
| 96 | args[arg] = info[field] |
---|
| 97 | interswitch_amount = int(info['surcharge'])*100 |
---|
| 98 | uni_amount = int(info['amount'])*100 |
---|
| 99 | total_amount = interswitch_amount + uni_amount |
---|
| 100 | args['Amount'] = "%d" % (total_amount) |
---|
| 101 | args['cust_name_desc'] = "Student Name" |
---|
[3778] | 102 | args['xml_data'] = info['xml_data'] ='' |
---|
[2857] | 103 | info['args'] = args |
---|
| 104 | return context.goto_interswitch_form(info=info) |
---|