[3841] | 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_interswitch.py 2619 2007-11-10 17:39:36Z henrik $ |
---|
| 11 | """ |
---|
| 12 | pay online |
---|
| 13 | """ |
---|
| 14 | from urllib import urlencode |
---|
| 15 | import logging |
---|
| 16 | logger = logging.getLogger('Skins.pay_interswitch') |
---|
| 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 | info = {} |
---|
| 37 | info['student'] = student_record |
---|
| 38 | info['payment_possible'] = False |
---|
| 39 | info['amount'] = '0' |
---|
| 40 | info['bank'] = '' |
---|
| 41 | info['type_description'] = '' |
---|
| 42 | info['pay_bill_to'] = '' |
---|
| 43 | fee_dict = context.getSchoolFee(student_record) |
---|
| 44 | fulltime = student_record.mode.endswith('_ft') |
---|
| 45 | |
---|
| 46 | if not fee_dict: |
---|
| 47 | return context.interswitch_form(info=info) |
---|
| 48 | |
---|
[3898] | 49 | info['site_id'] = '119' |
---|
[3841] | 50 | info['currency_id'] = '566' |
---|
[3872] | 51 | pay_item_id = "11900" |
---|
[3841] | 52 | |
---|
| 53 | #info['type_code'] = sbrain.course #type_code is redundant and will be removed soon |
---|
| 54 | info['bank'] = '' |
---|
| 55 | info['payment_possible'] = True |
---|
| 56 | info['type_description'] = fee_dict['description'] |
---|
| 57 | info['pay_bill_to'] = student_record.name |
---|
| 58 | info['student_id'] = student_id |
---|
| 59 | info['student_name'] = student_record.name |
---|
| 60 | info['type'] = 'online' |
---|
| 61 | info['status'] = 'started' |
---|
| 62 | info['session_id'] = fee_dict['next_session_id'] |
---|
| 63 | info['item'] = student_record.course |
---|
| 64 | info['category'] = 'schoolfee' |
---|
| 65 | info['student_email'] = student_record.email |
---|
| 66 | now = DateTime.DateTime() |
---|
| 67 | info['date'] = now |
---|
[3872] | 68 | info['pay_ship_to'] = "Ambrose Alli University Ekpoma" |
---|
[3841] | 69 | timestamp = "%d" % int(now.timeTime()*1000) |
---|
| 70 | info['order_id'] = "%s%s" % (student_id[1:],timestamp) |
---|
| 71 | p_id = "p%s" % timestamp |
---|
[3872] | 72 | info['surcharge'] = interswitch_amount = 300 |
---|
[3898] | 73 | amount = fee_dict['all'] |
---|
[3841] | 74 | |
---|
[3898] | 75 | bt_amount = 4000 |
---|
| 76 | aaue_split = 1000 |
---|
| 77 | info['amount'] = amount + bt_amount + aaue_split |
---|
| 78 | |
---|
[3841] | 79 | if student_id is None: |
---|
| 80 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 81 | |
---|
| 82 | if True: |
---|
[3906] | 83 | info['action'] = "https://webpay.interswitchng.com/paydirect/webpay/pay.aspx" |
---|
[3841] | 84 | else: |
---|
| 85 | #pass |
---|
| 86 | #return None |
---|
| 87 | info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id) |
---|
| 88 | |
---|
| 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 | if request.has_key('epayment'): |
---|
| 100 | return context.interswitch_form(info=info) |
---|
| 101 | |
---|
| 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 | |
---|
| 111 | info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(), |
---|
| 112 | p_id, |
---|
| 113 | p_id) |
---|
[3872] | 114 | |
---|
[3841] | 115 | |
---|
[3872] | 116 | |
---|
| 117 | |
---|
[3841] | 118 | logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info) |
---|
| 119 | payment_fields = (('product_id','site_id'), |
---|
| 120 | ('site_redirect_url','callback_url'), |
---|
| 121 | ('Currency','currency_id'), |
---|
| 122 | ('cust_id','student_id'), |
---|
| 123 | ('cust_id_desc','type_description'), |
---|
| 124 | ('cust_name','student_name'), |
---|
| 125 | ('txn_ref','order_id'), |
---|
| 126 | ('Amount','amount'), |
---|
| 127 | ) |
---|
| 128 | args = {} |
---|
| 129 | for arg,field in payment_fields: |
---|
| 130 | args[arg] = info[field] |
---|
| 131 | |
---|
| 132 | |
---|
[3898] | 133 | |
---|
[3872] | 134 | #getSchoolFee provides pure school fee, the other fees have to be added |
---|
[3898] | 135 | total_amount = 100* (amount + interswitch_amount + bt_amount + aaue_split) |
---|
[3872] | 136 | |
---|
| 137 | |
---|
[3898] | 138 | |
---|
[3841] | 139 | xmldict = {} |
---|
| 140 | xmldict['detail_ref'] = args['txn_ref'] |
---|
| 141 | xmldict['department'] = student_record.department |
---|
| 142 | xmldict['faculty'] = student_record.faculty |
---|
[3872] | 143 | xmldict['amount'] = "%d" % int(100*amount) |
---|
[3841] | 144 | xmldict['bt_amount'] = "%d" % int(100*bt_amount) |
---|
[3872] | 145 | |
---|
[4021] | 146 | if student_record.mode in ('ug_ft','ug_pt','pg_ft','pgd_ft'): |
---|
[3872] | 147 | xmldict['aaue_acct'] = "6020008887" |
---|
| 148 | xmldict['bank_id'] = '123' |
---|
[3841] | 149 | else: |
---|
[3872] | 150 | xmldict['aaue_acct'] = "0000000000000" |
---|
| 151 | xmldict['bank_id'] = '0' |
---|
[3841] | 152 | |
---|
[3872] | 153 | xmldict['aaue_split'] = "%d" % int(100*aaue_split) |
---|
[3841] | 154 | |
---|
| 155 | xmltext = """<payment_item_detail> |
---|
[3872] | 156 | <item_details detail_ref="%(detail_ref)s" college="aaue" department="%(department)s" faculty="%(faculty)s" > |
---|
| 157 | <item_detail item_id="1" item_name="AAUE School Fee" item_amt="%(amount)s" bank_id="123" acct_num="6020008887" /> |
---|
| 158 | <item_detail item_id="2" item_name="AAUE Split" item_amt="%(aaue_split)s" bank_id="123" acct_num="6020008887" /> |
---|
[4014] | 159 | <item_detail item_id="3" item_name="BT" item_amt="%(bt_amount)s" bank_id="117" acct_num="6012015294" /> |
---|
[3841] | 160 | </item_details> |
---|
| 161 | </payment_item_detail>""" % xmldict |
---|
| 162 | |
---|
| 163 | info['xml_data'] = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 164 | |
---|
| 165 | args['Amount'] = "%d" % (total_amount) |
---|
| 166 | args['site_name'] = "aaue.waeup.org" |
---|
| 167 | args['cust_name_desc'] = "Student Name" |
---|
| 168 | args['pay_item_id'] = pay_item_id |
---|
[3872] | 169 | args['pay_item_name'] = "Ambrose Alli University Ekpoma Tuition Payments" |
---|
[3841] | 170 | args['payment_params'] = 'college_split' |
---|
| 171 | #args['xml_data'] = '' |
---|
[5255] | 172 | #args['xml_data'] = xmltext # info['xml_data']can be used instead |
---|
[3841] | 173 | info['args'] = args |
---|
| 174 | |
---|
[4021] | 175 | return context.goto_interswitch_form(info=info) |
---|