dolibarr 21.0.0-beta
paypal.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.org>
4 * Copyright (C) 2011-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
34
35$servicename = 'PayPal';
36
46// Load translation files required by the page
47$langs->loadLangs(array('admin', 'other', 'paypal', 'paybox', 'stripe'));
48
49if (!$user->admin) {
51}
52
53$action = GETPOST('action', 'aZ09');
54$error = 0;
55
56if ($action == 'setvalue' && $user->admin) {
57 $db->begin();
58
59 $result = dolibarr_set_const($db, "PAYPAL_API_USER", GETPOST('PAYPAL_API_USER', 'alpha'), 'chaine', 0, '', $conf->entity);
60 if (!($result > 0)) {
61 $error++;
62 }
63 $result = dolibarr_set_const($db, "PAYPAL_API_PASSWORD", GETPOST('PAYPAL_API_PASSWORD', 'alpha'), 'chaine', 0, '', $conf->entity);
64 if (!($result > 0)) {
65 $error++;
66 }
67 $result = dolibarr_set_const($db, "PAYPAL_API_SIGNATURE", GETPOST('PAYPAL_API_SIGNATURE', 'alpha'), 'chaine', 0, '', $conf->entity);
68 if (!($result > 0)) {
69 $error++;
70 }
71 $result = dolibarr_set_const($db, "PAYPAL_SSLVERSION", GETPOST('PAYPAL_SSLVERSION', 'alpha'), 'chaine', 0, '', $conf->entity);
72 if (!($result > 0)) {
73 $error++;
74 }
75 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
76 if (!($result > 0)) {
77 $error++;
78 }
79 $result = dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS", GETPOSTINT('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS'), 'chaine', 0, '', $conf->entity);
80 if (!($result > 0)) {
81 $error++;
82 }
83 $result = dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY", GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY', 'alpha'), 'chaine', 0, '', $conf->entity);
84 if (!($result > 0)) {
85 $error++;
86 }
87 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
88 if (!($result > 0)) {
89 $error++;
90 }
91 $result = dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL", GETPOST('PAYPAL_ADD_PAYMENT_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
92 if (!($result > 0)) {
93 $error++;
94 }
95 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'restricthtml'), 'chaine', 0, '', $conf->entity);
96 if (!($result > 0)) {
97 $error++;
98 }
99 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'restricthtml'), 'chaine', 0, '', $conf->entity);
100 if (!($result > 0)) {
101 $error++;
102 }
103 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'restricthtml'), 'chaine', 0, '', $conf->entity);
104 if (!($result > 0)) {
105 $error++;
106 }
107 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL', 'alpha'), 'chaine', 0, '', $conf->entity);
108 if (!($result > 0)) {
109 $error++;
110 }
111 // Payment token for URL
112 $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
113 if (!($result > 0)) {
114 $error++;
115 }
116 if (empty($conf->use_javascript_ajax)) {
117 $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
118 if (!($result > 0)) {
119 $error++;
120 }
121 }
122
123 if (!$error) {
124 $db->commit();
125 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
126 } else {
127 $db->rollback();
128 dol_print_error($db);
129 }
130}
131
132if ($action == "setlive") {
133 $liveenable = GETPOSTINT('value') ? 0 : 1;
134 $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable, 'yesno', 0, '', $conf->entity);
135 if (!($res > 0)) {
136 $error++;
137 }
138 if (!$error) {
139 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
140 } else {
141 setEventMessages($langs->trans("Error"), null, 'errors');
142 }
143}
144
145
146/*
147 * View
148 */
149
150$form = new Form($db);
151
152llxHeader('', $langs->trans("PaypalSetup"), '', '', 0, 0, '', '', '', 'mod-paypal page-admin_paypal');
153
154
155$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
156print load_fiche_titre($langs->trans("ModuleSetup").' PayPal', $linkback);
157
159
160print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
161print '<input type="hidden" name="token" value="'.newToken().'">';
162print '<input type="hidden" name="action" value="setvalue">';
163
164
165print dol_get_fiche_head($head, 'paypalaccount', '', -1);
166
167print '<span class="opacitymedium">'.$langs->trans("PaypalDesc")."</span><br>\n";
168
169// Test if php curl exist
170if (!function_exists('curl_version')) {
171 $langs->load("errors");
172 setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
173}
174
175
176print '<br>';
177
178print '<div class="div-table-responsive-no-min">';
179print '<table class="noborder centpercent">';
180
181// Account Parameters
182print '<tr class="liste_titre">';
183print '<td>'.$langs->trans("AccountParameter").'</td>';
184print '<td>'.$langs->trans("Value").'</td>';
185print "</tr>\n";
186
187print '<tr class="oddeven">';
188print '<td>';
189print $langs->trans("PaypalLiveEnabled").'</td><td>';
190if (!(getDolGlobalInt('PAYPAL_API_SANDBOX'))) {
191 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=0">';
192 print img_picto($langs->trans("Activated"), 'switch_on');
193} else {
194 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=1">';
195 print img_picto($langs->trans("Disabled"), 'switch_off');
196}
197print '</td></tr>';
198
199print '<tr class="oddeven"><td class="fieldrequired">';
200print $langs->trans("PAYPAL_API_USER").'</td><td>';
201print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.getDolGlobalString('PAYPAL_API_USER').'">';
202print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': admin-facilitator_api1.example.com, paypal_api1.mywebsite.com</span>';
203print '</td></tr>';
204
205
206print '<tr class="oddeven"><td class="fieldrequired">';
207print $langs->trans("PAYPAL_API_PASSWORD").'</td><td>';
208print '<input size="32" type="text" name="PAYPAL_API_PASSWORD" value="'.getDolGlobalString('PAYPAL_API_PASSWORD').'">';
209print '</td></tr>';
210
211
212print '<tr class="oddeven"><td class="fieldrequired">';
213print $langs->trans("PAYPAL_API_SIGNATURE").'</td><td>';
214print '<input size="64" type="text" name="PAYPAL_API_SIGNATURE" value="'.getDolGlobalString('PAYPAL_API_SIGNATURE').'">';
215print '<br><span class="opacitymedium">'.$langs->trans("Example").': ASsqXEmw4KzmX-CPChWSVDNCNfd.A3YNR7uz-VncXXAERFDFDFDF</span>';
216print '</td></tr>';
217
218
219print '<tr class="oddeven"><td>';
220print $langs->trans("PAYPAL_SSLVERSION").'</td><td>';
221print $form->selectarray("PAYPAL_SSLVERSION", array('1'=> $langs->trans('TLSv1'), '6'=> $langs->trans('TLSv1.2')), getDolGlobalString('PAYPAL_SSLVERSION'));
222print '</td></tr>';
223
224print '</table>';
225print '</div>';
226
227print '<br>';
228
229
230print '<div class="div-table-responsive-no-min">';
231print '<table class="noborder centpercent">';
232
233// Usage Parameters
234print '<tr class="liste_titre">';
235print '<td>'.$langs->trans("UsageParameter").'</td>';
236print '<td>'.$langs->trans("Value").'</td>';
237print "</tr>\n";
238
239
240print '<tr class="oddeven"><td>';
241print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
242print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY", array('integral'=> $langs->trans('PaypalModeIntegral'), 'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')), getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY'));
243print '</td></tr>';
244
245/*
246print '<tr class="oddeven"><td>';
247print '<span class="fieldrequired">'.$langs->trans("PAYPAL_API_EXPRESS").'</span></td><td>';
248print $form->selectyesno("PAYPAL_API_EXPRESS",$conf->global->PAYPAL_API_EXPRESS);
249print '</td></tr>';
250*/
251
252
253print '<tr class="oddeven"><td>';
254print $langs->trans("PublicVendorName").'</td><td>';
255print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'">';
256print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
257print '</td></tr>';
258
259if (isModEnabled("bank")) {
260 print '<tr class="oddeven"><td>';
261 print $langs->trans("BankAccount").'</td><td>';
262 print img_picto('', 'bank_account').' ';
263 $form->select_comptes(getDolGlobalString('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS'), 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
264 print '</td></tr>';
265}
266
267print '<tr class="oddeven"><td>';
268print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
269print '<input size="64" type="text" name="ONLINE_PAYMENT_CSS_URL" value="'.getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'">';
270print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
271print '</td></tr>';
272
273
274print '<tr class="oddeven"><td>';
275print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
276print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL", getDolGlobalString('PAYPAL_ADD_PAYMENT_URL'), 1);
277print '</td></tr>';
278
279
280print '<tr class="oddeven"><td>';
281print $langs->trans("MessageForm").'</td><td>';
282$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM'), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
283$doleditor->Create();
284print '</td></tr>';
285
286
287print '<tr class="oddeven"><td>';
288print $langs->trans("MessageOK").'</td><td>';
289$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', getDolGlobalString('ONLINE_PAYMENT_MESSAGE_OK'), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
290$doleditor->Create();
291print '</td></tr>';
292
293
294print '<tr class="oddeven"><td>';
295print $langs->trans("MessageKO").'</td><td>';
296$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', getDolGlobalString('ONLINE_PAYMENT_MESSAGE_KO'), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
297$doleditor->Create();
298print '</td></tr>';
299
300
301print '<tr class="oddeven"><td>';
302print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
303print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="'.getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'">';
304print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
305print '</td></tr>';
306
307print '</table>';
308print '</div>';
309
310print '<br>';
311
312print '<div class="div-table-responsive-no-min">';
313print '<table class="noborder centpercent">';
314
315print '<tr class="liste_titre">';
316print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
317print '<td>'.$langs->trans("Value").'</td>';
318print "</tr>\n";
319
320// Payment token for URL
321print '<tr class="oddeven"><td>';
322print $langs->trans("SecurityToken").'</td><td>';
323print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.getDolGlobalString('PAYMENT_SECURITY_TOKEN').'">';
324if (!empty($conf->use_javascript_ajax)) {
325 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
326}
327if (getDolGlobalString('PAYMENT_SECURITY_ACCEPT_ANY_TOKEN')) {
328 $langs->load("errors");
329 print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
330}
331print '</td></tr>';
332
333print '<tr class="oddeven"><td>';
334print $langs->trans("SecurityTokenIsUnique").'</td><td>';
335if ($conf->use_javascript_ajax) {
336 print ajax_constantonoff('PAYMENT_SECURITY_TOKEN_UNIQUE');
337} else {
338 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
339 print $form->selectarray("PAYMENT_SECURITY_TOKEN_UNIQUE", $arrval, getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE'));
340}
341print '</td></tr>';
342
343print '</table>';
344print '</div>';
345
346print dol_get_fiche_end();
347
348print $form->buttonsSaveCancel("Save", '');
349
350print '</form>';
351
352print '<br><br>';
353
354// Help doc
355print '<u>'.$langs->trans("InformationToFindParameters", "Paypal").'</u>:<br>';
356if (!empty($conf->use_javascript_ajax)) {
357 print '<a class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
358}
359
360$realpaypalurl = 'www.paypal.com';
361$sandboxpaypalurl = 'developer.paypal.com';
362
363print '<div id="apidoc">';
364print 'Your API authentication information can be found with following steps. We recommend that you open a separate Web browser session when carrying out this procedure.<br>
3651. Log in to your PayPal account (on real paypal <a href="https://'.$realpaypalurl.'" target="_blank" rel="noopener noreferrer external">'.$realpaypalurl.'</a> (or sandbox <a href="https://'.$sandboxpaypalurl.'" target="_blank" rel="noopener noreferrer external">'.$sandboxpaypalurl.'</a>).<br>
3662. Click the "Profile" or "Preferencies" subtab located under the My Account heading.<br>
3673. Click the link "API Access".<br>
3684. Click the View API Certificate link in the right column.<br>
3695. Click the Request API signature radio button on the Request API Credentials page.<br>
3706. Complete the Request API Credential Request form by clicking the agreement checkbox and clicking Submit.<br>
3717. Save the values for API Username, Password and Signature (make sure this long character signature is copied).<br>
3728. Click the "Modify" button after copying your API Username, Password, and Signature.
373';
374print '</div>';
375
376if (!empty($conf->use_javascript_ajax)) {
377 print "\n".'<script type="text/javascript">';
378 print '$(document).ready(function () {
379 $("#apidoc").hide();
380 $("#apidoca").click(function() {
381 console.log("We click on apidoca so we show/hide");
382 $("#apidoc").show();
383 $("#apidoca").hide();
384 return false;
385 })
386 });';
387 print '</script>';
388}
389
390print '<br><br>';
391
392$token = '';
393
394include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
395
396// End of page
397llxFooter();
398$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
paypaladmin_prepare_head()
Define head array for tabs of paypal tools setup pages.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.