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

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

Fiddle with Interswitch surcharge which is, in contrast to school fee payment, not included in the FUTMinna amount.

  • 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 6955 2011-10-26 08:04:39Z 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']
73total_amount = 100*(int(amount) + info['surcharge'])
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"
82info['action'] = "https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx"
83
84if "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')
91else:
92    payments = getattr(student,'payments')
93
94if request.has_key('epayment'):
95    return context.interswitch_form_accept(info=info)
96
97payments.invokeFactory('Payment', p_id)
98payment = getattr(payments,p_id)
99wftool.doActionFor(payment,'open')
100d = {}
101d.update(info)
102payment.getContent().edit(mapping=d)
103
104info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(),
105                                                                  p_id,
106                                                                  p_id)
107
108logger.info('%(student_id)s initiated acceptance fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
109payment_fields = (('product_id','site_id'),
110                  ('site_redirect_url','callback_url'),
111                  ('Currency','currency_id'),
112                  ('cust_id','student_id'),
113                  ('cust_id_desc','type_description'),
114                  ('cust_name','student_name'),
115                  ('txn_ref','order_id'),
116                  ('Amount','amount'),
117                  )
118args = {}
119for arg,field in payment_fields:
120    args[arg] = info[field]
121
122
123xmldict = {}
124xmldict['detail_ref'] = args['txn_ref']
125xmldict['department'] = student_record.department
126xmldict['level'] = student_record.level
127xmldict['faculty'] = student_record.faculty
128xmldict['fut_amount'] = 100*amount
129
130
131xmltext = """<payment_item_detail>
132<item_details detail_ref="%(detail_ref)s" college="FUT Minna" department="%(department)s" faculty="%(faculty)s">
133<item_detail item_id="1" item_name="FUT Minna Acceptance Fee" item_amt="%(fut_amount)s" bank_id="120" acct_num="1750005063" />
134</item_details>
135</payment_item_detail>""" % xmldict
136
137info['xml_data'] = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
138
139args['Amount'] = "%d" % (total_amount)
140args['site_name'] = "futminna.waeup.org"
141args['cust_name_desc'] = "Student Name"
142args['pay_item_id'] = info['pay_item_id']
143args['pay_item_name'] = "FUT Minna Acceptance Fee Payments"
144args['payment_params'] = 'college_split'
145#args['xml_data'] = ''
146#args['xml_data'] = xmltext   # info['xml_data']can be used instead
147info['args'] = args
148
149return context.goto_interswitch_form_accept(info=info)
Note: See TracBrowser for help on using the repository browser.