From 732df85e0f3b99e3998fcd9d2da3dfd8610e89dd Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Thu, 31 Mar 2005 12:46:24 +0000 Subject: [PATCH] micropaiements - menage + paypal git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-523 --- htdocs/paiement/index.php | 3 +- htdocs/paiement/paypal_retour.php | 129 ++++++++++++++++++++++++++++++ include/money.inc.php | 6 +- include/money/cyberpaiement.inc.php | 96 ++++++++-------------- include/money/paypal.inc.php | 104 ++++++++++++++++++++++++ templates/{paiment => paiement}/index.tpl | 51 +++++++++++- templates/paiement/retour_paypal.tpl | 32 ++++++++ 7 files changed, 355 insertions(+), 66 deletions(-) create mode 100644 htdocs/paiement/paypal_retour.php create mode 100644 include/money/paypal.inc.php rename templates/{paiment => paiement}/index.tpl (67%) create mode 100644 templates/paiement/retour_paypal.tpl diff --git a/htdocs/paiement/index.php b/htdocs/paiement/index.php index 72e96e6..7186aec 100644 --- a/htdocs/paiement/index.php +++ b/htdocs/paiement/index.php @@ -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 index 0000000..05033ae --- /dev/null +++ b/htdocs/paiement/paypal_retour.php @@ -0,0 +1,129 @@ +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,$conf_text); +$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); +$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(); +?> diff --git a/include/money.inc.php b/include/money.inc.php index ce39294..78979ba 100644 --- a/include/money.inc.php +++ b/include/money.inc.php @@ -78,11 +78,11 @@ class Payment } // }}} - // {{{ function form() + // {{{ function prepareform() - function form() + function prepareform() { - return $this->api->form($this); + return $this->api->prepareform($this); } } diff --git a/include/money/cyberpaiement.inc.php b/include/money/cyberpaiement.inc.php index c52bd20..f9b3e26 100644 --- a/include/money/cyberpaiement.inc.php +++ b/include/money/cyberpaiement.inc.php @@ -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 << - - 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; + $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 index 0000000..0d57b01 --- /dev/null +++ b/include/money/paypal.inc.php @@ -0,0 +1,104 @@ +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'; + +?> diff --git a/templates/paiment/index.tpl b/templates/paiement/index.tpl similarity index 67% rename from templates/paiment/index.tpl rename to templates/paiement/index.tpl index 95f2e76..259af66 100644 --- a/templates/paiment/index.tpl +++ b/templates/paiement/index.tpl @@ -23,7 +23,56 @@ {if $smarty.request.op eq "submit" and !$xorg_error->errs|count} -{$pay->form($montant)|smarty:nodefaults} + + + + + + + + + + + + + + + + +
Paiement via {$meth->text}
Transaction{$pay->text}
Montant (euros){$montant}
  +
+
+ + {foreach from=$pay->api->infos.commercant key="name" item="value"} + + {/foreach} + + {foreach from=$pay->api->infos.client key="name" item="value"} + + {/foreach} + + {foreach from=$pay->api->infos.commande key="name" item="value"} + + {/foreach} + + + {foreach from=$pay->api->infos.divers key="name" item="value"} + + {/foreach} + +
+
+
+

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

+{if $pay->api->text} +

+{$pay->api->text} +

+{/if} {else} diff --git a/templates/paiement/retour_paypal.tpl b/templates/paiement/retour_paypal.tpl new file mode 100644 index 0000000..140600d --- /dev/null +++ b/templates/paiement/retour_paypal.tpl @@ -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 * + ***************************************************************************} + + +

Micropaiments

+ +{if $erreur} +

Aucun paiement n'a été effectué.

+{else} +

Merci de nous avoir fait confiance pour ton paiement

+ +

{$texte|nl2br}

+{/if} +

[retour aux micropaiements]

+{* vim:set et sw=2 sts=2 sws=2: *} -- 2.1.4