Merge commit 'origin/master' into fusionax
[platal.git] / modules / payment / money / paypal.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
8d84c630 3 * Copyright (C) 2003-2009 Polytechnique.org *
0337d704 4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22class PayPal
23{
24 // {{{ properties
25
26 var $val_number;
27 var $urlform;
28 var $nomsite = "PayPal";
29 var $text;
eaf30d86 30
0337d704 31 var $infos;
32
33 // }}}
34 // {{{ constructor
eaf30d86 35
0337d704 36 function PayPal($val)
37 {
f057316b 38 $this->val_number = $val;
0337d704 39 }
40
41 // }}}
42 // {{{ function form()
43
44 function prepareform(&$pay)
45 {
f057316b
FB
46 // toute la doc sur :
47 // https://www.paypal.com/fr_FR/pdf/integration_guide.pdf
48 // attention : le renvoi automatique ne fonctionne que si
49 // on oblige les gens à créer un compte paypal
50 // nous ne l'utilisons pas ; il faut donc que l'utilisateur
51 // revienne sur le site
98a7e9dc 52 global $globals, $platal;
0337d704 53
f057316b 54 $this->urlform = 'https://'.$globals->money->paypal_site.'/cgi-bin/webscr';
98a7e9dc 55 $req = XDB::query("SELECT IF(nom_usage!='', nom_usage, nom) AS nom
c2ad0ec1
FB
56 FROM auth_user_md5
57 WHERE user_id = {?}",S::v('uid'));
f057316b 58 $name = $req->fetchOneCell();
0337d704 59
60 $roboturl = str_replace("https://","http://",$globals->baseurl)
98a7e9dc 61 . '/' . $platal->ns . "payment/paypal_return/".S::v('uid')."?comment=".urlencode(Env::v('comment'));
0337d704 62
f057316b
FB
63 $this->infos = Array();
64
65 $this->infos['commercant'] = Array(
66 'business' => $globals->money->paypal_compte,
67 'rm' => 2,
68 'return' => $roboturl,
69 'cn' => 'Commentaires',
70 'no_shipping' => 1,
eaf30d86 71 'cbt' => empty($GLOBALS['IS_XNET_SITE']) ?
f057316b
FB
72 'Revenir sur polytechnique.org' :
73 'Revenir sur polytechnique.net');
74
75 $info_client = Array(
76 'first_name' => S::v('prenom'),
77 'last_name' => $name,
7912097e 78 'email' => S::user()->bestEmail());
f057316b
FB
79
80 $res = XDB::query(
81 "SELECT a.adr1 AS address1, a.adr2 AS address2,
82 a.city, a.postcode AS zip, a.country,
5e4417a9 83 IF(t1.display_tel != '', t1.display_tel, t2.display_tel) AS night_phone_b
f057316b
FB
84 FROM auth_user_quick AS q
85 LEFT JOIN adresses AS a ON (q.user_id = a.uid AND FIND_IN_SET('active', a.statut))
b235d980
GB
86 LEFT JOIN profile_phones AS t1 ON (t1.uid = a.uid AND t1.link_type = 'address' AND t1.link_id = a.adrid)
87 LEFT JOIN profile_phones AS t2 ON (t2.uid = a.uid AND t2.link_type = 'user' AND t2.link_id = 0)
f057316b
FB
88 WHERE q.user_id = {?}
89 LIMIT 1", S::v('uid'));
c2ad0ec1 90 $this->infos['client'] = array_map('replace_accent', array_merge($info_client, $res->fetchOneAssoc()));
f057316b 91
c2ad0ec1 92 // on constuit la reference de la transaction
c2ad0ec1
FB
93 $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id();
94 $fullref = substr("$prefix-xorg-{$pay->id}",-15);
f057316b 95
c2ad0ec1
FB
96 $this->infos['commande'] = Array(
97 'item_name' => replace_accent($pay->text),
98 'amount' => $this->val_number,
99 'currency_code' => 'EUR',
100 'custom' => $fullref);
f057316b 101
c2ad0ec1 102 $this->infos['divers'] = Array('cmd' => '_xclick');
0337d704 103 }
104
105 // }}}
106}
107
108$api = 'PayPal';
109
a7de4ef7 110// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 111?>