Remove occurences of flag 'unique' for payments.
[platal.git] / modules / payment / money / paypal.inc.php
CommitLineData
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
22class 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
6643b3f0 36 function prepareform($pay, $user)
0337d704 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';
0337d704 46
47 $roboturl = str_replace("https://","http://",$globals->baseurl)
688bec5e 48 . '/' . $platal->ns . "payment/paypal_return/" . $user->id()
6278dfc0 49 . "?comment=" . urlencode(Env::v('comment')) . '&display=' . Post::i('display');
0337d704 50
b2d6af6a
SJ
51 $this->infos = array(
52 'commercant' => array(
53 'business' => $globals->money->paypal_compte,
54 'rm' => 2,
55 'return' => $roboturl,
56 'cn' => 'Commentaires',
57 'no_shipping' => 1,
58 'cbt' => empty($GLOBALS['IS_XNET_SITE']) ? 'Revenir sur polytechnique.org.' : 'Revenir sur polytechnique.net.'
59 )
8f60459a 60 );
f057316b 61
8f60459a 62 $info_client = array(
b2d6af6a
SJ
63 'first_name' => $user->firstName(),
64 'last_name' => $user->lastName(),
65 'email' => $user->bestEmail()
8f60459a 66 );
f057316b 67
d8923e94 68 if ($user->hasProfile()) {
07b0a566
SJ
69 $res = XDB::query("SELECT pa.text, GROUP_CONCAT(pace2.short_name) AS city,
70 GROUP_CONCAT(pace3.short_name) AS zip, GROUP_CONCAT(pace1.short_name) AS country,
c789e299 71 IF(pp1.display_tel != '', pp1.display_tel, pp2.display_tel) AS night_phone_b
c9a1b3ff
SJ
72 FROM profile_addresses AS pa
73 LEFT JOIN profile_phones AS pp1 ON (pp1.pid = pa.pid AND pp1.link_type = 'address' AND pp1.link_id = pa.id)
74 LEFT JOIN profile_phones AS pp2 ON (pp2.pid = pa.pid AND pp2.link_type = 'user' AND pp2.link_id = 0)
07b0a566
SJ
75 LEFT JOIN profile_addresses_components AS pc ON (pa.pid = pc.pid AND pa.jobid = pc.jobid AND pa.groupid = pc.groupid
76 AND pa.type = pc.type AND pa.id = pc.id)
fa0c836f
SJ
77 LEFT JOIN profile_addresses_components_enum AS pace1 ON (FIND_IN_SET('country', pace1.types) AND pace1.id = pc.component_id)
78 LEFT JOIN profile_addresses_components_enum AS pace2 ON (FIND_IN_SET('locality', pace2.types) AND pace2.id = pc.component_id)
79 LEFT JOIN profile_addresses_components_enum AS pace3 ON (FIND_IN_SET('postal_code', pace3.types) AND pace3.id = pc.component_id)
c789e299 80 WHERE pa.pid = {?} AND FIND_IN_SET('current', pa.flags)
c9a1b3ff 81 GROUP BY pa.pid, pa.jobid, pa.groupid, pa.id, pa.type
c789e299
SJ
82 LIMIT 1",
83 $user->profile()->id());
84 $this->infos['client'] = array_map('replace_accent', array_merge($info_client, $res->fetchOneAssoc()));
85 list($this->infos['client']['address1'], $this->infos['client']['address2']) =
86 explode("\n", Geocoder::getFirstLines($this->infos['client']['text'],
87 $this->infos['client']['zip'], 2));
88 unset($this->infos['client']['text']);
89 } else {
90 $this->infos['client'] = replace_accent($info_client);
91 }
8f60459a
SJ
92
93 // We build the transaction's reference
1c02b178 94 $prefix = rand_url_id();
8f60459a
SJ
95 $fullref = substr("$prefix-xorg-{$pay->id}", -15);
96
97 $this->infos['commande'] = array(
98 'item_name' => replace_accent($pay->text),
99 'amount' => $this->val_number,
c2ad0ec1 100 'currency_code' => 'EUR',
8f60459a
SJ
101 'custom' => $fullref
102 );
f057316b 103
8f60459a 104 $this->infos['divers'] = array('cmd' => '_xclick');
0337d704 105 }
0337d704 106}
107
108$api = 'PayPal';
109
a7de4ef7 110// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 111?>