dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
35require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
36
37$servicename = 'Stripe';
38
48// Load translation files required by the page
49$langs->loadLangs(array('admin', 'other', 'paypal', 'paybox', 'stripe'));
50
51if (empty($user->admin)) {
53}
54if (empty($conf->stripe->enabled)) {
56}
57
58$action = GETPOST('action', 'aZ09');
59
60
61/*
62 * Actions
63 */
64$error = 0;
65
66if ($action == 'setvalue' && $user->admin) {
67 $db->begin();
68
69 if (empty($conf->stripeconnect->enabled)) {
70 $result = dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY", GETPOST('STRIPE_TEST_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
71 if (!($result > 0)) {
72 $error++;
73 }
74 $result = dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY", GETPOST('STRIPE_TEST_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
75 if (!($result > 0)) {
76 $error++;
77 }
78 $result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_ID", GETPOST('STRIPE_TEST_WEBHOOK_ID', 'alpha'), 'chaine', 0, '', $conf->entity);
79 if (!($result > 0)) {
80 $error++;
81 }
82 $result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_KEY", GETPOST('STRIPE_TEST_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
83 if (!($result > 0)) {
84 $error++;
85 }
86 $result = dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY", GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
87 if (!($result > 0)) {
88 $error++;
89 }
90 $result = dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY", GETPOST('STRIPE_LIVE_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
91 if (!($result > 0)) {
92 $error++;
93 }
94 $result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_ID", GETPOST('STRIPE_LIVE_WEBHOOK_ID', 'alpha'), 'chaine', 0, '', $conf->entity);
95 if (!($result > 0)) {
96 $error++;
97 }
98 $result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_KEY", GETPOST('STRIPE_LIVE_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
99 if (!($result > 0)) {
100 $error++;
101 }
102 }
103 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
104 if (!($result > 0)) {
105 $error++;
106 }
107 $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOSTINT('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'), 'chaine', 0, '', $conf->entity);
108 if (!($result > 0)) {
109 $error++;
110 }
111 $result = dolibarr_set_const($db, "STRIPE_USER_ACCOUNT_FOR_ACTIONS", GETPOSTINT('STRIPE_USER_ACCOUNT_FOR_ACTIONS'), 'chaine', 0, '', $conf->entity);
112 if (!($result > 0)) {
113 $error++;
114 }
115 $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOSTINT('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS'), 'chaine', 0, '', $conf->entity);
116 if (!($result > 0)) {
117 $error++;
118 }
119 if (GETPOSTISSET('STRIPE_LOCATION')) {
120 $result = dolibarr_set_const($db, "STRIPE_LOCATION", GETPOST('STRIPE_LOCATION', 'alpha'), 'chaine', 0, '', $conf->entity);
121 if (!$result > 0) {
122 $error++;
123 }
124 }
125 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
126 if (!($result > 0)) {
127 $error++;
128 }
129 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'restricthtml'), 'chaine', 0, '', $conf->entity);
130 if (!($result > 0)) {
131 $error++;
132 }
133 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'restricthtml'), 'chaine', 0, '', $conf->entity);
134 if (!($result > 0)) {
135 $error++;
136 }
137 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'restricthtml'), 'chaine', 0, '', $conf->entity);
138 if (!($result > 0)) {
139 $error++;
140 }
141 $result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
142 if (!($result > 0)) {
143 $error++;
144 }
145 // Stock decrement
146 //$result = dolibarr_set_const($db, "ONLINE_PAYMENT_WAREHOUSE", (GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') > 0 ? GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
147 //if (! $result > 0)
148 // $error ++;
149
150 // Payment token for URL
151 $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
152 if (!($result > 0)) {
153 $error++;
154 }
155 if (empty($conf->use_javascript_ajax)) {
156 $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
157 if (!($result > 0)) {
158 $error++;
159 }
160 }
161
162 if (!$error) {
163 $db->commit();
164 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
165 } else {
166 $db->rollback();
167 dol_print_error($db);
168 }
169}
170
171if ($action == "setlive") {
172 $liveenable = GETPOSTINT('value');
173 $res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity);
174 if ($res > 0) {
175 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
176 } else {
177 setEventMessages($langs->trans("Error"), null, 'errors');
178 }
179}
180//TODO: import script for stripe account saving in alone or connect mode for stripe.class.php
181
182
183/*
184 * View
185 */
186
187$form = new Form($db);
188$formproduct = new FormProduct($db);
189
190llxHeader('', $langs->trans("StripeSetup"));
191
192$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
193print load_fiche_titre($langs->trans("ModuleSetup").' Stripe', $linkback);
194
196
197print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
198print '<input type="hidden" name="token" value="'.newToken().'">';
199print '<input type="hidden" name="action" value="setvalue">';
200
201print dol_get_fiche_head($head, 'stripeaccount', '', -1);
202
203$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');
204
205print '<span class="opacitymedium">'.$langs->trans("StripeDesc")."</span><br>\n";
206
207print '<br>';
208
209print '<div class="div-table-responsive-no-min">';
210print '<table class="noborder centpercent">';
211print '<tr class="liste_titre">';
212print '<td>'.$langs->trans("AccountParameter").'</td>';
213print '<td>'.$langs->trans("Value").'</td>';
214print '<td></td>';
215print "</tr>\n";
216
217print '<tr class="oddeven">';
218print '<td>';
219print $langs->trans("StripeLiveEnabled").'</td><td>';
220if ($conf->use_javascript_ajax) {
221 print ajax_constantonoff('STRIPE_LIVE');
222} else {
223 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
224 print $form->selectarray("STRIPE_LIVE", $arrval, $conf->global->STRIPE_LIVE);
225}
226print '</td><td></td></tr>';
227
228if (empty($conf->stripeconnect->enabled)) {
229 print '<tr class="oddeven"><td>';
230 print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>';
231 print '<input class="minwidth300" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="' . getDolGlobalString('STRIPE_TEST_PUBLISHABLE_KEY').'" placeholder="'.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx">';
232 print '</td><td></td></tr>';
233
234 print '<tr class="oddeven"><td>';
235 print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
236 print '<input class="minwidth300" type="text" name="STRIPE_TEST_SECRET_KEY" value="' . getDolGlobalString('STRIPE_TEST_SECRET_KEY').'" placeholder="'.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx">';
237 print '</td><td></td></tr>';
238
239 print '<tr class="oddeven"><td>';
240 print '<span class="titlefield">'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>';
241 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
242 print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_ID" value="'.getDolGlobalString('STRIPE_TEST_WEBHOOK_ID').'" placeholder="'.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx">';
243 print '<br>';
244 }
245 print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_KEY" value="'.getDolGlobalString('STRIPE_TEST_WEBHOOK_KEY').'" placeholder="'.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx">';
246 $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForTestWebhook").'</span> ';
247 $url = dol_buildpath('/public/stripe/ipn.php', 3);
248 $url .= '?test=1';
249 //global $dolibarr_main_instance_unique_id;
250 //$url .= '&securitykey='.dol_hash('stripeipn-'.$dolibarr_main_instance_unique_id.'-'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY, 'md5');
251 $out .= '<input type="text" id="onlinetestwebhookurl" class="minwidth500" value="'.$url.'" disabled>';
252 $out .= ajax_autoselect("onlinetestwebhookurl");
253 print '<br>'.$out;
254 print '</td><td>';
255 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
256 if (getDolGlobalString('STRIPE_TEST_WEBHOOK_KEY') && getDolGlobalString('STRIPE_TEST_SECRET_KEY') && getDolGlobalString('STRIPE_TEST_WEBHOOK_ID')) {
257 if (utf8_check($conf->global->STRIPE_TEST_SECRET_KEY)) {
258 try {
259 \Stripe\Stripe::setApiKey($conf->global->STRIPE_TEST_SECRET_KEY);
260 $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_TEST_WEBHOOK_ID);
261 $endpoint->enabled_events = $stripearrayofwebhookevents;
262 if (GETPOST('webhook', 'alpha') == $conf->global->STRIPE_TEST_WEBHOOK_ID) {
263 if (!GETPOST('status', 'alpha')) {
264 $endpoint->disabled = true;
265 } else {
266 $endpoint->disabled = false;
267 }
268 }
269 $endpoint->url = $url;
270 // @phan-suppress-next-line PhanDeprecatedFunction
271 $endpoint->save();
272
273 if ($endpoint->status == 'enabled') {
274 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
275 print img_picto($langs->trans("Activated"), 'switch_on');
276 } else {
277 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
278 print img_picto($langs->trans("Disabled"), 'switch_off');
279 }
280 } catch (Exception $e) {
281 print $e->getMessage();
282 }
283 } else {
284 print 'Bad value for the secret key. Reenter and save it again to fix this.';
285 }
286 } else {
287 print img_picto($langs->trans("Inactive"), 'statut5');
288 }
289 }
290 print'</td></tr>';
291} else {
292 print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
293 print '<td><b>'.$langs->trans("StripeConnect_Mode").'</b><br>';
294 print $langs->trans("STRIPE_APPLICATION_FEE_PLATFORM").' ';
295 print price($conf->global->STRIPE_APPLICATION_FEE_PERCENT);
296 print '% + ';
297 print price($conf->global->STRIPE_APPLICATION_FEE);
298 print ' '.$langs->getCurrencySymbol($conf->currency).' '.$langs->trans("minimum").' '.price($conf->global->STRIPE_APPLICATION_FEE_MINIMAL).' '.$langs->getCurrencySymbol($conf->currency);
299 print '</td><td></td></tr>';
300}
301
302if (empty($conf->stripeconnect->enabled)) {
303 print '<tr class="oddeven"><td>';
304 print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
305 print '<input class="minwidth300" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.getDolGlobalString('STRIPE_LIVE_PUBLISHABLE_KEY').'" placeholder="'.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
306 print '</td><td></td></tr>';
307
308 print '<tr class="oddeven"><td>';
309 print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
310 print '<input class="minwidth300" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.getDolGlobalString('STRIPE_LIVE_SECRET_KEY').'" placeholder="'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
311 print '</td><td></td></tr>';
312
313 print '<tr class="oddeven"><td>';
314 print '<span class="titlefield">'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
315 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
316 print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID').'" placeholder="'.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx">';
317 print '<br>';
318 }
319 print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_KEY').'" placeholder="'.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx">';
320 $out = img_picto('', 'globe', 'class="pictofixedwidth"').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForLiveWebhook").'</span> ';
321 $url = dol_buildpath('/public/stripe/ipn.php', 3);
322 //global $dolibarr_main_instance_unique_id;
323 //$url .= '?securitykey='.dol_hash('stripeipn-'.$dolibarr_main_instance_unique_id.'-'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY, 'md5');
324 $out .= '<input type="text" id="onlinelivewebhookurl" class="minwidth500" value="'.$url.'" disabled>';
325 $out .= ajax_autoselect("onlinelivewebhookurl", '0');
326 print '<br>'.$out;
327 print '</td><td>';
328 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
329 if (getDolGlobalString('STRIPE_LIVE_WEBHOOK_KEY') && getDolGlobalString('STRIPE_LIVE_SECRET_KEY') && getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID')) {
330 if (utf8_check($conf->global->STRIPE_TEST_SECRET_KEY)) {
331 try {
332 \Stripe\Stripe::setApiKey($conf->global->STRIPE_LIVE_SECRET_KEY);
333 $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK_ID);
334 $endpoint->enabled_events = $stripearrayofwebhookevents;
335 if (GETPOST('webhook', 'alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID) {
336 if (empty(GETPOST('status', 'alpha'))) {
337 $endpoint->disabled = true;
338 } else {
339 $endpoint->disabled = false;
340 }
341 }
342 $endpoint->url = $url;
343 // @phan-suppress-next-line PhanDeprecatedFunction
344 $endpoint->save();
345 if ($endpoint->status == 'enabled') {
346 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
347 print img_picto($langs->trans("Activated"), 'switch_on');
348 } else {
349 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
350 print img_picto($langs->trans("Disabled"), 'switch_off');
351 }
352 } catch (Exception $e) {
353 print $e->getMessage();
354 }
355 }
356 } else {
357 print img_picto($langs->trans("Inactive"), 'statut5');
358 }
359 }
360 print '</td></tr>';
361}
362
363print '</table>';
364print '</div>';
365
366print '<br>';
367
368
369print '<div class="div-table-responsive-no-min">';
370print '<table class="noborder centpercent">';
371print '<tr class="liste_titre">';
372print '<td>'.$langs->trans("UsageParameter").'</td>';
373print '<td>'.$langs->trans("Value").'</td>';
374print "</tr>\n";
375
376print '<tr class="oddeven"><td>';
377print $langs->trans("PublicVendorName").'</td><td>';
378print '<input class="minwidth300" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'">';
379print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
380print '</td></tr>';
381
382print '<tr class="oddeven"><td>';
383print $langs->trans("StripeUserAccountForActions").'</td><td>';
384print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS'), 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0);
385print '</td></tr>';
386
387print '<tr class="oddeven"><td>';
388print $langs->trans("BankAccount").'</td><td>';
389print img_picto('', 'bank_account', 'class="pictofixedwidth"');
390$form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'), 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
391print '</td></tr>';
392
393if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // What is this for ?
394 print '<tr class="oddeven"><td>';
395 print $langs->trans("BankAccountForBankTransfer").'</td><td>';
396 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
397 $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS'), 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
398 print '</td></tr>';
399}
400
401// Card Present for Stripe Terminal
402if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
403 print '<tr class="oddeven"><td>';
404 print $langs->trans("STRIPE_CARD_PRESENT").'</td><td>';
405 if ($conf->use_javascript_ajax) {
406 print ajax_constantonoff('STRIPE_CARD_PRESENT');
407 } else {
408 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
409 print $form->selectarray("STRIPE_CARD_PRESENT", $arrval, $conf->global->STRIPE_CARD_PRESENT);
410 }
411 print '</td></tr>';
412}
413
414// Locations for Stripe Terminal
415if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
416 print '<tr class="oddeven"><td>';
417 print $langs->trans("TERMINAL_LOCATION").'</td><td>';
418 $service = 'StripeTest';
419 $servicestatus = 0;
420 if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) {
421 $service = 'StripeLive';
422 $servicestatus = 1;
423 }
424
425 try {
426 global $stripearrayofkeysbyenv;
427 $site_account = $stripearrayofkeysbyenv[$servicestatus]['secret_key'];
428 if (!empty($site_account)) {
429 \Stripe\Stripe::setApiKey($site_account);
430 }
431 if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
432 $service = 'StripeTest';
433 $servicestatus = '0';
434 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning');
435 } else {
436 $service = 'StripeLive';
437 $servicestatus = '1';
438 }
439 $stripe = new Stripe($db);
440 if (!empty($site_account)) {
441 // If $site_account not defined, then key not set and no way to call API Location
442 $stripeacc = $stripe->getStripeAccount($service);
443 if ($stripeacc) {
444 $locations = \Stripe\Terminal\Location::all('', array("stripe_account" => $stripeacc));
445 } else {
446 $locations = \Stripe\Terminal\Location::all();
447 }
448 }
449 } catch (Exception $e) {
450 print $e->getMessage().'<br>';
451 }
452
453 // Define the array $location
454 $location = array();
455 $location[""] = $langs->trans("NotDefined");
456 if (!empty($locations)) {
457 foreach ($locations as $tmplocation) {
458 $location[$tmplocation->id] = $tmplocation->display_name;
459 }
460 }
461
462 print $form->selectarray("STRIPE_LOCATION", $location, getDolGlobalString('STRIPE_LOCATION'));
463 print '</td></tr>';
464}
465
466print '<tr class="oddeven"><td>';
467print $langs->trans("STRIPE_SEPA_DIRECT_DEBIT").'</td><td>';
468if ($conf->use_javascript_ajax) {
469 print ajax_constantonoff('STRIPE_SEPA_DIRECT_DEBIT');
470} else {
471 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
472 print $form->selectarray("STRIPE_SEPA_DIRECT_DEBIT", $arrval, getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT'));
473}
474print '</td></tr>';
475
476
477// Activate Klarna
478if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
479 print '<tr class="oddeven"><td>';
480 print $langs->trans("STRIPE_KLARNA").'</td><td>';
481 if ($conf->use_javascript_ajax) {
482 print ajax_constantonoff('STRIPE_KLARNA');
483 } else {
484 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
485 print $form->selectarray("STRIPE_KLARNA", $arrval, $conf->global->STRIPE_KLARNA);
486 }
487 print '</td></tr>';
488}
489
490// Activate Bancontact
491if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
492 print '<tr class="oddeven"><td>';
493 print $langs->trans("STRIPE_BANCONTACT").'</td><td>';
494 if ($conf->use_javascript_ajax) {
495 print ajax_constantonoff('STRIPE_BANCONTACT');
496 } else {
497 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
498 print $form->selectarray("STRIPE_BANCONTACT", $arrval, $conf->global->STRIPE_BANCONTACT);
499 }
500 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForBECustomers").'</span>';
501 print '</td></tr>';
502}
503
504// Activate iDEAL
505if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
506 print '<tr class="oddeven"><td>';
507 print $langs->trans("STRIPE_IDEAL").'</td><td>';
508 if ($conf->use_javascript_ajax) {
509 print ajax_constantonoff('STRIPE_IDEAL');
510 } else {
511 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
512 print $form->selectarray("STRIPE_IDEAL", $arrval, $conf->global->STRIPE_SEPA_DIRECT_DEBIT);
513 }
514 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForNLCustomers").'</span>';
515 print '</td></tr>';
516}
517
518// Activate Giropay
519if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
520 print '<tr class="oddeven"><td>';
521 print $langs->trans("STRIPE_GIROPAY").'</td><td>';
522 if ($conf->use_javascript_ajax) {
523 print ajax_constantonoff('STRIPE_GIROPAY');
524 } else {
525 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
526 print $form->selectarray("STRIPE_GIROPAY", $arrval, $conf->global->STRIPE_GIROPAY);
527 }
528 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForDECustomers").'</span>';
529 print '</td></tr>';
530}
531
532// Activate Sofort
533if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
534 print '<tr class="oddeven"><td>';
535 print $langs->trans("STRIPE_SOFORT").'</td><td>';
536 if ($conf->use_javascript_ajax) {
537 print ajax_constantonoff('STRIPE_SOFORT');
538 } else {
539 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
540 print $form->selectarray("STRIPE_SOFORT", $arrval, $conf->global->STRIPE_SOFORT);
541 }
542 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForATBEDEITNLESCustomers").'</span>';
543 print '</td></tr>';
544}
545
546print '<tr class="oddeven"><td>';
547print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
548print '<input class="width500" type="text" name="ONLINE_PAYMENT_CSS_URL" value="' . getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'">';
549print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
550print '</td></tr>';
551
552print '<tr class="oddeven"><td>';
553print $langs->trans("MessageForm").'</td><td>';
554$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', getDolGlobalString("ONLINE_PAYMENT_MESSAGE_FORM"), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
555$doleditor->Create();
556print '</td></tr>';
557
558print '<tr class="oddeven"><td>';
559print $langs->trans("MessageOK").'</td><td>';
560$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', getDolGlobalString("ONLINE_PAYMENT_MESSAGE_OK"), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
561$doleditor->Create();
562print '</td></tr>';
563
564print '<tr class="oddeven"><td>';
565print $langs->trans("MessageKO").'</td><td>';
566$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', getDolGlobalString("ONLINE_PAYMENT_MESSAGE_KO"), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
567$doleditor->Create();
568print '</td></tr>';
569
570print '<tr class="oddeven"><td>';
571print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
572print img_picto('', 'email', 'class="pictofixedwidth"');
573print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="' . getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'">';
574print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
575print '</td></tr>';
576
577print '</table>';
578print '</div>';
579
580print '<br>';
581
582print '<div class="div-table-responsive-no-min">';
583print '<table class="noborder centpercent">';
584
585print '<tr class="liste_titre">';
586print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
587print '<td>'.$langs->trans("Value").'</td>';
588print "</tr>\n";
589
590// Payment token for URL
591print '<tr class="oddeven"><td>';
592print $langs->trans("SecurityToken").'</td><td>';
593print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="' . getDolGlobalString('PAYMENT_SECURITY_TOKEN').'">';
594if (!empty($conf->use_javascript_ajax)) {
595 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
596}
597if (getDolGlobalString('PAYMENT_SECURITY_ACCEPT_ANY_TOKEN')) {
598 $langs->load("errors");
599 print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
600}
601print '</td></tr>';
602
603print '<tr class="oddeven"><td>';
604print $langs->trans("SecurityTokenIsUnique").'</td><td>';
605if ($conf->use_javascript_ajax) {
606 print ajax_constantonoff('PAYMENT_SECURITY_TOKEN_UNIQUE', array(), null, 0, 0, 1);
607} else {
608 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
609 print $form->selectarray("PAYMENT_SECURITY_TOKEN_UNIQUE", $arrval, $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE);
610}
611print '</td></tr>';
612
613print '</table>';
614print '</div>';
615
616print dol_get_fiche_end();
617
618print $form->buttonsSaveCancel("Save", '');
619
620print '</form>';
621
622print '<br><br>';
623
624
625$token = '';
626
627include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
628
629print 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'));
630
631if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
632 print info_admin($langs->trans("ExampleOfTestBankAcountForSEPA", 'AT611904300234573201 (pending->succeed) or AT861904300235473202 (pending->failed)'));
633}
634
635
636
637if (!empty($conf->use_javascript_ajax)) {
638 print "\n".'<script type="text/javascript">';
639 print '$(document).ready(function () {
640 $("#apidoc").hide();
641 $("#apidoca").click(function() {
642 console.log("We click on apidoca show/hide");
643 $("#apidoc").show();
644 $("#apidoca").hide();
645 return false;
646 });
647 });';
648 print '</script>';
649}
650
651// End of page
652llxFooter();
653$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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
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 @TODO No reason to extends CommonObject.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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 a Dolibarr global constant int value.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
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 a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
utf8_check($str)
Check if a string is in UTF8.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.