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 | """ |
---|
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 |
---|
71 | info['acceptance_fee'] = 20000 |
---|
72 | info['amount'] = amount = info['acceptance_fee'] |
---|
73 | total_amount = 100*(int(amount) + info['surcharge']) |
---|
74 | |
---|
75 | if student_id is None: |
---|
76 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
77 | |
---|
78 | if not student_record.review_state == 'admitted': |
---|
79 | return 'not allowed' |
---|
80 | |
---|
81 | info['action'] = "https://webpay.interswitchng.com/paydirect/webpay/pay.aspx" |
---|
82 | info['action'] = "https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx" |
---|
83 | |
---|
84 | if "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') |
---|
91 | else: |
---|
92 | payments = getattr(student,'payments') |
---|
93 | |
---|
94 | if request.has_key('epayment'): |
---|
95 | return context.interswitch_form_accept(info=info) |
---|
96 | |
---|
97 | payments.invokeFactory('Payment', p_id) |
---|
98 | payment = getattr(payments,p_id) |
---|
99 | wftool.doActionFor(payment,'open') |
---|
100 | d = {} |
---|
101 | d.update(info) |
---|
102 | payment.getContent().edit(mapping=d) |
---|
103 | |
---|
104 | info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(), |
---|
105 | p_id, |
---|
106 | p_id) |
---|
107 | |
---|
108 | logger.info('%(student_id)s initiated acceptance fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info) |
---|
109 | payment_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 | ) |
---|
118 | args = {} |
---|
119 | for arg,field in payment_fields: |
---|
120 | args[arg] = info[field] |
---|
121 | |
---|
122 | |
---|
123 | xmldict = {} |
---|
124 | xmldict['detail_ref'] = args['txn_ref'] |
---|
125 | xmldict['department'] = student_record.department |
---|
126 | xmldict['level'] = student_record.level |
---|
127 | xmldict['faculty'] = student_record.faculty |
---|
128 | xmldict['fut_amount'] = 100*amount |
---|
129 | |
---|
130 | |
---|
131 | xmltext = """<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 | |
---|
137 | info['xml_data'] = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
138 | |
---|
139 | args['Amount'] = "%d" % (total_amount) |
---|
140 | args['site_name'] = "futminna.waeup.org" |
---|
141 | args['cust_name_desc'] = "Student Name" |
---|
142 | args['pay_item_id'] = info['pay_item_id'] |
---|
143 | args['pay_item_name'] = "FUT Minna Acceptance Fee Payments" |
---|
144 | args['payment_params'] = 'college_split' |
---|
145 | #args['xml_data'] = '' |
---|
146 | #args['xml_data'] = xmltext # info['xml_data']can be used instead |
---|
147 | info['args'] = args |
---|
148 | |
---|
149 | return context.goto_interswitch_form_accept(info=info) |
---|