stripe.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/stripe/admin/stripe.php
  23. * \ingroup stripe
  24. * \brief Page to setup stripe module
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
  33. $servicename = 'Stripe';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array('admin', 'other', 'paypal', 'paybox', 'stripe'));
  36. if (empty($user->admin)) {
  37. accessforbidden();
  38. }
  39. if (empty($conf->stripe->enabled)) {
  40. accessforbidden();
  41. }
  42. $action = GETPOST('action', 'aZ09');
  43. /*
  44. * Actions
  45. */
  46. if ($action == 'setvalue' && $user->admin) {
  47. $db->begin();
  48. if (empty($conf->stripeconnect->enabled)) {
  49. $result = dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY", GETPOST('STRIPE_TEST_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
  50. if (!($result > 0)) {
  51. $error++;
  52. }
  53. $result = dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY", GETPOST('STRIPE_TEST_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
  54. if (!($result > 0)) {
  55. $error++;
  56. }
  57. $result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_ID", GETPOST('STRIPE_TEST_WEBHOOK_ID', 'alpha'), 'chaine', 0, '', $conf->entity);
  58. if (!($result > 0)) {
  59. $error++;
  60. }
  61. $result = dolibarr_set_const($db, "STRIPE_TEST_WEBHOOK_KEY", GETPOST('STRIPE_TEST_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
  62. if (!($result > 0)) {
  63. $error++;
  64. }
  65. $result = dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY", GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
  66. if (!($result > 0)) {
  67. $error++;
  68. }
  69. $result = dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY", GETPOST('STRIPE_LIVE_SECRET_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
  70. if (!($result > 0)) {
  71. $error++;
  72. }
  73. $result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_ID", GETPOST('STRIPE_LIVE_WEBHOOK_ID', 'alpha'), 'chaine', 0, '', $conf->entity);
  74. if (!($result > 0)) {
  75. $error++;
  76. }
  77. $result = dolibarr_set_const($db, "STRIPE_LIVE_WEBHOOK_KEY", GETPOST('STRIPE_LIVE_WEBHOOK_KEY', 'alpha'), 'chaine', 0, '', $conf->entity);
  78. if (!($result > 0)) {
  79. $error++;
  80. }
  81. }
  82. $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CREDITOR", GETPOST('ONLINE_PAYMENT_CREDITOR', 'alpha'), 'chaine', 0, '', $conf->entity);
  83. if (!($result > 0)) {
  84. $error++;
  85. }
  86. $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
  87. if (!($result > 0)) {
  88. $error++;
  89. }
  90. $result = dolibarr_set_const($db, "STRIPE_USER_ACCOUNT_FOR_ACTIONS", GETPOST('STRIPE_USER_ACCOUNT_FOR_ACTIONS', 'int'), 'chaine', 0, '', $conf->entity);
  91. if (!($result > 0)) {
  92. $error++;
  93. }
  94. $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity);
  95. if (!($result > 0)) {
  96. $error++;
  97. }
  98. if (GETPOSTISSET('STRIPE_LOCATION')) {
  99. $result = dolibarr_set_const($db, "STRIPE_LOCATION", GETPOST('STRIPE_LOCATION', 'alpha'), 'chaine', 0, '', $conf->entity);
  100. if (!$result > 0) {
  101. $error++;
  102. }
  103. }
  104. $result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
  105. if (!($result > 0)) {
  106. $error++;
  107. }
  108. $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_FORM", GETPOST('ONLINE_PAYMENT_MESSAGE_FORM', 'restricthtml'), 'chaine', 0, '', $conf->entity);
  109. if (!($result > 0)) {
  110. $error++;
  111. }
  112. $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_OK", GETPOST('ONLINE_PAYMENT_MESSAGE_OK', 'restricthtml'), 'chaine', 0, '', $conf->entity);
  113. if (!($result > 0)) {
  114. $error++;
  115. }
  116. $result = dolibarr_set_const($db, "ONLINE_PAYMENT_MESSAGE_KO", GETPOST('ONLINE_PAYMENT_MESSAGE_KO', 'restricthtml'), 'chaine', 0, '', $conf->entity);
  117. if (!($result > 0)) {
  118. $error++;
  119. }
  120. $result = dolibarr_set_const($db, "ONLINE_PAYMENT_SENDEMAIL", GETPOST('ONLINE_PAYMENT_SENDEMAIL'), 'chaine', 0, '', $conf->entity);
  121. if (!($result > 0)) {
  122. $error++;
  123. }
  124. // Stock decrement
  125. //$result = dolibarr_set_const($db, "ONLINE_PAYMENT_WAREHOUSE", (GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') > 0 ? GETPOST('ONLINE_PAYMENT_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
  126. //if (! $result > 0)
  127. // $error ++;
  128. // Payment token for URL
  129. $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", GETPOST('PAYMENT_SECURITY_TOKEN', 'alpha'), 'chaine', 0, '', $conf->entity);
  130. if (!($result > 0)) {
  131. $error++;
  132. }
  133. if (empty($conf->use_javascript_ajax)) {
  134. $result = dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN_UNIQUE", GETPOST('PAYMENT_SECURITY_TOKEN_UNIQUE', 'alpha'), 'chaine', 0, '', $conf->entity);
  135. if (!($result > 0)) {
  136. $error++;
  137. }
  138. }
  139. if (!$error) {
  140. $db->commit();
  141. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  142. } else {
  143. $db->rollback();
  144. dol_print_error($db);
  145. }
  146. }
  147. if ($action == "setlive") {
  148. $liveenable = GETPOST('value', 'int');
  149. $res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity);
  150. if ($res > 0) {
  151. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  152. } else {
  153. setEventMessages($langs->trans("Error"), null, 'errors');
  154. }
  155. }
  156. //TODO: import script for stripe account saving in alone or connect mode for stripe.class.php
  157. /*
  158. * View
  159. */
  160. $form = new Form($db);
  161. $formproduct = new FormProduct($db);
  162. llxHeader('', $langs->trans("StripeSetup"));
  163. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  164. print load_fiche_titre($langs->trans("ModuleSetup").' Stripe', $linkback);
  165. $head = stripeadmin_prepare_head();
  166. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  167. print '<input type="hidden" name="token" value="'.newToken().'">';
  168. print '<input type="hidden" name="action" value="setvalue">';
  169. print dol_get_fiche_head($head, 'stripeaccount', '', -1);
  170. $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');
  171. print '<span class="opacitymedium">'.$langs->trans("StripeDesc")."</span><br>\n";
  172. print '<br>';
  173. print '<div class="div-table-responsive-no-min">';
  174. print '<table class="noborder centpercent">';
  175. print '<tr class="liste_titre">';
  176. print '<td>'.$langs->trans("AccountParameter").'</td>';
  177. print '<td>'.$langs->trans("Value").'</td>';
  178. print '<td></td>';
  179. print "</tr>\n";
  180. print '<tr class="oddeven">';
  181. print '<td>';
  182. print $langs->trans("StripeLiveEnabled").'</td><td>';
  183. if ($conf->use_javascript_ajax) {
  184. print ajax_constantonoff('STRIPE_LIVE');
  185. } else {
  186. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  187. print $form->selectarray("STRIPE_LIVE", $arrval, $conf->global->STRIPE_LIVE);
  188. }
  189. print '</td><td></td></tr>';
  190. if (empty($conf->stripeconnect->enabled)) {
  191. print '<tr class="oddeven"><td>';
  192. print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>';
  193. print '<input class="minwidth300" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY.'" placeholder="'.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx">';
  194. print '</td><td></td></tr>';
  195. print '<tr class="oddeven"><td>';
  196. print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
  197. print '<input class="minwidth300" type="text" name="STRIPE_TEST_SECRET_KEY" value="'.$conf->global->STRIPE_TEST_SECRET_KEY.'" placeholder="'.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx">';
  198. print '</td><td></td></tr>';
  199. print '<tr class="oddeven"><td>';
  200. print '<span class="titlefield">'.$langs->trans("STRIPE_TEST_WEBHOOK_KEY").'</span></td><td>';
  201. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
  202. print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_ID" value="'.getDolGlobalString('STRIPE_TEST_WEBHOOK_ID').'" placeholder="'.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx">';
  203. print '<br>';
  204. }
  205. print '<input class="minwidth300" type="text" name="STRIPE_TEST_WEBHOOK_KEY" value="'.getDolGlobalString('STRIPE_TEST_WEBHOOK_KEY').'" placeholder="'.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx">';
  206. $out = img_picto('', 'globe').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForTestWebhook").'</span> ';
  207. $url = dol_buildpath('/public/stripe/ipn.php?test', 3);
  208. $out .= '<input type="text" id="onlinetestwebhookurl" class="minwidth500" value="'.$url.'" disabled>';
  209. $out .= ajax_autoselect("onlinetestwebhookurl", 0);
  210. print '<br>'.$out;
  211. print '</td><td>';
  212. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
  213. if (!empty($conf->global->STRIPE_TEST_WEBHOOK_KEY) && !empty($conf->global->STRIPE_TEST_SECRET_KEY) && !empty($conf->global->STRIPE_TEST_WEBHOOK_ID)) {
  214. \Stripe\Stripe::setApiKey($conf->global->STRIPE_TEST_SECRET_KEY);
  215. $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_TEST_WEBHOOK_ID);
  216. $endpoint->enabled_events = $stripearrayofwebhookevents;
  217. if (GETPOST('webhook', 'alpha') == $conf->global->STRIPE_TEST_WEBHOOK_ID) {
  218. if (!GETPOST('status', 'alpha')) {
  219. $endpoint->disabled = true;
  220. } else {
  221. $endpoint->disabled = false;
  222. }
  223. }
  224. $endpoint->url = dol_buildpath('/public/stripe/ipn.php?test', 3);
  225. $endpoint->save();
  226. if ($endpoint->status == 'enabled') {
  227. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
  228. print img_picto($langs->trans("Activated"), 'switch_on');
  229. } else {
  230. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
  231. print img_picto($langs->trans("Disabled"), 'switch_off');
  232. }
  233. //print $endpoint;
  234. } else {
  235. print img_picto($langs->trans("Inactive"), 'statut5');
  236. }
  237. }
  238. print'</td></tr>';
  239. } else {
  240. print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
  241. print '<td><b>'.$langs->trans("StripeConnect_Mode").'</b><br>';
  242. print $langs->trans("STRIPE_APPLICATION_FEE_PLATFORM").' ';
  243. print price($conf->global->STRIPE_APPLICATION_FEE_PERCENT);
  244. print '% + ';
  245. print price($conf->global->STRIPE_APPLICATION_FEE);
  246. print ' '.$langs->getCurrencySymbol($conf->currency).' '.$langs->trans("minimum").' '.price($conf->global->STRIPE_APPLICATION_FEE_MINIMAL).' '.$langs->getCurrencySymbol($conf->currency);
  247. print '</td><td></td></tr>';
  248. }
  249. if (empty($conf->stripeconnect->enabled)) {
  250. print '<tr class="oddeven"><td>';
  251. print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
  252. print '<input class="minwidth300" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.getDolGlobalString('STRIPE_LIVE_PUBLISHABLE_KEY').'" placeholder="'.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
  253. print '</td><td></td></tr>';
  254. print '<tr class="oddeven"><td>';
  255. print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
  256. print '<input class="minwidth300" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.getDolGlobalString('STRIPE_LIVE_SECRET_KEY').'" placeholder="'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
  257. print '</td><td></td></tr>';
  258. print '<tr class="oddeven"><td>';
  259. print '<span class="titlefield">'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
  260. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
  261. print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID').'" placeholder="'.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx">';
  262. print '<br>';
  263. }
  264. print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_KEY').'" placeholder="'.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx">';
  265. $out = img_picto('', 'globe', 'class="pictofixedwidth"').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForLiveWebhook").'</span> ';
  266. $url = dol_buildpath('/public/stripe/ipn.php', 3);
  267. $out .= '<input type="text" id="onlinelivewebhookurl" class="minwidth500" value="'.$url.'" disabled>';
  268. $out .= ajax_autoselect("onlinelivewebhookurl", 0);
  269. print '<br>'.$out;
  270. print '</td><td>';
  271. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
  272. if (!empty($conf->global->STRIPE_LIVE_WEBHOOK_KEY) && !empty($conf->global->STRIPE_LIVE_SECRET_KEY) && !empty($conf->global->STRIPE_LIVE_WEBHOOK_ID)) {
  273. \Stripe\Stripe::setApiKey($conf->global->STRIPE_LIVE_SECRET_KEY);
  274. $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK_ID);
  275. $endpoint->enabled_events = $stripearrayofwebhookevents;
  276. if (GETPOST('webhook', 'alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID) {
  277. if (empty(GETPOST('status', 'alpha'))) {
  278. $endpoint->disabled = true;
  279. } else {
  280. $endpoint->disabled = false;
  281. }
  282. }
  283. $endpoint->url = dol_buildpath('/public/stripe/ipn.php', 3);
  284. $endpoint->save();
  285. if ($endpoint->status == 'enabled') {
  286. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
  287. print img_picto($langs->trans("Activated"), 'switch_on');
  288. } else {
  289. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
  290. print img_picto($langs->trans("Disabled"), 'switch_off');
  291. }
  292. //print $endpoint;
  293. } else {
  294. print img_picto($langs->trans("Inactive"), 'statut5');
  295. }
  296. }
  297. print '</td></tr>';
  298. } else {
  299. print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
  300. print '<td>'.$langs->trans("StripeConnect_Mode").'</td><td></td></tr>';
  301. }
  302. print '</table>';
  303. print '</div>';
  304. print '<br>';
  305. print '<div class="div-table-responsive-no-min">';
  306. print '<table class="noborder centpercent">';
  307. print '<tr class="liste_titre">';
  308. print '<td>'.$langs->trans("UsageParameter").'</td>';
  309. print '<td>'.$langs->trans("Value").'</td>';
  310. print "</tr>\n";
  311. print '<tr class="oddeven"><td>';
  312. print $langs->trans("PublicVendorName").'</td><td>';
  313. print '<input class="minwidth300" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'">';
  314. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
  315. print '</td></tr>';
  316. print '<tr class="oddeven"><td>';
  317. print $langs->trans("StripeUserAccountForActions").'</td><td>';
  318. print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS'), 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0);
  319. print '</td></tr>';
  320. print '<tr class="oddeven"><td>';
  321. print $langs->trans("BankAccount").'</td><td>';
  322. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  323. $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'), 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
  324. print '</td></tr>';
  325. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // What is this for ?
  326. print '<tr class="oddeven"><td>';
  327. print $langs->trans("BankAccountForBankTransfer").'</td><td>';
  328. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  329. $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS'), 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
  330. print '</td></tr>';
  331. }
  332. // Card Present for Stripe Terminal
  333. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
  334. print '<tr class="oddeven"><td>';
  335. print $langs->trans("STRIPE_CARD_PRESENT").'</td><td>';
  336. if ($conf->use_javascript_ajax) {
  337. print ajax_constantonoff('STRIPE_CARD_PRESENT');
  338. } else {
  339. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  340. print $form->selectarray("STRIPE_CARD_PRESENT", $arrval, $conf->global->STRIPE_CARD_PRESENT);
  341. }
  342. print '</td></tr>';
  343. }
  344. // Locations for Stripe Terminal
  345. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
  346. print '<tr class="oddeven"><td>';
  347. print $langs->trans("TERMINAL_LOCATION").'</td><td>';
  348. $service = 'StripeTest';
  349. $servicestatus = 0;
  350. if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) {
  351. $service = 'StripeLive';
  352. $servicestatus = 1;
  353. }
  354. global $stripearrayofkeysbyenv;
  355. $site_account = $stripearrayofkeysbyenv[$servicestatus]['secret_key'];
  356. if (!empty($site_account)) {
  357. \Stripe\Stripe::setApiKey($site_account);
  358. }
  359. if (isModEnabled('stripe') && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
  360. $service = 'StripeTest';
  361. $servicestatus = '0';
  362. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
  363. } else {
  364. $service = 'StripeLive';
  365. $servicestatus = '1';
  366. }
  367. $stripe = new Stripe($db);
  368. if (!empty($site_account)) {
  369. // If $site_account not defined, then key not set and no way to call API Location
  370. $stripeacc = $stripe->getStripeAccount($service);
  371. if ($stripeacc) {
  372. $locations = \Stripe\Terminal\Location::all('', array("stripe_account" => $stripeacc));
  373. } else {
  374. $locations = \Stripe\Terminal\Location::all();
  375. }
  376. }
  377. $location = array();
  378. $location[""] = $langs->trans("NotDefined");
  379. foreach ($locations as $tmplocation) {
  380. $location[$tmplocation->id] = $tmplocation->display_name;
  381. }
  382. print $form->selectarray("STRIPE_LOCATION", $location, getDolGlobalString('STRIPE_LOCATION'));
  383. print '</td></tr>';
  384. }
  385. // Activate Payment Request API
  386. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
  387. print '<tr class="oddeven"><td>';
  388. print $langs->trans("STRIPE_PAYMENT_REQUEST_API").' ?? Not used, what is it for ??</td><td>';
  389. if ($conf->use_javascript_ajax) {
  390. print ajax_constantonoff('STRIPE_PAYMENT_REQUEST_API');
  391. } else {
  392. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  393. print $form->selectarray("STRIPE_PAYMENT_REQUEST_API", $arrval, getDolGlobalString('STRIPE_PAYMENT_REQUEST_API'));
  394. }
  395. print '</td></tr>';
  396. }
  397. // Activate SEPA DIRECT_DEBIT
  398. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
  399. print '<tr class="oddeven"><td>';
  400. print $langs->trans("STRIPE_SEPA_DIRECT_DEBIT").'</td><td>';
  401. if ($conf->use_javascript_ajax) {
  402. print ajax_constantonoff('STRIPE_SEPA_DIRECT_DEBIT');
  403. } else {
  404. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  405. print $form->selectarray("STRIPE_SEPA_DIRECT_DEBIT", $arrval, getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT'));
  406. }
  407. print '</td></tr>';
  408. }
  409. // Activate Klarna
  410. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
  411. print '<tr class="oddeven"><td>';
  412. print $langs->trans("STRIPE_KLARNA").'</td><td>';
  413. if ($conf->use_javascript_ajax) {
  414. print ajax_constantonoff('STRIPE_KLARNA');
  415. } else {
  416. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  417. print $form->selectarray("STRIPE_KLARNA", $arrval, $conf->global->STRIPE_KLARNA);
  418. }
  419. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForKlarnaCustomers").'</span>';
  420. print '</td></tr>';
  421. }
  422. // Activate Bancontact
  423. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
  424. print '<tr class="oddeven"><td>';
  425. print $langs->trans("STRIPE_BANCONTACT").'</td><td>';
  426. if ($conf->use_javascript_ajax) {
  427. print ajax_constantonoff('STRIPE_BANCONTACT');
  428. } else {
  429. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  430. print $form->selectarray("STRIPE_BANCONTACT", $arrval, $conf->global->STRIPE_BANCONTACT);
  431. }
  432. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForBECustomers").'</span>';
  433. print '</td></tr>';
  434. }
  435. // Activate iDEAL
  436. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
  437. print '<tr class="oddeven"><td>';
  438. print $langs->trans("STRIPE_IDEAL").'</td><td>';
  439. if ($conf->use_javascript_ajax) {
  440. print ajax_constantonoff('STRIPE_IDEAL');
  441. } else {
  442. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  443. print $form->selectarray("STRIPE_IDEAL", $arrval, $conf->global->STRIPE_SEPA_DIRECT_DEBIT);
  444. }
  445. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForNLCustomers").'</span>';
  446. print '</td></tr>';
  447. }
  448. // Activate Giropay
  449. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
  450. print '<tr class="oddeven"><td>';
  451. print $langs->trans("STRIPE_GIROPAY").'</td><td>';
  452. if ($conf->use_javascript_ajax) {
  453. print ajax_constantonoff('STRIPE_GIROPAY');
  454. } else {
  455. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  456. print $form->selectarray("STRIPE_GIROPAY", $arrval, $conf->global->STRIPE_GIROPAY);
  457. }
  458. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForDECustomers").'</span>';
  459. print '</td></tr>';
  460. }
  461. // Activate Sofort
  462. if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
  463. print '<tr class="oddeven"><td>';
  464. print $langs->trans("STRIPE_SOFORT").'</td><td>';
  465. if ($conf->use_javascript_ajax) {
  466. print ajax_constantonoff('STRIPE_SOFORT');
  467. } else {
  468. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  469. print $form->selectarray("STRIPE_SOFORT", $arrval, $conf->global->STRIPE_SOFORT);
  470. }
  471. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForATBEDEITNLESCustomers").'</span>';
  472. print '</td></tr>';
  473. }
  474. print '<tr class="oddeven"><td>';
  475. print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
  476. print '<input size="64" type="text" name="ONLINE_PAYMENT_CSS_URL" value="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'">';
  477. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
  478. print '</td></tr>';
  479. print '<tr class="oddeven"><td>';
  480. print $langs->trans("MessageForm").'</td><td>';
  481. $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', $conf->global->ONLINE_PAYMENT_MESSAGE_FORM, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
  482. $doleditor->Create();
  483. print '</td></tr>';
  484. print '<tr class="oddeven"><td>';
  485. print $langs->trans("MessageOK").'</td><td>';
  486. $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', $conf->global->ONLINE_PAYMENT_MESSAGE_OK, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
  487. $doleditor->Create();
  488. print '</td></tr>';
  489. print '<tr class="oddeven"><td>';
  490. print $langs->trans("MessageKO").'</td><td>';
  491. $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', $conf->global->ONLINE_PAYMENT_MESSAGE_KO, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
  492. $doleditor->Create();
  493. print '</td></tr>';
  494. print '<tr class="oddeven"><td>';
  495. print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
  496. print img_picto('', 'email', 'class="pictofixedwidth"');
  497. print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="'.$conf->global->ONLINE_PAYMENT_SENDEMAIL.'">';
  498. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
  499. print '</td></tr>';
  500. print '</table>';
  501. print '</div>';
  502. print '<br>';
  503. print '<div class="div-table-responsive-no-min">';
  504. print '<table class="noborder centpercent">';
  505. print '<tr class="liste_titre">';
  506. print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
  507. print '<td>'.$langs->trans("Value").'</td>';
  508. print "</tr>\n";
  509. // Payment token for URL
  510. print '<tr class="oddeven"><td>';
  511. print $langs->trans("SecurityToken").'</td><td>';
  512. print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="'.$conf->global->PAYMENT_SECURITY_TOKEN.'">';
  513. if (!empty($conf->use_javascript_ajax)) {
  514. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  515. }
  516. if (!empty($conf->global->PAYMENT_SECURITY_ACCEPT_ANY_TOKEN)) {
  517. $langs->load("errors");
  518. print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
  519. }
  520. print '</td></tr>';
  521. print '<tr class="oddeven"><td>';
  522. print $langs->trans("SecurityTokenIsUnique").'</td><td>';
  523. if ($conf->use_javascript_ajax) {
  524. print ajax_constantonoff('PAYMENT_SECURITY_TOKEN_UNIQUE', null, null, 0, 0, 1);
  525. } else {
  526. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  527. print $form->selectarray("PAYMENT_SECURITY_TOKEN_UNIQUE", $arrval, $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE);
  528. }
  529. print '</td></tr>';
  530. print '</table>';
  531. print '</div>';
  532. print dol_get_fiche_end();
  533. print $form->buttonsSaveCancel("Save", '');
  534. print '</form>';
  535. print '<br><br>';
  536. $token = '';
  537. include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
  538. print 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'));
  539. if (!empty($conf->use_javascript_ajax)) {
  540. print "\n".'<script type="text/javascript">';
  541. print '$(document).ready(function () {
  542. $("#apidoc").hide();
  543. $("#apidoca").click(function() {
  544. console.log("We click on apidoca show/hide");
  545. $("#apidoc").show();
  546. $("#apidoca").hide();
  547. return false;
  548. });
  549. });';
  550. print '</script>';
  551. }
  552. // End of page
  553. llxFooter();
  554. $db->close();