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