1
|
|
|
<?php |
2
|
|
|
// ------------------------------------------------------------------------ // |
3
|
|
|
// BOOKSHOP - MODULE FOR XOOPS 2 // |
4
|
|
|
// Copyright (c) 2007, 2008 Instant Zero // |
5
|
|
|
// <http://www.instant-zero.com/> // |
6
|
|
|
// ------------------------------------------------------------------------- // |
7
|
|
|
// This program is free software; you can redistribute it and/or modify // |
8
|
|
|
// it under the terms of the GNU General Public License as published by // |
9
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
10
|
|
|
// (at your option) any later version. // |
11
|
|
|
// // |
12
|
|
|
// You may not change or alter any portion of this comment or credits // |
13
|
|
|
// of supporting developers from this source code or any supporting // |
14
|
|
|
// source code which is considered copyrighted (c) material of the // |
15
|
|
|
// original comment or credit authors. // |
16
|
|
|
// // |
17
|
|
|
// This program is distributed in the hope that it will be useful, // |
18
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
19
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
20
|
|
|
// GNU General Public License for more details. // |
21
|
|
|
// // |
22
|
|
|
// You should have received a copy of the GNU General Public License // |
23
|
|
|
// along with this program; if not, write to the Free Software // |
24
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
25
|
|
|
// ------------------------------------------------------------------------ // |
26
|
|
|
/** |
27
|
|
|
* Classe responsable de la gestion de tout ce qui est relatif à Paypal |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class bookshop_paypal |
34
|
|
|
*/ |
35
|
|
|
class bookshop_paypal |
36
|
|
|
{ |
37
|
|
|
public $testMode; |
38
|
|
|
public $email; |
39
|
|
|
public $moneyCode; |
40
|
|
|
public $useIpn; |
41
|
|
|
public $passwordCancel; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param $testMode |
45
|
|
|
* @param $emailPaypal |
46
|
|
|
* @param $moneyCode |
47
|
|
|
* @param bool $ipn |
48
|
|
|
* @param string $passwordCancel |
49
|
|
|
*/ |
50
|
|
|
public function __construct($testMode, $emailPaypal, $moneyCode, $ipn = false, $passwordCancel = '') |
51
|
|
|
{ |
52
|
|
|
$this->testMode = $testMode; |
53
|
|
|
$this->email = $emailPaypal; |
54
|
|
|
$this->moneyCode = $moneyCode; |
55
|
|
|
$this->useIpn = $ipn; |
56
|
|
|
$this->passwordCancel = $passwordCancel; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Renvoie l'url à utiliser en tenant compte du fait qu'on est en mode test ou pas |
61
|
|
|
* |
62
|
|
|
* @param bool $securized |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
public function getURL($securized = false) |
67
|
|
|
{ |
68
|
|
|
if (!$securized) { |
69
|
|
|
if ($this->testMode == 1) { |
70
|
|
|
return 'https://www.sandbox.paypal.com/cgi-bin/webscr'; |
71
|
|
|
} else { |
72
|
|
|
return 'https://www.paypal.com/cgi-bin/webscr'; |
73
|
|
|
} |
74
|
|
|
} else { |
75
|
|
|
if ($this->testMode == 1) { |
76
|
|
|
return 'www.sandbox.paypal.com'; |
77
|
|
|
} else { |
78
|
|
|
return 'www.paypal.com'; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Renvoie les éléments à ajouter au formulaire en tant que zones cachées |
85
|
|
|
* |
86
|
|
|
* @param $commandId |
87
|
|
|
* @param float $ttc TTC à facturer |
88
|
|
|
* |
89
|
|
|
* @param $emailClient |
90
|
|
|
* |
91
|
|
|
* @internal param int $commmandId Num�ro de la commande |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
public function getFormContent($commandId, $ttc, $emailClient) |
95
|
|
|
{ |
96
|
|
|
global $xoopsConfig; |
97
|
|
|
$ret = array(); |
98
|
|
|
$ret['cmd'] = '_xclick'; |
99
|
|
|
$ret['upload'] = '1'; |
100
|
|
|
$ret['currency_code'] = $this->moneyCode; |
101
|
|
|
$ret['business'] = $this->email; |
102
|
|
|
$ret['return'] = BOOKSHOP_URL.'thankyou.php'; // Page (générique) de remerciement après paiement |
103
|
|
|
$ret['image_url'] = XOOPS_URL . '/images/logo.gif'; |
104
|
|
|
$ret['cpp_header_image'] = XOOPS_URL . '/images/logo.gif'; |
105
|
|
|
$ret['invoice'] = $commandId; |
106
|
|
|
$ret['item_name'] = _BOOKSHOP_COMMAND . $commandId . ' - ' . $xoopsConfig['sitename']; |
107
|
|
|
$ret['item_number'] = $commandId; |
108
|
|
|
$ret['tax'] = 0; // ajout 25/03/2008 |
109
|
|
|
$ret['amount'] = $ttc; |
110
|
|
|
$ret['custom'] = $commandId; |
111
|
|
|
//$ret['rm'] = 2; // Renvoyer les données par POST (normalement) |
112
|
|
|
$ret['email'] = $emailClient; |
113
|
|
|
// paypal_pdt |
114
|
|
|
if(xoops_trim($this->passwordCancel) != '') { // URL à laquelle le navigateur du client est ramené si le paiement est annulé |
115
|
|
|
$ret['cancel_return'] = BOOKSHOP_URL . 'cancel-payment.php?id=' . $this->passwordCancel; |
116
|
|
|
} |
117
|
|
|
if ($this->useIpn == 1) { |
118
|
|
|
$ret['notify_url'] = BOOKSHOP_URL . 'paypal-notify.php'; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return $ret; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|