[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 2967 2007-12-28 16:38:37Z 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: |
---|
| 43 | info = context.getInterswitchParams(paytype,student,payment_id) |
---|
| 44 | info['student'] = student_record |
---|
[2967] | 45 | |
---|
| 46 | #else: |
---|
| 47 | # info = {} |
---|
| 48 | # info['student'] = student_record |
---|
| 49 | # info['payment_possible'] = False |
---|
| 50 | # info['amount'] = '0' |
---|
| 51 | # info['bank'] = '' |
---|
| 52 | # info['type_description'] = '' |
---|
| 53 | # info['pay_bill_to'] = '' |
---|
| 54 | # fee_dict = context.getSchoolFee(student_record) |
---|
| 55 | # fulltime = student_record.mode.endswith('_ft') |
---|
| 56 | # new = student_record.review_state == 'cleared_and_validated' |
---|
| 57 | # returning = student_record.review_state == 'returning' |
---|
| 58 | # if not fee_dict or (not new and fulltime) or not (new or returning): |
---|
| 59 | # return context.interswitch_form(info=info) |
---|
| 60 | # if new: |
---|
| 61 | # amount = info['amount'] = fee_dict['new'] |
---|
| 62 | # elif returning: |
---|
| 63 | # amount = info['amount'] = fee_dict['returning'] |
---|
| 64 | # if fulltime: |
---|
| 65 | # pay_item_id = "6100" |
---|
| 66 | # #info['type_code'] = student_record.faculty #type_code is redundant and will be removed soon |
---|
| 67 | # info['bank'] = '' |
---|
| 68 | # else: |
---|
| 69 | # pay_item_id = "6101" |
---|
| 70 | # #info['type_code'] = student_record.course #type_code is redundant and will be removed soon |
---|
| 71 | # info['bank'] = '' |
---|
| 72 | # info['payment_possible'] = True |
---|
| 73 | # info['type_description'] = fee_dict['description'] |
---|
| 74 | # info['pay_ship_to'] = "University of Benin" |
---|
| 75 | |
---|
[2857] | 76 | info['pay_bill_to'] = student_record.name |
---|
| 77 | info['student_id'] = student_id |
---|
| 78 | info['student_name'] = student_record.name |
---|
[2891] | 79 | info['session_id'] = student_record.session |
---|
[2857] | 80 | info['student_email'] = student_record.email |
---|
| 81 | info['date'] = now |
---|
| 82 | info['order_id'] = "%s%s" % (student_id[1:],timestamp) |
---|
| 83 | |
---|
| 84 | if "payments" not in student.objectIds(): |
---|
| 85 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 86 | payments = getattr(student,'payments') |
---|
| 87 | d = {} |
---|
| 88 | d['Title'] = 'Payments' |
---|
| 89 | payments.getContent().edit(mapping=d) |
---|
| 90 | wftool.doActionFor(payments,'open') |
---|
| 91 | else: |
---|
| 92 | payments = getattr(student,'payments') |
---|
| 93 | if request.has_key('epayment'): |
---|
| 94 | return context.interswitch_form(info=info) |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | payments.invokeFactory('Payment', payment_id) |
---|
| 98 | payment = getattr(payments,payment_id) |
---|
| 99 | wftool.doActionFor(payment,'open') |
---|
| 100 | d = {} |
---|
| 101 | d.update(info) |
---|
| 102 | payment.getContent().edit(mapping=d) |
---|
| 103 | #wftool.doActionFor(payment,'close') |
---|
| 104 | #wftool.doActionFor(student,'pay_school_fee') |
---|
| 105 | info['callback_url'] = "%s/payments/%s/%s?echo=%s" % (student.absolute_url(), |
---|
| 106 | payment_id, |
---|
| 107 | info['callback_function'], |
---|
| 108 | payment_id) |
---|
| 109 | |
---|
[2891] | 110 | logger.info('%(student_id)s initiated %(type_description)s payment with order_id %(order_id)s and callback url %(callback_url)s' % info) |
---|
[2857] | 111 | payment_fields = (('product_id','site_id'), |
---|
| 112 | ('site_name','site_name'), |
---|
| 113 | ('site_redirect_url','callback_url'), |
---|
| 114 | ('Currency','currency_id'), |
---|
| 115 | ('cust_id','student_id'), |
---|
| 116 | ('cust_id_desc','type_description'), |
---|
| 117 | ('cust_name','student_name'), |
---|
| 118 | ('txn_ref','order_id'), |
---|
| 119 | ('Amount','amount'), |
---|
| 120 | ('pay_item_id','pay_item_id'), |
---|
| 121 | ('pay_item_name','pay_item_name'), |
---|
| 122 | ('payment_params','payment_params'), |
---|
| 123 | ) |
---|
| 124 | args = {} |
---|
| 125 | for arg,field in payment_fields: |
---|
| 126 | args[arg] = info[field] |
---|
| 127 | interswitch_amount = int(info['surcharge'])*100 |
---|
| 128 | uni_amount = int(info['amount'])*100 |
---|
| 129 | total_amount = interswitch_amount + uni_amount |
---|
| 130 | args['Amount'] = "%d" % (total_amount) |
---|
| 131 | args['cust_name_desc'] = "Student Name" |
---|
| 132 | args['xml_data'] = '' |
---|
| 133 | info['args'] = args |
---|
| 134 | return context.goto_interswitch_form(info=info) |
---|