Working on a reimplemntation of the really suckin' Payment part.
Now all is cleanly implemented into beautifull classes !
Moreover, I guess I've found the nasty bug, that was really our fault here,
and not really the BPLC one : our random generator created rand tokens that
had non alphanumeric values.
/me slaps himself a lot, I was really sure it was my fault, wasn't it ?
---> to resolve the problem in prod,
just ask Jeremy to make a new debian package of the HEAD libdiogenes
and put it on djali, period
I've tested with a rand id that had only alphanumeric chars,
and I received our mail (meaning the paiment was successful).
I'me still waiting for the BPLC one
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-47
+++ /dev/null
-<?php
-
-global $globals,$ref_flags,$fullref,$montant,$ref_text,$ref,$ref_mail;
-
-// on construit l'adresse de retour pour le robot de la banque
-$roboturl = str_replace("https://","http://",$globals->baseurl)."/paiement/cyberpaiement_retour.php?uid={$_SESSION['uid']}&CHAMPBPX";
-
-// on construit l'adresse de retour pour l'utilisateur
-$returnurl = $globals->baseurl."/";
-if (! isset($_COOKIE[session_name()]))
- $returnurl .= "?".SID;
-
-// on constuit la reference de la transaction
-$prefix = ($ref_flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
-$fullref = substr("$prefix-xorg-$ref",-15);
-
-// on recupere les infos sur l'utilisateur
-$res = mysql_query("SELECT a.alias, u.nom, u.prenom
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (u.user_id=a.id AND a.type='a_vie')
- WHERE user_id={$_SESSION['uid']}");
-list($username,$nom,$prenom) = mysql_fetch_row($res);
-mysql_free_result($res);
-?>
-
-<form method="post" action="https://ecom.cimetz.com/telepaie/cgishell.exe/epaie01.exe">
- <table class="bicol">
- <tr>
- <th colspan="2">Paiement via CyberP@iement</th>
- </tr>
- <tr>
- <td><b>Transaction</b></td>
- <td><?php echo $ref_text; ?></td>
- </tr>
- <tr>
- <td><b>Montant (euros)</b></td>
- <td><?php echo $montant; ?></td>
- </tr>
- <tr>
- <td> </td>
- <td>
- <!-- infos commercant -->
- <input type="hidden" name="CHAMP000" value="510879" />
- <input type="hidden" name="CHAMP001" value="5965" />
- <input type="hidden" name="CHAMP002" value="5429159012" />
- <input type="hidden" name="CHAMP003" value="I" />
- <input type="hidden" name="CHAMP004" value="Polytechnique.org" />
- <input type="hidden" name="CHAMP005" value="<?php echo $roboturl; ?>" />
- <input type="hidden" name="CHAMP006" value="Polytechnique.org" />
- <input type="hidden" name="CHAMP007" value="<?php echo $returnurl; ?>" />
- <input type="hidden" name="CHAMP008" value="<?php echo $ref_mail; ?>" />
- <!-- infos client -->
- <input type="hidden" name="CHAMP100" value="<?php echo $nom; ?>" />
- <input type="hidden" name="CHAMP101" value="<?php echo $prenom; ?>" />
- <input type="hidden" name="CHAMP102" value="." />
- <input type="hidden" name="CHAMP103" value="." />
- <input type="hidden" name="CHAMP104" value="<?php echo $username; ?>@polytechnique.org" />
- <input type="hidden" name="CHAMP106" value="." />
- <input type="hidden" name="CHAMP107" value="." />
- <input type="hidden" name="CHAMP108" value="." />
- <input type="hidden" name="CHAMP109" value="." />
- <input type="hidden" name="CHAMP110" value="." />
- <!-- infos commande -->
- <input type="hidden" name="CHAMP200" value="<?php echo $fullref; ?>" />
- <input type="hidden" name="CHAMP201" value="<?php echo $montant; ?>" />
- <input type="hidden" name="CHAMP202" value="EUR" />
- <!-- infos divers -->
- <input type="hidden" name="CHAMP900" value="01" />
- <input type="submit" value="Valider" />
- </td>
- </tr>
- </table>
-</form>
-
-<p class="normal">
-En cliquant sur "Valider", tu seras
-redirigé<?php if ($_SESSION['femme']) echo "e"; ?> vers le site de la
-BP Lorraine Champagne, où il te sera demandé de saisir ton numéro de
-carte bancaire. Lorsque le paiement aura été effectué, tu recevras
-une confirmation par email.
-</p>
-
$conf_text = str_replace("<promo>",$promo,$conf_text);
$conf_text = str_replace("<montant>",$montant,$conf_text);
$conf_text = str_replace("<salutation>",$femme ? "Chère" : "Cher",$conf_text);
+$conf_text = str_replace("<cher>",$femme ? "Chère" : "Cher",$conf_text);
$mymail = new HermesMailer();
$mymail->setFrom($conf_mail);
require_once("xorg.inc.php");
new_skinned_page('paiment/index.tpl', AUTH_MDP);
require_once('profil.func.inc.php');
-setlocale(LC_NUMERIC,'fr_FR');
-
-function comp($s1,$s2) {
- list($r1,$a1) = split(',', $s1);
- list($r2,$a2) = split(',', $s2);
- $n1 = $r1*100+$a1;
- $n2 = $r2*100+$a2;
- if($n1>$n2) return 1;
- if($n1<$n2) return -1;
- return 0;
-}
+require_once("money.inc.php");
// initialisation
$op = isset($_REQUEST['op']) ? $_REQUEST['op'] : 'select';
-$methode = isset($_REQUEST['methode']) ? $_REQUEST['methode'] : 0;
$erreur = Array();
-// on recupere les infos relatives a la transaction choisie
-$ref = isset($_REQUEST['ref']) ? $_REQUEST['ref'] : 0;
-$res = $globals->db->query("SELECT text,url,flags,mail,montant_min,montant_max,montant_def FROM paiement.paiements WHERE id=$ref");
-
-if (!list($ref_text,$ref_url,$ref_flags,$ref_mail,$montant_min,$montant_max,$montant_def) = mysql_fetch_row($res)) {
- $erreur[] = "La transaction selectionnée n'est pas valide.";
-}
-$ref_flags = new flagset($ref_flags);
+$meth = new PayMethod(isset($_REQUEST['methode']) ? $_REQUEST['methode'] : -1);
+$pay = new Payment(isset($_REQUEST['ref']) ? $_REQUEST['ref'] : -1);
-if($ref_flags->hasflag('old')){
+if($pay->flags->hasflag('old')){
$erreur[] = "La transaction selectionnée est périmée.";
- //Don x.org, toujours valable :)
- $ref = 0;
- $res = $globals->db->query("SELECT text,url,flags,mail,montant_min,montant_max,montant_def FROM paiement.paiements WHERE id=$ref");
- if (!list($ref_text,$ref_url,$ref_flags,$ref_mail,$montant_min,$montant_max,$montant_def) = mysql_fetch_row($res)) {
- $erreur[] = "La transaction selectionnée n'est pas valide.";
- }
- $ref_flags = new flagset($ref_flags);
-}
-
-// on remplace les points par des virgules
-$montant_min=strtr($montant_min,".",",");
-$montant_max=strtr($montant_max,".",",");
-$montant_def=strtr($montant_def,".",",");
-
-// on recupere les infos relatives à la methode choisie
-$methode = isset($_REQUEST['methode']) ? $_REQUEST['methode'] : 0;
-$res = $globals->db->query("SELECT include FROM paiement.methodes WHERE id=$methode");
-if (!list($methode_include) = mysql_fetch_row($res)) {
- $erreur[] = "La méthode de paiement sélectionnée n'est pas valide.";
-}
-
-// verifications
-$montant = (($op=="submit") && isset($_REQUEST['montant'])) ? $_REQUEST['montant'] : $montant_def;
-$montant = strtr($montant, ".", ",");
-
-// on ajoute les centimes
-if (ereg("^[0-9]+$",$montant))
- $montant .= ",00";
-elseif (ereg("^[0-9]+,[0-9]$",$montant))
- $montant .= "0";
-
-// on verifie que le montant est bien formatté
-if (!ereg("^[0-9]+,[0-9]{2}$",$montant)) {
- $erreur[] = "Montant invalide.";
- $montant = $montant_def;
+ $pay = new Payment();
}
+$val = (($op=="submit") && isset($_REQUEST['montant'])) ? $_REQUEST['montant'] : $pay->montant_def;
-if (comp($montant,$montant_min)<0) {
- $erreur[] = "Montant inférieur au minimum autorisé ($montant_min).";
- $montant = $montant_min;
+if (($e = $pay->check($val)) !== true) {
+ $erreur[] = $e;
}
-if (comp($montant,$montant_max)>0) {
- $erreur[] = "Montant supérieur au maximum autorisé ($montant_max).";
- $montant = $montant_max;
+if ($op=='submit') {
+ $pay->init($val, $meth);
}
-$page->assign('op',$op);
-$page->assign('erreur',$erreur);
-$page->assign('montant',$montant);
-
-$page->assign('methode',$methode);
-$page->assign('methode_include',$methode_include);
+$page->assign('erreur', $erreur);
+$page->assign('montant',$val);
-$page->assign('ref',$ref);
-$page->assign('ref_url',$ref_url);
+$page->assign('meth', $meth);
+$page->assign('pay', $pay);
+$page->assign('prefix',$globals->money->table_prefix);
$page->run();
?>
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2004 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************/
+
+// {{{ class MoneyConfig
+
+class MoneyConfig
+{
+ var $payment_def = 0;
+ var $method_def = 0;
+ var $table_prefix = 'paiement.';
+}
+
+// }}}
+
+$this->money = new MoneyConfig;
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
+?>
--- /dev/null
+<?php
+$this->addPrivateEntry(XOM_SERVICES, 30, 'Micropaiments', 'paiement/');
+?>
$this->addPrivateEntry(XOM_CUSTOM, 50, 'Mes préférences', 'preferences.php');
$this->addPrivateEntry(XOM_SERVICES, 00, 'Envoyer un mail', 'sendmail.php');
-$this->addPrivateEntry(XOM_SERVICES, 30, 'Envoyer un mail', 'sendmail.php');
$this->addPrivateEntry(XOM_SERVICES, 40, 'Patte cassée', 'pattecassee.php');
$this->addPrivateEntry(XOM_GROUPS, 10, 'Trombi promo', 'trombipromo.php');
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2004 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************/
+
+// {{{ class Payment
+
+class Payment
+{
+ // {{{ properties
+
+ var $id;
+ var $text;
+ var $url;
+ var $flags;
+ var $mail;
+ var $montant_min;
+ var $montant_max;
+ var $montant_def;
+
+ var $api = null;
+
+ // }}}
+ // {{{ constructor
+
+ function Payment($ref=-1)
+ {
+ global $globals;
+ $r = $ref==-1 ? $globals->money->payment_def : $ref;
+ $res = $globals->db->query("SELECT id, text, url, flags, mail, montant_min, montant_max, montant_def
+ FROM {$globals->money->table_prefix}paiements WHERE id='$r'");
+ list($this->id, $this->text, $this->url, $flags, $this->mail,
+ $this->montant_min, $this->montant_max, $this->montant_def)
+ = mysql_fetch_row($res);
+ mysql_free_result($res);
+
+ $this->montant_min = (float)$this->montant_min;
+ $this->montant_max = (float)$this->montant_max;
+ $this->flags = new Flagset($flags);
+ }
+
+ // }}}
+ // {{{ function check()
+
+ function check($value)
+ {
+ $v = (float)strtr($value, ',', '.');
+ if ($this->montant_min > $v) {
+ return "Montant inférieur au minimum autorisé ({$this->montant_min}).";
+ } elseif ($v > $this->montant_max) {
+ return "Montant supérieur au maximum autorisé ({$this->montant_max}).";
+ } else {
+ return true;
+ }
+ }
+
+ // }}}
+ // {{{ function init()
+
+ function init($val, &$meth)
+ {
+ require_once('money/'.$meth->inc);
+ $this->api = new $api($val);
+ }
+
+ // }}}
+ // {{{ function form()
+
+ function form()
+ {
+ return $this->api->form($this);
+ }
+}
+
+// }}}
+// {{{ class PayMethod
+
+class PayMethod
+{
+ // {{{ properties
+
+ var $id;
+ var $text;
+ var $inc;
+
+ // }}}
+ // {{{ constructor
+
+ function PayMethod($id=-1)
+ {
+ global $globals;
+ $i = $id==-1 ? $globals->money->method_def : $id;
+ $res = $globals->db->query("SELECT id,text,include FROM {$globals->money->table_prefix}methodes WHERE id='$i'");
+ list($this->id, $this->text, $this->inc) = mysql_fetch_row($res);
+ mysql_free_result($res);
+ }
+
+ // }}}
+}
+
+// }}}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
+?>
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2004 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************/
+
+class CyberPayment
+{
+ // {{{ properties
+
+ var $val;
+
+ // }}}
+ // {{{ constructor
+
+ function CyberPayment($val)
+ {
+ $this->val = strtr(sprintf("%.02f", (float)$val), '.', ',');
+ }
+
+ // }}}
+ // {{{ function form()
+
+ function form(&$pay)
+ {
+ global $globals;
+
+ $roboturl = str_replace("https://","http://",$globals->baseurl)
+ ."/paiement/cyberpaiement_retour.php?uid={$_SESSION['uid']}&CHAMPBPX";
+ if (! isset($_COOKIE[session_name()])) {
+ $returnurl .= "?".SID;
+ }
+
+ // on constuit la reference de la transaction
+ $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
+ $fullref = substr("$prefix-xorg-{$pay->id}",-15);
+
+ $e = $_SESSION['sexe'] ? 'e' : '';
+
+ return <<<EOF
+<form method="post" action="https://ecom.cimetz.com/telepaie/cgishell.exe/epaie01.exe">
+ <table class="bicol">
+ <tr>
+ <th colspan="2">Paiement via CyberP@iement</th>
+ </tr>
+ <tr>
+ <td><b>Transaction</b></td>
+ <td>{$pay->text}</td>
+ </tr>
+ <tr>
+ <td><b>Montant (euros)</b></td>
+ <td>{$this->val}</td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td>
+ <!-- infos commercant -->
+ <input type="hidden" name="CHAMP000" value="510879" />
+ <input type="hidden" name="CHAMP001" value="5965" />
+ <input type="hidden" name="CHAMP002" value="5429159012" />
+ <input type="hidden" name="CHAMP003" value="I" />
+ <input type="hidden" name="CHAMP004" value="Polytechnique.org" />
+ <input type="hidden" name="CHAMP005" value="$roboturl" />
+ <input type="hidden" name="CHAMP006" value="Polytechnique.org" />
+ <input type="hidden" name="CHAMP007" value="{$globals->baseurl}/" />
+ <input type="hidden" name="CHAMP008" value="{$pay->mail}" />
+ <!-- infos client -->
+ <input type="hidden" name="CHAMP100" value="{$_SESSION['nom']}" />
+ <input type="hidden" name="CHAMP101" value="{$_SESSION['prenom']}" />
+ <input type="hidden" name="CHAMP102" value="." />
+ <input type="hidden" name="CHAMP103" value="." />
+ <input type="hidden" name="CHAMP104" value="{$_SESSION['bestalias']}@polytechnique.org" />
+ <input type="hidden" name="CHAMP106" value="." />
+ <input type="hidden" name="CHAMP107" value="." />
+ <input type="hidden" name="CHAMP108" value="." />
+ <input type="hidden" name="CHAMP109" value="." />
+ <input type="hidden" name="CHAMP110" value="." />
+ <!-- infos commande -->
+ <input type="hidden" name="CHAMP200" value="$fullref" />
+ <input type="hidden" name="CHAMP201" value="{$this->val}" />
+ <input type="hidden" name="CHAMP202" value="EUR" />
+ <!-- infos divers -->
+ <input type="hidden" name="CHAMP900" value="01" />
+ <input type="submit" value="Valider" />
+ </td>
+ </tr>
+ </table>
+</form>
+
+<p>
+En cliquant sur "Valider", tu seras redirigé$e vers le site de la BP Lorraine Champagne, où il te
+sera demandé de saisir ton numéro de carte bancaire. Lorsque le paiement aura été effectué, tu
+recevras une confirmation par email.
+</p>
+EOF;
+ }
+
+ // }}}
+}
+
+$api = 'CyberPayment';
+
+?>
htdocs/admin/gerer_paiement.php
-htdocs/paiement/cyberpaiement.inc.php
htdocs/paiement/cyberpaiement_retour.php
htdocs/paiement/index.php
htdocs/trezo/gere_operations.php
htdocs/trezo/index.php
+include/conf.d/money.globals.inc.php
+include/conf.d/money.menu.inc.php
+include/money/cyberpaiement.inc.php
+include/money.inc.php
include/trezo.inc.php
templates/paiment/index.tpl
templates/trezo/choix_date.tpl
+++ /dev/null
-; {{{ [Core]
-
-[Core]
-
-debug = true
-dbuser = "***"
-dbpwd = "***"
-
-; base url of the site, WITHOUT LEADING /
-baseurl = "http://dev.m4x.org/~x2000habouzit";
-spoolroot = "/home/x2000habouzit/dev/public/";
-
-econfiance = "***";
-
-; }}}
-; {{{ [Global]
-
-[Banana]
-
-password = "***"
-web_user = "***"
-web_pass = "***"
-
-; }}}
-
-; vim:set syntax=dosini:
***************************************************************************}
-<h1>
- Micropaiments
-</h1>
+<h1>Micropaiments</h1>
+
{dynamic}
-{if $op eq "submit" and !$error}
-{include_php file=$methode_include}
+{if $smarty.request.op eq "submit" and !$erreur|count}
+
+{$pay->form($montant)|smarty:nodefaults}
+
{else}
+
{foreach from=$erreur item=e}
<p class="erreur">{$e}</p>
{/foreach}
<td>Transaction</td>
<td>
<select name="ref" onchange="this.form.op.value='select'; this.form.submit();">
- {select_db_table table="paiement.paiements" valeur=$ref where=" WHERE FIND_IN_SET('old',flags)=0"}
+ {select_db_table table="`$prefix`paiements" valeur=$pay->id where=" WHERE FIND_IN_SET('old',flags)=0"}
</select>
- {if $ref_url}
- <a href="{$ref_url}">plus d'informations</a>
+ {if $pay->url}
+ <br />
+ <a href="{$pay->url}">plus d'informations</a>
{/if}
</td>
</tr>
</tr>
<tr>
<td>Montant (euros)</td>
- <td><input type="text" name="montant" size="13" value="{$montant}" /></td>
+ <td><input type="text" name="montant" size="13" class='right' value="{$montant}" /></td>
</tr>
<tr>
<td> </td>