dolibarr  17.0.4
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
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32 require_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 
39 if (!$user->admin) {
41 }
42 
43 $action = GETPOST('action', 'aZ09');
44 
45 if ($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", GETPOST('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), '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 
121 if ($action == "setlive") {
122  $liveenable = GETPOST('value', 'int') ? 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 
141 llxHeader('', $langs->trans("PaypalSetup"));
142 
143 
144 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
145 print load_fiche_titre($langs->trans("ModuleSetup").' PayPal', $linkback);
146 
147 $head = paypaladmin_prepare_head();
148 
149 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
150 print '<input type="hidden" name="token" value="'.newToken().'">';
151 print '<input type="hidden" name="action" value="setvalue">';
152 
153 
154 print dol_get_fiche_head($head, 'paypalaccount', '', -1);
155 
156 print '<span class="opacitymedium">'.$langs->trans("PaypalDesc")."</span><br>\n";
157 
158 // Test if php curl exist
159 if (!function_exists('curl_version')) {
160  $langs->load("errors");
161  setEventMessages($langs->trans("ErrorPhpCurlNotInstalled"), null, 'errors');
162 }
163 
164 
165 print '<br>';
166 
167 print '<div class="div-table-responsive-no-min">';
168 print '<table class="noborder centpercent">';
169 
170 // Account Parameters
171 print '<tr class="liste_titre">';
172 print '<td>'.$langs->trans("AccountParameter").'</td>';
173 print '<td>'.$langs->trans("Value").'</td>';
174 print "</tr>\n";
175 
176 print '<tr class="oddeven">';
177 print '<td>';
178 print $langs->trans("PaypalLiveEnabled").'</td><td>';
179 if (!(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 }
186 print '</td></tr>';
187 
188 print '<tr class="oddeven"><td class="fieldrequired">';
189 print $langs->trans("PAYPAL_API_USER").'</td><td>';
190 print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.getDolGlobalString('PAYPAL_API_USER').'">';
191 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': admin-facilitator_api1.example.com, paypal_api1.mywebsite.com</span>';
192 print '</td></tr>';
193 
194 
195 print '<tr class="oddeven"><td class="fieldrequired">';
196 print $langs->trans("PAYPAL_API_PASSWORD").'</td><td>';
197 print '<input size="32" type="text" name="PAYPAL_API_PASSWORD" value="'.getDolGlobalString('PAYPAL_API_PASSWORD').'">';
198 print '</td></tr>';
199 
200 
201 print '<tr class="oddeven"><td class="fieldrequired">';
202 print $langs->trans("PAYPAL_API_SIGNATURE").'</td><td>';
203 print '<input size="64" type="text" name="PAYPAL_API_SIGNATURE" value="'.getDolGlobalString('PAYPAL_API_SIGNATURE').'">';
204 print '<br><span class="opacitymedium">'.$langs->trans("Example").': ASsqXEmw4KzmX-CPChWSVDNCNfd.A3YNR7uz-VncXXAERFDFDFDF</span>';
205 print '</td></tr>';
206 
207 
208 print '<tr class="oddeven"><td>';
209 print $langs->trans("PAYPAL_SSLVERSION").'</td><td>';
210 print $form->selectarray("PAYPAL_SSLVERSION", array('1'=> $langs->trans('TLSv1'), '6'=> $langs->trans('TLSv1.2')), getDolGlobalString('PAYPAL_SSLVERSION'));
211 print '</td></tr>';
212 
213 print '</table>';
214 print '</div>';
215 
216 print '<br>';
217 
218 
219 print '<div class="div-table-responsive-no-min">';
220 print '<table class="noborder centpercent">';
221 
222 // Usage Parameters
223 print '<tr class="liste_titre">';
224 print '<td>'.$langs->trans("UsageParameter").'</td>';
225 print '<td>'.$langs->trans("Value").'</td>';
226 print "</tr>\n";
227 
228 
229 print '<tr class="oddeven"><td>';
230 print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
231 print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY", array('integral'=> $langs->trans('PaypalModeIntegral'), 'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')), getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY'));
232 print '</td></tr>';
233 
234 /*
235 print '<tr class="oddeven"><td>';
236 print '<span class="fieldrequired">'.$langs->trans("PAYPAL_API_EXPRESS").'</span></td><td>';
237 print $form->selectyesno("PAYPAL_API_EXPRESS",$conf->global->PAYPAL_API_EXPRESS);
238 print '</td></tr>';
239 */
240 
241 
242 print '<tr class="oddeven"><td>';
243 print $langs->trans("PublicVendorName").'</td><td>';
244 print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'">';
245 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
246 print '</td></tr>';
247 
248 if (isModEnabled("banque")) {
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 
256 print '<tr class="oddeven"><td>';
257 print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
258 print '<input size="64" type="text" name="ONLINE_PAYMENT_CSS_URL" value="'.getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'">';
259 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
260 print '</td></tr>';
261 
262 
263 print '<tr class="oddeven"><td>';
264 print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
265 print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL", getDolGlobalString('PAYPAL_ADD_PAYMENT_URL'), 1);
266 print '</td></tr>';
267 
268 
269 print '<tr class="oddeven"><td>';
270 print $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();
273 print '</td></tr>';
274 
275 
276 print '<tr class="oddeven"><td>';
277 print $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();
280 print '</td></tr>';
281 
282 
283 print '<tr class="oddeven"><td>';
284 print $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();
287 print '</td></tr>';
288 
289 
290 print '<tr class="oddeven"><td>';
291 print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
292 print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="'.getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'">';
293 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
294 print '</td></tr>';
295 
296 print '</table>';
297 print '</div>';
298 
299 print '<br>';
300 
301 print '<div class="div-table-responsive-no-min">';
302 print '<table class="noborder centpercent">';
303 
304 print '<tr class="liste_titre">';
305 print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
306 print '<td>'.$langs->trans("Value").'</td>';
307 print "</tr>\n";
308 
309 // Payment token for URL
310 print '<tr class="oddeven"><td>';
311 print $langs->trans("SecurityToken").'</td><td>';
312 print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.getDolGlobalString('PAYMENT_SECURITY_TOKEN').'">';
313 if (!empty($conf->use_javascript_ajax)) {
314  print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
315 }
316 if (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 }
320 print '</td></tr>';
321 
322 print '<tr class="oddeven"><td>';
323 print $langs->trans("SecurityTokenIsUnique").'</td><td>';
324 if ($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 }
330 print '</td></tr>';
331 
332 print '</table>';
333 print '</div>';
334 
335 print dol_get_fiche_end();
336 
337 print $form->buttonsSaveCancel("Modify", '');
338 
339 print '</form>';
340 
341 print '<br><br>';
342 
343 // Help doc
344 print '<u>'.$langs->trans("InformationToFindParameters", "Paypal").'</u>:<br>';
345 if (!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 
352 print '<div id="apidoc">';
353 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>
354 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>
355 2. Click the "Profile" or "Preferencies" subtab located under the My Account heading.<br>
356 3. Click the link "API Access".<br>
357 4. Click the View API Certificate link in the right column.<br>
358 5. Click the Request API signature radio button on the Request API Credentials page.<br>
359 6. Complete the Request API Credential Request form by clicking the agreement checkbox and clicking Submit.<br>
360 7. Save the values for API Username, Password and Signature (make sure this long character signature is copied).<br>
361 8. Click the "Modify" button after copying your API Username, Password, and Signature.
362 ';
363 print '</div>';
364 
365 if (!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 show/hide");
371  $("#apidoc").show();
372  $("#apidoca").hide();
373  return false;
374  })
375  });';
376  print '</script>';
377 }
378 
379 print '<br><br>';
380 
381 $token = '';
382 
383 include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
384 
385 // End of page
386 llxFooter();
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).
Definition: admin.lib.php:632
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:600
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage a WYSIWYG editor.
Class to manage generation of HTML components Only common components must be here.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
paypaladmin_prepare_head()
Define head array for tabs of paypal tools setup pages.
Definition: paypal.lib.php:33
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.