stripe.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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="' . getDolGlobalString('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="' . getDolGlobalString('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 (getDolGlobalInt('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', 3);
  208. $url .= '?test=1';
  209. //global $dolibarr_main_instance_unique_id;
  210. //$url .= '&securitykey='.dol_hash('stripeipn-'.$dolibarr_main_instance_unique_id.'-'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY, 'md5');
  211. $out .= '<input type="text" id="onlinetestwebhookurl" class="minwidth500" value="'.$url.'" disabled>';
  212. $out .= ajax_autoselect("onlinetestwebhookurl", 0);
  213. print '<br>'.$out;
  214. print '</td><td>';
  215. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
  216. if (getDolGlobalString('STRIPE_TEST_WEBHOOK_KEY') && getDolGlobalString('STRIPE_TEST_SECRET_KEY') && getDolGlobalString('STRIPE_TEST_WEBHOOK_ID')) {
  217. if (utf8_check($conf->global->STRIPE_TEST_SECRET_KEY)) {
  218. try {
  219. \Stripe\Stripe::setApiKey($conf->global->STRIPE_TEST_SECRET_KEY);
  220. $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_TEST_WEBHOOK_ID);
  221. $endpoint->enabled_events = $stripearrayofwebhookevents;
  222. if (GETPOST('webhook', 'alpha') == $conf->global->STRIPE_TEST_WEBHOOK_ID) {
  223. if (!GETPOST('status', 'alpha')) {
  224. $endpoint->disabled = true;
  225. } else {
  226. $endpoint->disabled = false;
  227. }
  228. }
  229. $endpoint->url = $url;
  230. $endpoint->save();
  231. if ($endpoint->status == 'enabled') {
  232. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
  233. print img_picto($langs->trans("Activated"), 'switch_on');
  234. } else {
  235. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
  236. print img_picto($langs->trans("Disabled"), 'switch_off');
  237. }
  238. } catch (Exception $e) {
  239. print $e->getMessage();
  240. }
  241. } else {
  242. print 'Bad value for the secret key. Reenter and save it again to fix this.';
  243. }
  244. } else {
  245. print img_picto($langs->trans("Inactive"), 'statut5');
  246. }
  247. }
  248. print'</td></tr>';
  249. } else {
  250. print '<tr class="oddeven"><td>'.$langs->trans("StripeConnect").'</td>';
  251. print '<td><b>'.$langs->trans("StripeConnect_Mode").'</b><br>';
  252. print $langs->trans("STRIPE_APPLICATION_FEE_PLATFORM").' ';
  253. print price($conf->global->STRIPE_APPLICATION_FEE_PERCENT);
  254. print '% + ';
  255. print price($conf->global->STRIPE_APPLICATION_FEE);
  256. print ' '.$langs->getCurrencySymbol($conf->currency).' '.$langs->trans("minimum").' '.price($conf->global->STRIPE_APPLICATION_FEE_MINIMAL).' '.$langs->getCurrencySymbol($conf->currency);
  257. print '</td><td></td></tr>';
  258. }
  259. if (empty($conf->stripeconnect->enabled)) {
  260. print '<tr class="oddeven"><td>';
  261. print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
  262. print '<input class="minwidth300" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.getDolGlobalString('STRIPE_LIVE_PUBLISHABLE_KEY').'" placeholder="'.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
  263. print '</td><td></td></tr>';
  264. print '<tr class="oddeven"><td>';
  265. print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
  266. print '<input class="minwidth300" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.getDolGlobalString('STRIPE_LIVE_SECRET_KEY').'" placeholder="'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx">';
  267. print '</td><td></td></tr>';
  268. print '<tr class="oddeven"><td>';
  269. print '<span class="titlefield">'.$langs->trans("STRIPE_LIVE_WEBHOOK_KEY").'</span></td><td>';
  270. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
  271. print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_ID" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID').'" placeholder="'.$langs->trans("Example").': we_xxxxxxxxxxxxxxxxxxxxxxxx">';
  272. print '<br>';
  273. }
  274. print '<input class="minwidth300" type="text" name="STRIPE_LIVE_WEBHOOK_KEY" value="'.getDolGlobalString('STRIPE_LIVE_WEBHOOK_KEY').'" placeholder="'.$langs->trans("Example").': whsec_xxxxxxxxxxxxxxxxxxxxxxxx">';
  275. $out = img_picto('', 'globe', 'class="pictofixedwidth"').' <span class="opacitymedium">'.$langs->trans("ToOfferALinkForLiveWebhook").'</span> ';
  276. $url = dol_buildpath('/public/stripe/ipn.php', 3);
  277. //global $dolibarr_main_instance_unique_id;
  278. //$url .= '?securitykey='.dol_hash('stripeipn-'.$dolibarr_main_instance_unique_id.'-'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY, 'md5');
  279. $out .= '<input type="text" id="onlinelivewebhookurl" class="minwidth500" value="'.$url.'" disabled>';
  280. $out .= ajax_autoselect("onlinelivewebhookurl", 0);
  281. print '<br>'.$out;
  282. print '</td><td>';
  283. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
  284. if (getDolGlobalString('STRIPE_LIVE_WEBHOOK_KEY') && getDolGlobalString('STRIPE_LIVE_SECRET_KEY') && getDolGlobalString('STRIPE_LIVE_WEBHOOK_ID')) {
  285. if (utf8_check($conf->global->STRIPE_TEST_SECRET_KEY)) {
  286. try {
  287. \Stripe\Stripe::setApiKey($conf->global->STRIPE_LIVE_SECRET_KEY);
  288. $endpoint = \Stripe\WebhookEndpoint::retrieve($conf->global->STRIPE_LIVE_WEBHOOK_ID);
  289. $endpoint->enabled_events = $stripearrayofwebhookevents;
  290. if (GETPOST('webhook', 'alpha') == $conf->global->STRIPE_LIVE_WEBHOOK_ID) {
  291. if (empty(GETPOST('status', 'alpha'))) {
  292. $endpoint->disabled = true;
  293. } else {
  294. $endpoint->disabled = false;
  295. }
  296. }
  297. $endpoint->url = $url;
  298. $endpoint->save();
  299. if ($endpoint->status == 'enabled') {
  300. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=0">';
  301. print img_picto($langs->trans("Activated"), 'switch_on');
  302. } else {
  303. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=ipn&webhook='.$endpoint->id.'&status=1">';
  304. print img_picto($langs->trans("Disabled"), 'switch_off');
  305. }
  306. } catch (Exception $e) {
  307. print $e->getMessage();
  308. }
  309. }
  310. } else {
  311. print img_picto($langs->trans("Inactive"), 'statut5');
  312. }
  313. }
  314. print '</td></tr>';
  315. }
  316. print '</table>';
  317. print '</div>';
  318. print '<br>';
  319. print '<div class="div-table-responsive-no-min">';
  320. print '<table class="noborder centpercent">';
  321. print '<tr class="liste_titre">';
  322. print '<td>'.$langs->trans("UsageParameter").'</td>';
  323. print '<td>'.$langs->trans("Value").'</td>';
  324. print "</tr>\n";
  325. print '<tr class="oddeven"><td>';
  326. print $langs->trans("PublicVendorName").'</td><td>';
  327. print '<input class="minwidth300" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.getDolGlobalString('ONLINE_PAYMENT_CREDITOR').'">';
  328. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': '.$mysoc->name.'</span>';
  329. print '</td></tr>';
  330. print '<tr class="oddeven"><td>';
  331. print $langs->trans("StripeUserAccountForActions").'</td><td>';
  332. print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers(getDolGlobalString('STRIPE_USER_ACCOUNT_FOR_ACTIONS'), 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0);
  333. print '</td></tr>';
  334. print '<tr class="oddeven"><td>';
  335. print $langs->trans("BankAccount").'</td><td>';
  336. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  337. $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'), 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
  338. print '</td></tr>';
  339. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // What is this for ?
  340. print '<tr class="oddeven"><td>';
  341. print $langs->trans("BankAccountForBankTransfer").'</td><td>';
  342. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  343. $form->select_comptes(getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS'), 'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 0, '', 1);
  344. print '</td></tr>';
  345. }
  346. // Card Present for Stripe Terminal
  347. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
  348. print '<tr class="oddeven"><td>';
  349. print $langs->trans("STRIPE_CARD_PRESENT").'</td><td>';
  350. if ($conf->use_javascript_ajax) {
  351. print ajax_constantonoff('STRIPE_CARD_PRESENT');
  352. } else {
  353. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  354. print $form->selectarray("STRIPE_CARD_PRESENT", $arrval, $conf->global->STRIPE_CARD_PRESENT);
  355. }
  356. print '</td></tr>';
  357. }
  358. // Locations for Stripe Terminal
  359. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
  360. print '<tr class="oddeven"><td>';
  361. print $langs->trans("TERMINAL_LOCATION").'</td><td>';
  362. $service = 'StripeTest';
  363. $servicestatus = 0;
  364. if (getDolGlobalString('STRIPE_LIVE') && !GETPOST('forcesandbox', 'alpha')) {
  365. $service = 'StripeLive';
  366. $servicestatus = 1;
  367. }
  368. try {
  369. global $stripearrayofkeysbyenv;
  370. $site_account = $stripearrayofkeysbyenv[$servicestatus]['secret_key'];
  371. if (!empty($site_account)) {
  372. \Stripe\Stripe::setApiKey($site_account);
  373. }
  374. if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
  375. $service = 'StripeTest';
  376. $servicestatus = '0';
  377. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
  378. } else {
  379. $service = 'StripeLive';
  380. $servicestatus = '1';
  381. }
  382. $stripe = new Stripe($db);
  383. if (!empty($site_account)) {
  384. // If $site_account not defined, then key not set and no way to call API Location
  385. $stripeacc = $stripe->getStripeAccount($service);
  386. if ($stripeacc) {
  387. $locations = \Stripe\Terminal\Location::all('', array("stripe_account" => $stripeacc));
  388. } else {
  389. $locations = \Stripe\Terminal\Location::all();
  390. }
  391. }
  392. } catch (Exception $e) {
  393. print $e->getMessage().'<br>';
  394. }
  395. // Define the array $location
  396. $location = array();
  397. $location[""] = $langs->trans("NotDefined");
  398. if (!empty($locations)) {
  399. foreach ($locations as $tmplocation) {
  400. $location[$tmplocation->id] = $tmplocation->display_name;
  401. }
  402. }
  403. print $form->selectarray("STRIPE_LOCATION", $location, getDolGlobalString('STRIPE_LOCATION'));
  404. print '</td></tr>';
  405. }
  406. print '<tr class="oddeven"><td>';
  407. print $langs->trans("STRIPE_SEPA_DIRECT_DEBIT").'</td><td>';
  408. if ($conf->use_javascript_ajax) {
  409. print ajax_constantonoff('STRIPE_SEPA_DIRECT_DEBIT');
  410. } else {
  411. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  412. print $form->selectarray("STRIPE_SEPA_DIRECT_DEBIT", $arrval, getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT'));
  413. }
  414. print '</td></tr>';
  415. // Activate Klarna
  416. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
  417. print '<tr class="oddeven"><td>';
  418. print $langs->trans("STRIPE_KLARNA").'</td><td>';
  419. if ($conf->use_javascript_ajax) {
  420. print ajax_constantonoff('STRIPE_KLARNA');
  421. } else {
  422. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  423. print $form->selectarray("STRIPE_KLARNA", $arrval, $conf->global->STRIPE_KLARNA);
  424. }
  425. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForKlarnaCustomers").'</span>';
  426. print '</td></tr>';
  427. }
  428. // Activate Bancontact
  429. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
  430. print '<tr class="oddeven"><td>';
  431. print $langs->trans("STRIPE_BANCONTACT").'</td><td>';
  432. if ($conf->use_javascript_ajax) {
  433. print ajax_constantonoff('STRIPE_BANCONTACT');
  434. } else {
  435. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  436. print $form->selectarray("STRIPE_BANCONTACT", $arrval, $conf->global->STRIPE_BANCONTACT);
  437. }
  438. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForBECustomers").'</span>';
  439. print '</td></tr>';
  440. }
  441. // Activate iDEAL
  442. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
  443. print '<tr class="oddeven"><td>';
  444. print $langs->trans("STRIPE_IDEAL").'</td><td>';
  445. if ($conf->use_javascript_ajax) {
  446. print ajax_constantonoff('STRIPE_IDEAL');
  447. } else {
  448. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  449. print $form->selectarray("STRIPE_IDEAL", $arrval, $conf->global->STRIPE_SEPA_DIRECT_DEBIT);
  450. }
  451. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForNLCustomers").'</span>';
  452. print '</td></tr>';
  453. }
  454. // Activate Giropay
  455. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
  456. print '<tr class="oddeven"><td>';
  457. print $langs->trans("STRIPE_GIROPAY").'</td><td>';
  458. if ($conf->use_javascript_ajax) {
  459. print ajax_constantonoff('STRIPE_GIROPAY');
  460. } else {
  461. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  462. print $form->selectarray("STRIPE_GIROPAY", $arrval, $conf->global->STRIPE_GIROPAY);
  463. }
  464. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForDECustomers").'</span>';
  465. print '</td></tr>';
  466. }
  467. // Activate Sofort
  468. if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current code
  469. print '<tr class="oddeven"><td>';
  470. print $langs->trans("STRIPE_SOFORT").'</td><td>';
  471. if ($conf->use_javascript_ajax) {
  472. print ajax_constantonoff('STRIPE_SOFORT');
  473. } else {
  474. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  475. print $form->selectarray("STRIPE_SOFORT", $arrval, $conf->global->STRIPE_SOFORT);
  476. }
  477. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("ExampleOnlyForATBEDEITNLESCustomers").'</span>';
  478. print '</td></tr>';
  479. }
  480. print '<tr class="oddeven"><td>';
  481. print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
  482. print '<input class="width500" type="text" name="ONLINE_PAYMENT_CSS_URL" value="' . getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'">';
  483. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': http://mysite/mycss.css</span>';
  484. print '</td></tr>';
  485. print '<tr class="oddeven"><td>';
  486. print $langs->trans("MessageForm").'</td><td>';
  487. $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_FORM', $conf->global->ONLINE_PAYMENT_MESSAGE_FORM, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
  488. $doleditor->Create();
  489. print '</td></tr>';
  490. print '<tr class="oddeven"><td>';
  491. print $langs->trans("MessageOK").'</td><td>';
  492. $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_OK', $conf->global->ONLINE_PAYMENT_MESSAGE_OK, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
  493. $doleditor->Create();
  494. print '</td></tr>';
  495. print '<tr class="oddeven"><td>';
  496. print $langs->trans("MessageKO").'</td><td>';
  497. $doleditor = new DolEditor('ONLINE_PAYMENT_MESSAGE_KO', $conf->global->ONLINE_PAYMENT_MESSAGE_KO, '', 100, 'dolibarr_details', 'In', false, true, true, ROWS_2, '90%');
  498. $doleditor->Create();
  499. print '</td></tr>';
  500. print '<tr class="oddeven"><td>';
  501. print $langs->trans("ONLINE_PAYMENT_SENDEMAIL").'</td><td>';
  502. print img_picto('', 'email', 'class="pictofixedwidth"');
  503. print '<input class="minwidth200" type="text" name="ONLINE_PAYMENT_SENDEMAIL" value="' . getDolGlobalString('ONLINE_PAYMENT_SENDEMAIL').'">';
  504. print ' &nbsp; <span class="opacitymedium">'.$langs->trans("Example").': myemail@myserver.com, Payment service &lt;myemail2@myserver2.com&gt;</span>';
  505. print '</td></tr>';
  506. print '</table>';
  507. print '</div>';
  508. print '<br>';
  509. print '<div class="div-table-responsive-no-min">';
  510. print '<table class="noborder centpercent">';
  511. print '<tr class="liste_titre">';
  512. print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
  513. print '<td>'.$langs->trans("Value").'</td>';
  514. print "</tr>\n";
  515. // Payment token for URL
  516. print '<tr class="oddeven"><td>';
  517. print $langs->trans("SecurityToken").'</td><td>';
  518. print '<input class="minwidth300" type="text" id="PAYMENT_SECURITY_TOKEN" name="PAYMENT_SECURITY_TOKEN" value="' . getDolGlobalString('PAYMENT_SECURITY_TOKEN').'">';
  519. if (!empty($conf->use_javascript_ajax)) {
  520. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  521. }
  522. if (getDolGlobalString('PAYMENT_SECURITY_ACCEPT_ANY_TOKEN')) {
  523. $langs->load("errors");
  524. print img_warning($langs->trans("WarningTheHiddenOptionIsOn", 'PAYMENT_SECURITY_ACCEPT_ANY_TOKEN'), '', 'pictowarning marginleftonly');
  525. }
  526. print '</td></tr>';
  527. print '<tr class="oddeven"><td>';
  528. print $langs->trans("SecurityTokenIsUnique").'</td><td>';
  529. if ($conf->use_javascript_ajax) {
  530. print ajax_constantonoff('PAYMENT_SECURITY_TOKEN_UNIQUE', null, null, 0, 0, 1);
  531. } else {
  532. $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
  533. print $form->selectarray("PAYMENT_SECURITY_TOKEN_UNIQUE", $arrval, $conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE);
  534. }
  535. print '</td></tr>';
  536. print '</table>';
  537. print '</div>';
  538. print dol_get_fiche_end();
  539. print $form->buttonsSaveCancel("Save", '');
  540. print '</form>';
  541. print '<br><br>';
  542. $token = '';
  543. include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
  544. 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'));
  545. if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
  546. print info_admin($langs->trans("ExampleOfTestBankAcountForSEPA", 'AT611904300234573201 (pending->succeed) or AT861904300235473202 (pending->failed)'));
  547. }
  548. if (!empty($conf->use_javascript_ajax)) {
  549. print "\n".'<script type="text/javascript">';
  550. print '$(document).ready(function () {
  551. $("#apidoc").hide();
  552. $("#apidoca").click(function() {
  553. console.log("We click on apidoca show/hide");
  554. $("#apidoc").show();
  555. $("#apidoca").hide();
  556. return false;
  557. });
  558. });';
  559. print '</script>';
  560. }
  561. // End of page
  562. llxFooter();
  563. $db->close();