micropaiements - menage + paypal
authorPascal Corpet <pascal.corpet@m4x.org>
Thu, 31 Mar 2005 12:46:24 +0000 (12:46 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:28:22 +0000 (23:28 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-523

htdocs/paiement/index.php
htdocs/paiement/paypal_retour.php [new file with mode: 0644]
include/money.inc.php
include/money/cyberpaiement.inc.php
include/money/paypal.inc.php [new file with mode: 0644]
templates/paiement/index.tpl [moved from templates/paiment/index.tpl with 67% similarity]
templates/paiement/retour_paypal.tpl [new file with mode: 0644]

index 72e96e6..7186aec 100644 (file)
@@ -20,7 +20,7 @@
  ***************************************************************************/
 
 require_once("xorg.inc.php");
-new_skinned_page('paiment/index.tpl', AUTH_MDP);
+new_skinned_page('paiement/index.tpl', AUTH_MDP);
 require_once('profil.func.inc.php');
 require_once('money.inc.php');
 
@@ -41,6 +41,7 @@ if (($e = $pay->check($val)) !== true) {
 
 if ($op=='submit') {
     $pay->init($val, $meth);
+    $pay->prepareform($pay);
 }
 
 $page->assign('montant',$val);
diff --git a/htdocs/paiement/paypal_retour.php b/htdocs/paiement/paypal_retour.php
new file mode 100644 (file)
index 0000000..05033ae
--- /dev/null
@@ -0,0 +1,129 @@
+<?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                *
+ ***************************************************************************/
+
+require_once("xorg.inc.php");
+new_skinned_page('paiement/retour_paypal.tpl', AUTH_MDP);
+require_once("diogenes/diogenes.hermes.inc.php");
+
+/* sort en affichant une erreur */
+function erreur($text, $send=true) {
+    global $page, $erreur;
+    if ($erreur) return;
+    $erreur = $text;
+    if (!$send) return;
+
+    $mymail = new HermesMailer();
+    $mymail->addTo("webmaster@polytechnique.org");
+    $mymail->setFrom("webmaster@polytechnique.org");
+    $mymail->setSubject("erreur lors d'un télépaiement");
+    $mymail->setTxtBody("\n\n".var_export($_REQUEST,true));
+    $mymail->send();
+
+    $page->trig($text);
+}
+
+/* user id */
+$uid = clean_request('uid');
+/* reference banque (numero de transaction) */
+$no_transaction = clean_request('tx');
+/* token a renvoyer pour avoir plus d'information */
+$clef = clean_request('sig');
+/* code retour */
+$status = clean_request('st');
+/* raison */
+$reason = ($status == 'Pending')?clean_request('pending_reason'):clean_request('reason_code');
+/* reference complete de la commande */
+$fullref = clean_request('cm');
+/* montant de la transaction */
+$montant_nb = clean_request('amt');
+/* devise */
+$montant_dev = clean_request('cc');
+$montant = "$montant_nb $montant_dev";
+
+/* on extrait le code de retour */
+if ($status != "Completed") {
+       if ($status)
+               erreur("erreur lors du paiement : $status - $reason");
+       else
+               erreur("Paiement annulé", false);
+}
+
+/* on extrait les informations sur l'utilisateur */
+$res = $globals->xdb->query("
+    SELECT  a.prenom,a.nom,a.promo,l.alias,FIND_IN_SET(a.flags,'femme')
+      FROM  auth_user_md5 AS a
+INNER JOIN  aliases       AS l ON (a.user_id=l.id AND type!='homonyme')
+     WHERE  a.user_id={?}", $uid);
+if (!list($prenom,$nom,$promo,$forlife,$femme) = $res->fetchOneRow()) {
+    erreur("uid invalide");
+}
+
+/* on extrait la reference de la commande */
+if (!ereg('-xorg-([0-9]+)$',$fullref,$matches)) {
+    erreur("référence de commande invalide");
+}
+
+$ref = $matches[1];
+$res = $globals->xdb->query("SELECT mail,text,confirmation FROM paiement.paiements WHERE id={?}", $ref);
+if (!list($conf_mail,$conf_title,$conf_text) = $res->fetchOneRow()) {
+    erreur("référence de commande inconnue");
+}
+
+/* on fait l'insertion en base de donnees */
+$globals->xdb->execute("INSERT INTO  paiement.transactions (id,uid,ref,fullref,montant,cle)
+                             VALUES  ({?},{?},{?},{?},{?},{?})",
+                        $no_transaction, $uid, $ref, $fullref, $montant, $clef);
+
+/* on genere le mail de confirmation */
+$conf_text = str_replace("<prenom>",$prenom,$conf_text);
+$conf_text = str_replace("<nom>",$nom,$conf_text);
+$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);
+$mymail->addTo("\"$prenom $nom\" <$forlife@polytechnique.org>");
+$mymail->addCc($conf_mail);
+$mymail->setSubject($conf_title);
+$mymail->setTxtBody($conf_text);
+$mymail->send();
+
+/* on envoie les details de la transaction à telepaiement@ */
+$mymail = new HermesMailer();
+$mymail->setFrom("webmaster@polytechnique.org");
+$mymail->addTo("telepaiement@polytechnique.org");
+$mymail->setSubject($conf_title);
+$msg = "utilisateur : $prenom $nom ($uid)\n".
+       "mail : $forlife@polytechnique.org\n\n".
+       "paiement : $conf_title ($conf_mail)\n".
+       "reference : $no_transaction\n".
+       "montant : $montant\n\n".
+       "dump de REQUEST:\n".
+       var_export($_REQUEST,true);
+$mymail->setTxtBody($msg);
+$mymail->send();
+
+$page->assign('texte', $conf_text);
+$page->assign('erreur', $erreur);
+$page->run();
+?>
index ce39294..78979ba 100644 (file)
@@ -78,11 +78,11 @@ class Payment
     }
 
     // }}}
-    // {{{ function form()
+    // {{{ function prepareform()
 
-    function form()
+    function prepareform()
     {
-        return $this->api->form($this);
+        return $this->api->prepareform($this);
     }
 }
 
index c52bd20..f9b3e26 100644 (file)
@@ -25,6 +25,10 @@ class CyberPayment
 
     var $val;
 
+    var $urlform;
+    var $nomsite = "la BP Lorraine Champagne";
+    var $infos;
+
     // }}}
     // {{{ constructor
     
@@ -36,8 +40,11 @@ class CyberPayment
     // }}}
     // {{{ function form()
 
-    function form(&$pay)
+    function prepareform(&$pay)
     {
+       // toute la doc se trouve sur
+       // http://www.cyberpaiement.tm.fr/donnees.htm
+
         global $globals;
 
         $roboturl = str_replace("https://","http://",$globals->baseurl)
@@ -52,66 +59,33 @@ class CyberPayment
         $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
         $fullref = substr("$prefix-xorg-{$pay->id}",-15);
 
-        $e = Session::getBool('sexe') ? 'e' : '';
-        
-        return <<<EOF
-<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>&nbsp;</td>
-    <td>
-      <form method="post" action="https://ecom.cimetz.com/telepaie/cgishell.exe/epaie01.exe">
-      <div>
-       <!-- 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" />
-      </div>
-      </form>
-    </td>
-  </tr>
-</table>
-
-<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;
+        $this->urlform = "https://ecom.cimetz.com/telepaie/cgishell.exe/epaie01.exe";
+       $this->infos['commercant'] = Array(
+               'CHAMP000' => 510879,
+               'CHAMP001' => 5965,
+               'CHAMP002' => 5429159012,
+               'CHAMP003' => "I",
+               'CHAMP004' => "Polytechnique.org",
+               'CHAMP005' => $roboturl,
+               'CHAMP006' => "Polytechnique.org",
+               'CHAMP007' => $globals->baseurl,
+               'CHAMP008' => $pay->mail);
+       $this->infos['client'] = Array(
+               'CHAMP100' => Session::get('nom'),
+               'CHAMP101' => Session::get('prenom'),
+               'CHAMP102' => '.',
+               'CHAMP103' => '.',
+               'CHAMP104' => Session::get('bestalias').'@polytechnique.org',
+               'CHAMP106' => '.',
+               'CHAMP107' => '.',
+               'CHAMP108' => '.',
+               'CHAMP109' => '.',
+               'CHAMP110' => '.');
+       $this->infos['commande'] = Array(
+               'CHAMP200' => $fullref,
+               'CHAMP201' => $this->val,
+               'CHAMP202' => "EUR");
+       $this->infos['divers'] = Array('CHAMP900' => '01');
     }
 
     // }}}
diff --git a/include/money/paypal.inc.php b/include/money/paypal.inc.php
new file mode 100644 (file)
index 0000000..0d57b01
--- /dev/null
@@ -0,0 +1,104 @@
+<?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 PayPal
+{
+    // {{{ properties
+
+    var $val_number;
+    var $urlform;
+    var $nomsite = "PayPal";
+    var $text;
+    
+    var $infos;
+
+    // }}}
+    // {{{ constructor
+    
+    function PayPal($val)
+    {
+       $this->val_number = $val;
+    }
+
+    // }}}
+    // {{{ function form()
+
+    function prepareform(&$pay)
+    {
+       // toute la doc sur :
+       // https://www.paypal.com/fr_FR/pdf/integration_guide.pdf
+       // attention : le renvoi automatique ne fonctionne que si
+       // on oblige les gens à créer un compte paypal
+       // nous ne l'utilisons pas ; il faut donc que l'utilisateur
+       // revienne sur le site
+        global $globals;
+
+       $this->urlform = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
+
+        $roboturl = str_replace("https://","http://",$globals->baseurl)
+            ."/paiement/paypal_retour.php?uid="
+            .Session::getInt('uid');
+
+       $this->infos = Array();
+       
+       $this->infos['commercant'] = Array(
+               'business'    => 'caribou+paypalsandbox@m4x.org',
+               'rm'          => 2,
+               'return'      => $roboturl,
+               'cn'          => 'Commentaires',
+               'no_shipping' => 1,
+               'cbt'         => 'Revenir sur polytechnique.org');
+       
+       $info_client = Array(
+               'first_name' => Session::get('prenom'),
+               'last_name'  => Session::get('nom'),
+               'email'      => Session::get('bestalias').'@polytechnique.org');
+               
+       $res = $globals->xdb->query(
+               "SELECT a.adr1 AS address1, a.adr2 AS address2,
+                       a.ville AS city, a.cp AS zip, a.pays AS country,
+                       IF(a.tel, a.tel, q.profile_mobile) AS night_phone_b
+                  FROM auth_user_quick AS q
+             LEFT JOIN adresses        AS a ON (q.user_id = a.uid)
+                 WHERE q.user_id = {?} AND FIND_IN_SET('active', a.statut)
+                 LIMIT 1", Session::getInt('uid'));
+       $this->infos['client']=array_merge($info_client, $res->fetchOneAssoc());
+
+        // 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);
+
+       $this->infos['commande'] = Array(
+               'item_name'     => $pay->text,
+               'amount'        => $this->val_number,
+               'currency_code' => 'EUR',
+               'custom'        => $fullref);
+
+       $this->infos['divers'] = Array('cmd' => '_xclick');
+
+    }
+
+    // }}}
+}
+
+$api = 'PayPal';
+
+?>
similarity index 67%
rename from templates/paiment/index.tpl
rename to templates/paiement/index.tpl
index 95f2e76..259af66 100644 (file)
 
 {if $smarty.request.op eq "submit" and !$xorg_error->errs|count}
 
-{$pay->form($montant)|smarty:nodefaults}
+<table class="bicol">
+  <tr>
+    <th colspan="2">Paiement via {$meth->text}</th>
+  </tr>
+  <tr>
+    <td><b>Transaction</b></td>
+    <td>{$pay->text}</td>
+  </tr>
+  <tr>
+    <td><b>Montant (euros)</b></td>
+    <td>{$montant}</td>
+  </tr>
+  <tr>
+    <td>&nbsp;</td>
+    <td>
+      <form method="post" action="{$pay->api->urlform}">
+      <div>
+       <!-- infos commercant -->
+        {foreach from=$pay->api->infos.commercant key="name" item="value"}
+       <input type="hidden" name="{$name}" value="{$value}" />
+        {/foreach}
+       <!-- infos client -->
+        {foreach from=$pay->api->infos.client key="name" item="value"}
+       <input type="hidden" name="{$name}" value="{$value}" />
+        {/foreach}
+       <!-- infos commande -->
+        {foreach from=$pay->api->infos.commande key="name" item="value"}
+       <input type="hidden" name="{$name}" value="{$value}" />
+        {/foreach}
+       
+       <!-- infos divers -->
+        {foreach from=$pay->api->infos.divers key="name" item="value"}
+       <input type="hidden" name="{$name}" value="{$value}" />
+        {/foreach}
+       <input type="submit" value="Valider" />
+      </div>
+      </form>
+    </td>
+  </tr>
+</table>
+<p>
+En cliquant sur "Valider", tu seras redirigé{if $smarty.session.sexe}e{/if} vers le site de {$pay->api->nomsite}, 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>
+{if $pay->api->text}
+<p>
+{$pay->api->text}
+</p>
+{/if}
 
 {else}
 
diff --git a/templates/paiement/retour_paypal.tpl b/templates/paiement/retour_paypal.tpl
new file mode 100644 (file)
index 0000000..140600d
--- /dev/null
@@ -0,0 +1,32 @@
+{***************************************************************************
+ *  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                *
+ ***************************************************************************}
+
+
+<h1>Micropaiments</h1>
+
+{if $erreur}
+<p>Aucun paiement n'a été effectué.</p>
+{else}
+<p>Merci de nous avoir fait confiance pour ton paiement</p>
+
+<p>{$texte|nl2br}</p>
+{/if}
+<p>[<a href='index.php'>retour aux micropaiements</a>]</p>
+{* vim:set et sw=2 sts=2 sws=2: *}