View Javadoc
1   /*
2    *
3    *  * Copyright (c) 2002-2017, Mairie de Paris
4    *  * All rights reserved.
5    *  *
6    *  * Redistribution and use in source and binary forms, with or without
7    *  * modification, are permitted provided that the following conditions
8    *  * are met:
9    *  *
10   *  *  1. Redistributions of source code must retain the above copyright notice
11   *  *     and the following disclaimer.
12   *  *
13   *  *  2. Redistributions in binary form must reproduce the above copyright notice
14   *  *     and the following disclaimer in the documentation and/or other materials
15   *  *     provided with the distribution.
16   *  *
17   *  *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
18   *  *     contributors may be used to endorse or promote products derived from
19   *  *     this software without specific prior written permission.
20   *  *
21   *  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22   *  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   *  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24   *  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25   *  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   *  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   *  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28   *  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29   *  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30   *  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31   *  * POSSIBILITY OF SUCH DAMAGE.
32   *  *
33   *  * License 1.0
34   *
35   */
36  
37  package fr.paris.lutece.plugins.tipi.business;
38  
39  import java.io.Serializable;
40  import java.security.InvalidParameterException;
41  import java.util.List;
42  
43  import org.apache.commons.lang.StringUtils;
44  
45  import fr.paris.lutece.portal.service.util.AppLogService;
46  import fr.paris.vdp.tipi.create.url.utils.PaiementUtils;
47  
48  /**
49   * @author stephane.raynaud
50   *
51   */
52  public abstract class TipiProcessor implements Serializable
53  {
54      private static final long serialVersionUID = 547069111354940576L;
55  
56      /**
57       * Default constructor
58       */
59      public TipiProcessor( )
60      {
61          // Empty constructor
62      }
63  
64      /**
65       * Action en cas de succès du paiement
66       * 
67       * @param tipi
68       *            les paramètres Tipi
69       */
70      public abstract void paymentSuccess( Tipi tipi );
71  
72      /**
73       * Action en cas de refus du paiement
74       * 
75       * @param tipi
76       *            les paramètres Tipi
77       */
78      public abstract void paymentDenied( Tipi tipi );
79  
80      /**
81       * Action en cas d'annulation du paiement
82       * 
83       * @param tipi
84       *            les paramètres Tipi
85       */
86      public abstract void paymentCancelled( Tipi tipi );
87  
88      /**
89       * Récupère la liste des transactions en cours
90       * 
91       * @return la liste des idop en cours
92       */
93      public abstract List<String> getPendingTransactions( );
94  
95      /**
96       * Gère le résultat dans le result handler
97       * 
98       * @param tipi
99       *            la connexion Tipi
100      * @return l'instance de gestion de Tipi
101      */
102     public Tipi process( Tipi tipi )
103     {
104         // On vérifie que la requete contient bien les données nécessaires
105         final String invalidReqParamMessage = PaiementUtils.requestParamsInvalid( tipi.getParameters( ) );
106 
107         if ( !StringUtils.isEmpty( invalidReqParamMessage ) )
108         {
109             AppLogService.error( invalidReqParamMessage );
110             throw new InvalidParameterException( "Erreur lors de la récupération des paramètres Tipi : " + invalidReqParamMessage );
111         }
112 
113         // Si Resultat
114         if ( tipi.isPaymentSuccess( ) )
115         {
116             // Paiement validé
117             this.paymentSuccess( tipi );
118 
119         } else if ( tipi.isPaymentDenied( ) )
120         {
121             // Paiement refusé
122             this.paymentDenied( tipi );
123         } else
124         {
125             // Paiement abandonné
126             this.paymentCancelled( tipi );
127         }
128 
129         return tipi;
130     }
131 }