Commit | Line | Data |
---|---|---|
0337d704 | 1 | <?php |
2 | /*************************************************************************** | |
5e1513f6 | 3 | * Copyright (C) 2003-2011 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 | 46 | $user = S::user(); |
0337d704 | 47 | |
48 | $roboturl = str_replace("https://","http://",$globals->baseurl) | |
8f60459a SJ |
49 | . '/' . $platal->ns . "payment/paypal_return/" . S::v('uid') |
50 | . "?comment=" . urlencode(Env::v('comment')); | |
0337d704 | 51 | |
b2d6af6a SJ |
52 | $this->infos = array( |
53 | 'commercant' => array( | |
54 | 'business' => $globals->money->paypal_compte, | |
55 | 'rm' => 2, | |
56 | 'return' => $roboturl, | |
57 | 'cn' => 'Commentaires', | |
58 | 'no_shipping' => 1, | |
59 | 'cbt' => empty($GLOBALS['IS_XNET_SITE']) ? 'Revenir sur polytechnique.org.' : 'Revenir sur polytechnique.net.' | |
60 | ) | |
8f60459a | 61 | ); |
f057316b | 62 | |
8f60459a | 63 | $info_client = array( |
b2d6af6a SJ |
64 | 'first_name' => $user->firstName(), |
65 | 'last_name' => $user->lastName(), | |
66 | 'email' => $user->bestEmail() | |
8f60459a | 67 | ); |
f057316b | 68 | |
d8923e94 | 69 | if ($user->hasProfile()) { |
c789e299 SJ |
70 | $res = XDB::query("SELECT pa.text, gl.name AS city, pa.postalCode AS zip, pa.countryId AS country, |
71 | IF(pp1.display_tel != '', pp1.display_tel, pp2.display_tel) AS night_phone_b | |
72 | FROM profile_addresses AS pa | |
73 | LEFT JOIN profile_phones AS pp1 ON (pp1.pid = pa.pid AND pp1.link_type = 'address' | |
74 | AND pp1.link_id = pa.id) | |
75 | LEFT JOIN profile_phones AS pp2 ON (pp2.pid = pa.pid AND pp2.link_type = 'user' | |
76 | AND pp2.link_id = 0) | |
77 | LEFT JOIN geoloc_localities AS gl ON (gl.id = pa.localityId) | |
78 | WHERE pa.pid = {?} AND FIND_IN_SET('current', pa.flags) | |
79 | LIMIT 1", | |
80 | $user->profile()->id()); | |
81 | $this->infos['client'] = array_map('replace_accent', array_merge($info_client, $res->fetchOneAssoc())); | |
82 | list($this->infos['client']['address1'], $this->infos['client']['address2']) = | |
83 | explode("\n", Geocoder::getFirstLines($this->infos['client']['text'], | |
84 | $this->infos['client']['zip'], 2)); | |
85 | unset($this->infos['client']['text']); | |
86 | } else { | |
87 | $this->infos['client'] = replace_accent($info_client); | |
88 | } | |
8f60459a SJ |
89 | |
90 | // We build the transaction's reference | |
91 | $prefix = ($pay->flags->hasflag('unique')) ? str_pad("", 15, "0") : rand_url_id(); | |
92 | $fullref = substr("$prefix-xorg-{$pay->id}", -15); | |
93 | ||
94 | $this->infos['commande'] = array( | |
95 | 'item_name' => replace_accent($pay->text), | |
96 | 'amount' => $this->val_number, | |
c2ad0ec1 | 97 | 'currency_code' => 'EUR', |
8f60459a SJ |
98 | 'custom' => $fullref |
99 | ); | |
f057316b | 100 | |
8f60459a | 101 | $this->infos['divers'] = array('cmd' => '_xclick'); |
0337d704 | 102 | } |
0337d704 | 103 | } |
104 | ||
105 | $api = 'PayPal'; | |
106 | ||
a7de4ef7 | 107 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 108 | ?> |