dolibarr 20.0.2
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 *
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 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
33
34$servicename = 'PayPal';
35
36// Load translation files required by the page
37$langs->loadLangs(array('admin', 'other', 'paypal', 'paybox', 'stripe'));
38
39if (!$user->admin) {
41}
42
43$action = GETPOST('action', 'aZ09');
44
45if ($action == 'setvalue' && $user->admin) {
46 $db->begin();
47
48 $result = dolibarr_set_const($db, "PAYPAL_API_USER", GETPOST('PAYPAL_API_USER', 'alpha'), 'chaine', 0, '', $conf->entity);
49 if (!($result > 0)) {
50 $error++;
51 }
52 $result = dolibarr_set_const($db, "PAYPAL_API_PASSWORD", GETPOST('PAYPAL_API_PASSWORD', 'alpha'), 'chaine', 0, '', $conf->entity);
53 if (!($result > 0)) {
54 $error++;
55 }
56 $result = dolibarr_set_const($db, "PAYPAL_API_SIGNATURE", GETPOST('PAYPAL_API_SIGNATURE', 'alpha'), 'chaine', 0, '', $conf->entity);
57 if (!($result > 0)) {
58 $error++;
59 }
60 $result = dolibarr_set_const($db, "PAYPAL_SSLVERSION", GETPOST('PAYPAL_SSLVERSION', 'alpha'), 'chaine', 0, '', $conf->entity);
61 if (!($result > 0)) {
62 $error++;
63 }
64 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
65 if (!($result > 0)) {
66 $error++;
67 }
68 $result = dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS", GETPOSTINT('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS'), 'chaine', 0, '', $conf->entity);
69 if (!($result > 0)) {
70 $error++;
71 }
72 $result = dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY", GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY', 'alpha'), 'chaine', 0, '', $conf->entity);
73 if (!($result > 0)) {
74 $error++;
75 }
76 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
77 if (!($result > 0)) {
78 $error++;
79 }
80 $result = dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL", GETPOST('PAYPAL_ADD_PAYMENT_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
81 if (!($result > 0)) {
82 $error++;
83 }
84 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'restricthtml'), 'chaine', 0, '', $conf->entity);
85 if (!($result > 0)) {
86 $error++;
87 }
88 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'restricthtml'), 'chaine', 0, '', $conf->entity);
89 if (!($result > 0)) {
90 $error++;
91 }
92 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'restricthtml'), 'chaine', 0, '', $conf->entity);
93 if (!($result > 0)) {
94 $error++;
95 }
96 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL', 'alpha'), 'chaine', 0, '', $conf->entity);
97 if (!($result > 0)) {
98 $error++;
99 }
100 // Payment token for URL
101 $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
102 if (!($result > 0)) {
103 $error++;
104 }
105 if (empty($conf->use_javascript_ajax)) {
106 $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
107 if (!($result > 0)) {
108 $error++;
109 }
110 }
111
112 if (!$error) {
113 $db->commit();
114 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
115 } else {
116 $db->rollback();
117 dol_print_error($db);
118 }
119}
120
121if ($action == "setlive") {
122 $liveenable = GETPOSTINT('value') ? 0 : 1;
123 $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable, 'yesno', 0, '', $conf->entity);
124 if (!($res > 0)) {
125 $error++;
126 }
127 if (!$error) {
128 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
129 } else {
130 setEventMessages($langs->trans("Error"), null, 'errors');
131 }
132}
133
134
135/*
136 * View
137 */
138
139$form = new Form($db);
140
141llxHeader('', $langs->trans("PaypalSetup"));
142
143
144$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
145print load_fiche_titre($langs->trans("ModuleSetup").' PayPal', $linkback);
146
148
149print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
150print '<input type="hidden" name="token" value="'.newToken().'">';
151print '<input type="hidden" name="action" value="setvalue">';
152
153
154print dol_get_fiche_head($head, 'paypalaccount', '', -1);
155
156print '<span class="opacitymedium">'.$langs->trans("PaypalDesc")."</span><br>\n";
157
158// Test if php curl exist
159if (!function_exists('curl_version')) {
160 $langs->load("errors");
161 setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
162}
163
164
165print '<br>';
166
167print '<div class="div-table-responsive-no-min">';
168print '<table class="noborder centpercent">';
169
170// Account Parameters
171print '<tr class="liste_titre">';
172print '<td>'.$langs->trans("AccountParameter").'</td>';
173print '<td>'.$langs->trans("Value").'</td>';
174print "</tr>\n";
175
176print '<tr class="oddeven">';
177print '<td>';
178print $langs->trans("PaypalLiveEnabled").'</td><td>';
179if (!(getDolGlobalInt('PAYPAL_API_SANDBOX'))) {
180 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=0">';
181 print img_picto($langs->trans("Activated"), 'switch_on');
182} else {
183 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=1">';
184 print img_picto($langs->trans("Disabled"), 'switch_off');
185}
186print '</td></tr>';
187
188print '<tr class="oddeven"><td class="fieldrequired">';
189print $langs->trans("PAYPAL_API_USER").'</td><td>';
190print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.getDolGlobalString('PAYPAL_API_USER').'">';
191print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': admin-facilitator_api1.example.com, paypal_api1.mywebsite.com</span>';
192print '</td></tr>';
193
194
195print '<tr class="oddeven"><td class="fieldrequired">';
196print $langs->trans("PAYPAL_API_PASSWORD").'</td><td>';
197print '<input size="32" type="text" name="PAYPAL_API_PASSWORD" value="'.getDolGlobalString('PAYPAL_API_PASSWORD').'">';
198print '</td></tr>';
199
200
201print '<tr class="oddeven"><td class="fieldrequired">';
202print $langs->trans("PAYPAL_API_SIGNATURE").'</td><td>';
203print '<input size="64" type="text" name="PAYPAL_API_SIGNATURE" value="'.getDolGlobalString('PAYPAL_API_SIGNATURE').'">';
204print '<br><span class="opacitymedium">'.$langs->trans("Example").': ASsqXEmw4KzmX-CPChWSVDNCNfd.A3YNR7uz-VncXXAERFDFDFDF</span>';
205print '</td></tr>';
206
207
208print '<tr class="oddeven"><td>';
209print $langs->trans("PAYPAL_SSLVERSION").'</td><td>';
210print $form->selectarray("PAYPAL_SSLVERSION", array('1'=> $langs->trans('TLSv1'), '6'=> $langs->trans('TLSv1.2')), getDolGlobalString('PAYPAL_SSLVERSION'));
211print '</td></tr>';
212
213print '</table>';
214print '</div>';
215
216print '<br>';
217
218
219print '<div class="div-table-responsive-no-min">';
220print '<table class="noborder centpercent">';
221
222// Usage Parameters
223print '<tr class="liste_titre">';
224print '<td>'.$langs->trans("UsageParameter").'</td>';
225print '<td>'.$langs->trans("Value").'</td>';
226print "</tr>\n";
227
228
229print '<tr class="oddeven"><td>';
230print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
231print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY", array('integral'=> $langs->trans('PaypalModeIntegral'), 'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')), getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY'));
232print '</td></tr>';
233
234/*
235print '<tr class="oddeven"><td>';
236print '<span class="fieldrequired">'.$langs->trans("PAYPAL_API_EXPRESS").'</span></td><td>';
237print $form->selectyesno("PAYPAL_API_EXPRESS",$conf->global->PAYPAL_API_EXPRESS);
238print '</td></tr>';
239*/
240
241
242print '<tr class="oddeven"><td>';
243print $langs->trans("PublicVendorName").'</td><td>';
244print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'">';
245print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
246print '</td></tr>';
247
248if (isModEnabled("bank")) {
249 print '<tr class="oddeven"><td>';
250 print $langs->trans("BankAccount").'</td><td>';
251 print img_picto('', 'bank_account').' ';
252 $form->select_comptes(getDolGlobalString('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS'), 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
253 print '</td></tr>';
254}
255
256print '<tr class="oddeven"><td>';
257print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
258print '<input size="64" type="text" name="ONLINE_PAYMENT_CSS_URL" value="'.getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'">';
259print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
260print '</td></tr>';
261
262
263print '<tr class="oddeven"><td>';
264print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
265print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL", getDolGlobalString('PAYPAL_ADD_PAYMENT_URL'), 1);
266print '</td></tr>';
267
268
269print '<tr class="oddeven"><td>';
270print $langs->trans("MessageForm").'</td><td>';
271$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', getDolGlobalString('ONLINE_PAYMENT_MESSAGE_FORM'), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
272$doleditor->Create();
273print '</td></tr>';
274
275
276print '<tr class="oddeven"><td>';
277print $langs->trans("MessageOK").'</td><td>';
278$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', getDolGlobalString('ONLINE_PAYMENT_MESSAGE_OK'), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
279$doleditor->Create();
280print '</td></tr>';
281
282
283print '<tr class="oddeven"><td>';
284print $langs->trans("MessageKO").'</td><td>';
285$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', getDolGlobalString('ONLINE_PAYMENT_MESSAGE_KO'), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
286$doleditor->Create();
287print '</td></tr>';
288
289
290print '<tr class="oddeven"><td>';
291print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
292print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="'.getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'">';
293print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
294print '</td></tr>';
295
296print '</table>';
297print '</div>';
298
299print '<br>';
300
301print '<div class="div-table-responsive-no-min">';
302print '<table class="noborder centpercent">';
303
304print '<tr class="liste_titre">';
305print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
306print '<td>'.$langs->trans("Value").'</td>';
307print "</tr>\n";
308
309// Payment token for URL
310print '<tr class="oddeven"><td>';
311print $langs->trans("SecurityToken").'</td><td>';
312print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.getDolGlobalString('PAYMENT_SECURITY_TOKEN').'">';
313if (!empty($conf->use_javascript_ajax)) {
314 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
315}
316if (getDolGlobalString('PAYMENT_SECURITY_ACCEPT_ANY_TOKEN')) {
317 $langs->load("errors");
318 print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
319}
320print '</td></tr>';
321
322print '<tr class="oddeven"><td>';
323print $langs->trans("SecurityTokenIsUnique").'</td><td>';
324if ($conf->use_javascript_ajax) {
325 print ajax_constantonoff('PAYMENT_SECURITY_TOKEN_UNIQUE');
326} else {
327 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
328 print $form->selectarray("PAYMENT_SECURITY_TOKEN_UNIQUE", $arrval, getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE'));
329}
330print '</td></tr>';
331
332print '</table>';
333print '</div>';
334
335print dol_get_fiche_end();
336
337print $form->buttonsSaveCancel("Save", '');
338
339print '</form>';
340
341print '<br><br>';
342
343// Help doc
344print '<u>'.$langs->trans("InformationToFindParameters", "Paypal").'</u>:<br>';
345if (!empty($conf->use_javascript_ajax)) {
346 print '<a class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
347}
348
349$realpaypalurl = 'www.paypal.com';
350$sandboxpaypalurl = 'developer.paypal.com';
351
352print '<div id="apidoc">';
353print '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>
3541. 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>
3552. Click the "Profile" or "Preferencies" subtab located under the My Account heading.<br>
3563. Click the link "API Access".<br>
3574. Click the View API Certificate link in the right column.<br>
3585. Click the Request API signature radio button on the Request API Credentials page.<br>
3596. Complete the Request API Credential Request form by clicking the agreement checkbox and clicking Submit.<br>
3607. Save the values for API Username, Password and Signature (make sure this long character signature is copied).<br>
3618. Click the "Modify" button after copying your API Username, Password, and Signature.
362';
363print '</div>';
364
365if (!empty($conf->use_javascript_ajax)) {
366 print "\n".'<script type="text/javascript">';
367 print '$(document).ready(function () {
368 $("#apidoc").hide();
369 $("#apidoca").click(function() {
370 console.log("We click on apidoca so we show/hide");
371 $("#apidoc").show();
372 $("#apidoca").hide();
373 return false;
374 })
375 });';
376 print '</script>';
377}
378
379print '<br><br>';
380
381$token = '';
382
383include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
384
385// End of page
386llxFooter();
387$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()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 dolibarr global constant string value.
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.