dolibarr 24.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-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/class/doleditor.class.php';
34
35$servicename = 'PayPal';
36
46// Load translation files required by the page
47$langs->loadLangs(array('admin', 'other', 'paypal', '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
117 if (!$error) {
118 $db->commit();
119 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
120 } else {
121 $db->rollback();
123 }
124}
125
126if ($action == "setlive") {
127 $liveenable = GETPOSTINT('value') ? 0 : 1;
128 $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable, 'yesno', 0, '', $conf->entity);
129 if (!($res > 0)) {
130 $error++;
131 }
132 if (!$error) {
133 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
134 } else {
135 setEventMessages($langs->trans("Error"), null, 'errors');
136 }
137}
138
139
140/*
141 * View
142 */
143
144$form = new Form($db);
145
146llxHeader('', $langs->trans("PaypalSetup"), '', '', 0, 0, '', '', '', 'mod-paypal page-admin_paypal');
147
148
149$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>';
150print load_fiche_titre($langs->trans("ModuleSetup").' PayPal', $linkback);
151
153
154print '<form method="post" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
155print '<input type="hidden" name="token" value="'.newToken().'">';
156print '<input type="hidden" name="action" value="setvalue">';
157
158
159print dol_get_fiche_head($head, 'paypalaccount', '', -1);
160
161print '<span class="opacitymedium">'.$langs->trans("PaypalDesc")."</span><br>\n";
162
163// Test if php curl exist
164if (!function_exists('curl_version')) {
165 $langs->load("errors");
166 setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
167}
168
169
170print '<br>';
171
172print '<div class="div-table-responsive-no-min">';
173print '<table class="noborder centpercent">';
174
175// Account Parameters
176print '<tr class="liste_titre">';
177print '<td>'.$langs->trans("AccountParameter").'</td>';
178print '<td>'.$langs->trans("Value").'</td>';
179print "</tr>\n";
180
181print '<tr class="oddeven">';
182print '<td>';
183print $langs->trans("PaypalLiveEnabled").'</td><td>';
184if (!(getDolGlobalInt('PAYPAL_API_SANDBOX'))) {
185 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=0">';
186 print img_picto($langs->trans("Activated"), 'switch_on');
187} else {
188 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=1">';
189 print img_picto($langs->trans("Disabled"), 'switch_off');
190}
191print '</td></tr>';
192
193print '<tr class="oddeven"><td class="fieldrequired">';
194print $langs->trans("PAYPAL_API_USER").'</td><td>';
195print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.getDolGlobalString('PAYPAL_API_USER').'">';
196print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': admin-facilitator_api1.example.com, paypal_api1.mywebsite.com</span>';
197print '</td></tr>';
198
199
200print '<tr class="oddeven"><td class="fieldrequired">';
201print $langs->trans("PAYPAL_API_PASSWORD").'</td><td>';
202print '<input size="32" type="text" name="PAYPAL_API_PASSWORD" value="'.getDolGlobalString('PAYPAL_API_PASSWORD').'">';
203print '</td></tr>';
204
205
206print '<tr class="oddeven"><td class="fieldrequired">';
207print $langs->trans("PAYPAL_API_SIGNATURE").'</td><td>';
208print '<input size="64" type="text" name="PAYPAL_API_SIGNATURE" value="'.getDolGlobalString('PAYPAL_API_SIGNATURE').'">';
209print '<br><span class="opacitymedium">'.$langs->trans("Example").': ASsqXEmw4KzmX-CPChWSVDNCNfd.A3YNR7uz-VncXXAERFDFDFDF</span>';
210print '</td></tr>';
211
212
213print '<tr class="oddeven"><td>';
214print $langs->trans("PAYPAL_SSLVERSION").'</td><td>';
215print $form->selectarray("PAYPAL_SSLVERSION", array('1'=> $langs->trans('TLSv1'), '6'=> $langs->trans('TLSv1.2')), getDolGlobalString('PAYPAL_SSLVERSION'));
216print '</td></tr>';
217
218print '</table>';
219print '</div>';
220
221print '<br>';
222
223
224print '<div class="div-table-responsive-no-min">';
225print '<table class="noborder centpercent">';
226
227// Usage Parameters
228print '<tr class="liste_titre">';
229print '<td>'.$langs->trans("UsageParameter").'</td>';
230print '<td>'.$langs->trans("Value").'</td>';
231print "</tr>\n";
232
233
234print '<tr class="oddeven"><td>';
235print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
236print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY", array('integral'=> $langs->trans('PaypalModeIntegral'), 'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')), getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY'));
237print '</td></tr>';
238
239/*
240print '<tr class="oddeven"><td>';
241print '<span class="fieldrequired">'.$langs->trans("PAYPAL_API_EXPRESS").'</span></td><td>';
242print $form->selectyesno("PAYPAL_API_EXPRESS",$conf->global->PAYPAL_API_EXPRESS);
243print '</td></tr>';
244*/
245
246
247print '<tr class="oddeven"><td>';
248print $langs->trans("PublicVendorName").'</td><td>';
249print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'">';
250print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
251print '</td></tr>';
252
253if (isModEnabled("bank")) {
254 print '<tr class="oddeven"><td>';
255 print $langs->trans("BankAccount").'</td><td>';
256 print img_picto('', 'bank_account').' ';
257 $form->select_comptes(getDolGlobalString('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS'), 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
258 print '</td></tr>';
259}
260
261print '<tr class="oddeven"><td>';
262print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
263print '<input size="64" type="text" name="ONLINE_PAYMENT_CSS_URL" value="'.getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'">';
264print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': https://mysite/mycss.css</span>';
265print '</td></tr>';
266
267
268print '<tr class="oddeven"><td>';
269print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
270print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL", getDolGlobalString('PAYPAL_ADD_PAYMENT_URL'), 1);
271print '</td></tr>';
272
273
274print '<tr class="oddeven"><td>';
275print $langs->trans("MessageForm").'</td><td>';
276$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM'), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
277$doleditor->Create();
278print '</td></tr>';
279
280
281print '<tr class="oddeven"><td>';
282print $langs->trans("MessageOK").'</td><td>';
283$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', getDolGlobalString('ONLINE_PAYMENT_MESSAGE_OK'), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
284$doleditor->Create();
285print '</td></tr>';
286
287
288print '<tr class="oddeven"><td>';
289print $langs->trans("MessageKO").'</td><td>';
290$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', getDolGlobalString('ONLINE_PAYMENT_MESSAGE_KO'), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
291$doleditor->Create();
292print '</td></tr>';
293
294
295print '<tr class="oddeven"><td>';
296print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
297print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="'.getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'">';
298print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
299print '</td></tr>';
300
301print '</table>';
302print '</div>';
303
304print '<br>';
305
306print '<div class="div-table-responsive-no-min">';
307print '<table class="noborder centpercent">';
308
309print '<tr class="liste_titre">';
310print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
311print '<td>'.$langs->trans("Value").'</td>';
312print "</tr>\n";
313
314// Payment token for URL
315print '<tr class="oddeven"><td>';
316print $langs->trans("SecurityToken").'</td><td>';
317print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.getDolGlobalString('PAYMENT_SECURITY_TOKEN').'">';
318if (!empty($conf->use_javascript_ajax)) {
319 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
320}
321if (getDolGlobalString('PAYMENT_SECURITY_ACCEPT_ANY_TOKEN')) {
322 $langs->load("errors");
323 print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
324}
325print '</td></tr>';
326
327print '</table>';
328print '</div>';
329
330print dol_get_fiche_end();
331
332print $form->buttonsSaveCancel("Save", '');
333
334print '</form>';
335
336print '<br><br>';
337
338// Help doc
339print '<u>'.$langs->trans("InformationToFindParameters", "Paypal").'</u>:<br>';
340if (!empty($conf->use_javascript_ajax)) {
341 print '<a class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
342}
343
344$realpaypalurl = 'www.paypal.com';
345$sandboxpaypalurl = 'developer.paypal.com';
346
347print '<div id="apidoc">';
348print '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>
3491. 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>
3502. Click the "Profile" or "Preferencies" subtab located under the My Account heading.<br>
3513. Click the link "API Access".<br>
3524. Click the View API Certificate link in the right column.<br>
3535. Click the Request API signature radio button on the Request API Credentials page.<br>
3546. Complete the Request API Credential Request form by clicking the agreement checkbox and clicking Submit.<br>
3557. Save the values for API Username, Password and Signature (make sure this long character signature is copied).<br>
3568. Click the "Modify" button after copying your API Username, Password, and Signature.
357';
358print '</div>';
359
360if (!empty($conf->use_javascript_ajax)) {
361 print '
362 <script type="text/javascript">
363 $(document).ready(function () {
364 $("#apidoc").hide();
365 $("#apidoca").click(function() {
366 console.log("We click on apidoca so we show/hide");
367 $("#apidoc").show();
368 $("#apidoca").hide();
369 return false;
370 })
371 });
372 </script>
373 ';
374}
375
376print '<br><br>';
377
378$token = '';
379
380include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
381
382// End of page
383llxFooter();
384$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
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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, $morecssdiv='')
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.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.