dolibarr  18.0.6
stripe.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
3  * Copyright (C) 2017 Olivier Geffroy <jeff@jeffinfo.com>
4  * Copyright (C) 2017 Saasprov <saasprov@gmail.com>
5  * Copyright (C) 2018-2022 Thibault FOUCART <support@ptibogxiv.net>
6  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.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 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
35 
36 $servicename = 'Stripe';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('admin', 'other', 'paypal', 'paybox', 'stripe'));
40 
41 if (empty($user->admin)) {
43 }
44 if (empty($conf->stripe->enabled)) {
46 }
47 
48 $action = GETPOST('action', 'aZ09');
49 
50 
51 /*
52  * Actions
53  */
54 
55 if ($action == 'setvalue' && $user->admin) {
56  $db->begin();
57 
58  if (empty($conf->stripeconnect->enabled)) {
59  $result = dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY", GETPOST('STRIPE_TEST_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
60  if (!($result > 0)) {
61  $error++;
62  }
63  $result = dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY", GETPOST('STRIPE_TEST_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
64  if (!($result > 0)) {
65  $error++;
66  }
67  $result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_ID", GETPOST('STRIPE_TEST_WEBHOOK_ID', 'alpha'), 'chaine', 0, '', $conf->entity);
68  if (!($result > 0)) {
69  $error++;
70  }
71  $result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_KEY", GETPOST('STRIPE_TEST_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
72  if (!($result > 0)) {
73  $error++;
74  }
75  $result = dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY", GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
76  if (!($result > 0)) {
77  $error++;
78  }
79  $result = dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY", GETPOST('STRIPE_LIVE_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
80  if (!($result > 0)) {
81  $error++;
82  }
83  $result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_ID", GETPOST('STRIPE_LIVE_WEBHOOK_ID', 'alpha'), 'chaine', 0, '', $conf->entity);
84  if (!($result > 0)) {
85  $error++;
86  }
87  $result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_KEY", GETPOST('STRIPE_LIVE_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
88  if (!($result > 0)) {
89  $error++;
90  }
91  }
92  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
93  if (!($result > 0)) {
94  $error++;
95  }
96  $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
97  if (!($result > 0)) {
98  $error++;
99  }
100  $result = dolibarr_set_const($db, "STRIPE_USER_ACCOUNT_FOR_ACTIONS", GETPOST('STRIPE_USER_ACCOUNT_FOR_ACTIONS', 'int'), 'chaine', 0, '', $conf->entity);
101  if (!($result > 0)) {
102  $error++;
103  }
104  $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity);
105  if (!($result > 0)) {
106  $error++;
107  }
108  if (GETPOSTISSET('STRIPE_LOCATION')) {
109  $result = dolibarr_set_const($db, "STRIPE_LOCATION", GETPOST('STRIPE_LOCATION', 'alpha'), 'chaine', 0, '', $conf->entity);
110  if (!$result > 0) {
111  $error++;
112  }
113  }
114  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
115  if (!($result > 0)) {
116  $error++;
117  }
118  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'restricthtml'), 'chaine', 0, '', $conf->entity);
119  if (!($result > 0)) {
120  $error++;
121  }
122  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'restricthtml'), 'chaine', 0, '', $conf->entity);
123  if (!($result > 0)) {
124  $error++;
125  }
126  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'restricthtml'), 'chaine', 0, '', $conf->entity);
127  if (!($result > 0)) {
128  $error++;
129  }
130  $result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
131  if (!($result > 0)) {
132  $error++;
133  }
134  // Stock decrement
135  //$result = dolibarr_set_const($db, "ONLINE_PAYMENT_WAREHOUSE", (GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') > 0 ? GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
136  //if (! $result > 0)
137  // $error ++;
138 
139  // Payment token for URL
140  $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
141  if (!($result > 0)) {
142  $error++;
143  }
144  if (empty($conf->use_javascript_ajax)) {
145  $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
146  if (!($result > 0)) {
147  $error++;
148  }
149  }
150 
151  if (!$error) {
152  $db->commit();
153  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
154  } else {
155  $db->rollback();
156  dol_print_error($db);
157  }
158 }
159 
160 if ($action == "setlive") {
161  $liveenable = GETPOST('value', 'int');
162  $res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity);
163  if ($res > 0) {
164  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
165  } else {
166  setEventMessages($langs->trans("Error"), null, 'errors');
167  }
168 }
169 //TODO: import script for stripe account saving in alone or connect mode for stripe.class.php
170 
171 
172 /*
173  * View
174  */
175 
176 $form = new Form($db);
177 $formproduct = new FormProduct($db);
178 
179 llxHeader('', $langs->trans("StripeSetup"));
180 
181 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
182 print load_fiche_titre($langs->trans("ModuleSetup").' Stripe', $linkback);
183 
184 $head = stripeadmin_prepare_head();
185 
186 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
187 print '<input type="hidden" name="token" value="'.newToken().'">';
188 print '<input type="hidden" name="action" value="setvalue">';
189 
190 print dol_get_fiche_head($head, 'stripeaccount', '', -1);
191 
192 $stripearrayofwebhookevents = array('account.updated', 'payout.created', 'payout.paid', 'charge.pending', 'charge.refunded', 'charge.succeeded', 'charge.failed', 'payment_intent.succeeded', 'payment_intent.payment_failed', 'payment_method.attached', 'payment_method.updated', 'payment_method.card_automatically_updated', 'payment_method.detached', 'source.chargeable', 'customer.deleted');
193 
194 print '<span class="opacitymedium">'.$langs->trans("StripeDesc")."</span><br>\n";
195 
196 print '<br>';
197 
198 print '<div class="div-table-responsive-no-min">';
199 print '<table class="noborder centpercent">';
200 print '<tr class="liste_titre">';
201 print '<td>'.$langs->trans("AccountParameter").'</td>';
202 print '<td>'.$langs->trans("Value").'</td>';
203 print '<td></td>';
204 print "</tr>\n";
205 
206 print '<tr class="oddeven">';
207 print '<td>';
208 print $langs->trans("StripeLiveEnabled").'</td><td>';
209 if ($conf->use_javascript_ajax) {
210  print ajax_constantonoff('STRIPE_LIVE');
211 } else {
212  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
213  print $form->selectarray("STRIPE_LIVE", $arrval, $conf->global->STRIPE_LIVE);
214 }
215 print '</td><td></td></tr>';
216 
217 if (empty($conf->stripeconnect->enabled)) {
218  print '<tr class="oddeven"><td>';
219  print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>';
220  print '<input class="minwidth300" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY.'" placeholder="'.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx">';
221  print '</td><td></td></tr>';
222 
223  print '<tr class="oddeven"><td>';
224  print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
225  print '<input class="minwidth300" type="text" name="STRIPE_TEST_SECRET_KEY" value="'.$conf->global->STRIPE_TEST_SECRET_KEY.'" placeholder="'.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx">';
226  print '</td><td></td></tr>';
227 
228  print '<tr class="oddeven"><td>';
229  print '<span class="titlefield">'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>';
230  if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
231  print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_ID" value="'.getDolGlobalString('STRIPE_TEST_WEBHOOK_ID').'" placeholder="'.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx">';
232  print '<br>';
233  }
234  print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_KEY" value="'.getDolGlobalString('STRIPE_TEST_WEBHOOK_KEY').'" placeholder="'.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx">';
235  $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForTestWebhook").'</span> ';
236  $url = dol_buildpath('/public/stripe/ipn.php', 3);
237  $url .= '?test=1';
238  //global $dolibarr_main_instance_unique_id;
239  //$url .= '&securitykey='.dol_hash('stripeipn-'.$dolibarr_main_instance_unique_id.'-'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY, 'md5');
240  $out .= '<input type="text" id="onlinetestwebhookurl" class="minwidth500" value="'.$url.'" disabled>';
241  $out .= ajax_autoselect("onlinetestwebhookurl", 0);
242  print '<br>'.$out;
243  print '</td><td>';
244  if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
245  if (!empty($conf->global->STRIPE_TEST_WEBHOOK_KEY) && !empty($conf->global->STRIPE_TEST_SECRET_KEY) && !empty($conf->global->STRIPE_TEST_WEBHOOK_ID)) {
246  if (utf8_check($conf->global->STRIPE_TEST_SECRET_KEY)) {
247  try {
248  \Stripe\Stripe::setApiKey($conf->global->STRIPE_TEST_SECRET_KEY);
249  $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_TEST_WEBHOOK_ID);
250  $endpoint->enabled_events = $stripearrayofwebhookevents;
251  if (GETPOST('webhook', 'alpha') == $conf->global->STRIPE_TEST_WEBHOOK_ID) {
252  if (!GETPOST('status', 'alpha')) {
253  $endpoint->disabled = true;
254  } else {
255  $endpoint->disabled = false;
256  }
257  }
258  $endpoint->url = $url;
259  $endpoint->save();
260 
261  if ($endpoint->status == 'enabled') {
262  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
263  print img_picto($langs->trans("Activated"), 'switch_on');
264  } else {
265  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
266  print img_picto($langs->trans("Disabled"), 'switch_off');
267  }
268  } catch (Exception $e) {
269  print $e->getMessage();
270  }
271  } else {
272  print 'Bad value for the secret key. Reenter and save it again to fix this.';
273  }
274  } else {
275  print img_picto($langs->trans("Inactive"), 'statut5');
276  }
277  }
278  print'</td></tr>';
279 } else {
280  print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
281  print '<td><b>'.$langs->trans("StripeConnect_Mode").'</b><br>';
282  print $langs->trans("STRIPE_APPLICATION_FEE_PLATFORM").' ';
283  print price($conf->global->STRIPE_APPLICATION_FEE_PERCENT);
284  print '% + ';
285  print price($conf->global->STRIPE_APPLICATION_FEE);
286  print ' '.$langs->getCurrencySymbol($conf->currency).' '.$langs->trans("minimum").' '.price($conf->global->STRIPE_APPLICATION_FEE_MINIMAL).' '.$langs->getCurrencySymbol($conf->currency);
287  print '</td><td></td></tr>';
288 }
289 
290 if (empty($conf->stripeconnect->enabled)) {
291  print '<tr class="oddeven"><td>';
292  print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
293  print '<input class="minwidth300" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.getDolGlobalString('STRIPE_LIVE_PUBLISHABLE_KEY').'" placeholder="'.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
294  print '</td><td></td></tr>';
295 
296  print '<tr class="oddeven"><td>';
297  print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
298  print '<input class="minwidth300" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.getDolGlobalString('STRIPE_LIVE_SECRET_KEY').'" placeholder="'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
299  print '</td><td></td></tr>';
300 
301  print '<tr class="oddeven"><td>';
302  print '<span class="titlefield">'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
303  if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
304  print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID').'" placeholder="'.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx">';
305  print '<br>';
306  }
307  print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_KEY').'" placeholder="'.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx">';
308  $out = img_picto('', 'globe', 'class="pictofixedwidth"').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForLiveWebhook").'</span> ';
309  $url = dol_buildpath('/public/stripe/ipn.php', 3);
310  //global $dolibarr_main_instance_unique_id;
311  //$url .= '?securitykey='.dol_hash('stripeipn-'.$dolibarr_main_instance_unique_id.'-'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY, 'md5');
312  $out .= '<input type="text" id="onlinelivewebhookurl" class="minwidth500" value="'.$url.'" disabled>';
313  $out .= ajax_autoselect("onlinelivewebhookurl", 0);
314  print '<br>'.$out;
315  print '</td><td>';
316  if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
317  if (!empty($conf->global->STRIPE_LIVE_WEBHOOK_KEY) && !empty($conf->global->STRIPE_LIVE_SECRET_KEY) && !empty($conf->global->STRIPE_LIVE_WEBHOOK_ID)) {
318  if (utf8_check($conf->global->STRIPE_TEST_SECRET_KEY)) {
319  try {
320  \Stripe\Stripe::setApiKey($conf->global->STRIPE_LIVE_SECRET_KEY);
321  $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK_ID);
322  $endpoint->enabled_events = $stripearrayofwebhookevents;
323  if (GETPOST('webhook', 'alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID) {
324  if (empty(GETPOST('status', 'alpha'))) {
325  $endpoint->disabled = true;
326  } else {
327  $endpoint->disabled = false;
328  }
329  }
330  $endpoint->url = $url;
331  $endpoint->save();
332  if ($endpoint->status == 'enabled') {
333  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
334  print img_picto($langs->trans("Activated"), 'switch_on');
335  } else {
336  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
337  print img_picto($langs->trans("Disabled"), 'switch_off');
338  }
339  } catch (Exception $e) {
340  print $e->getMessage();
341  }
342  }
343  } else {
344  print img_picto($langs->trans("Inactive"), 'statut5');
345  }
346  }
347  print '</td></tr>';
348 }
349 
350 print '</table>';
351 print '</div>';
352 
353 print '<br>';
354 
355 
356 print '<div class="div-table-responsive-no-min">';
357 print '<table class="noborder centpercent">';
358 print '<tr class="liste_titre">';
359 print '<td>'.$langs->trans("UsageParameter").'</td>';
360 print '<td>'.$langs->trans("Value").'</td>';
361 print "</tr>\n";
362 
363 print '<tr class="oddeven"><td>';
364 print $langs->trans("PublicVendorName").'</td><td>';
365 print '<input class="minwidth300" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'">';
366 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
367 print '</td></tr>';
368 
369 print '<tr class="oddeven"><td>';
370 print $langs->trans("StripeUserAccountForActions").'</td><td>';
371 print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS'), 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0);
372 print '</td></tr>';
373 
374 print '<tr class="oddeven"><td>';
375 print $langs->trans("BankAccount").'</td><td>';
376 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
377 $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'), 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
378 print '</td></tr>';
379 
380 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // What is this for ?
381  print '<tr class="oddeven"><td>';
382  print $langs->trans("BankAccountForBankTransfer").'</td><td>';
383  print img_picto('', 'bank_account', 'class="pictofixedwidth"');
384  $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS'), 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
385  print '</td></tr>';
386 }
387 
388 // Card Present for Stripe Terminal
389 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
390  print '<tr class="oddeven"><td>';
391  print $langs->trans("STRIPE_CARD_PRESENT").'</td><td>';
392  if ($conf->use_javascript_ajax) {
393  print ajax_constantonoff('STRIPE_CARD_PRESENT');
394  } else {
395  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
396  print $form->selectarray("STRIPE_CARD_PRESENT", $arrval, $conf->global->STRIPE_CARD_PRESENT);
397  }
398  print '</td></tr>';
399 }
400 
401 // Locations for Stripe Terminal
402 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
403  print '<tr class="oddeven"><td>';
404  print $langs->trans("TERMINAL_LOCATION").'</td><td>';
405  $service = 'StripeTest';
406  $servicestatus = 0;
407  if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) {
408  $service = 'StripeLive';
409  $servicestatus = 1;
410  }
411 
412  try {
413  global $stripearrayofkeysbyenv;
414  $site_account = $stripearrayofkeysbyenv[$servicestatus]['secret_key'];
415  if (!empty($site_account)) {
416  \Stripe\Stripe::setApiKey($site_account);
417  }
418  if (isModEnabled('stripe') && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
419  $service = 'StripeTest';
420  $servicestatus = '0';
421  dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
422  } else {
423  $service = 'StripeLive';
424  $servicestatus = '1';
425  }
426  $stripe = new Stripe($db);
427  if (!empty($site_account)) {
428  // If $site_account not defined, then key not set and no way to call API Location
429  $stripeacc = $stripe->getStripeAccount($service);
430  if ($stripeacc) {
431  $locations = \Stripe\Terminal\Location::all('', array("stripe_account" => $stripeacc));
432  } else {
433  $locations = \Stripe\Terminal\Location::all();
434  }
435  }
436  } catch (Exception $e) {
437  print $e->getMessage().'<br>';
438  }
439 
440  // Define the array $location
441  $location = array();
442  $location[""] = $langs->trans("NotDefined");
443  if (!empty($locations)) {
444  foreach ($locations as $tmplocation) {
445  $location[$tmplocation->id] = $tmplocation->display_name;
446  }
447  }
448 
449  print $form->selectarray("STRIPE_LOCATION", $location, getDolGlobalString('STRIPE_LOCATION'));
450  print '</td></tr>';
451 }
452 
453 print '<tr class="oddeven"><td>';
454 print $langs->trans("STRIPE_SEPA_DIRECT_DEBIT").'</td><td>';
455 if ($conf->use_javascript_ajax) {
456  print ajax_constantonoff('STRIPE_SEPA_DIRECT_DEBIT');
457 } else {
458  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
459  print $form->selectarray("STRIPE_SEPA_DIRECT_DEBIT", $arrval, getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT'));
460 }
461 print '</td></tr>';
462 
463 
464 // Activate Klarna
465 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
466  print '<tr class="oddeven"><td>';
467  print $langs->trans("STRIPE_KLARNA").'</td><td>';
468  if ($conf->use_javascript_ajax) {
469  print ajax_constantonoff('STRIPE_KLARNA');
470  } else {
471  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
472  print $form->selectarray("STRIPE_KLARNA", $arrval, $conf->global->STRIPE_KLARNA);
473  }
474  print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForKlarnaCustomers").'</span>';
475  print '</td></tr>';
476 }
477 
478 // Activate Bancontact
479 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
480  print '<tr class="oddeven"><td>';
481  print $langs->trans("STRIPE_BANCONTACT").'</td><td>';
482  if ($conf->use_javascript_ajax) {
483  print ajax_constantonoff('STRIPE_BANCONTACT');
484  } else {
485  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
486  print $form->selectarray("STRIPE_BANCONTACT", $arrval, $conf->global->STRIPE_BANCONTACT);
487  }
488  print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForBECustomers").'</span>';
489  print '</td></tr>';
490 }
491 
492 // Activate iDEAL
493 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
494  print '<tr class="oddeven"><td>';
495  print $langs->trans("STRIPE_IDEAL").'</td><td>';
496  if ($conf->use_javascript_ajax) {
497  print ajax_constantonoff('STRIPE_IDEAL');
498  } else {
499  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
500  print $form->selectarray("STRIPE_IDEAL", $arrval, $conf->global->STRIPE_SEPA_DIRECT_DEBIT);
501  }
502  print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForNLCustomers").'</span>';
503  print '</td></tr>';
504 }
505 
506 // Activate Giropay
507 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
508  print '<tr class="oddeven"><td>';
509  print $langs->trans("STRIPE_GIROPAY").'</td><td>';
510  if ($conf->use_javascript_ajax) {
511  print ajax_constantonoff('STRIPE_GIROPAY');
512  } else {
513  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
514  print $form->selectarray("STRIPE_GIROPAY", $arrval, $conf->global->STRIPE_GIROPAY);
515  }
516  print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForDECustomers").'</span>';
517  print '</td></tr>';
518 }
519 
520 // Activate Sofort
521 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
522  print '<tr class="oddeven"><td>';
523  print $langs->trans("STRIPE_SOFORT").'</td><td>';
524  if ($conf->use_javascript_ajax) {
525  print ajax_constantonoff('STRIPE_SOFORT');
526  } else {
527  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
528  print $form->selectarray("STRIPE_SOFORT", $arrval, $conf->global->STRIPE_SOFORT);
529  }
530  print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForATBEDEITNLESCustomers").'</span>';
531  print '</td></tr>';
532 }
533 
534 print '<tr class="oddeven"><td>';
535 print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
536 print '<input class="width500" type="text" name="ONLINE_PAYMENT_CSS_URL" value="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'">';
537 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
538 print '</td></tr>';
539 
540 print '<tr class="oddeven"><td>';
541 print $langs->trans("MessageForm").'</td><td>';
542 $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', $conf->global->ONLINE_PAYMENT_MESSAGE_FORM, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
543 $doleditor->Create();
544 print '</td></tr>';
545 
546 print '<tr class="oddeven"><td>';
547 print $langs->trans("MessageOK").'</td><td>';
548 $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', $conf->global->ONLINE_PAYMENT_MESSAGE_OK, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
549 $doleditor->Create();
550 print '</td></tr>';
551 
552 print '<tr class="oddeven"><td>';
553 print $langs->trans("MessageKO").'</td><td>';
554 $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', $conf->global->ONLINE_PAYMENT_MESSAGE_KO, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
555 $doleditor->Create();
556 print '</td></tr>';
557 
558 print '<tr class="oddeven"><td>';
559 print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
560 print img_picto('', 'email', 'class="pictofixedwidth"');
561 print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="'.$conf->global->ONLINE_PAYMENT_SENDEMAIL.'">';
562 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
563 print '</td></tr>';
564 
565 print '</table>';
566 print '</div>';
567 
568 print '<br>';
569 
570 print '<div class="div-table-responsive-no-min">';
571 print '<table class="noborder centpercent">';
572 
573 print '<tr class="liste_titre">';
574 print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
575 print '<td>'.$langs->trans("Value").'</td>';
576 print "</tr>\n";
577 
578 // Payment token for URL
579 print '<tr class="oddeven"><td>';
580 print $langs->trans("SecurityToken").'</td><td>';
581 print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
582 if (!empty($conf->use_javascript_ajax)) {
583  print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
584 }
585 if (!empty($conf->global->PAYMENT_SECURITY_ACCEPT_ANY_TOKEN)) {
586  $langs->load("errors");
587  print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
588 }
589 print '</td></tr>';
590 
591 print '<tr class="oddeven"><td>';
592 print $langs->trans("SecurityTokenIsUnique").'</td><td>';
593 if ($conf->use_javascript_ajax) {
594  print ajax_constantonoff('PAYMENT_SECURITY_TOKEN_UNIQUE', null, null, 0, 0, 1);
595 } else {
596  $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
597  print $form->selectarray("PAYMENT_SECURITY_TOKEN_UNIQUE", $arrval, $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE);
598 }
599 print '</td></tr>';
600 
601 print '</table>';
602 print '</div>';
603 
604 print dol_get_fiche_end();
605 
606 print $form->buttonsSaveCancel("Save", '');
607 
608 print '</form>';
609 
610 print '<br><br>';
611 
612 
613 $token = '';
614 
615 include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
616 
617 print info_admin($langs->trans("ExampleOfTestCreditCard", '4242424242424242 (no 3DSecure) or 4000000000003063 (3DSecure required) or 4000002760003184 (3DSecure2 required on all transaction) or 4000003800000446 (3DSecure2 required, the off-session allowed)', '4000000000000101', '4000000000000069', '4000000000000341'));
618 
619 if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
620  print info_admin($langs->trans("ExampleOfTestBankAcountForSEPA", 'AT611904300234573201 (pending->succeed) or AT861904300235473202 (pending->failed)'));
621 }
622 
623 
624 
625 if (!empty($conf->use_javascript_ajax)) {
626  print "\n".'<script type="text/javascript">';
627  print '$(document).ready(function () {
628  $("#apidoc").hide();
629  $("#apidoca").click(function() {
630  console.log("We click on apidoca show/hide");
631  $("#apidoc").show();
632  $("#apidoca").hide();
633  return false;
634  });
635  });';
636  print '</script>';
637 }
638 
639 // End of page
640 llxFooter();
641 $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:638
ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0, $forcereload=0, $marginleftonlyshort=2, $forcenoajax=0, $setzeroinsteadofdel=0, $suffix='', $mode='', $morecss='')
On/off button for constant.
Definition: ajax.lib.php:630
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.
Class with static methods for building HTML components related to products Only components common to ...
Stripe class.
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.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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_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.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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)
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
utf8_check($str)
Check if a string is in UTF8.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
stripeadmin_prepare_head()
Define head array for tabs of stripe tools setup pages.
Definition: stripe.lib.php:31