[6910] | 1 | ## Script (Python) "pay_interswitch_accept" |
---|
| 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_interswitch_accept.py 6964 2011-10-29 12:30:52Z henrik $ |
---|
| 11 | """ |
---|
| 12 | pay online |
---|
| 13 | """ |
---|
| 14 | from urllib import urlencode |
---|
| 15 | import logging |
---|
| 16 | logger = logging.getLogger('Skins.pay_interswitch_accept') |
---|
| 17 | import DateTime |
---|
| 18 | |
---|
| 19 | if context.portal_membership.isAnonymousUser(): |
---|
| 20 | return None |
---|
| 21 | |
---|
| 22 | try: |
---|
| 23 | from Products.zdb import set_trace |
---|
| 24 | except: |
---|
| 25 | def set_trace(): |
---|
| 26 | pass |
---|
| 27 | request = context.REQUEST |
---|
| 28 | wftool = context.portal_workflow |
---|
| 29 | students = context.portal_url.getPortalObject().campus.students |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | student_id = context.getStudentId() |
---|
| 33 | student = getattr(students,student_id) |
---|
| 34 | |
---|
| 35 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 36 | |
---|
| 37 | info = {} |
---|
| 38 | info['student'] = student_record |
---|
| 39 | info['payment_possible'] = False |
---|
| 40 | info['amount'] = '' |
---|
| 41 | info['bank'] = '' |
---|
| 42 | info['type_description'] = '' |
---|
| 43 | info['pay_bill_to'] = '' |
---|
| 44 | fulltime = student_record.mode.endswith('_ft') |
---|
| 45 | |
---|
| 46 | info['site_id'] = '117' |
---|
| 47 | info['currency_id'] = '566' |
---|
| 48 | info['pay_item_id'] = '11706' |
---|
| 49 | |
---|
| 50 | info['bank'] = '' |
---|
| 51 | info['payment_possible'] = True |
---|
| 52 | info['type_description'] = 'Acceptance Fee' |
---|
| 53 | info['pay_bill_to'] = student_record.name |
---|
| 54 | info['student_id'] = student_id |
---|
| 55 | info['student_name'] = student_record.name |
---|
| 56 | info['type'] = 'online' |
---|
| 57 | info['status'] = 'started' |
---|
| 58 | info['session_id'] = student_record.session |
---|
| 59 | info['item'] = student_record.course |
---|
| 60 | info['category'] = 'acceptance' |
---|
| 61 | info['student_email'] = student_record.email |
---|
| 62 | now = DateTime.DateTime() |
---|
| 63 | info['date'] = now |
---|
| 64 | info['pay_ship_to'] = "Federal University of Technology, Minna, Nigeria" |
---|
| 65 | timestamp = "%d" % int(now.timeTime()*1000) |
---|
| 66 | info['order_id'] = "%s%s" % (student_id[1:],timestamp) |
---|
| 67 | p_id = "p%s" % timestamp |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | info['surcharge'] = 300 |
---|
[6964] | 71 | |
---|
| 72 | #students in faculties 'EET','ICT' and Department 'ARC' pay 25000 while others pay 20000 |
---|
| 73 | if student_record.faculty in ['EET','ICT'] or student_record.department in ['ARC']: |
---|
| 74 | info['acceptance_fee'] = 25000 |
---|
| 75 | else: |
---|
| 76 | info['acceptance_fee'] = 20000 |
---|
| 77 | |
---|
[6955] | 78 | info['amount'] = amount = info['acceptance_fee'] |
---|
[6964] | 79 | total_amount = 100*(info['amount'] + info['surcharge']) |
---|
[6910] | 80 | |
---|
| 81 | if student_id is None: |
---|
| 82 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 83 | |
---|
| 84 | if not student_record.review_state == 'admitted': |
---|
| 85 | return 'not allowed' |
---|
| 86 | |
---|
| 87 | info['action'] = "https://webpay.interswitchng.com/paydirect/webpay/pay.aspx" |
---|
[6964] | 88 | #info['action'] = "https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx" |
---|
[6910] | 89 | |
---|
| 90 | if "payments" not in student.objectIds(): |
---|
| 91 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 92 | payments = getattr(student,'payments') |
---|
| 93 | d = {} |
---|
| 94 | d['Title'] = 'Payments' |
---|
| 95 | payments.getContent().edit(mapping=d) |
---|
| 96 | wftool.doActionFor(payments,'open') |
---|
| 97 | else: |
---|
| 98 | payments = getattr(student,'payments') |
---|
| 99 | |
---|
| 100 | if request.has_key('epayment'): |
---|
| 101 | return context.interswitch_form_accept(info=info) |
---|
| 102 | |
---|
| 103 | payments.invokeFactory('Payment', p_id) |
---|
| 104 | payment = getattr(payments,p_id) |
---|
| 105 | wftool.doActionFor(payment,'open') |
---|
| 106 | d = {} |
---|
| 107 | d.update(info) |
---|
| 108 | payment.getContent().edit(mapping=d) |
---|
| 109 | |
---|
| 110 | info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(), |
---|
| 111 | p_id, |
---|
| 112 | p_id) |
---|
| 113 | |
---|
| 114 | logger.info('%(student_id)s initiated acceptance fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info) |
---|
| 115 | payment_fields = (('product_id','site_id'), |
---|
| 116 | ('site_redirect_url','callback_url'), |
---|
| 117 | ('Currency','currency_id'), |
---|
| 118 | ('cust_id','student_id'), |
---|
| 119 | ('cust_id_desc','type_description'), |
---|
| 120 | ('cust_name','student_name'), |
---|
| 121 | ('txn_ref','order_id'), |
---|
| 122 | ('Amount','amount'), |
---|
| 123 | ) |
---|
| 124 | args = {} |
---|
| 125 | for arg,field in payment_fields: |
---|
| 126 | args[arg] = info[field] |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | xmldict = {} |
---|
| 130 | xmldict['detail_ref'] = args['txn_ref'] |
---|
| 131 | xmldict['department'] = student_record.department |
---|
| 132 | xmldict['level'] = student_record.level |
---|
| 133 | xmldict['faculty'] = student_record.faculty |
---|
[6955] | 134 | xmldict['fut_amount'] = 100*amount |
---|
[6910] | 135 | |
---|
| 136 | |
---|
| 137 | xmltext = """<payment_item_detail> |
---|
| 138 | <item_details detail_ref="%(detail_ref)s" college="FUT Minna" department="%(department)s" faculty="%(faculty)s"> |
---|
| 139 | <item_detail item_id="1" item_name="FUT Minna Acceptance Fee" item_amt="%(fut_amount)s" bank_id="120" acct_num="1750005063" /> |
---|
| 140 | </item_details> |
---|
| 141 | </payment_item_detail>""" % xmldict |
---|
| 142 | |
---|
| 143 | info['xml_data'] = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 144 | |
---|
| 145 | args['Amount'] = "%d" % (total_amount) |
---|
| 146 | args['site_name'] = "futminna.waeup.org" |
---|
| 147 | args['cust_name_desc'] = "Student Name" |
---|
| 148 | args['pay_item_id'] = info['pay_item_id'] |
---|
| 149 | args['pay_item_name'] = "FUT Minna Acceptance Fee Payments" |
---|
| 150 | args['payment_params'] = 'college_split' |
---|
| 151 | #args['xml_data'] = '' |
---|
| 152 | #args['xml_data'] = xmltext # info['xml_data']can be used instead |
---|
| 153 | info['args'] = args |
---|
| 154 | |
---|
[6955] | 155 | return context.goto_interswitch_form_accept(info=info) |
---|