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