paymentko.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. // Load Dolibarr environment
  46. require '../../main.inc.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  48. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  49. if (isModEnabled('paypal')) {
  50. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
  51. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
  52. }
  53. $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paybox", "paypal", "stripe"));
  54. if (isModEnabled('paypal')) {
  55. $PAYPALTOKEN = GETPOST('TOKEN');
  56. if (empty($PAYPALTOKEN)) {
  57. $PAYPALTOKEN = GETPOST('token');
  58. }
  59. $PAYPALPAYERID = GETPOST('PAYERID');
  60. if (empty($PAYPALPAYERID)) {
  61. $PAYPALPAYERID = GETPOST('PayerID');
  62. }
  63. }
  64. if (isModEnabled('paybox')) {
  65. }
  66. if (isModEnabled('stripe')) {
  67. }
  68. $FULLTAG = GETPOST('FULLTAG');
  69. if (empty($FULLTAG)) {
  70. $FULLTAG = GETPOST('fulltag');
  71. }
  72. $suffix = GETPOST("suffix", 'aZ09');
  73. // Detect $paymentmethod
  74. $paymentmethod = '';
  75. $reg = array();
  76. if (preg_match('/PM=([^\.]+)/', $FULLTAG, $reg)) {
  77. $paymentmethod = $reg[1];
  78. }
  79. if (empty($paymentmethod)) {
  80. dol_print_error(null, 'The back url does not contains a parameter fulltag that should help us to find the payment method used');
  81. exit;
  82. } else {
  83. dol_syslog("paymentmethod=".$paymentmethod);
  84. }
  85. $validpaymentmethod = array();
  86. if (isModEnabled('paypal')) {
  87. $validpaymentmethod['paypal'] = 'paypal';
  88. }
  89. if (isModEnabled('paybox')) {
  90. $validpaymentmethod['paybox'] = 'paybox';
  91. }
  92. if (isModEnabled('stripe')) {
  93. $validpaymentmethod['stripe'] = 'stripe';
  94. }
  95. // Security check
  96. if (empty($validpaymentmethod)) {
  97. httponly_accessforbidden('No valid payment mode');
  98. }
  99. $object = new stdClass(); // For triggers
  100. /*
  101. * Actions
  102. */
  103. /*
  104. * View
  105. */
  106. 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');
  107. $tracepost = "";
  108. foreach ($_POST as $k => $v) {
  109. if (is_scalar($k) && is_scalar($v)) {
  110. $tracepost .= "{$k} - {$v}\n";
  111. }
  112. }
  113. dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
  114. // Set $appli for emails title
  115. $appli = $mysoc->name;
  116. if (!empty($_SESSION['ipaddress'])) { // To avoid to make action twice
  117. // Get on url call
  118. $fulltag = $FULLTAG;
  119. $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
  120. $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
  121. // Set by newpayment.php
  122. $paymentType = $_SESSION['PaymentType'];
  123. $currencyCodeType = $_SESSION['currencyCodeType'];
  124. $FinalPaymentAmt = $_SESSION['FinalPaymentAmt'];
  125. // From env
  126. $ipaddress = $_SESSION['ipaddress'];
  127. $errormessage = $_SESSION['errormessage'];
  128. if (is_object($object) && method_exists($object, 'call_trigger')) {
  129. // Call trigger
  130. $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_KO', $user);
  131. if ($result < 0) {
  132. $error++;
  133. }
  134. // End call triggers
  135. }
  136. // Send an email
  137. $sendemail = '';
  138. if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
  139. $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
  140. }
  141. // Send warning of error to administrator
  142. if ($sendemail) {
  143. $companylangs = new Translate('', $conf);
  144. $companylangs->setDefaultLang($mysoc->default_lang);
  145. $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
  146. $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM : getDolGlobalString("MAIN_MAIL_EMAIL_FROM");
  147. $sendto = $sendemail;
  148. $urlback = $_SERVER["REQUEST_URI"];
  149. $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentFailed");
  150. $content = "";
  151. $content .= '<span style="color: orange">'.$companylangs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."</span>\n";
  152. $content .= "<br><br>\n";
  153. $content .= '<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
  154. $content .= $companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
  155. $content .= $companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
  156. $content .= $companylangs->transnoentitiesnoconv("Error").': '.$errormessage."<br>\n";
  157. $content .= "<br>\n";
  158. $content .= "tag=".$fulltag." token=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
  159. $ishtml = dol_textishtml($content); // May contain urls
  160. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  161. $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
  162. $result = $mailfile->sendfile();
  163. if ($result) {
  164. dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
  165. } else {
  166. dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
  167. }
  168. }
  169. unset($_SESSION['ipaddress']);
  170. }
  171. $head = '';
  172. if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
  173. $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
  174. }
  175. $conf->dol_hide_topmenu = 1;
  176. $conf->dol_hide_leftmenu = 1;
  177. $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  178. llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
  179. // Show ko message
  180. print '<span id="dolpaymentspan"></span>'."\n";
  181. print '<div id="dolpaymentdiv" align="center">'."\n";
  182. // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
  183. // Define logo and logosmall
  184. $logosmall = $mysoc->logo_small;
  185. $logo = $mysoc->logo;
  186. $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
  187. if (!empty($conf->global->$paramlogo)) {
  188. $logosmall = $conf->global->$paramlogo;
  189. } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
  190. $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
  191. }
  192. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  193. // Define urllogo
  194. $urllogo = '';
  195. $urllogofull = '';
  196. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
  197. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  198. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  199. } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
  200. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  201. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  202. }
  203. // Output html code for logo
  204. if ($urllogo) {
  205. print '<div class="backgreypublicpayment">';
  206. print '<div class="logopublicpayment">';
  207. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  208. print '>';
  209. print '</div>';
  210. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  211. 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>';
  212. }
  213. print '</div>';
  214. }
  215. if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
  216. print '<div class="backimagepublicpayment">';
  217. print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.'">';
  218. print '</div>';
  219. }
  220. print '<br><br>';
  221. print $langs->trans("YourPaymentHasNotBeenRecorded")."<br><br>";
  222. $key = 'ONLINE_PAYMENT_MESSAGE_KO';
  223. if (!empty($conf->global->$key)) {
  224. print $conf->global->$key;
  225. }
  226. $type = GETPOST('s', 'alpha');
  227. $ref = GETPOST('ref', 'alphanohtml');
  228. $tag = GETPOST('tag', 'alpha');
  229. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  230. if ($type || $tag) {
  231. $urlsubscription = getOnlinePaymentUrl(0, ($type ? $type : 'free'), $ref, $FinalPaymentAmt, $tag);
  232. print $langs->trans("ClickHereToTryAgain", $urlsubscription);
  233. }
  234. print "\n</div>\n";
  235. htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
  236. llxFooter('', 'public');
  237. $db->close();