[5599] | 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 5628 2011-01-10 15:00:05Z 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 |
---|
| 21 | logger = logging.getLogger('Skins.pay_interswitch_acco') |
---|
| 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 |
---|
[5603] | 41 | order_id = "%s%s" % (student_id[1:],timestamp) |
---|
[5628] | 42 | hostel = paytype in ('HOM','HOMH',) |
---|
[5599] | 43 | if hostel: |
---|
[5603] | 44 | info = context.getInterswitchParams(paytype,student,payment_id,order_id,student_record) |
---|
[5599] | 45 | info['student'] = student_record |
---|
| 46 | else: |
---|
| 47 | return None |
---|
| 48 | |
---|
| 49 | info['pay_bill_to'] = student_record.name |
---|
| 50 | info['student_id'] = student_id |
---|
| 51 | info['student_name'] = student_record.name |
---|
| 52 | info['session_id'] = student_record.session |
---|
| 53 | info['student_email'] = student_record.email |
---|
| 54 | info['date'] = now |
---|
[5603] | 55 | info['order_id'] = order_id |
---|
[5599] | 56 | |
---|
| 57 | if "payments" not in student.objectIds(): |
---|
| 58 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 59 | payments = getattr(student,'payments') |
---|
| 60 | d = {} |
---|
| 61 | d['Title'] = 'Payments' |
---|
| 62 | payments.getContent().edit(mapping=d) |
---|
| 63 | wftool.doActionFor(payments,'open') |
---|
| 64 | else: |
---|
| 65 | payments = getattr(student,'payments') |
---|
| 66 | if request.has_key('epayment'): |
---|
| 67 | return context.interswitch_form(info=info) |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | payments.invokeFactory('Payment', payment_id) |
---|
| 71 | payment = getattr(payments,payment_id) |
---|
| 72 | wftool.doActionFor(payment,'open') |
---|
| 73 | d = {} |
---|
| 74 | d.update(info) |
---|
| 75 | payment.getContent().edit(mapping=d) |
---|
| 76 | #wftool.doActionFor(payment,'close') |
---|
| 77 | #wftool.doActionFor(student,'pay_school_fee') |
---|
| 78 | info['callback_url'] = "%s/payments/%s/%s?echo=%s" % (student.absolute_url(), |
---|
| 79 | payment_id, |
---|
| 80 | info['callback_function'], |
---|
| 81 | payment_id) |
---|
| 82 | |
---|
| 83 | logger.info('%(student_id)s initiated %(type_description)s payment with order_id %(order_id)s and callback url %(callback_url)s' % info) |
---|
| 84 | payment_fields = (('product_id','site_id'), |
---|
| 85 | ('site_name','site_name'), |
---|
| 86 | ('site_redirect_url','callback_url'), |
---|
| 87 | ('Currency','currency_id'), |
---|
| 88 | ('cust_id','student_id'), |
---|
| 89 | ('cust_id_desc','type_description'), |
---|
| 90 | ('cust_name','student_name'), |
---|
| 91 | ('txn_ref','order_id'), |
---|
| 92 | ('Amount','amount'), |
---|
| 93 | ('pay_item_id','pay_item_id'), |
---|
| 94 | ('pay_item_name','pay_item_name'), |
---|
| 95 | ('payment_params','payment_params'), |
---|
[5601] | 96 | #('xml_data','xml_data'), |
---|
[5599] | 97 | ) |
---|
| 98 | args = {} |
---|
| 99 | for arg,field in payment_fields: |
---|
| 100 | args[arg] = info[field] |
---|
| 101 | interswitch_amount = int(info['surcharge'])*100 |
---|
| 102 | uni_amount = int(info['amount'])*100 |
---|
| 103 | total_amount = interswitch_amount + uni_amount |
---|
| 104 | args['Amount'] = "%d" % (total_amount) |
---|
| 105 | args['cust_name_desc'] = "Student Name" |
---|
| 106 | info['args'] = args |
---|
| 107 | return context.goto_interswitch_form(info=info) |
---|