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