dolibarr 25.0.0-alpha
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-2025 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/lib/security2.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
35
36$servicename = 'PayPal';
37
47// Load translation files required by the page
48$langs->loadLangs(array('admin', 'other', 'paypal', 'stripe'));
49
50if (!$user->admin) {
52}
53
54$action = GETPOST('action', 'aZ09');
55$error = 0;
56
57if ($action == 'setvalue' && $user->admin) {
58 $db->begin();
59
60 $result = dolibarr_set_const($db, "PAYPAL_API_USER", GETPOST('PAYPAL_API_USER', 'alpha'), 'chaine', 0, '', $conf->entity);
61 if (!($result > 0)) {
62 $error++;
63 }
64 $result = dolibarr_set_const($db, "PAYPAL_API_PASSWORD", GETPOST('PAYPAL_API_PASSWORD', 'alpha'), 'chaine', 0, '', $conf->entity);
65 if (!($result > 0)) {
66 $error++;
67 }
68 $result = dolibarr_set_const($db, "PAYPAL_API_SIGNATURE", GETPOST('PAYPAL_API_SIGNATURE', 'alpha'), 'chaine', 0, '', $conf->entity);
69 if (!($result > 0)) {
70 $error++;
71 }
72 $result = dolibarr_set_const($db, "PAYPAL_SSLVERSION", GETPOST('PAYPAL_SSLVERSION', 'alpha'), 'chaine', 0, '', $conf->entity);
73 if (!($result > 0)) {
74 $error++;
75 }
76 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
77 if (!($result > 0)) {
78 $error++;
79 }
80 $result = dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS", GETPOSTINT('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS'), 'chaine', 0, '', $conf->entity);
81 if (!($result > 0)) {
82 $error++;
83 }
84 $result = dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY", GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY', 'alpha'), 'chaine', 0, '', $conf->entity);
85 if (!($result > 0)) {
86 $error++;
87 }
88 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
89 if (!($result > 0)) {
90 $error++;
91 }
92 $result = dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL", GETPOST('PAYPAL_ADD_PAYMENT_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
93 if (!($result > 0)) {
94 $error++;
95 }
96 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'restricthtml'), 'chaine', 0, '', $conf->entity);
97 if (!($result > 0)) {
98 $error++;
99 }
100 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'restricthtml'), 'chaine', 0, '', $conf->entity);
101 if (!($result > 0)) {
102 $error++;
103 }
104 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'restricthtml'), 'chaine', 0, '', $conf->entity);
105 if (!($result > 0)) {
106 $error++;
107 }
108 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL', 'alpha'), 'chaine', 0, '', $conf->entity);
109 if (!($result > 0)) {
110 $error++;
111 }
112 // Payment token for URL
113 $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
114 if (!($result > 0)) {
115 $error++;
116 }
117
118 if (!$error) {
119 $db->commit();
120 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
121 } else {
122 $db->rollback();
123 dol_print_error($db);
124 }
125}
126
127if ($action == "setlive") {
128 $liveenable = GETPOSTINT('value') ? 0 : 1;
129 $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable, 'yesno', 0, '', $conf->entity);
130 if (!($res > 0)) {
131 $error++;
132 }
133 if (!$error) {
134 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
135 } else {
136 setEventMessages($langs->trans("Error"), null, 'errors');
137 }
138}
139
140
141/*
142 * View
143 */
144
145$form = new Form($db);
146
147llxHeader('', $langs->trans("PaypalSetup"), '', '', 0, 0, '', '', '', 'mod-paypal page-admin_paypal');
148
149
150$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
151print load_fiche_titre($langs->trans("ModuleSetup").' PayPal', $linkback);
152
154
155print '<form method="post" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'" spellcheck="false">';
156print '<input type="hidden" name="token" value="'.newToken().'">';
157print '<input type="hidden" name="action" value="setvalue">';
158
159
160print dol_get_fiche_head($head, 'paypalaccount', '', -1);
161
162print '<div class="info">'.$langs->trans("PaypalDesc")."</div>\n";
163
164// Test if php curl exist
165if (!function_exists('curl_version')) {
166 $langs->load("errors");
167 setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
168}
169
170
171print '<br>';
172
173print '<div class="div-table-responsive-no-min">';
174print '<table class="noborder centpercent">';
175
176// Account Parameters
177print '<tr class="liste_titre">';
178print '<td>'.$langs->trans("AccountParameter").'</td>';
179print '<td>'.$langs->trans("Value").'</td>';
180print "</tr>\n";
181
182print '<tr class="oddeven">';
183print '<td>';
184print $langs->trans("PaypalLiveEnabled").'</td><td>';
185if (!(getDolGlobalInt('PAYPAL_API_SANDBOX'))) {
186 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=0">';
187 print img_picto($langs->trans("Activated"), 'switch_on');
188} else {
189 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=1">';
190 print img_picto($langs->trans("Disabled"), 'switch_off');
191}
192print '</td></tr>';
193
194print '<tr class="oddeven"><td class="fieldrequired">';
195print $langs->trans("PAYPAL_API_USER").'</td><td>';
196print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.getDolGlobalString('PAYPAL_API_USER').'">';
197print ' &nbsp; <span class="opacitymedium small">'.$langs->trans("Example").': admin-facilitator_api1.example.com, paypal_api1.mywebsite.com</span>';
198print '</td></tr>';
199
200
201print '<tr class="oddeven"><td class="fieldrequired">';
202print $langs->trans("PAYPAL_API_PASSWORD").'</td><td>';
203print '<input size="32" type="password" id="PAYPAL_API_PASSWORD" name="PAYPAL_API_PASSWORD" value="'.getDolGlobalString('PAYPAL_API_PASSWORD').'">';
204if (getDolGlobalString('PAYPAL_API_PASSWORD')) {
205 print showEyeForField('eyePAYPAL_API_PASSWORD', 'PAYPAL_API_PASSWORD');
206}
207print '</td></tr>';
208
209
210print '<tr class="oddeven"><td class="fieldrequired">';
211print $langs->trans("PAYPAL_API_SIGNATURE").'</td><td>';
212print '<input size="64" type="password" id="PAYPAL_API_SIGNATURE" name="PAYPAL_API_SIGNATURE" value="'.getDolGlobalString('PAYPAL_API_SIGNATURE').'">';
213if (getDolGlobalString('PAYPAL_API_SIGNATURE')) {
214 print showEyeForField('eyePAYPAL_API_SIGNATURE', 'PAYPAL_API_SIGNATURE');
215}
216print '<br><span class="opacitymedium small">'.$langs->trans("Example").': ASsqXEmw4KzmX-CPChWSVDNCNfd.A3YNR7uz-VncXXAERFDFDFDF</span>';
217print '</td></tr>';
218
219
220print '<tr class="oddeven"><td>';
221print $langs->trans("PAYPAL_SSLVERSION").'</td><td>';
222print $form->selectarray("PAYPAL_SSLVERSION", array('1'=> $langs->trans('TLSv1'), '6'=> $langs->trans('TLSv1.2')), getDolGlobalString('PAYPAL_SSLVERSION'));
223print '</td></tr>';
224
225print '</table>';
226print '</div>';
227
228print '<br>';
229
230
231print '<div class="div-table-responsive-no-min">';
232print '<table class="noborder centpercent">';
233
234// Usage Parameters
235print '<tr class="liste_titre">';
236print '<td>'.$langs->trans("UsageParameter").'</td>';
237print '<td>'.$langs->trans("Value").'</td>';
238print "</tr>\n";
239
240
241print '<tr class="oddeven"><td>';
242print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
243print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY", array('integral'=> $langs->trans('PaypalModeIntegral'), 'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')), getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY'));
244print '</td></tr>';
245
246/*
247print '<tr class="oddeven"><td>';
248print '<span class="fieldrequired">'.$langs->trans("PAYPAL_API_EXPRESS").'</span></td><td>';
249print $form->selectyesno("PAYPAL_API_EXPRESS",$conf->global->PAYPAL_API_EXPRESS);
250print '</td></tr>';
251*/
252
253
254print '<tr class="oddeven"><td>';
255print $langs->trans("PublicVendorName").'</td><td>';
256print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'" placeholder="'.dolPrintHTMLForAttribute($mysoc->name).'">';
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 small">'.$langs->trans("Example").': https://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 small">'.$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 '</table>';
334print '</div>';
335
336print dol_get_fiche_end();
337
338print $form->buttonsSaveCancel("Save", '');
339
340print '</form>';
341
342print '<br><br>';
343
344// Help doc
345print '<u>'.$langs->trans("InformationToFindParameters", "Paypal").'</u>:<br>';
346if (!empty($conf->use_javascript_ajax)) {
347 print '<a class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
348}
349
350$realpaypalurl = 'www.paypal.com';
351$sandboxpaypalurl = 'developer.paypal.com';
352
353print '<div id="apidoc">';
354print '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>
3551. 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>
3562. Click the "Profile" or "Preferencies" subtab located under the My Account heading.<br>
3573. Click the link "API Access".<br>
3584. Click the View API Certificate link in the right column.<br>
3595. Click the Request API signature radio button on the Request API Credentials page.<br>
3606. Complete the Request API Credential Request form by clicking the agreement checkbox and clicking Submit.<br>
3617. Save the values for API Username, Password and Signature (make sure this long character signature is copied).<br>
3628. Click the "Modify" button after copying your API Username, Password, and Signature.
363';
364print '</div>';
365
366if (!empty($conf->use_javascript_ajax)) {
367 print '
368 <script type="text/javascript">
369 $(document).ready(function () {
370 $("#apidoc").hide();
371 $("#apidoca").click(function() {
372 console.log("We click on apidoca so we show/hide");
373 $("#apidoc").show();
374 $("#apidoca").hide();
375 return false;
376 })
377 });
378 </script>
379 ';
380}
381
382print '<br><br>';
383
384$token = '';
385
386include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
387
388// End of page
389llxFooter();
390$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).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
global $mysoc
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
paypaladmin_prepare_head()
Define head array for tabs of paypal tools setup pages.
showEyeForField($htmlname, $htmlnameofinput)
Output the eye picto to show/hide a password HTML field.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.