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