dolibarr  16.0.5
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 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
32 
33 $servicename = 'PayPal';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('admin', 'other', 'paypal', 'paybox', 'stripe'));
37 
38 if (!$user->admin) {
40 }
41 
42 $action = GETPOST('action', 'aZ09');
43 
44 if ($action == 'setvalue' && $user->admin) {
45  $db->begin();
46 
47  $result = dolibarr_set_const($db, "PAYPAL_API_USER", GETPOST('PAYPAL_API_USER', 'alpha'), 'chaine', 0, '', $conf->entity);
48  if (!($result > 0)) {
49  $error++;
50  }
51  $result = dolibarr_set_const($db, "PAYPAL_API_PASSWORD", GETPOST('PAYPAL_API_PASSWORD', 'alpha'), 'chaine', 0, '', $conf->entity);
52  if (!($result > 0)) {
53  $error++;
54  }
55  $result = dolibarr_set_const($db, "PAYPAL_API_SIGNATURE", GETPOST('PAYPAL_API_SIGNATURE', 'alpha'), 'chaine', 0, '', $conf->entity);
56  if (!($result > 0)) {
57  $error++;
58  }
59  $result = dolibarr_set_const($db, "PAYPAL_SSLVERSION", GETPOST('PAYPAL_SSLVERSION', 'alpha'), 'chaine', 0, '', $conf->entity);
60  if (!($result > 0)) {
61  $error++;
62  }
63  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
64  if (!($result > 0)) {
65  $error++;
66  }
67  $result = dolibarr_set_const($db, "PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
68  if (!($result > 0)) {
69  $error++;
70  }
71  $result = dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY", GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY', 'alpha'), 'chaine', 0, '', $conf->entity);
72  if (!($result > 0)) {
73  $error++;
74  }
75  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
76  if (!($result > 0)) {
77  $error++;
78  }
79  $result = dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL", GETPOST('PAYPAL_ADD_PAYMENT_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
80  if (!($result > 0)) {
81  $error++;
82  }
83  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'restricthtml'), 'chaine', 0, '', $conf->entity);
84  if (!($result > 0)) {
85  $error++;
86  }
87  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'restricthtml'), 'chaine', 0, '', $conf->entity);
88  if (!($result > 0)) {
89  $error++;
90  }
91  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'restricthtml'), 'chaine', 0, '', $conf->entity);
92  if (!($result > 0)) {
93  $error++;
94  }
95  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL', 'alpha'), 'chaine', 0, '', $conf->entity);
96  if (!($result > 0)) {
97  $error++;
98  }
99  // Payment token for URL
100  $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
101  if (!($result > 0)) {
102  $error++;
103  }
104  if (empty($conf->use_javascript_ajax)) {
105  $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
106  if (!($result > 0)) {
107  $error++;
108  }
109  }
110 
111  if (!$error) {
112  $db->commit();
113  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
114  } else {
115  $db->rollback();
116  dol_print_error($db);
117  }
118 }
119 
120 if ($action == "setlive") {
121  $liveenable = GETPOST('value', 'int') ? 0 : 1;
122  $res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $liveenable, 'yesno', 0, '', $conf->entity);
123  if (!($res > 0)) {
124  $error++;
125  }
126  if (!$error) {
127  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
128  } else {
129  setEventMessages($langs->trans("Error"), null, 'errors');
130  }
131 }
132 
133 
134 /*
135  * View
136  */
137 
138 $form = new Form($db);
139 
140 llxHeader('', $langs->trans("PaypalSetup"));
141 
142 
143 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
144 print load_fiche_titre($langs->trans("ModuleSetup").' PayPal', $linkback);
145 
146 $head = paypaladmin_prepare_head();
147 
148 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
149 print '<input type="hidden" name="token" value="'.newToken().'">';
150 print '<input type="hidden" name="action" value="setvalue">';
151 
152 
153 print dol_get_fiche_head($head, 'paypalaccount', '', -1);
154 
155 print '<span class="opacitymedium">'.$langs->trans("PaypalDesc")."</span><br>\n";
156 
157 // Test if php curl exist
158 if (!function_exists('curl_version')) {
159  $langs->load("errors");
160  setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
161 }
162 
163 
164 print '<br>';
165 
166 print '<div class="div-table-responsive-no-min">';
167 print '<table class="noborder centpercent">';
168 
169 // Account Parameters
170 print '<tr class="liste_titre">';
171 print '<td>'.$langs->trans("AccountParameter").'</td>';
172 print '<td>'.$langs->trans("Value").'</td>';
173 print "</tr>\n";
174 
175 print '<tr class="oddeven">';
176 print '<td>';
177 print $langs->trans("PaypalLiveEnabled").'</td><td>';
178 if (empty($conf->global->PAYPAL_API_SANDBOX)) {
179  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=0">';
180  print img_picto($langs->trans("Activated"), 'switch_on');
181 } else {
182  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlive&token='.newToken().'&value=1">';
183  print img_picto($langs->trans("Disabled"), 'switch_off');
184 }
185 print '</td></tr>';
186 
187 print '<tr class="oddeven"><td class="fieldrequired">';
188 print $langs->trans("PAYPAL_API_USER").'</td><td>';
189 print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.$conf->global->PAYPAL_API_USER.'">';
190 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': admin-facilitator_api1.example.com, paypal_api1.mywebsite.com</span>';
191 print '</td></tr>';
192 
193 
194 print '<tr class="oddeven"><td class="fieldrequired">';
195 print $langs->trans("PAYPAL_API_PASSWORD").'</td><td>';
196 print '<input size="32" type="text" name="PAYPAL_API_PASSWORD" value="'.$conf->global->PAYPAL_API_PASSWORD.'">';
197 print '</td></tr>';
198 
199 
200 print '<tr class="oddeven"><td class="fieldrequired">';
201 print $langs->trans("PAYPAL_API_SIGNATURE").'</td><td>';
202 print '<input size="64" type="text" name="PAYPAL_API_SIGNATURE" value="'.$conf->global->PAYPAL_API_SIGNATURE.'">';
203 print '<br><span class="opacitymedium">'.$langs->trans("Example").': ASsqXEmw4KzmX-CPChWSVDNCNfd.A3YNR7uz-VncXXAERFDFDFDF</span>';
204 print '</td></tr>';
205 
206 
207 print '<tr class="oddeven"><td>';
208 print $langs->trans("PAYPAL_SSLVERSION").'</td><td>';
209 print $form->selectarray("PAYPAL_SSLVERSION", array('1'=> $langs->trans('TLSv1'), '6'=> $langs->trans('TLSv1.2')), $conf->global->PAYPAL_SSLVERSION);
210 print '</td></tr>';
211 
212 print '</table>';
213 print '</div>';
214 
215 print '<br>';
216 
217 
218 print '<div class="div-table-responsive-no-min">';
219 print '<table class="noborder centpercent">';
220 
221 // Usage Parameters
222 print '<tr class="liste_titre">';
223 print '<td>'.$langs->trans("UsageParameter").'</td>';
224 print '<td>'.$langs->trans("Value").'</td>';
225 print "</tr>\n";
226 
227 
228 print '<tr class="oddeven"><td>';
229 print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
230 print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY", array('integral'=> $langs->trans('PaypalModeIntegral'), 'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')), $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY);
231 print '</td></tr>';
232 
233 /*
234 print '<tr class="oddeven"><td>';
235 print '<span class="fieldrequired">'.$langs->trans("PAYPAL_API_EXPRESS").'</span></td><td>';
236 print $form->selectyesno("PAYPAL_API_EXPRESS",$conf->global->PAYPAL_API_EXPRESS);
237 print '</td></tr>';
238 */
239 
240 
241 print '<tr class="oddeven"><td>';
242 print $langs->trans("PublicVendorName").'</td><td>';
243 print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.$conf->global->ONLINE_PAYMENT_CREDITOR.'">';
244 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
245 print '</td></tr>';
246 
247 if (!empty($conf->banque->enabled)) {
248  print '<tr class="oddeven"><td>';
249  print $langs->trans("BankAccount").'</td><td>';
250  print img_picto('', 'bank_account').' ';
251  $form->select_comptes($conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS, 'PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
252  print '</td></tr>';
253 }
254 
255 print '<tr class="oddeven"><td>';
256 print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
257 print '<input size="64" type="text" name="ONLINE_PAYMENT_CSS_URL" value="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'">';
258 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
259 print '</td></tr>';
260 
261 
262 print '<tr class="oddeven"><td>';
263 print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
264 print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL", $conf->global->PAYPAL_ADD_PAYMENT_URL, 1);
265 print '</td></tr>';
266 
267 
268 print '<tr class="oddeven"><td>';
269 print $langs->trans("MessageForm").'</td><td>';
270 $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', $conf->global->ONLINE_PAYMENT_MESSAGE_FORM, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
271 $doleditor->Create();
272 print '</td></tr>';
273 
274 
275 print '<tr class="oddeven"><td>';
276 print $langs->trans("MessageOK").'</td><td>';
277 $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', $conf->global->ONLINE_PAYMENT_MESSAGE_OK, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
278 $doleditor->Create();
279 print '</td></tr>';
280 
281 
282 print '<tr class="oddeven"><td>';
283 print $langs->trans("MessageKO").'</td><td>';
284 $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', $conf->global->ONLINE_PAYMENT_MESSAGE_KO, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_4, '90%');
285 $doleditor->Create();
286 print '</td></tr>';
287 
288 
289 print '<tr class="oddeven"><td>';
290 print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
291 print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="'.$conf->global->ONLINE_PAYMENT_SENDEMAIL.'">';
292 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
293 print '</td></tr>';
294 
295 print '</table>';
296 print '</div>';
297 
298 print '<br>';
299 
300 print '<div class="div-table-responsive-no-min">';
301 print '<table class="noborder centpercent">';
302 
303 print '<tr class="liste_titre">';
304 print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
305 print '<td>'.$langs->trans("Value").'</td>';
306 print "</tr>\n";
307 
308 // Payment token for URL
309 print '<tr class="oddeven"><td>';
310 print $langs->trans("SecurityToken").'</td><td>';
311 print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
312 if (!empty($conf->use_javascript_ajax)) {
313  print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
314 }
315 if (!empty($conf->global->PAYMENT_SECURITY_ACCEPT_ANY_TOKEN)) {
316  $langs->load("errors");
317  print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
318 }
319 print '</td></tr>';
320 
321 print '<tr class="oddeven"><td>';
322 print $langs->trans("SecurityTokenIsUnique").'</td><td>';
323 if ($conf->use_javascript_ajax) {
324  print ajax_constantonoff('PAYMENT_SECURITY_TOKEN_UNIQUE');
325 } else {
326  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
327  print $form->selectarray("PAYMENT_SECURITY_TOKEN_UNIQUE", $arrval, $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE);
328 }
329 print '</td></tr>';
330 
331 print '</table>';
332 print '</div>';
333 
334 print dol_get_fiche_end();
335 
336 print $form->buttonsSaveCancel("Modify", '');
337 
338 print '</form>';
339 
340 print '<br><br>';
341 
342 // Help doc
343 print '<u>'.$langs->trans("InformationToFindParameters", "Paypal").'</u>:<br>';
344 if (!empty($conf->use_javascript_ajax)) {
345  print '<a class="reposition" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
346 }
347 
348 $realpaypalurl = 'www.paypal.com';
349 $sandboxpaypalurl = 'developer.paypal.com';
350 
351 print '<div id="apidoc">';
352 print '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>
353 1. 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>
354 2. Click the "Profile" or "Preferencies" subtab located under the My Account heading.<br>
355 3. Click the link "API Access".<br>
356 4. Click the View API Certificate link in the right column.<br>
357 5. Click the Request API signature radio button on the Request API Credentials page.<br>
358 6. Complete the Request API Credential Request form by clicking the agreement checkbox and clicking Submit.<br>
359 7. Save the values for API Username, Password and Signature (make sure this long character signature is copied).<br>
360 8. Click the "Modify" button after copying your API Username, Password, and Signature.
361 ';
362 print '</div>';
363 
364 if (!empty($conf->use_javascript_ajax)) {
365  print "\n".'<script type="text/javascript">';
366  print '$(document).ready(function () {
367  $("#apidoc").hide();
368  $("#apidoca").click(function() {
369  console.log("We click on apidoca show/hide");
370  $("#apidoc").show();
371  $("#apidoca").hide();
372  return false;
373  })
374  });';
375  print '</script>';
376 }
377 
378 print '<br><br>';
379 
380 $token = '';
381 
382 include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
383 
384 // End of page
385 llxFooter();
386 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
ajax_constantonoff
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='')
On/off button for constant.
Definition: ajax.lib.php:573
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
paypaladmin_prepare_head
paypaladmin_prepare_head()
Define head array for tabs of paypal tools setup pages.
Definition: paypal.lib.php:33
dolibarr_set_const
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).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30