paymentko.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  27. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  28. // For MultiCompany module.
  29. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  30. // TODO This should be useless. Because entity must be retreive from object ref and not from url.
  31. $entity = (!empty($_GET['e']) ? (int) $_GET['e'] : (!empty($_POST['e']) ? (int) $_POST['e'] : 1));
  32. if (is_numeric($entity)) define("DOLENTITY", $entity);
  33. require '../../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  36. if (!empty($conf->paypal->enabled))
  37. {
  38. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
  40. }
  41. $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paybox", "paypal", "stripe"));
  42. if (!empty($conf->paypal->enabled))
  43. {
  44. $PAYPALTOKEN = GETPOST('TOKEN');
  45. if (empty($PAYPALTOKEN)) $PAYPALTOKEN = GETPOST('token');
  46. $PAYPALPAYERID = GETPOST('PAYERID');
  47. if (empty($PAYPALPAYERID)) $PAYPALPAYERID = GETPOST('PayerID');
  48. }
  49. if (!empty($conf->paybox->enabled))
  50. {
  51. }
  52. if (!empty($conf->stripe->enabled))
  53. {
  54. }
  55. $FULLTAG = GETPOST('FULLTAG');
  56. if (empty($FULLTAG)) $FULLTAG = GETPOST('fulltag');
  57. $suffix = GETPOST("suffix", 'aZ09');
  58. // Detect $paymentmethod
  59. $paymentmethod = '';
  60. $reg = array();
  61. if (preg_match('/PM=([^\.]+)/', $FULLTAG, $reg))
  62. {
  63. $paymentmethod = $reg[1];
  64. }
  65. if (empty($paymentmethod))
  66. {
  67. dol_print_error(null, 'The back url does not contains a parameter fulltag that should help us to find the payment method used');
  68. exit;
  69. }
  70. else
  71. {
  72. dol_syslog("paymentmethod=".$paymentmethod);
  73. }
  74. $validpaymentmethod = array();
  75. if (!empty($conf->paypal->enabled)) $validpaymentmethod['paypal'] = 'paypal';
  76. if (!empty($conf->paybox->enabled)) $validpaymentmethod['paybox'] = 'paybox';
  77. if (!empty($conf->stripe->enabled)) $validpaymentmethod['stripe'] = 'stripe';
  78. // Security check
  79. if (empty($validpaymentmethod)) accessforbidden('', 0, 0, 1);
  80. $object = new stdClass(); // For triggers
  81. /*
  82. * Actions
  83. */
  84. /*
  85. * View
  86. */
  87. 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');
  88. $tracepost = "";
  89. foreach ($_POST as $k => $v) $tracepost .= "{$k} - {$v}\n";
  90. dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
  91. if (!empty($_SESSION['ipaddress'])) // To avoid to make action twice
  92. {
  93. // Get on url call
  94. $fulltag = $FULLTAG;
  95. $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
  96. $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
  97. // Set by newpayment.php
  98. $paymentType = $_SESSION['PaymentType'];
  99. $currencyCodeType = $_SESSION['currencyCodeType'];
  100. $FinalPaymentAmt = $_SESSION['FinalPaymentAmt'];
  101. // From env
  102. $ipaddress = $_SESSION['ipaddress'];
  103. $errormessage = $_SESSION['errormessage'];
  104. // Call trigger
  105. $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_KO', $user);
  106. if ($result < 0) $error++;
  107. // End call triggers
  108. // Send an email
  109. $sendemail = '';
  110. if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL))
  111. {
  112. $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
  113. }
  114. // Send warning of error to administrator
  115. if ($sendemail)
  116. {
  117. $companylangs = new Translate('', $conf);
  118. $companylangs->setDefaultLang($mysoc->default_lang);
  119. $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
  120. $from = $conf->global->MAILING_EMAIL_FROM;
  121. $sendto = $sendemail;
  122. // Define link to login card
  123. $appli = constant('DOL_APPLICATION_TITLE');
  124. if (!empty($conf->global->MAIN_APPLICATION_TITLE))
  125. {
  126. $appli = $conf->global->MAIN_APPLICATION_TITLE;
  127. if (preg_match('/\d\.\d/', $appli))
  128. {
  129. if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
  130. }
  131. else $appli .= " ".DOL_VERSION;
  132. }
  133. else $appli .= " ".DOL_VERSION;
  134. $urlback = $_SERVER["REQUEST_URI"];
  135. $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentFailed");
  136. $content = "";
  137. $content .= '<font color="orange">'.$companylangs->transnoentitiesnoconv("ValidationOfOnlinePaymentFailed")."</font>\n";
  138. $content .= "<br><br>\n";
  139. $content .= '<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
  140. $content .= $companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
  141. $content .= $companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
  142. $content .= $companylangs->transnoentitiesnoconv("Error").': '.$errormessage."<br>\n";
  143. $content .= "<br>\n";
  144. $content .= "tag=".$fulltag." token=".$onlinetoken." paymentType=".$paymentType." currencycodeType=".$currencyCodeType." payerId=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt;
  145. $ishtml = dol_textishtml($content); // May contain urls
  146. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  147. $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
  148. $result = $mailfile->sendfile();
  149. if ($result)
  150. {
  151. dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
  152. }
  153. else
  154. {
  155. dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
  156. }
  157. }
  158. unset($_SESSION['ipaddress']);
  159. }
  160. $head = '';
  161. if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
  162. $conf->dol_hide_topmenu = 1;
  163. $conf->dol_hide_leftmenu = 1;
  164. $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  165. llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
  166. // Show ko message
  167. print '<span id="dolpaymentspan"></span>'."\n";
  168. print '<div id="dolpaymentdiv" align="center">'."\n";
  169. // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
  170. $width = 0;
  171. // Define logo and logosmall
  172. $logosmall = $mysoc->logo_small;
  173. $logo = $mysoc->logo;
  174. $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
  175. if (!empty($conf->global->$paramlogo)) $logosmall = $conf->global->$paramlogo;
  176. elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
  177. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  178. // Define urllogo
  179. $urllogo = '';
  180. $urllogofull = '';
  181. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall))
  182. {
  183. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  184. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  185. $width = 150;
  186. }
  187. elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo))
  188. {
  189. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  190. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  191. $width = 150;
  192. }
  193. // Output html code for logo
  194. if ($urllogo)
  195. {
  196. print '<div class="backgreypublicpayment">';
  197. print '<div class="logopublicpayment">';
  198. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  199. if ($width) print ' width="'.$width.'"';
  200. print '>';
  201. print '</div>';
  202. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  203. print '<div class="poweredbypublicpayment opacitymedium right"><a href="https://www.dolibarr.org" target="dolibarr">'.$langs->trans("PoweredBy").'<br><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.png" width="80px"></a></div>';
  204. }
  205. print '</div>';
  206. }
  207. print '<br><br>';
  208. print $langs->trans("YourPaymentHasNotBeenRecorded")."<br><br>";
  209. $key = 'ONLINE_PAYMENT_MESSAGE_KO';
  210. if (!empty($conf->global->$key)) print $conf->global->$key;
  211. $type = GETPOST('s', 'alpha');
  212. $ref = GETPOST('ref', 'none');
  213. $tag = GETPOST('tag', 'alpha');
  214. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  215. if ($type || $tag)
  216. {
  217. $urlsubscription = getOnlinePaymentUrl(0, ($type ? $type : 'free'), $ref, $FinalPaymentAmt, $tag);
  218. print $langs->trans("ClickHereToTryAgain", $urlsubscription);
  219. }
  220. print "\n</div>\n";
  221. htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
  222. llxFooter('', 'public');
  223. $db->close();