1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 package fr.paris.lutece.plugins.tipi.business;
41
42 import java.io.File;
43 import java.io.Serializable;
44 import java.math.BigDecimal;
45 import java.rmi.RemoteException;
46 import java.text.ParseException;
47 import java.util.Date;
48
49 import javax.servlet.http.HttpServletRequest;
50 import javax.xml.rpc.ServiceException;
51
52 import org.apache.commons.lang.StringUtils;
53
54 import fr.paris.lutece.plugins.tipi.util.Constants;
55 import fr.paris.lutece.plugins.tipi.util.Utils;
56 import fr.paris.lutece.portal.service.spring.SpringContextService;
57 import fr.paris.lutece.portal.service.util.AppLogService;
58 import fr.paris.lutece.portal.service.util.AppPropertiesService;
59 import fr.paris.tipi.generated.CreerPaiementSecuriseRequest;
60 import fr.paris.tipi.generated.RecupererDetailPaiementSecuriseRequest;
61 import fr.paris.vdp.tipi.create.url.utils.PaiementUtils;
62 import fr.paris.vdp.tipi.create.url.webservice.CreateURLWebService;
63 import fr.paris.vdp.tipi.create.url.webservice.ParametresPaiementTipi;
64
65
66
67
68 public class Tipi implements Serializable
69 {
70 private static final long serialVersionUID = 7173528813310268296L;
71
72 private static final String TRUSTSTORE = "tipi.ssl.truststore";
73 private static final String TRUSTSTORE_PASSWORD = "tipi.ssl.truststore.password";
74 private static final String KEYSTORE = "tipi.ssl.keystore";
75 private static final String KEYSTORE_PASSWORD = "tipi.ssl.keystore.password";
76
77 private static final String URLWSDL = "tipi.urlwsdl";
78
79 private static final String CLIENT = "client";
80 private static final String URL_TYPE = "tipi.url";
81
82 private String identifier;
83 private ParametresPaiementTipi parameters;
84
85 private TipiProcessor processor = SpringContextService.getBean( "tipiProcessor" );
86
87
88
89
90 private Tipi( )
91 {
92
93 this.setCertificateValues( );
94 }
95
96
97
98
99
100 private static Tipi newInstance( )
101 {
102 return new Tipi( );
103 }
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 public static Tipi create( String email, String refDet, BigDecimal amount ) throws RemoteException, ServiceException
119 {
120 Tipi tipi = newInstance( );
121
122 final String urlWsdl = getWsdlUrl( );
123
124 final CreerPaiementSecuriseRequest request = TipiRequestFactory.createRequest( email, refDet, amount );
125
126 AppLogService.debug( "url du webservice : " + urlWsdl );
127 AppLogService.debug( "parametre de la requete : " + Utils.object2String( request ) );
128
129 tipi.identifier = new CreateURLWebService( ).appelWebServiceCreerPaiement( urlWsdl, request );
130
131 return tipi;
132 }
133
134
135
136
137
138
139
140
141
142
143 public static Tipi read( String idOp ) throws ServiceException, RemoteException
144 {
145 Tipi tipi = newInstance( );
146
147 final String urlWsdl = getWsdlUrl( );
148
149 RecupererDetailPaiementSecuriseRequest request = new RecupererDetailPaiementSecuriseRequest( );
150 request.setIdOp( idOp );
151
152 AppLogService.debug( "url du webservice : " + urlWsdl );
153 AppLogService.debug( "parametre de la requete : " + Utils.object2String( request ) );
154
155 tipi.identifier = idOp;
156 tipi.parameters = new CreateURLWebService( ).appelWebserviceDetailPaiement( request, urlWsdl );
157
158 return tipi;
159 }
160
161
162
163
164
165
166
167
168
169
170 public static Tipi read( HttpServletRequest request ) throws RemoteException, ServiceException
171 {
172 String idOp = request.getParameter( "idOp" );
173
174 if ( StringUtils.isBlank( idOp ) )
175 {
176 idOp = String.valueOf( request.getParameter( "idop" ) );
177 }
178
179 if ( StringUtils.isBlank( idOp ) )
180 {
181 AppLogService.error( "echec traitement servlet, idOp is null" );
182 return null;
183 }
184
185 return read( idOp );
186 }
187
188
189
190
191
192 private static final String getWsdlUrl( )
193 {
194 return AppPropertiesService.getProperty( URLWSDL );
195 }
196
197
198
199
200 private final void setCertificateValues( )
201 {
202
203 if ( AppPropertiesService.getProperty( KEYSTORE ).isEmpty( ) )
204 {
205 File file = new File( getClass( ).getClassLoader( ).getResource( "security/cacerts" ).getFile( ) );
206 System.setProperty( "javax.net.ssl.trustStore", file.getAbsolutePath( ) );
207 System.setProperty( "javax.net.ssl.keyStore", file.getAbsolutePath( ) );
208 } else
209 {
210 System.setProperty( "javax.net.ssl.trustStore", AppPropertiesService.getProperty( TRUSTSTORE ) );
211 System.setProperty( "javax.net.ssl.keyStore", AppPropertiesService.getProperty( KEYSTORE ) );
212 }
213
214 System.setProperty( "javax.net.ssl.trustStorePassword", AppPropertiesService.getProperty( TRUSTSTORE_PASSWORD ) );
215 System.setProperty( "javax.net.ssl.keyStorePassword", AppPropertiesService.getProperty( KEYSTORE_PASSWORD ) );
216 }
217
218
219
220
221
222
223 public ParametresPaiementTipi getParameters( )
224 {
225 return parameters;
226 }
227
228
229
230
231
232
233 public Date getDate( )
234 {
235 Date date = null;
236
237 if ( parameters != null )
238 {
239 try
240 {
241 date = PaiementUtils.constructDate( parameters.getDatTrans( ), parameters.getHeurTrans( ) );
242 } catch ( ParseException e )
243 {
244
245 }
246 }
247
248 return date;
249 }
250
251
252
253
254
255
256
257
258
259 public static ParametresPaiementTipi getParameters( String idop ) throws RemoteException, ServiceException
260 {
261 return read( idop ).getParameters( );
262 }
263
264
265
266
267
268
269 public boolean isPaymentSuccess( )
270 {
271 return Constants.PAYMENT_SUCCESS.equals( parameters.getResultrans( ) );
272 }
273
274
275
276
277
278
279 public boolean isPaymentDenied( )
280 {
281 return Constants.PAYMENT_DENIED.equals( parameters.getResultrans( ) );
282 }
283
284
285
286
287
288
289 public boolean isPaymentCancelled( )
290 {
291 return Constants.PAYMENT_CANCELLED.equals( parameters.getResultrans( ) );
292 }
293
294
295
296
297
298
299 public Tipi process( )
300 {
301 if ( this.processor == null )
302 {
303 AppLogService.info( "Aucun handler n'a été défini pour gérer le retour du service Tipi" );
304 } else
305 {
306 this.processor.process( this );
307 }
308
309 return this;
310 }
311
312 public String getLink( )
313 {
314 Boolean isClient = CLIENT.equals( AppPropertiesService.getProperty( URL_TYPE ) );
315 return Utils.getUrlApplicationTipi( identifier, isClient );
316 }
317
318
319
320
321
322
323 public String getIdentifier( )
324 {
325 return identifier;
326 }
327 }