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