dolibarr 22.0.5
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', 'paybox', '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="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
203print load_fiche_titre($langs->trans("ModuleSetup").' Stripe', $linkback);
204
206
207print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
208print '<input type="hidden" name="token" value="'.newToken().'">';
209print '<input type="hidden" name="action" value="setvalue">';
210
211print dol_get_fiche_head($head, 'stripeaccount', '', -1);
212
213$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');
214
215print '<span class="opacitymedium">'.$langs->trans("StripeDesc")."</span><br>\n";
216
217print '<br>';
218
219print '<div class="div-table-responsive-no-min">';
220print '<table class="noborder centpercent">';
221print '<tr class="liste_titre">';
222print '<td>'.$langs->trans("AccountParameter").'</td>';
223print '<td></td>';
224print '<td></td>';
225print "</tr>\n";
226
227print '<tr class="oddeven">';
228print '<td>';
229print $langs->trans("StripeLiveEnabled").'</td><td>';
230if ($conf->use_javascript_ajax) {
231 print ajax_constantonoff('STRIPE_LIVE');
232} else {
233 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
234 print $form->selectarray("STRIPE_LIVE", $arrval, $conf->global->STRIPE_LIVE);
235}
236print '</td><td></td></tr>';
237
238if (empty($conf->stripeconnect->enabled)) {
239 print '<tr class="oddeven"><td>';
240 print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>';
241 print '<input class="minwidth300" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="' . getDolGlobalString('STRIPE_TEST_PUBLISHABLE_KEY').'" placeholder="'.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx">';
242 print '</td><td></td></tr>';
243
244 print '<tr class="oddeven"><td>';
245 print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
246 print '<input class="minwidth300" type="text" name="STRIPE_TEST_SECRET_KEY" value="' . getDolGlobalString('STRIPE_TEST_SECRET_KEY').'" placeholder="'.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx">';
247 print '</td><td></td></tr>';
248
249 print '<tr class="oddeven"><td>';
250 print '<span class="titlefield">'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>';
251 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
252 print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_ID" value="'.getDolGlobalString('STRIPE_TEST_WEBHOOK_ID').'" placeholder="'.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx">';
253 print '<br>';
254 }
255 print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_KEY" value="'.getDolGlobalString('STRIPE_TEST_WEBHOOK_KEY').'" placeholder="'.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx">';
256 $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForTestWebhook").'</span> ';
257 $url = dol_buildpath('/public/stripe/ipn.php', 3);
258 $url .= '?test=1';
259 //global $dolibarr_main_instance_unique_id;
260 //$url .= '&securitykey='.dol_hash('stripeipn-'.$dolibarr_main_instance_unique_id.'-'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY, 'md5');
261 $out .= '<input type="text" id="onlinetestwebhookurl" class="minwidth500" value="'.$url.'" disabled>';
262 $out .= ajax_autoselect("onlinetestwebhookurl");
263 print '<br>'.$out;
264 print $form->textwithpicto('', $langs->trans('ListOfSupportedHooksToActivate').':<br><br>'.implode('<br>', $listofsupportedhooks), 1, 'help', 'valignmiddle', 0, 3, 'webhookscodetest');
265 print '</td><td>';
266 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
267 if (getDolGlobalString('STRIPE_TEST_WEBHOOK_KEY') && getDolGlobalString('STRIPE_TEST_SECRET_KEY') && getDolGlobalString('STRIPE_TEST_WEBHOOK_ID')) {
268 if (utf8_check(getDolGlobalString('STRIPE_TEST_SECRET_KEY'))) {
269 try {
270 \Stripe\Stripe::setApiKey(getDolGlobalString('STRIPE_TEST_SECRET_KEY'));
271 $endpoint = \Stripe\WebhookEndpoint::retrieve(getDolGlobalString('STRIPE_TEST_WEBHOOK_ID'));
272 $endpoint->enabled_events = $stripearrayofwebhookevents;
273 if (GETPOST('webhook', 'alpha') == getDolGlobalString('STRIPE_TEST_WEBHOOK_ID')) {
274 if (!GETPOST('status', 'alpha')) {
275 $endpoint->disabled = true;
276 } else {
277 $endpoint->disabled = false;
278 }
279 }
280 $endpoint->url = $url;
281 // @phan-suppress-next-line PhanDeprecatedFunction
282 $endpoint->save();
283
284 if ($endpoint->status == 'enabled') {
285 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
286 print img_picto($langs->trans("Activated"), 'switch_on');
287 } else {
288 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
289 print img_picto($langs->trans("Disabled"), 'switch_off');
290 }
291 } catch (Exception $e) {
292 print $e->getMessage();
293 }
294 } else {
295 print 'Bad value for the secret key. Reenter and save it again to fix this.';
296 }
297 } else {
298 print img_picto($langs->trans("Inactive"), 'statut5');
299 }
300 }
301 print'</td></tr>';
302} else {
303 print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
304 print '<td><b>'.$langs->trans("StripeConnect_Mode").'</b><br>';
305 print $langs->trans("STRIPE_APPLICATION_FEE_PLATFORM").' ';
306 print price(getDolGlobalString('STRIPE_APPLICATION_FEE_PERCENT'));
307 print '% + ';
308 print price(getDolGlobalString('STRIPE_APPLICATION_FEE'));
309 print ' '.$langs->getCurrencySymbol($conf->currency).' '.$langs->trans("minimum").' '.price(getDolGlobalString('STRIPE_APPLICATION_FEE_MINIMAL')).' '.$langs->getCurrencySymbol($conf->currency);
310 print '</td><td></td></tr>';
311}
312
313if (empty($conf->stripeconnect->enabled)) {
314 print '<tr class="oddeven"><td>';
315 print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
316 print '<input class="minwidth300" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.getDolGlobalString('STRIPE_LIVE_PUBLISHABLE_KEY').'" placeholder="'.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
317 print '</td><td></td></tr>';
318
319 print '<tr class="oddeven"><td>';
320 print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
321 print '<input class="minwidth300" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.getDolGlobalString('STRIPE_LIVE_SECRET_KEY').'" placeholder="'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
322 print '</td><td></td></tr>';
323
324 print '<tr class="oddeven"><td>';
325 print '<span class="titlefield">'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
326 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
327 print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID').'" placeholder="'.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx">';
328 print '<br>';
329 }
330 print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_KEY').'" placeholder="'.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx">';
331 $out = img_picto('', 'globe', 'class="pictofixedwidth"').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForLiveWebhook").'</span> ';
332 $url = dol_buildpath('/public/stripe/ipn.php', 3);
333 //global $dolibarr_main_instance_unique_id;
334 //$url .= '?securitykey='.dol_hash('stripeipn-'.$dolibarr_main_instance_unique_id.'-'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY, 'md5');
335 $out .= '<input type="text" id="onlinelivewebhookurl" class="minwidth500" value="'.$url.'" disabled>';
336 $out .= ajax_autoselect("onlinelivewebhookurl", '0');
337 print '<br>'.$out;
338 print $form->textwithpicto('', $langs->trans('ListOfSupportedHooksToActivate').':<br><br>'.implode('<br>', $listofsupportedhooks), 1, 'help', 'valignmiddle', 0, 3, 'webhookscodeprod');
339 print '</td><td>';
340 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
341 if (getDolGlobalString('STRIPE_LIVE_WEBHOOK_KEY') && getDolGlobalString('STRIPE_LIVE_SECRET_KEY') && getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID')) {
342 if (utf8_check(getDolGlobalString('STRIPE_TEST_SECRET_KEY'))) {
343 try {
344 \Stripe\Stripe::setApiKey(getDolGlobalString('STRIPE_LIVE_SECRET_KEY'));
345 $endpoint = \Stripe\WebhookEndpoint::retrieve(getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID'));
346 $endpoint->enabled_events = $stripearrayofwebhookevents;
347 if (GETPOST('webhook', 'alpha') == getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID')) {
348 if (empty(GETPOST('status', 'alpha'))) {
349 $endpoint->disabled = true;
350 } else {
351 $endpoint->disabled = false;
352 }
353 }
354 $endpoint->url = $url;
355 // @phan-suppress-next-line PhanDeprecatedFunction
356 $endpoint->save();
357 if ($endpoint->status == 'enabled') {
358 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
359 print img_picto($langs->trans("Activated"), 'switch_on');
360 } else {
361 print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
362 print img_picto($langs->trans("Disabled"), 'switch_off');
363 }
364 } catch (Exception $e) {
365 print $e->getMessage();
366 }
367 }
368 } else {
369 print img_picto($langs->trans("Inactive"), 'statut5');
370 }
371 }
372 print '</td></tr>';
373}
374
375print '</table>';
376print '</div>';
377
378print '<br>';
379
380
381print '<div class="div-table-responsive-no-min">';
382print '<table class="noborder centpercent">';
383print '<tr class="liste_titre">';
384print '<td>'.$langs->trans("UsageParameter").'</td>';
385print '<td></td>';
386print "</tr>\n";
387
388print '<tr class="oddeven"><td>';
389print $langs->trans("PublicVendorName").'</td><td>';
390print '<input class="minwidth300" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'">';
391print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
392print '</td></tr>';
393
394print '<tr class="oddeven"><td>';
395print $langs->trans("BankAccount").'</td><td>';
396print img_picto('', 'bank_account', 'class="pictofixedwidth"');
397$form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'), 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
398print '</td></tr>';
399
400
401// Param to record automatically payouts (received from IPN payout.paid and payout.created)
402// https://docs.stripe.com/api/events/types#event_types-payout.created
403// https://docs.stripe.com/api/events/types#event_types-payout.paid
404print '<tr class="oddeven"><td>';
405print $langs->trans("StripeAutoRecordPayout").'</td><td>';
406if ($conf->use_javascript_ajax) {
407 print ajax_constantonoff('STRIPE_AUTO_RECORD_PAYOUT', array(), null, 0, 0, 1);
408} else {
409 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
410 print $form->selectarray("STRIPE_AUTO_RECORD_PAYOUT", $arrval, getDolGlobalInt('STRIPE_AUTO_RECORD_PAYOUT'));
411}
412print '</td></tr>';
413
414if (getDolGlobalInt('STRIPE_AUTO_RECORD_PAYOUT')) {
415 print '<tr class="oddeven"><td>';
416 print $langs->trans("StripeUserAccountForActions").'</td><td>';
417 print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS'), 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0);
418 print '</td></tr>';
419
420 print '<tr class="oddeven"><td>';
421 print $langs->trans("BankAccountForBankTransfer").'</td><td>';
422 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
423 $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS'), 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
424 print '</td></tr>';
425}
426
427// Card Present for Stripe Terminal
428if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
429 print '<tr class="oddeven"><td>';
430 print $langs->trans("STRIPE_CARD_PRESENT").'</td><td>';
431 if ($conf->use_javascript_ajax) {
432 print ajax_constantonoff('STRIPE_CARD_PRESENT');
433 } else {
434 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
435 print $form->selectarray("STRIPE_CARD_PRESENT", $arrval, $conf->global->STRIPE_CARD_PRESENT);
436 }
437 print '</td></tr>';
438}
439
440// Locations for Stripe Terminal
441if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
442 print '<tr class="oddeven"><td>';
443 print $langs->trans("TERMINAL_LOCATION").'</td><td>';
444 $service = 'StripeTest';
445 $servicestatus = 0;
446 if (getDolGlobalString('STRIPE_LIVE')/* && !GETPOST('forcesandbox', 'alpha') */) {
447 $service = 'StripeLive';
448 $servicestatus = 1;
449 }
450
451 try {
452 global $stripearrayofkeysbyenv;
453 $site_account = $stripearrayofkeysbyenv[$servicestatus]['secret_key'];
454 if (!empty($site_account)) {
455 \Stripe\Stripe::setApiKey($site_account);
456 }
457 if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE')/* || GETPOST('forcesandbox', 'alpha') */)) {
458 $service = 'StripeTest';
459 $servicestatus = '0';
460 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning');
461 } else {
462 $service = 'StripeLive';
463 $servicestatus = '1';
464 }
465 $stripe = new Stripe($db);
466 if (!empty($site_account)) {
467 // If $site_account not defined, then key not set and no way to call API Location
468 $stripeacc = $stripe->getStripeAccount($service);
469 if ($stripeacc) {
470 $locations = \Stripe\Terminal\Location::all(null, array("stripe_account" => $stripeacc));
471 } else {
472 $locations = \Stripe\Terminal\Location::all();
473 }
474 }
475 } catch (Exception $e) {
476 print $e->getMessage().'<br>';
477 }
478
479 // Define the array $location
480 $location = array();
481 $location[""] = $langs->trans("NotDefined");
482 if (!empty($locations)) {
483 foreach ($locations as $tmplocation) {
484 $location[$tmplocation->id] = $tmplocation->display_name;
485 }
486 }
487
488 print $form->selectarray("STRIPE_LOCATION", $location, getDolGlobalString('STRIPE_LOCATION'));
489 print '</td></tr>';
490}
491
492print '<tr class="oddeven"><td>';
493print $langs->trans("STRIPE_SEPA_DIRECT_DEBIT").'</td><td>';
494if ($conf->use_javascript_ajax) {
495 print ajax_constantonoff('STRIPE_SEPA_DIRECT_DEBIT');
496} else {
497 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
498 print $form->selectarray("STRIPE_SEPA_DIRECT_DEBIT", $arrval, getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT'));
499}
500print '</td></tr>';
501
502
503// Activate Klarna
504if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
505 print '<tr class="oddeven"><td>';
506 print $langs->trans("STRIPE_KLARNA").'</td><td>';
507 if ($conf->use_javascript_ajax) {
508 print ajax_constantonoff('STRIPE_KLARNA');
509 } else {
510 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
511 print $form->selectarray("STRIPE_KLARNA", $arrval, $conf->global->STRIPE_KLARNA);
512 }
513 print '</td></tr>';
514}
515
516// Activate Bancontact
517if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
518 print '<tr class="oddeven"><td>';
519 print $langs->trans("STRIPE_BANCONTACT").'</td><td>';
520 if ($conf->use_javascript_ajax) {
521 print ajax_constantonoff('STRIPE_BANCONTACT');
522 } else {
523 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
524 print $form->selectarray("STRIPE_BANCONTACT", $arrval, $conf->global->STRIPE_BANCONTACT);
525 }
526 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForBECustomers").'</span>';
527 print '</td></tr>';
528}
529
530// Activate iDEAL
531if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
532 print '<tr class="oddeven"><td>';
533 print $langs->trans("STRIPE_IDEAL").'</td><td>';
534 if ($conf->use_javascript_ajax) {
535 print ajax_constantonoff('STRIPE_IDEAL');
536 } else {
537 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
538 print $form->selectarray("STRIPE_IDEAL", $arrval, $conf->global->STRIPE_SEPA_DIRECT_DEBIT);
539 }
540 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForNLCustomers").'</span>';
541 print '</td></tr>';
542}
543
544// Activate Giropay
545if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
546 print '<tr class="oddeven"><td>';
547 print $langs->trans("STRIPE_GIROPAY").'</td><td>';
548 if ($conf->use_javascript_ajax) {
549 print ajax_constantonoff('STRIPE_GIROPAY');
550 } else {
551 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
552 print $form->selectarray("STRIPE_GIROPAY", $arrval, $conf->global->STRIPE_GIROPAY);
553 }
554 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForDECustomers").'</span>';
555 print '</td></tr>';
556}
557
558// Activate Sofort
559if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
560 print '<tr class="oddeven"><td>';
561 print $langs->trans("STRIPE_SOFORT").'</td><td>';
562 if ($conf->use_javascript_ajax) {
563 print ajax_constantonoff('STRIPE_SOFORT');
564 } else {
565 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
566 print $form->selectarray("STRIPE_SOFORT", $arrval, $conf->global->STRIPE_SOFORT);
567 }
568 print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForATBEDEITNLESCustomers").'</span>';
569 print '</td></tr>';
570}
571
572print '<tr class="oddeven"><td>';
573print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
574print '<input class="width500" type="text" name="ONLINE_PAYMENT_CSS_URL" value="' . getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'">';
575print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
576print '</td></tr>';
577
578print '<tr class="oddeven"><td>';
579print $langs->trans("MessageForm").'</td><td>';
580$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', getDolGlobalString("ONLINE_PAYMENT_MESSAGE_FORM"), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
581$doleditor->Create();
582print '</td></tr>';
583
584print '<tr class="oddeven"><td>';
585print $langs->trans("MessageOK").'</td><td>';
586$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', getDolGlobalString("ONLINE_PAYMENT_MESSAGE_OK"), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
587$doleditor->Create();
588print '</td></tr>';
589
590print '<tr class="oddeven"><td>';
591print $langs->trans("MessageKO").'</td><td>';
592$doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', getDolGlobalString("ONLINE_PAYMENT_MESSAGE_KO"), '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
593$doleditor->Create();
594print '</td></tr>';
595
596print '<tr class="oddeven"><td>';
597print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
598print img_picto('', 'email', 'class="pictofixedwidth"');
599print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="' . getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'">';
600print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
601print '</td></tr>';
602
603print '</table>';
604print '</div>';
605
606print '<br>';
607
608print '<div class="div-table-responsive-no-min">';
609print '<table class="noborder centpercent">';
610
611print '<tr class="liste_titre">';
612print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
613print '<td>'.$langs->trans("Value").'</td>';
614print "</tr>\n";
615
616// Payment token for URL
617print '<tr class="oddeven"><td>';
618print $langs->trans("SecurityToken").'</td><td>';
619print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="' . getDolGlobalString('PAYMENT_SECURITY_TOKEN').'">';
620if (!empty($conf->use_javascript_ajax)) {
621 print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
622}
623if (getDolGlobalString('PAYMENT_SECURITY_ACCEPT_ANY_TOKEN')) {
624 $langs->load("errors");
625 print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
626}
627print '</td></tr>';
628
629print '<tr class="oddeven"><td>';
630print $langs->trans("SecurityTokenIsUnique").'</td><td>';
631if ($conf->use_javascript_ajax) {
632 print ajax_constantonoff('PAYMENT_SECURITY_TOKEN_UNIQUE', array(), null, 0, 0, 1);
633} else {
634 $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
635 print $form->selectarray("PAYMENT_SECURITY_TOKEN_UNIQUE", $arrval, $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE);
636}
637print '</td></tr>';
638
639print '</table>';
640print '</div>';
641
642print dol_get_fiche_end();
643
644print $form->buttonsSaveCancel("Save", '');
645
646print '</form>';
647
648print '<br><br>';
649
650
651$token = '';
652
653include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
654
655print 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'));
656
657if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
658 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'));
659}
660
661
662
663if (!empty($conf->use_javascript_ajax)) {
664 print "\n".'<script type="text/javascript">';
665 print '$(document).ready(function () {
666 $("#apidoc").hide();
667 $("#apidoca").click(function() {
668 console.log("We click on apidoca show/hide");
669 $("#apidoc").show();
670 $("#apidoca").hide();
671 return false;
672 });
673 });';
674 print '</script>';
675}
676
677// End of page
678llxFooter();
679$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.
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, $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.
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.