source: WAeUP_SRP/trunk/skins/waeup_futminna/pay_interswitch_accept.py @ 12065

Last change on this file since 12065 was 6983, checked in by Henrik Bettermann, 13 years ago

See last revision. This was missing.

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