Commit | Line | Data |
---|---|---|
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 | ||
22 | class PayPal | |
23 | { | |
0337d704 | 24 | var $val_number; |
25 | var $urlform; | |
26 | var $nomsite = "PayPal"; | |
27 | var $text; | |
eaf30d86 | 28 | |
0337d704 | 29 | var $infos; |
30 | ||
0337d704 | 31 | function PayPal($val) |
32 | { | |
f057316b | 33 | $this->val_number = $val; |
0337d704 | 34 | } |
35 | ||
0337d704 | 36 | function prepareform(&$pay) |
37 | { | |
8f60459a SJ |
38 | // Documentation: |
39 | // https://www.paypal.com/developer | |
40 | // Warning: the automatic return only works if we force the | |
41 | // users to create a paypal account. We do not use it; thus | |
42 | // the user must come back on the site. | |
98a7e9dc | 43 | global $globals, $platal; |
0337d704 | 44 | |
8f60459a | 45 | $this->urlform = 'https://' . $globals->money->paypal_site . '/cgi-bin/webscr'; |
1eaaa62d FB |
46 | $user = S::user(); |
47 | $name = $user->lastName(); | |
0337d704 | 48 | |
49 | $roboturl = str_replace("https://","http://",$globals->baseurl) | |
8f60459a SJ |
50 | . '/' . $platal->ns . "payment/paypal_return/" . S::v('uid') |
51 | . "?comment=" . urlencode(Env::v('comment')); | |
0337d704 | 52 | |
8f60459a | 53 | $this->infos = array(); |
f057316b | 54 | |
8f60459a | 55 | $this->infos['commercant'] = array( |
f057316b | 56 | 'business' => $globals->money->paypal_compte, |
8f60459a | 57 | 'rm' => 2, |
f057316b | 58 | 'return' => $roboturl, |
8f60459a | 59 | 'cn' => 'Commentaires', |
f057316b | 60 | 'no_shipping' => 1, |
eaf30d86 | 61 | 'cbt' => empty($GLOBALS['IS_XNET_SITE']) ? |
8f60459a SJ |
62 | 'Revenir sur polytechnique.org.' : |
63 | 'Revenir sur polytechnique.net.' | |
64 | ); | |
f057316b | 65 | |
8f60459a | 66 | $info_client = array( |
f057316b FB |
67 | 'first_name' => S::v('prenom'), |
68 | 'last_name' => $name, | |
8f60459a SJ |
69 | 'email' => S::user()->bestEmail() |
70 | ); | |
f057316b | 71 | |
1eaaa62d | 72 | // XXX: waiting for port of adresses. |
f057316b | 73 | $res = XDB::query( |
8f60459a SJ |
74 | "SELECT a.text, l.name AS city, a.postalCode AS zip, a.countryiId AS country, |
75 | IF(t1.display_tel != '', t1.display_tel, t2.display_tel) AS night_phone_b | |
76 | FROM auth_user_quick AS q | |
77 | LEFT JOIN profile_addresses AS a ON (q.user_id = a.pid AND FIND_IN_SET('current', a.flags)) | |
78 | LEFT JOIN profile_phones AS t1 ON (t1.uid = a.uid AND t1.link_type = 'address' | |
79 | AND t1.link_id = a.adrid) | |
80 | LEFT JOIN profile_phones AS t2 ON (t2.uid = a.uid AND t2.link_type = 'user' | |
81 | AND t2.link_id = 0) | |
82 | LEFT JOIN geoloc_localities AS l ON (l.id = a.localityId) | |
83 | WHERE q.user_id = {?} | |
84 | LIMIT 1", | |
85 | S::v('uid')); | |
c2ad0ec1 | 86 | $this->infos['client'] = array_map('replace_accent', array_merge($info_client, $res->fetchOneAssoc())); |
8f60459a SJ |
87 | list($this->infos['client']['address1'], $this->infos['client']['address2']) = |
88 | explode("\n", Geocoder::getFirstLines($this->infos['client']['text'], | |
89 | $this->infos['client']['zip'], 2)); | |
90 | unset($this->infos['client']['text']); | |
91 | ||
92 | // We build the transaction's reference | |
93 | $prefix = ($pay->flags->hasflag('unique')) ? str_pad("", 15, "0") : rand_url_id(); | |
94 | $fullref = substr("$prefix-xorg-{$pay->id}", -15); | |
95 | ||
96 | $this->infos['commande'] = array( | |
97 | 'item_name' => replace_accent($pay->text), | |
98 | 'amount' => $this->val_number, | |
c2ad0ec1 | 99 | 'currency_code' => 'EUR', |
8f60459a SJ |
100 | 'custom' => $fullref |
101 | ); | |
f057316b | 102 | |
8f60459a | 103 | $this->infos['divers'] = array('cmd' => '_xclick'); |
0337d704 | 104 | } |
0337d704 | 105 | } |
106 | ||
107 | $api = 'PayPal'; | |
108 | ||
a7de4ef7 | 109 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 110 | ?> |