dolibarr 21.0.3
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("BankAccount").'</td><td>';
384print img_picto('', 'bank_account', 'class="pictofixedwidth"');
385$form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'), 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
386print '</td></tr>';
387
388
389// Param to record automatically payouts (received from IPN payout.paid and payout.created)
390print '<tr class="oddeven"><td>';
391print $langs->trans("StripeAutoRecordPayout").'</td><td>';
392if ($conf->use_javascript_ajax) {
393 print ajax_constantonoff('STRIPE_AUTO_RECORD_PAYOUT', array(), null, 0, 0, 1);
394} else {
395 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
396 print $form->selectarray("STRIPE_AUTO_RECORD_PAYOUT", $arrval, getDolGlobalInt('STRIPE_AUTO_RECORD_PAYOUT'));
397}
398print '</td></tr>';
399
400if (getDolGlobalInt('STRIPE_AUTO_RECORD_PAYOUT')) {
401 print '<tr class="oddeven"><td>';
402 print $langs->trans("StripeUserAccountForActions").'</td><td>';
403 print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS'), 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0);
404 print '</td></tr>';
405
406 print '<tr class="oddeven"><td>';
407 print $langs->trans("BankAccountForBankTransfer").'</td><td>';
408 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
409 $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS'), 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
410 print '</td></tr>';
411}
412
413// Card Present for Stripe Terminal
414if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
415 print '<tr class="oddeven"><td>';
416 print $langs->trans("STRIPE_CARD_PRESENT").'</td><td>';
417 if ($conf->use_javascript_ajax) {
418 print ajax_constantonoff('STRIPE_CARD_PRESENT');
419 } else {
420 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
421 print $form->selectarray("STRIPE_CARD_PRESENT", $arrval, $conf->global->STRIPE_CARD_PRESENT);
422 }
423 print '</td></tr>';
424}
425
426// Locations for Stripe Terminal
427if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
428 print '<tr class="oddeven"><td>';
429 print $langs->trans("TERMINAL_LOCATION").'</td><td>';
430 $service = 'StripeTest';
431 $servicestatus = 0;
432 if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) {
433 $service = 'StripeLive';
434 $servicestatus = 1;
435 }
436
437 try {
438 global $stripearrayofkeysbyenv;
439 $site_account = $stripearrayofkeysbyenv[$servicestatus]['secret_key'];
440 if (!empty($site_account)) {
441 \Stripe\Stripe::setApiKey($site_account);
442 }
443 if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
444 $service = 'StripeTest';
445 $servicestatus = '0';
446 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning');
447 } else {
448 $service = 'StripeLive';
449 $servicestatus = '1';
450 }
451 $stripe = new Stripe($db);
452 if (!empty($site_account)) {
453 // If $site_account not defined, then key not set and no way to call API Location
454 $stripeacc = $stripe->getStripeAccount($service);
455 if ($stripeacc) {
456 $locations = \Stripe\Terminal\Location::all('', array("stripe_account" => $stripeacc));
457 } else {
458 $locations = \Stripe\Terminal\Location::all();
459 }
460 }
461 } catch (Exception $e) {
462 print $e->getMessage().'<br>';
463 }
464
465 // Define the array $location
466 $location = array();
467 $location[""] = $langs->trans("NotDefined");
468 if (!empty($locations)) {
469 foreach ($locations as $tmplocation) {
470 $location[$tmplocation->id] = $tmplocation->display_name;
471 }
472 }
473
474 print $form->selectarray("STRIPE_LOCATION", $location, getDolGlobalString('STRIPE_LOCATION'));
475 print '</td></tr>';
476}
477
478print '<tr class="oddeven"><td>';
479print $langs->trans("STRIPE_SEPA_DIRECT_DEBIT").'</td><td>';
480if ($conf->use_javascript_ajax) {
481 print ajax_constantonoff('STRIPE_SEPA_DIRECT_DEBIT');
482} else {
483 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
484 print $form->selectarray("STRIPE_SEPA_DIRECT_DEBIT", $arrval, getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT'));
485}
486print '</td></tr>';
487
488
489// Activate Klarna
490if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
491 print '<tr class="oddeven"><td>';
492 print $langs->trans("STRIPE_KLARNA").'</td><td>';
493 if ($conf->use_javascript_ajax) {
494 print ajax_constantonoff('STRIPE_KLARNA');
495 } else {
496 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
497 print $form->selectarray("STRIPE_KLARNA", $arrval, $conf->global->STRIPE_KLARNA);
498 }
499 print '</td></tr>';
500}
501
502// Activate Bancontact
503if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
504 print '<tr class="oddeven"><td>';
505 print $langs->trans("STRIPE_BANCONTACT").'</td><td>';
506 if ($conf->use_javascript_ajax) {
507 print ajax_constantonoff('STRIPE_BANCONTACT');
508 } else {
509 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
510 print $form->selectarray("STRIPE_BANCONTACT", $arrval, $conf->global->STRIPE_BANCONTACT);
511 }
512 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForBECustomers").'</span>';
513 print '</td></tr>';
514}
515
516// Activate iDEAL
517if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
518 print '<tr class="oddeven"><td>';
519 print $langs->trans("STRIPE_IDEAL").'</td><td>';
520 if ($conf->use_javascript_ajax) {
521 print ajax_constantonoff('STRIPE_IDEAL');
522 } else {
523 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
524 print $form->selectarray("STRIPE_IDEAL", $arrval, $conf->global->STRIPE_SEPA_DIRECT_DEBIT);
525 }
526 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForNLCustomers").'</span>';
527 print '</td></tr>';
528}
529
530// Activate Giropay
531if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
532 print '<tr class="oddeven"><td>';
533 print $langs->trans("STRIPE_GIROPAY").'</td><td>';
534 if ($conf->use_javascript_ajax) {
535 print ajax_constantonoff('STRIPE_GIROPAY');
536 } else {
537 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
538 print $form->selectarray("STRIPE_GIROPAY", $arrval, $conf->global->STRIPE_GIROPAY);
539 }
540 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForDECustomers").'</span>';
541 print '</td></tr>';
542}
543
544// Activate Sofort
545if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
546 print '<tr class="oddeven"><td>';
547 print $langs->trans("STRIPE_SOFORT").'</td><td>';
548 if ($conf->use_javascript_ajax) {
549 print ajax_constantonoff('STRIPE_SOFORT');
550 } else {
551 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
552 print $form->selectarray("STRIPE_SOFORT", $arrval, $conf->global->STRIPE_SOFORT);
553 }
554 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForATBEDEITNLESCustomers").'</span>';
555 print '</td></tr>';
556}
557
558print '<tr class="oddeven"><td>';
559print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
560print '<input class="width500" type="text" name="ONLINE_PAYMENT_CSS_URL" value="' . getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'">';
561print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
562print '</td></tr>';
563
564print '<tr class="oddeven"><td>';
565print $langs->trans("MessageForm").'</td><td>';
566$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', getDolGlobalString("ONLINE_PAYMENT_MESSAGE_FORM"), '', 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("MessageOK").'</td><td>';
572$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', getDolGlobalString("ONLINE_PAYMENT_MESSAGE_OK"), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
573$doleditor->Create();
574print '</td></tr>';
575
576print '<tr class="oddeven"><td>';
577print $langs->trans("MessageKO").'</td><td>';
578$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', getDolGlobalString("ONLINE_PAYMENT_MESSAGE_KO"), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
579$doleditor->Create();
580print '</td></tr>';
581
582print '<tr class="oddeven"><td>';
583print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
584print img_picto('', 'email', 'class="pictofixedwidth"');
585print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="' . getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'">';
586print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
587print '</td></tr>';
588
589print '</table>';
590print '</div>';
591
592print '<br>';
593
594print '<div class="div-table-responsive-no-min">';
595print '<table class="noborder centpercent">';
596
597print '<tr class="liste_titre">';
598print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
599print '<td>'.$langs->trans("Value").'</td>';
600print "</tr>\n";
601
602// Payment token for URL
603print '<tr class="oddeven"><td>';
604print $langs->trans("SecurityToken").'</td><td>';
605print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="' . getDolGlobalString('PAYMENT_SECURITY_TOKEN').'">';
606if (!empty($conf->use_javascript_ajax)) {
607 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
608}
609if (getDolGlobalString('PAYMENT_SECURITY_ACCEPT_ANY_TOKEN')) {
610 $langs->load("errors");
611 print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
612}
613print '</td></tr>';
614
615print '<tr class="oddeven"><td>';
616print $langs->trans("SecurityTokenIsUnique").'</td><td>';
617if ($conf->use_javascript_ajax) {
618 print ajax_constantonoff('PAYMENT_SECURITY_TOKEN_UNIQUE', array(), null, 0, 0, 1);
619} else {
620 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
621 print $form->selectarray("PAYMENT_SECURITY_TOKEN_UNIQUE", $arrval, $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE);
622}
623print '</td></tr>';
624
625print '</table>';
626print '</div>';
627
628print dol_get_fiche_end();
629
630print $form->buttonsSaveCancel("Save", '');
631
632print '</form>';
633
634print '<br><br>';
635
636
637$token = '';
638
639include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
640
641print 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').'. '.$langs->trans('SeeAlso', 'https://docs.stripe.com/testing?testing-method=card-numbers'));
642
643if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
644 print info_admin($langs->trans("ExampleOfTestBankAcountForSEPA", 'AT611904300234573201 (pending->succeed) or AT861904300235473202 (pending->failed)').'. '.$langs->trans('SeeAlso', 'https://docs.stripe.com/testing?payment-method=sepa-direct-debit'));
645}
646
647
648
649if (!empty($conf->use_javascript_ajax)) {
650 print "\n".'<script type="text/javascript">';
651 print '$(document).ready(function () {
652 $("#apidoc").hide();
653 $("#apidoca").click(function() {
654 console.log("We click on apidoca show/hide");
655 $("#apidoc").show();
656 $("#apidoca").hide();
657 return false;
658 });
659 });';
660 print '</script>';
661}
662
663// End of page
664llxFooter();
665$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).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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.
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_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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.