[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/ -> retourbplc.class.php (source)

   1  <?php
   2  /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   *
   4   * This program is free software; you can redistribute it and/or modify
   5   * it under the terms of the GNU General Public License as published by
   6   * the Free Software Foundation; either version 2 of the License, or
   7   * (at your option) any later version.
   8   *
   9   * This program is distributed in the hope that it will be useful,
  10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12   * GNU General Public License for more details.
  13   *
  14   * You should have received a copy of the GNU General Public License
  15   * along with this program; if not, write to the Free Software
  16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17   *
  18   * $Id: retourbplc.class.php,v 1.8 2005/03/18 23:56:41 eldy Exp $
  19   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/retourbplc.class.php,v $
  20   *
  21   * Classe de gestion du retour RSTS du systeme de paiement en ligne
  22   * CyberPaiement (TM) de la Banque Populaire de Lorraine
  23   *
  24   * Certaine fonction de cette classe existe de base dans PHP4 mais ont été
  25   * ré-écrites ici pour le support de PHP3
  26   */
  27  
  28  class Retourbplc
  29  {
  30    var $db;
  31  
  32    var $ipclient;
  33    var $montant;
  34    var $num_compte;
  35    var $ref_commande;
  36    var $num_contrat;
  37    var $num_transaction;
  38    var $date_transaction;
  39    var $heure_transaction;
  40    var $num_autorisation;
  41    var $cle_acceptation;
  42    var $code_retour;
  43  
  44    var $ref_commande;
  45      
  46    /*
  47     *   Initialisation des valeurs par défaut
  48     */
  49       
  50    function Retourbplc($db) 
  51    {
  52      $this->db = $db;
  53    }
  54      
  55    /**
  56     * \brief  Insertion dans la base de donnée de la transaction
  57     *
  58     */
  59       
  60    function insertdb()
  61    {
  62  
  63  
  64      $sql = "INSERT INTO ".MAIN_DB_PREFIX."transaction_bplc";
  65      $sql .= " (ipclient, 
  66                     num_transaction, 
  67                     date_transaction, 
  68                     heure_transaction, 
  69                     num_autorisation, 
  70                     cle_acceptation, 
  71                     code_retour, 
  72                     ref_commande)";
  73      
  74      $sql .= " VALUES ('$this->ipclient',
  75                        '$this->num_transaction',
  76                        '$this->date_transaction',
  77                        '$this->heure_transaction',
  78                        '$this->num_autorisation',
  79                        '$this->cle_acceptation',
  80                        $this->code_retour,
  81                         $this->ref_commande)";
  82  
  83      $result = $this->db->query($sql);
  84      
  85      if ($result) 
  86        {
  87      return $this->db->last_insert_id(MAIN_DB_PREFIX."transaction_bplc");
  88        }
  89      else
  90        {
  91      print $this->db->error();
  92      print "<h2><br>$sql<br></h2>";
  93      return 0;
  94        }             
  95    }
  96      
  97    /**
  98     * \brief  Verification de la validitée de la clé
  99     *
 100     */
 101       
 102    function check_key($key)
 103    {
 104  
 105      $A = $this->montant;
 106      $B = $this->num_contrat;
 107      $C = $this->num_transaction;
 108      $D = $this->ref_commande;
 109      $E = $this->num_compte;
 110  
 111      /*
 112       * Etape 1
 113       *
 114       */
 115      $A1 = $A . $E;
 116      $B1 = $B . $E;
 117      $C1 = $C . $E;
 118      $D1 = $D . $E;
 119  
 120      $map = range(0, 9);
 121  
 122      $L1= $this->cle_luhn($A1, $map);
 123  
 124      $L2= $this->cle_luhn($B1, $map);
 125  
 126      $L3= $this->cle_luhn($C1, $map);
 127  
 128      $L4= $this->cle_luhn($D1, $map);
 129      /*
 130       * Etape 2
 131       *
 132       */
 133  
 134      $N1 = $L1 . $L2 . $L3 . $L4;
 135      $N0 = $L1 + $L2 + $L3 + $L4;
 136  
 137      $C5 = $this->corres($N0);
 138      /*
 139       * Comparaison
 140       *
 141       */
 142  
 143      if ($key == $this->calcul_pos($N1,$N0, $C5))
 144        {
 145      return 1;
 146        }
 147      else 
 148        {
 149      return 0;
 150        }
 151    }
 152      
 153    /**
 154     * \brief  Table de correspondance de l'algorithme de Luhn
 155     *
 156     */
 157      
 158    function corres($value)
 159    {
 160      $map[0] = 0;
 161  
 162      for ($i = 65 ; $i < 91 ; $i++)
 163        {
 164      $map[$i-64] = chr($i);
 165        }
 166  
 167      for ($i = 0 ; $i < 10 ; $i++)
 168        {
 169      $map[27+$i] = $i;
 170        }
 171  
 172      return $map[$value];
 173  
 174    }
 175      
 176    /**
 177     * \brief  Calcul de la cle de Luhn
 178     * 
 179     */
 180    function cle_luhn($cle, $map)
 181    {
 182      $buffer = $this->array_reverse($cle);
 183   
 184      $totalVal = 0;
 185      $flip = 1;
 186   
 187      reset ($buffer);
 188  
 189      while (list($key, $posVal) = each ($buffer))
 190        {
 191  
 192      if (!isset($map[$posVal])){
 193        return FALSE;
 194      }
 195  
 196      $posVal = $map[$posVal];
 197  
 198      if ( $flip = !$flip)
 199        {
 200          $posVal *= 2;
 201        }
 202        
 203      while ($posVal>0)
 204        {
 205          $totalVal += $posVal % 10;
 206          $posVal = floor($posVal / 10);
 207        }
 208      }
 209  
 210      return substr($totalVal, strlen($totalVal)-1, 1);
 211    }
 212    /**
 213     * \brief Postion de C5 dans N0
 214     *
 215     *
 216     */
 217       
 218    function calcul_pos($N1, $N0, $C5)
 219    {
 220      if ($N0 >= 0 && $N0 <= 6)
 221        {
 222      /* clé = 2 premiers de N0 . C5 . 2 derniers de N0 */
 223  
 224      $cle = substr($N1,0,2) . $C5 . substr($N1,2,2);
 225  
 226        }
 227      elseif ($N0 >= 7 && $N0 <= 14)
 228        {
 229      /* clé = 4 premiers de N0 . C5 */
 230  
 231      $cle = substr($N1,0,4) . $C5;
 232  
 233        }
 234      elseif ($N0 >= 15 && $N0 <= 21)
 235        {
 236      /* clé = premier de N1 . C5 . 3 derniers de N1 */
 237  
 238      $cle = substr($N1,0,1) . $C5 . substr($N1,1,3);
 239  
 240        }
 241      elseif ($N0 >= 22 && $N0 <= 29)
 242        {
 243      /* clé = C5 . 4 derniers de N1 */
 244  
 245      $cle = $C5 . substr($N1,0,4);
 246  
 247        }
 248      elseif ($N0 >= 30 && $N0 <= 36)
 249        {
 250      /* clé = 3 premiers de N1 . C5 . dernier de N1 */
 251  
 252      $cle = substr($N1,0,3) . $C5 . substr($N1,1,1);
 253  
 254        }
 255      else
 256        {
 257      $cle = "ERREUR";
 258        }
 259  
 260      return $cle;
 261  
 262    }
 263      
 264    /**
 265     * \brief  Retournement du tableau
 266     *
 267     */
 268       
 269    function array_reverse($string)
 270    {
 271  
 272      $len = strlen($string);
 273  
 274      $i = $len;
 275      $j = 0;
 276      $rever = array();
 277      while ($i > 0)
 278        {
 279      $rever[$j]= substr($string, $i-1, 1);
 280      $i = $i - 1;
 281      $j = $j + 1;
 282        }
 283  
 284      return $rever;
 285    }
 286  }
 287  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics