paymentko.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/public/payment/paymentko.php
  21. * \ingroup core
  22. * \brief File to show page after a failed payment.
  23. * This page is called by payment system with url provided to it competed with parameter TOKEN=xxx
  24. * This token can be used to get more informations.
  25. */
  26. if (!defined('NOLOGIN')) {
  27. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  28. }
  29. if (!defined('NOCSRFCHECK')) {
  30. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  31. }
  32. if (!defined('NOIPCHECK')) {
  33. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  34. }
  35. if (!defined('NOBROWSERNOTIF')) {
  36. define('NOBROWSERNOTIF', '1');
  37. }
  38. // For MultiCompany module.
  39. // Do not use GETPOST here, function is not defined and this test must be done before including main.inc.php
  40. // TODO This should be useless. Because entity must be retrieve from object ref and not from url.
  41. $entity = (!empty($_GET['e']) ? (int) $_GET['e'] : (!empty($_POST['e']) ? (int) $_POST['e'] : 1));
  42. if (is_numeric($entity)) {
  43. define("DOLENTITY", $entity);
  44. }
  45. require '../../main.inc.php';
  46. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  48. if (!empty($conf->paypal->enabled)) {
  49. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
  50. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
  51. }
  52. $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paybox", "paypal", "stripe"));
  53. if (!empty($conf->paypal->enabled)) {
  54. $PAYPALTOKEN = GETPOST('TOKEN');
  55. if (empty($PAYPALTOKEN)) {
  56. $PAYPALTOKEN = GETPOST('token');
  57. }
  58. $PAYPALPAYERID = GETPOST('PAYERID');
  59. if (empty($PAYPALPAYERID)) {
  60. $PAYPALPAYERID = GETPOST('PayerID');
  61. }
  62. }
  63. if (!empty($conf->paybox->enabled)) {
  64. }
  65. if (!empty($conf->stripe->enabled)) {
  66. }
  67. $FULLTAG = GETPOST('FULLTAG');
  68. if (empty($FULLTAG)) {
  69. $FULLTAG = GETPOST('fulltag');
  70. }
  71. $suffix = GETPOST("suffix", 'aZ09');
  72. // Detect $paymentmethod
  73. $paymentmethod = '';
  74. $reg = array();
  75. if (preg_match('/PM=([^\.]+)/', $FULLTAG, $reg)) {
  76. $paymentmethod = $reg[1];
  77. }
  78. if (empty($paymentmethod)) {
  79. dol_print_error(null, 'The back url does not contains a parameter fulltag that should help us to find the payment method used');
  80. exit;
  81. } else {
  82. dol_syslog("paymentmethod=".$paymentmethod);
  83. }
  84. $validpaymentmethod = array();
  85. if (!empty($conf->paypal->enabled)) {
  86. $validpaymentmethod['paypal'] = 'paypal';
  87. }
  88. if (!empty($conf->paybox->enabled)) {
  89. $validpaymentmethod['paybox'] = 'paybox';
  90. }
  91. if (!empty($conf->stripe->enabled)) {
  92. $validpaymentmethod['stripe'] = 'stripe';
  93. }
  94. // Security check
  95. if (empty($validpaymentmethod)) {
  96. httponly_accessforbidden('No valid payment mode');
  97. }
  98. $object = new stdClass(); // For triggers
  99. /*
  100. * Actions
  101. */
  102. /*
  103. * View
  104. */
  105. dol_syslog("Callback url when an online payment is refused or canceled. query_string=".(empty($_SERVER["QUERY_STRING"]) ? '' : $_SERVER["QUERY_STRING"])." script_uri=".(empty($_SERVER["SCRIPT_URI"]) ? '' : $_SERVER["SCRIPT_URI"]), LOG_DEBUG, 0, '_payment');
  106. $tracepost = "";
  107. foreach ($_POST as $k => $v) {
  108. $tracepost .= "{$k} - {$v}\n";
  109. }
  110. dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
  111. if (!empty($_SESSION['ipaddress'])) { // To avoid to make action twice
  112. // Get on url call
  113. $fulltag = $FULLTAG;
  114. $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
  115. $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
  116. // Set by newpayment.php
  117. $paymentType = $_SESSION['PaymentType'];
  118. $currencyCodeType = $_SESSION['currencyCodeType'];
  119. $FinalPaymentAmt = $_SESSION['FinalPaymentAmt'];
  120. // From env
  121. $ipaddress = $_SESSION['ipaddress'];
  122. $errormessage = $_SESSION['errormessage'];
  123. if (is_object($object) && method_exists($object, 'call_trigger')) {
  124. // Call trigger
  125. $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_KO', $user);
  126. if ($result < 0) {
  127. $error++;
  128. }
  129. // End call triggers
  130. }
  131. // Send an email
  132. $sendemail = '';
  133. if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
  134. $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
  135. }
  136. // Send warning of error to administrator
  137. if ($sendemail) {
  138. $companylangs = new Translate('', $conf);
  139. $companylangs->setDefaultLang($mysoc->default_lang);
  140. $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
  141. $from = $conf->global->MAILING_EMAIL_FROM;
  142. $sendto = $sendemail;
  143. // Define link to login card
  144. $appli = constant('DOL_APPLICATION_TITLE');
  145. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  146. $appli = $conf->global->MAIN_APPLICATION_TITLE;
  147. if (preg_match('/\d\.\d/', $appli)) {
  148. if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
  149. $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
  150. }
  151. } else {
  152. $appli .= " ".DOL_VERSION;
  153. }
  154. } else {
  155. $appli .= " ".DOL_VERSION;
  156. }
  157. $urlback = $_SERVER["REQUEST_URI"];
  158. $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentFailed");
  159. $content = "";
  160. $content .= '<span style="color: orange">'.$companylangs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."</span>\n";
  161. $content .= "<br><br>\n";
  162. $content .= '<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
  163. $content .= $companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
  164. $content .= $companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
  165. $content .= $companylangs->transnoentitiesnoconv("Error").': '.$errormessage."<br>\n";
  166. $content .= "<br>\n";
  167. $content .= "tag=".$fulltag." token=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
  168. $ishtml = dol_textishtml($content); // May contain urls
  169. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  170. $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
  171. $result = $mailfile->sendfile();
  172. if ($result) {
  173. dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
  174. } else {
  175. dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
  176. }
  177. }
  178. unset($_SESSION['ipaddress']);
  179. }
  180. $head = '';
  181. if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
  182. $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
  183. }
  184. $conf->dol_hide_topmenu = 1;
  185. $conf->dol_hide_leftmenu = 1;
  186. $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  187. llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
  188. // Show ko message
  189. print '<span id="dolpaymentspan"></span>'."\n";
  190. print '<div id="dolpaymentdiv" align="center">'."\n";
  191. // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
  192. // Define logo and logosmall
  193. $logosmall = $mysoc->logo_small;
  194. $logo = $mysoc->logo;
  195. $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
  196. if (!empty($conf->global->$paramlogo)) {
  197. $logosmall = $conf->global->$paramlogo;
  198. } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
  199. $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
  200. }
  201. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  202. // Define urllogo
  203. $urllogo = '';
  204. $urllogofull = '';
  205. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
  206. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  207. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  208. } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
  209. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  210. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  211. }
  212. // Output html code for logo
  213. if ($urllogo) {
  214. print '<div class="backgreypublicpayment">';
  215. print '<div class="logopublicpayment">';
  216. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  217. print '>';
  218. print '</div>';
  219. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  220. print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img class="poweredbyimg" src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
  221. }
  222. print '</div>';
  223. }
  224. if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
  225. print '<div class="backimagepublicpayment">';
  226. print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.'">';
  227. print '</div>';
  228. }
  229. print '<br><br>';
  230. print $langs->trans("YourPaymentHasNotBeenRecorded")."<br><br>";
  231. $key = 'ONLINE_PAYMENT_MESSAGE_KO';
  232. if (!empty($conf->global->$key)) {
  233. print $conf->global->$key;
  234. }
  235. $type = GETPOST('s', 'alpha');
  236. $ref = GETPOST('ref', 'alphanohtml');
  237. $tag = GETPOST('tag', 'alpha');
  238. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  239. if ($type || $tag) {
  240. $urlsubscription = getOnlinePaymentUrl(0, ($type ? $type : 'free'), $ref, $FinalPaymentAmt, $tag);
  241. print $langs->trans("ClickHereToTryAgain", $urlsubscription);
  242. }
  243. print "\n</div>\n";
  244. htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
  245. llxFooter('', 'public');
  246. $db->close();