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