435c20e3461d1457899c8427b1a8196d60b23f89
[indico-PayWay] / MaKaC / plugins / EPayment / payWay / epayment.py
1 # -*- coding: utf-8 -*-
2 ##
3 ##
4 ## This file is part of Indico.
5 ## Copyright (C) 2002 - 2014 European Organization for Nuclear Research (CERN).
6 ##
7 ## Indico is free software; you can redistribute it and/or
8 ## modify it under the terms of the GNU General Public License as
9 ## published by the Free Software Foundation; either version 3 of the
10 ## License, or (at your option) any later version.
11 ##
12 ## Indico is distributed in the hope that it will be useful, but
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 ## General Public License for more details.
16 ##
17 ## You should have received a copy of the GNU General Public License
18 ## along with Indico;if not, see <http://www.gnu.org/licenses/>.
19
20 from MaKaC.epayment import BaseEPayMod, BaseTransaction
21 import MaKaC.webinterface.urlHandlers as urlHandlers
22 from MaKaC.webinterface.common.tools import strip_ml_tags
23
24
25 from MaKaC.plugins.EPayment.payWay.webinterface import urlHandlers as localUrlHandlers
26 from MaKaC.plugins.EPayment.payWay import MODULE_ID
27
28 class PayWayMod(BaseEPayMod):
29
30     def __init__(self, data=None):
31         BaseEPayMod.__init__(self)
32         self._title = "payway"
33
34         self._url="https://www.payway.com/cgi-bin/webscr"
35         self._business= ""
36
37         if data is not None:
38             setValue(data)
39
40     def getId(self):
41         return MODULE_ID
42
43     def clone(self, newSessions):
44         sesf = PayWayMod()
45         sesf.setTitle(self.getTitle())
46         sesf.setUrl(self.getUrl())
47         sesf.setBusiness(self.getBusiness())
48
49         return sesf
50
51     def setValues(self, data):
52         self.setTitle(data.get("title", "epayment"))
53         self.setUrl(data.get("url", ""))
54         self.setBusiness(data["business"])
55
56     def getUrl(self):
57         return self._url
58     def setUrl(self,url):
59         self._url=url
60
61     def getBusiness(self):
62         return self._business
63     def setBusiness(self,business):
64         self._business= business
65
66     def getFormHTML(self,prix,Currency,conf,registrant,lang = "en_GB", secure=False):
67         url_return=localUrlHandlers.UHPayConfirmPayWay.getURL(registrant)
68         url_cancel_return=localUrlHandlers.UHPayCancelPayWay.getURL(registrant)
69         url_notify=localUrlHandlers.UHPayParamsPayWay.getURL(registrant)
70         s=""" <form action="%s" method="POST" id="%s">
71                         <input type="hidden" name="cmd" value="_xclick">
72                         <input type="hidden" name="business" value="%s">
73                         <input type="hidden" name="item_name" value="%s">
74                         <input type="hidden" name="amount" value="%s">
75                         <INPUT TYPE="hidden" NAME="currency_code" value="%s">
76                         <input type="hidden" name="charset" value="utf-8">
77                         <input type="hidden" name="return" value="%s">
78                         <input type="hidden" name="cancel_return" value="%s">
79                         <input type="hidden" name="notify_url" value="%s">
80                    </form>
81                        """%(self.getUrl(),self.getId(),self.getBusiness(), "%s: registration for %s"%(registrant.getFullName(),strip_ml_tags(conf.getTitle())),prix,Currency,\
82                             url_return,url_cancel_return,url_notify)
83         #s=cgi.escape(s)
84         return s
85
86     def getConfModifEPaymentURL(self, conf):
87         return localUrlHandlers.UHConfModifEPaymentPayWay.getURL(conf)
88
89
90
91 class TransactionPayWay(BaseTransaction):
92
93     def __init__(self,parms):
94         BaseTransaction.__init__(self)
95         self._Data=parms
96
97
98     def getId(self):
99         try:
100             if self._id:
101                 pass
102         except AttributeError, e:
103             self._id="payway"
104         return self._id
105
106     def getTransactionHTML(self):
107         return"""<table>
108                           <tr>
109                             <td align="right"><b>Payment with:</b></td>
110                             <td align="left">PayWay</td>
111                           </tr>
112                           <tr>
113                             <td align="right"><b>Payment Date:</b></td>
114                             <td align="left">%s</td>
115                           </tr>
116                           <tr>
117                             <td align="right"><b>Payment ID:</b></td>
118                             <td align="left">%s</td>
119                           </tr>
120                           <tr>
121                             <td align="right"><b>Order Total:</b></td>
122                             <td align="left">%s %s</td>
123                           </tr>
124                           <tr>
125                             <td align="right"><b>verify sign:</b></td>
126                             <td align="left">%s</td>
127                           </tr>
128                         </table>"""%(self._Data["payment_date"],self._Data["payer_id"], self._Data["mc_gross"], \
129                              self._Data["mc_currency"], self._Data["verify_sign"])
130     def getTransactionTxt(self):
131         return"""
132 \tPayment with:PayWay\n
133 \tPayment Date:%s\n
134 \tPayment ID:%s\n
135 \tOrder Total:%s %s\n
136 \tverify sign:%s
137 """%(self._Data["payment_date"],self._Data["payer_id"], self._Data["mc_gross"], \
138                              self._Data["mc_currency"], self._Data["verify_sign"])
139
140
141
142 def getPayMod():
143     return PayWayMod()
144
145 def getPayModClass():
146     return PayWayMod