0337d704 |
1 | <?php |
2 | /*************************************************************************** |
50a40a33 |
3 | * Copyright (C) 2003-2006 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 | |
22 | class PayPal |
23 | { |
24 | // {{{ properties |
25 | |
26 | var $val_number; |
27 | var $urlform; |
28 | var $nomsite = "PayPal"; |
29 | var $text; |
30 | |
31 | var $infos; |
32 | |
33 | // }}} |
34 | // {{{ constructor |
35 | |
36 | function PayPal($val) |
37 | { |
38 | $this->val_number = $val; |
39 | } |
40 | |
41 | // }}} |
42 | // {{{ function form() |
43 | |
44 | function prepareform(&$pay) |
45 | { |
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 |
52 | global $globals; |
53 | |
54 | $this->urlform = 'https://'.$globals->money->paypal_site.'/cgi-bin/webscr'; |
cab08090 |
55 | $req = XDB::query("SELECT IF(nom_usage!='', nom_usage, nom) AS nom FROM auth_user_md5 WHERE user_id = {?}",S::v('uid')); |
237b6585 |
56 | $name = $req->fetchOneCell(); |
0337d704 |
57 | |
58 | $roboturl = str_replace("https://","http://",$globals->baseurl) |
bff6d838 |
59 | ."/payment/paypal_return/".S::v('uid')."?comment=".urlencode(Env::v('comment')); |
0337d704 |
60 | |
61 | $this->infos = Array(); |
62 | |
63 | $this->infos['commercant'] = Array( |
64 | 'business' => $globals->money->paypal_compte, |
65 | 'rm' => 2, |
66 | 'return' => $roboturl, |
67 | 'cn' => 'Commentaires', |
68 | 'no_shipping' => 1, |
69 | 'cbt' => 'Revenir sur polytechnique.org'); |
70 | |
71 | $info_client = Array( |
cab08090 |
72 | 'first_name' => S::v('prenom'), |
237b6585 |
73 | 'last_name' => $name, |
cab08090 |
74 | 'email' => S::v('bestalias').'@polytechnique.org'); |
0337d704 |
75 | |
08cce2ff |
76 | $res = XDB::query( |
0337d704 |
77 | "SELECT a.adr1 AS address1, a.adr2 AS address2, |
78 | a.city, a.postcode AS zip, a.country, |
79a5acea |
79 | IF(t.tel, t.tel, q.profile_mobile) AS night_phone_b |
0337d704 |
80 | FROM auth_user_quick AS q |
bff6d838 |
81 | LEFT JOIN adresses AS a ON (q.user_id = a.uid AND FIND_IN_SET('active', a.statut)) |
79a5acea |
82 | LEFT JOIN tels AS t ON (t.uid = a.uid AND t.adrid = a.adrid) |
bff6d838 |
83 | WHERE q.user_id = {?} |
cab08090 |
84 | LIMIT 1", S::v('uid')); |
0337d704 |
85 | $this->infos['client']=array_merge($info_client, $res->fetchOneAssoc()); |
86 | |
87 | // on constuit la reference de la transaction |
88 | $prefix = ($pay->flags->hasflag('unique')) ? str_pad("",15,"0") : rand_url_id(); |
89 | $fullref = substr("$prefix-xorg-{$pay->id}",-15); |
90 | |
91 | $this->infos['commande'] = Array( |
92 | 'item_name' => $pay->text, |
93 | 'amount' => $this->val_number, |
94 | 'currency_code' => 'EUR', |
95 | 'custom' => $fullref); |
96 | |
97 | $this->infos['divers'] = Array('cmd' => '_xclick'); |
98 | |
99 | } |
100 | |
101 | // }}} |
102 | } |
103 | |
104 | $api = 'PayPal'; |
105 | |
106 | ?> |