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

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

Implement FUTMinna acceptance fee payment.

  • Property svn:keywords set to Id
File size: 4.6 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 6910 2011-10-19 06:56:47Z 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
71info['acceptance_fee'] = 20000
72info['amount'] = amount = info['acceptance_fee'] + info['surcharge']
73total_amount = 100*int(amount)
74
75if student_id is None:
76    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
77
78if not student_record.review_state == 'admitted':
79    return 'not allowed'
80
81info['action'] = "https://webpay.interswitchng.com/paydirect/webpay/pay.aspx"
82
83if "payments" not in student.objectIds():
84    student.invokeFactory('PaymentsFolder','payments')
85    payments = getattr(student,'payments')
86    d = {}
87    d['Title'] = 'Payments'
88    payments.getContent().edit(mapping=d)
89    wftool.doActionFor(payments,'open')
90else:
91    payments = getattr(student,'payments')
92
93if request.has_key('epayment'):
94    return context.interswitch_form_accept(info=info)
95
96payments.invokeFactory('Payment', p_id)
97payment = getattr(payments,p_id)
98wftool.doActionFor(payment,'open')
99d = {}
100d.update(info)
101payment.getContent().edit(mapping=d)
102
103info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(),
104                                                                  p_id,
105                                                                  p_id)
106
107logger.info('%(student_id)s initiated acceptance fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
108payment_fields = (('product_id','site_id'),
109                  ('site_redirect_url','callback_url'),
110                  ('Currency','currency_id'),
111                  ('cust_id','student_id'),
112                  ('cust_id_desc','type_description'),
113                  ('cust_name','student_name'),
114                  ('txn_ref','order_id'),
115                  ('Amount','amount'),
116                  )
117args = {}
118for arg,field in payment_fields:
119    args[arg] = info[field]
120
121
122interswitch_amount = 300
123fut_amount = amount - interswitch_amount
124
125xmldict = {}
126xmldict['detail_ref'] = args['txn_ref']
127xmldict['department'] = student_record.department
128xmldict['level'] = student_record.level
129xmldict['faculty'] = student_record.faculty
130xmldict['fut_amount'] = "%d" % int(100*fut_amount)
131
132
133xmltext = """<payment_item_detail>
134<item_details detail_ref="%(detail_ref)s" college="FUT Minna" department="%(department)s" faculty="%(faculty)s">
135<item_detail item_id="1" item_name="FUT Minna Acceptance Fee" item_amt="%(fut_amount)s" bank_id="120" acct_num="1750005063" />
136</item_details>
137</payment_item_detail>""" % xmldict
138
139info['xml_data'] = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
140
141args['Amount'] = "%d" % (total_amount)
142args['site_name'] = "futminna.waeup.org"
143args['cust_name_desc'] = "Student Name"
144args['pay_item_id'] = info['pay_item_id']
145args['pay_item_name'] = "FUT Minna Acceptance Fee Payments"
146args['payment_params'] = 'college_split'
147#args['xml_data'] = ''
148#args['xml_data'] = xmltext   # info['xml_data']can be used instead
149info['args'] = args
150
151return context.goto_interswitch_form(info=info)
Note: See TracBrowser for help on using the repository browser.