From: Pierre Habouzit (MadCoder Date: Sun, 5 Dec 2004 09:11:37 +0000 (+0000) Subject: money module X-Git-Tag: xorg/old~697 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=5d2458ae5b57a8c35b3f16dc9e5c78a578e58f6c;p=platal.git money module 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 --- diff --git a/htdocs/paiement/cyberpaiement.inc.php b/htdocs/paiement/cyberpaiement.inc.php deleted file mode 100644 index cbf82ec..0000000 --- a/htdocs/paiement/cyberpaiement.inc.php +++ /dev/null @@ -1,82 +0,0 @@ -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); -?> - -
- - - - - - - - - - - - - - - - -
Paiement via CyberP@iement
Transaction
Montant (euros)
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- -

-En cliquant sur "Valider", tu seras -redirigé 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. -

- diff --git a/htdocs/paiement/cyberpaiement_retour.php b/htdocs/paiement/cyberpaiement_retour.php index b738817..0c035e9 100644 --- a/htdocs/paiement/cyberpaiement_retour.php +++ b/htdocs/paiement/cyberpaiement_retour.php @@ -124,6 +124,7 @@ $conf_text = str_replace("",$nom,$conf_text); $conf_text = str_replace("",$promo,$conf_text); $conf_text = str_replace("",$montant,$conf_text); $conf_text = str_replace("",$femme ? "Chère" : "Cher",$conf_text); +$conf_text = str_replace("",$femme ? "Chère" : "Cher",$conf_text); $mymail = new HermesMailer(); $mymail->setFrom($conf_mail); diff --git a/htdocs/paiement/index.php b/htdocs/paiement/index.php index 8ecbe08..581c37d 100644 --- a/htdocs/paiement/index.php +++ b/htdocs/paiement/index.php @@ -22,90 +22,35 @@ 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(); ?> diff --git a/include/conf.d/money.globals.inc.php b/include/conf.d/money.globals.inc.php new file mode 100644 index 0000000..1d57304 --- /dev/null +++ b/include/conf.d/money.globals.inc.php @@ -0,0 +1,36 @@ +money = new MoneyConfig; + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker: +?> diff --git a/include/conf.d/money.menu.inc.php b/include/conf.d/money.menu.inc.php new file mode 100644 index 0000000..fbee059 --- /dev/null +++ b/include/conf.d/money.menu.inc.php @@ -0,0 +1,3 @@ +addPrivateEntry(XOM_SERVICES, 30, 'Micropaiments', 'paiement/'); +?> diff --git a/include/conf.d/tmp.menu.inc.php b/include/conf.d/tmp.menu.inc.php index b486751..7af69ab 100644 --- a/include/conf.d/tmp.menu.inc.php +++ b/include/conf.d/tmp.menu.inc.php @@ -9,7 +9,6 @@ $this->addPrivateEntry(XOM_CUSTOM, 40, 'Mon mot de passe', 'motdepassemd5 $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'); diff --git a/include/money.inc.php b/include/money.inc.php new file mode 100644 index 0000000..3e094e2 --- /dev/null +++ b/include/money.inc.php @@ -0,0 +1,120 @@ +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: +?> diff --git a/include/money/cyberpaiement.inc.php b/include/money/cyberpaiement.inc.php new file mode 100644 index 0000000..b8453cf --- /dev/null +++ b/include/money/cyberpaiement.inc.php @@ -0,0 +1,118 @@ +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 << + + + + + + + + + + + + + + + + +
Paiement via CyberP@iement
Transaction{$pay->text}
Montant (euros){$this->val}
  + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

+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. +

+EOF; + } + + // }}} +} + +$api = 'CyberPayment'; + +?> diff --git a/install.d/money/files b/install.d/money/files index cb4b1a4..788f542 100644 --- a/install.d/money/files +++ b/install.d/money/files @@ -1,9 +1,12 @@ 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 diff --git a/install.d/platal.conf b/install.d/platal.conf deleted file mode 100644 index c9e4993..0000000 --- a/install.d/platal.conf +++ /dev/null @@ -1,26 +0,0 @@ -; {{{ [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: diff --git a/templates/paiment/index.tpl b/templates/paiment/index.tpl index 97bbea0..3f95cb2 100644 --- a/templates/paiment/index.tpl +++ b/templates/paiment/index.tpl @@ -19,13 +19,15 @@ ***************************************************************************} -

- Micropaiments -

+

Micropaiments

+ {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}

{$e}

{/foreach} @@ -46,10 +48,11 @@ Transaction - {if $ref_url} - plus d'informations + {if $pay->url} +
+ plus d'informations {/if} @@ -63,7 +66,7 @@ Montant (euros) - +