paymentok.php 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  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. * Copyright (C) 2021 Waël Almoman <info@almoman.com>
  6. * Copyright (C) 2021 Maxime Demarest <maxime@indelog.fr>
  7. * Copyright (C) 2021 Dorian Vabre <dorian.vabre@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/public/payment/paymentok.php
  24. * \ingroup core
  25. * \brief File to show page after a successful payment on a payment line system.
  26. * The payment was already really recorded. So an error here must send warning to admin but must still infor user that payment is ok.
  27. * This page is called by payment system with url provided to it completed with parameter TOKEN=xxx
  28. * This token and session can be used to get more informations.
  29. */
  30. if (!defined('NOLOGIN')) {
  31. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  32. }
  33. if (!defined('NOCSRFCHECK')) {
  34. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  35. }
  36. if (!defined('NOIPCHECK')) {
  37. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  38. }
  39. if (!defined('NOBROWSERNOTIF')) {
  40. define('NOBROWSERNOTIF', '1');
  41. }
  42. // For MultiCompany module.
  43. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  44. // TODO This should be useless. Because entity must be retrieve from object ref and not from url.
  45. $entity = (!empty($_GET['e']) ? (int) $_GET['e'] : (!empty($_POST['e']) ? (int) $_POST['e'] : 1));
  46. if (is_numeric($entity)) {
  47. define("DOLENTITY", $entity);
  48. }
  49. // Load Dolibarr environment
  50. require '../../main.inc.php';
  51. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  52. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  53. if (isModEnabled('paypal')) {
  54. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
  55. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
  56. }
  57. // Hook to be used by external payment modules (ie Payzen, ...)
  58. $hookmanager = new HookManager($db);
  59. $hookmanager->initHooks(array('newpayment'));
  60. $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paybox", "paypal"));
  61. // Clean parameters
  62. if (isModEnabled('paypal')) {
  63. $PAYPAL_API_USER = "";
  64. if (!empty($conf->global->PAYPAL_API_USER)) {
  65. $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
  66. }
  67. $PAYPAL_API_PASSWORD = "";
  68. if (!empty($conf->global->PAYPAL_API_PASSWORD)) {
  69. $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
  70. }
  71. $PAYPAL_API_SIGNATURE = "";
  72. if (!empty($conf->global->PAYPAL_API_SIGNATURE)) {
  73. $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
  74. }
  75. $PAYPAL_API_SANDBOX = "";
  76. if (!empty($conf->global->PAYPAL_API_SANDBOX)) {
  77. $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
  78. }
  79. $PAYPAL_API_OK = "";
  80. if ($urlok) {
  81. $PAYPAL_API_OK = $urlok;
  82. }
  83. $PAYPAL_API_KO = "";
  84. if ($urlko) {
  85. $PAYPAL_API_KO = $urlko;
  86. }
  87. $PAYPALTOKEN = GETPOST('TOKEN');
  88. if (empty($PAYPALTOKEN)) {
  89. $PAYPALTOKEN = GETPOST('token');
  90. }
  91. $PAYPALPAYERID = GETPOST('PAYERID');
  92. if (empty($PAYPALPAYERID)) {
  93. $PAYPALPAYERID = GETPOST('PayerID');
  94. }
  95. }
  96. $FULLTAG = GETPOST('FULLTAG');
  97. if (empty($FULLTAG)) {
  98. $FULLTAG = GETPOST('fulltag');
  99. }
  100. $source = GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha');
  101. $ref = GETPOST('ref');
  102. $suffix = GETPOST("suffix", 'aZ09');
  103. $membertypeid = GETPOST("membertypeid", 'int');
  104. // Detect $paymentmethod
  105. $paymentmethod = '';
  106. $reg = array();
  107. if (preg_match('/PM=([^\.]+)/', $FULLTAG, $reg)) {
  108. $paymentmethod = $reg[1];
  109. }
  110. if (empty($paymentmethod)) {
  111. dol_syslog("***** paymentok.php was called with a non valid parameter FULLTAG=".$FULLTAG, LOG_DEBUG, 0, '_payment');
  112. dol_print_error(null, 'The callback url does not contains a parameter fulltag that should help us to find the payment method used');
  113. exit;
  114. }
  115. dol_syslog("***** paymentok.php is called paymentmethod=".$paymentmethod." FULLTAG=".$FULLTAG." REQUEST_URI=".$_SERVER["REQUEST_URI"], LOG_DEBUG, 0, '_payment');
  116. $validpaymentmethod = array();
  117. if (isModEnabled('paypal')) {
  118. $validpaymentmethod['paypal'] = 'paypal';
  119. }
  120. if (isModEnabled('paybox')) {
  121. $validpaymentmethod['paybox'] = 'paybox';
  122. }
  123. if (isModEnabled('stripe')) {
  124. $validpaymentmethod['stripe'] = 'stripe';
  125. }
  126. // Security check
  127. if (empty($validpaymentmethod)) {
  128. httponly_accessforbidden('No valid payment mode');
  129. }
  130. $ispaymentok = false;
  131. // If payment is ok
  132. $PAYMENTSTATUS = $TRANSACTIONID = $TAXAMT = $NOTE = '';
  133. // If payment is ko
  134. $ErrorCode = $ErrorShortMsg = $ErrorLongMsg = $ErrorSeverityCode = '';
  135. $object = new stdClass(); // For triggers
  136. $error = 0;
  137. /*
  138. * Actions
  139. */
  140. /*
  141. * View
  142. */
  143. $now = dol_now();
  144. dol_syslog("Callback url when a payment was done. query_string=".(empty($_SERVER["QUERY_STRING"]) ? '' : dol_escape_htmltag($_SERVER["QUERY_STRING"]))." script_uri=".(empty($_SERVER["SCRIPT_URI"]) ? '' : dol_escape_htmltag($_SERVER["SCRIPT_URI"])), LOG_DEBUG, 0, '_payment');
  145. dol_syslog("_SERVER[SERVER_NAME] = ".(empty($_SERVER["SERVER_NAME"]) ? '' : dol_escape_htmltag($_SERVER["SERVER_NAME"])), LOG_DEBUG, 0, '_payment');
  146. dol_syslog("_SERVER[SERVER_ADDR] = ".(empty($_SERVER["SERVER_ADDR"]) ? '' : dol_escape_htmltag($_SERVER["SERVER_ADDR"])), LOG_DEBUG, 0, '_payment');
  147. $tracepost = "";
  148. foreach ($_POST as $k => $v) {
  149. if (is_scalar($k) && is_scalar($v)) {
  150. $tracepost .= "{$k} - {$v}\n";
  151. }
  152. }
  153. dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
  154. $tracesession = "";
  155. foreach ($_SESSION as $k => $v) {
  156. if (is_scalar($k) && is_scalar($v)) {
  157. $tracesession .= "{$k} - {$v}\n";
  158. }
  159. }
  160. dol_syslog("SESSION=".$tracesession, LOG_DEBUG, 0, '_payment');
  161. $head = '';
  162. if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
  163. $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
  164. }
  165. $conf->dol_hide_topmenu = 1;
  166. $conf->dol_hide_leftmenu = 1;
  167. $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  168. llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
  169. // Show message
  170. print '<span id="dolpaymentspan"></span>'."\n";
  171. print '<div id="dolpaymentdiv" class="center">'."\n";
  172. // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
  173. // Define logo and logosmall
  174. $logosmall = $mysoc->logo_small;
  175. $logo = $mysoc->logo;
  176. $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
  177. if (!empty($conf->global->$paramlogo)) {
  178. $logosmall = $conf->global->$paramlogo;
  179. } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
  180. $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
  181. }
  182. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  183. // Define urllogo
  184. $urllogo = '';
  185. $urllogofull = '';
  186. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
  187. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  188. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  189. } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
  190. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  191. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  192. }
  193. // Output html code for logo
  194. if ($urllogo) {
  195. print '<div class="backgreypublicpayment">';
  196. print '<div class="logopublicpayment">';
  197. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  198. print '>';
  199. print '</div>';
  200. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  201. 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>';
  202. }
  203. print '</div>';
  204. }
  205. if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
  206. print '<div class="backimagepublicpayment">';
  207. print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.'">';
  208. print '</div>';
  209. }
  210. print '<br><br><br>';
  211. if (isModEnabled('paypal')) {
  212. if ($paymentmethod === 'paypal') { // We call this page only if payment is ok on payment system
  213. if ($PAYPALTOKEN) {
  214. // Get on url call
  215. $onlinetoken = $PAYPALTOKEN;
  216. $fulltag = $FULLTAG;
  217. $payerID = $PAYPALPAYERID;
  218. // Set by newpayment.php
  219. $currencyCodeType = $_SESSION['currencyCodeType'];
  220. $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
  221. $paymentType = $_SESSION['PaymentType']; // Value can be 'Mark', 'Sole', 'Sale' for example
  222. // From env
  223. $ipaddress = $_SESSION['ipaddress'];
  224. dol_syslog("Call paymentok with token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_payment');
  225. // Validate record
  226. if (!empty($paymentType)) {
  227. dol_syslog("We call GetExpressCheckoutDetails", LOG_DEBUG, 0, '_payment');
  228. $resArray = getDetails($onlinetoken);
  229. //var_dump($resarray);
  230. $ack = strtoupper($resArray["ACK"]);
  231. if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
  232. // Nothing to do
  233. dol_syslog("Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0, '_payment');
  234. } else {
  235. dol_syslog("Call to GetExpressCheckoutDetails return error: ".json_encode($resArray), LOG_WARNING, '_payment');
  236. }
  237. dol_syslog("We call DoExpressCheckoutPayment token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_payment');
  238. $resArray2 = confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag);
  239. //var_dump($resarray);
  240. $ack = strtoupper($resArray2["ACK"]);
  241. if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
  242. dol_syslog("Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0, '_payment');
  243. $object->source = $source;
  244. $object->ref = $ref;
  245. $object->payerID = $payerID;
  246. $object->fulltag = $fulltag;
  247. $object->resArray = $resArray2;
  248. // resArray was built from a string like that
  249. // TOKEN=EC%2d1NJ057703V9359028&TIMESTAMP=2010%2d11%2d01T11%3a40%3a13Z&CORRELATIONID=1efa8c6a36bd8&ACK=Success&VERSION=56&BUILD=1553277&TRANSACTIONID=9B994597K9921420R&TRANSACTIONTYPE=expresscheckout&PAYMENTTYPE=instant&ORDERTIME=2010%2d11%2d01T11%3a40%3a12Z&AMT=155%2e57&FEEAMT=5%2e54&TAXAMT=0%2e00&CURRENCYCODE=EUR&PAYMENTSTATUS=Completed&PENDINGREASON=None&REASONCODE=None
  250. $PAYMENTSTATUS = urldecode($resArray2["PAYMENTSTATUS"]); // Should contains 'Completed'
  251. $TRANSACTIONID = urldecode($resArray2["TRANSACTIONID"]);
  252. $TAXAMT = urldecode($resArray2["TAXAMT"]);
  253. $NOTE = urldecode($resArray2["NOTE"]);
  254. $ispaymentok = true;
  255. } else {
  256. dol_syslog("Call to DoExpressCheckoutPayment return error: ".json_encode($resArray2), LOG_WARNING, 0, '_payment');
  257. //Display a user friendly Error on the page using any of the following error information returned by PayPal
  258. $ErrorCode = urldecode($resArray2["L_ERRORCODE0"]);
  259. $ErrorShortMsg = urldecode($resArray2["L_SHORTMESSAGE0"]);
  260. $ErrorLongMsg = urldecode($resArray2["L_LONGMESSAGE0"]);
  261. $ErrorSeverityCode = urldecode($resArray2["L_SEVERITYCODE0"]);
  262. }
  263. } else {
  264. $ErrorCode = "SESSIONEXPIRED";
  265. $ErrorLongMsg = "Session expired. Can't retreive PaymentType. Payment has not been validated.";
  266. $ErrorShortMsg = "Session expired";
  267. dol_syslog($ErrorLongMsg, LOG_WARNING, 0, '_payment');
  268. dol_print_error('', 'Session expired');
  269. }
  270. } else {
  271. $ErrorCode = "PAYPALTOKENNOTDEFINED";
  272. $ErrorLongMsg = "The parameter PAYPALTOKEN was not defined. Payment has not been validated.";
  273. $ErrorShortMsg = "Parameter PAYPALTOKEN not defined";
  274. dol_syslog($ErrorLongMsg, LOG_WARNING, 0, '_payment');
  275. dol_print_error('', 'PAYPALTOKEN not defined');
  276. }
  277. }
  278. }
  279. if (isModEnabled('paybox')) {
  280. if ($paymentmethod === 'paybox') {
  281. // TODO Add a check to validate that payment is ok.
  282. $ispaymentok = true; // We call this page only if payment is ok on payment system
  283. }
  284. }
  285. if (isModEnabled('stripe')) {
  286. if ($paymentmethod === 'stripe') {
  287. // TODO Add a check to validate that payment is ok. We can request Stripe with payment_intent and payment_intent_client_secret
  288. $ispaymentok = true; // We call this page only if payment is ok on payment system
  289. }
  290. }
  291. // Check status of the object to verify if it is paid by external payment modules
  292. $action = '';
  293. $parameters = [
  294. 'paymentmethod' => $paymentmethod,
  295. ];
  296. $reshook = $hookmanager->executeHooks('isPaymentOK', $parameters, $object, $action);
  297. if ($reshook >= 0) {
  298. if (isset($hookmanager->resArray['ispaymentok'])) {
  299. dol_syslog('ispaymentok overwrite by hook return with value='.$hookmanager->resArray['ispaymentok'], LOG_DEBUG, 0, '_payment');
  300. $ispaymentok = $hookmanager->resArray['ispaymentok'];
  301. }
  302. }
  303. // If data not provided into callback url, search them into the session env
  304. if (empty($ipaddress)) {
  305. $ipaddress = $_SESSION['ipaddress'];
  306. }
  307. if (empty($TRANSACTIONID)) {
  308. $TRANSACTIONID = $_SESSION['TRANSACTIONID']; // pi_... or ch_...
  309. if (empty($TRANSACTIONID) && GETPOST('payment_intent', 'alphanohtml')) {
  310. // For the case we use STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = 2
  311. $TRANSACTIONID = GETPOST('payment_intent', 'alphanohtml');
  312. }
  313. }
  314. if (empty($FinalPaymentAmt)) {
  315. $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
  316. }
  317. if (empty($currencyCodeType)) {
  318. $currencyCodeType = $_SESSION['currencyCodeType'];
  319. }
  320. // Seems used onyl by Paypal
  321. if (empty($paymentType)) {
  322. $paymentType = $_SESSION["paymentType"];
  323. }
  324. $fulltag = $FULLTAG;
  325. $tmptag = dolExplodeIntoArray($fulltag, '.', '=');
  326. dol_syslog("ispaymentok=".$ispaymentok." tmptag=".var_export($tmptag, true), LOG_DEBUG, 0, '_payment');
  327. // Make complementary actions
  328. $ispostactionok = 0;
  329. $postactionmessages = array();
  330. if ($ispaymentok) {
  331. // Set permission for the anonymous user
  332. if (empty($user->rights->societe)) {
  333. $user->rights->societe = new stdClass();
  334. }
  335. if (empty($user->rights->facture)) {
  336. $user->rights->facture = new stdClass();
  337. $user->rights->facture->invoice_advance = new stdClass();
  338. }
  339. if (empty($user->rights->adherent)) {
  340. $user->rights->adherent = new stdClass();
  341. $user->rights->adherent->cotisation = new stdClass();
  342. }
  343. $user->rights->societe->creer = 1;
  344. $user->rights->facture->creer = 1;
  345. $user->rights->facture->invoice_advance->validate = 1;
  346. $user->rights->adherent->cotisation->creer = 1;
  347. if (array_key_exists('MEM', $tmptag) && $tmptag['MEM'] > 0) {
  348. // Validate member
  349. // Create subscription
  350. // Create complementary actions (this include creation of thirdparty)
  351. // Send confirmation email
  352. $defaultdelay = 1;
  353. $defaultdelayunit = 'y';
  354. // Record subscription
  355. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  356. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  357. include_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  358. $adht = new AdherentType($db);
  359. $object = new Adherent($db);
  360. $result1 = $object->fetch((int) $tmptag['MEM']);
  361. $result2 = $adht->fetch($object->typeid);
  362. dol_syslog("We have to process member with id=".$tmptag['MEM']." result1=".$result1." result2=".$result2, LOG_DEBUG, 0, '_payment');
  363. if ($result1 > 0 && $result2 > 0) {
  364. $paymentTypeId = 0;
  365. if ($paymentmethod == 'paybox') {
  366. $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
  367. }
  368. if ($paymentmethod == 'paypal') {
  369. $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
  370. }
  371. if ($paymentmethod == 'stripe') {
  372. $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
  373. }
  374. if (empty($paymentTypeId)) {
  375. dol_syslog("paymentType = ".$paymentType, LOG_DEBUG, 0, '_payment');
  376. if (empty($paymentType)) {
  377. $paymentType = 'CB';
  378. }
  379. // May return nothing when paymentType means nothing
  380. // (for example when paymentType is 'Mark', 'Sole', 'Sale', for paypal)
  381. $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
  382. // If previous line has returned nothing, we force to get the ID of payment of Credit Card (hard coded code 'CB').
  383. if (empty($paymentTypeId) || $paymentTypeId < 0) {
  384. $paymentTypeId = dol_getIdFromCode($db, 'CB', 'c_paiement', 'code', 'id', 1);
  385. }
  386. }
  387. dol_syslog("FinalPaymentAmt=".$FinalPaymentAmt." paymentTypeId=".$paymentTypeId." currencyCodeType=".$currencyCodeType, LOG_DEBUG, 0, '_payment');
  388. // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
  389. if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
  390. // Security protection:
  391. if (empty($adht->caneditamount)) { // If we didn't allow members to choose their membership amount (if the amount is allowed in edit mode, no need to check)
  392. if ($object->status == $object::STATUS_DRAFT) { // If the member is not yet validated, we check that the amount is the same as expected.
  393. $typeid = $object->typeid;
  394. // Set amount for the subscription:
  395. // - First check the amount of the member type.
  396. $amountbytype = $adht->amountByType(1); // Load the array of amount per type
  397. $amountexpected = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid];
  398. // - If not found, take the default amount
  399. if (empty($amountexpected) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  400. $amountexpected = $conf->global->MEMBER_NEWFORM_AMOUNT;
  401. }
  402. if ($amountexpected && $amountexpected != $FinalPaymentAmt) {
  403. $error++;
  404. $errmsg = 'Value of FinalPayment ('.$FinalPaymentAmt.') differs from value expected for membership ('.$amountexpected.'). May be a hack to try to pay a different amount ?';
  405. $postactionmessages[] = $errmsg;
  406. $ispostactionok = -1;
  407. dol_syslog("Failed to validate member (bad amount check): ".$errmsg, LOG_ERR, 0, '_payment');
  408. }
  409. }
  410. }
  411. // Security protection:
  412. if (!empty($conf->global->MEMBER_MIN_AMOUNT)) {
  413. if ($FinalPaymentAmt < $conf->global->MEMBER_MIN_AMOUNT) {
  414. $error++;
  415. $errmsg = 'Value of FinalPayment ('.$FinalPaymentAmt.') is lower than the minimum allowed ('.$conf->global->MEMBER_MIN_AMOUNT.'). May be a hack to try to pay a different amount ?';
  416. $postactionmessages[] = $errmsg;
  417. $ispostactionok = -1;
  418. dol_syslog("Failed to validate member (amount lower than minimum): ".$errmsg, LOG_ERR, 0, '_payment');
  419. }
  420. }
  421. // Security protection:
  422. if ($currencyCodeType && $currencyCodeType != $conf->currency) { // Check that currency is the good one
  423. $error++;
  424. $errmsg = 'Value of currencyCodeType ('.$currencyCodeType.') differs from value expected for membership ('.$conf->currency.'). May be a hack to try to pay a different amount ?';
  425. $postactionmessages[] = $errmsg;
  426. $ispostactionok = -1;
  427. dol_syslog("Failed to validate member (bad currency check): ".$errmsg, LOG_ERR, 0, '_payment');
  428. }
  429. if (! $error) {
  430. // We validate the member (no effect if it is already validated)
  431. $result = ($object->status == $object::STATUS_EXCLUDED) ? -1 : $object->validate($user); // if membre is excluded (status == -2) the new validation is not possible
  432. if ($result < 0 || empty($object->datevalid)) {
  433. $error++;
  434. $errmsg = $object->error;
  435. $postactionmessages[] = $errmsg;
  436. $postactionmessages = array_merge($postactionmessages, $object->errors);
  437. $ispostactionok = -1;
  438. dol_syslog("Failed to validate member: ".$errmsg, LOG_ERR, 0, '_payment');
  439. }
  440. }
  441. // Subscription informations
  442. $datesubscription = $object->datevalid;
  443. if ($object->datefin > 0) {
  444. $datesubscription = dol_time_plus_duree($object->datefin, 1, 'd');
  445. }
  446. $datesubend = null;
  447. if ($datesubscription && $defaultdelay && $defaultdelayunit) {
  448. $datesubend = dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit);
  449. // the new end date of subscription must be in futur
  450. while ($datesubend < $now) {
  451. $datesubend = dol_time_plus_duree($datesubend, $defaultdelay, $defaultdelayunit);
  452. $datesubscription = dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit);
  453. }
  454. $datesubend = dol_time_plus_duree($datesubend, -1, 'd');
  455. }
  456. // Set output language
  457. $outputlangs = new Translate('', $conf);
  458. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  459. $paymentdate = $now;
  460. $amount = $FinalPaymentAmt;
  461. $formatteddate = dol_print_date($paymentdate, 'dayhour', 'auto', $outputlangs);
  462. $label = $langs->trans("OnlineSubscriptionPaymentLine", $formatteddate, $paymentmethod, $ipaddress, $TRANSACTIONID);
  463. // Payment informations
  464. $accountid = 0;
  465. if ($paymentmethod == 'paybox') {
  466. $accountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
  467. }
  468. if ($paymentmethod == 'paypal') {
  469. $accountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
  470. }
  471. if ($paymentmethod == 'stripe') {
  472. $accountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
  473. }
  474. if ($accountid < 0) {
  475. $error++;
  476. $errmsg = 'Setup of bank account to use for payment is not correctly done for payment method '.$paymentmethod;
  477. $postactionmessages[] = $errmsg;
  478. $ispostactionok = -1;
  479. dol_syslog("Failed to get the bank account to record payment: ".$errmsg, LOG_ERR, 0, '_payment');
  480. }
  481. $operation = dol_getIdFromCode($db, $paymentTypeId, 'c_paiement', 'id', 'code', 1); // Payment mode code returned from payment mode id
  482. $num_chq = '';
  483. $emetteur_nom = '';
  484. $emetteur_banque = '';
  485. // Define default choice for complementary actions
  486. $option = '';
  487. if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && isModEnabled("banque") && isModEnabled("societe") && isModEnabled('facture')) {
  488. $option = 'bankviainvoice';
  489. } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && isModEnabled("banque")) {
  490. $option = 'bankdirect';
  491. } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && isModEnabled("banque") && isModEnabled("societe") && isModEnabled('facture')) {
  492. $option = 'invoiceonly';
  493. }
  494. if (empty($option)) {
  495. $option = 'none';
  496. }
  497. $sendalsoemail = 1;
  498. // Record the subscription then complementary actions
  499. $db->begin();
  500. // Create subscription
  501. if (!$error) {
  502. dol_syslog("Call ->subscription to create subscription", LOG_DEBUG, 0, '_payment');
  503. $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $membertypeid);
  504. if ($crowid <= 0) {
  505. $error++;
  506. $errmsg = $object->error;
  507. $postactionmessages[] = $errmsg;
  508. $ispostactionok = -1;
  509. } else {
  510. $postactionmessages[] = 'Subscription created (id='.$crowid.')';
  511. $ispostactionok = 1;
  512. }
  513. }
  514. if (!$error) {
  515. dol_syslog("Call ->subscriptionComplementaryActions option=".$option, LOG_DEBUG, 0, '_payment');
  516. $autocreatethirdparty = 1; // will create thirdparty if member not yet linked to a thirdparty
  517. $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque, $autocreatethirdparty, $TRANSACTIONID, $service);
  518. if ($result < 0) {
  519. dol_syslog("Error ".$object->error." ".join(',', $object->errors), LOG_DEBUG, 0, '_payment');
  520. $error++;
  521. $postactionmessages[] = $object->error;
  522. $postactionmessages = array_merge($postactionmessages, $object->errors);
  523. $ispostactionok = -1;
  524. } else {
  525. if ($option == 'bankviainvoice') {
  526. $postactionmessages[] = 'Invoice, payment and bank record created';
  527. dol_syslog("Invoice, payment and bank record created", LOG_DEBUG, 0, '_payment');
  528. }
  529. if ($option == 'bankdirect') {
  530. $postactionmessages[] = 'Bank record created';
  531. dol_syslog("Bank record created", LOG_DEBUG, 0, '_payment');
  532. }
  533. if ($option == 'invoiceonly') {
  534. $postactionmessages[] = 'Invoice recorded';
  535. dol_syslog("Invoice recorded", LOG_DEBUG, 0, '_payment');
  536. }
  537. $ispostactionok = 1;
  538. // If an invoice was created, it is into $object->invoice
  539. }
  540. }
  541. if (!$error) {
  542. if ($paymentmethod == 'stripe' && $autocreatethirdparty && $option == 'bankviainvoice') {
  543. $thirdparty_id = $object->fk_soc;
  544. dol_syslog("Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0, '_payment');
  545. $service = 'StripeTest';
  546. $servicestatus = 0;
  547. if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) {
  548. $service = 'StripeLive';
  549. $servicestatus = 1;
  550. }
  551. $stripeacc = null; // No Oauth/connect use for public pages
  552. $thirdparty = new Societe($db);
  553. $thirdparty->fetch($thirdparty_id);
  554. include_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; // This also set $stripearrayofkeysbyenv
  555. $stripe = new Stripe($db);
  556. //$stripeacc = $stripe->getStripeAccount($service); Already defined previously
  557. $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
  558. if (!$customer && $TRANSACTIONID) { // Not linked to a stripe customer, we make the link
  559. dol_syslog("No stripe profile found, so we add it for TRANSACTIONID = ".$TRANSACTIONID, LOG_DEBUG, 0, '_payment');
  560. try {
  561. global $stripearrayofkeysbyenv;
  562. \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']);
  563. if (preg_match('/^pi_/', $TRANSACTIONID)) {
  564. // This may throw an error if not found.
  565. $chpi = \Stripe\PaymentIntent::retrieve($TRANSACTIONID); // payment_intent (pi_...)
  566. } else {
  567. // This throw an error if not found
  568. $chpi = \Stripe\Charge::retrieve($TRANSACTIONID); // old method, contains the charge id (ch_...)
  569. }
  570. if ($chpi) {
  571. $stripecu = $chpi->customer; // value 'cus_....'. WARNING: This property may be empty if first payment was recorded before the stripe customer was created.
  572. if (empty($stripecu)) {
  573. // This include the INSERT
  574. $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
  575. // Link this customer to the payment intent
  576. if (preg_match('/^pi_/', $TRANSACTIONID) && $customer) {
  577. \Stripe\PaymentIntent::update($chpi->id, array('customer' => $customer->id));
  578. }
  579. } else {
  580. $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
  581. $sql .= " VALUES (".((int) $object->fk_soc).", '', '".$db->escape($stripecu)."', 'stripe', '".$db->escape($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])."', ".((int) $servicestatus).", ".((int) $conf->entity).", '".$db->idate(dol_now())."', 0)";
  582. $resql = $db->query($sql);
  583. if (!$resql) { // should not happen
  584. $error++;
  585. $errmsg = 'Failed to insert customer stripe id in database : '.$db->lasterror();
  586. dol_syslog($errmsg, LOG_ERR, 0, '_payment');
  587. $postactionmessages[] = $errmsg;
  588. $ispostactionok = -1;
  589. }
  590. }
  591. } else { // should not happen
  592. $error++;
  593. $errmsg = 'Failed to retreive paymentintent or charge from id';
  594. dol_syslog($errmsg, LOG_ERR, 0, '_payment');
  595. $postactionmessages[] = $errmsg;
  596. $ispostactionok = -1;
  597. }
  598. } catch (Exception $e) { // should not happen
  599. $error++;
  600. $errmsg = 'Failed to get or save customer stripe id in database : '.$e->getMessage();
  601. dol_syslog($errmsg, LOG_ERR, 0, '_payment');
  602. $postactionmessages[] = $errmsg;
  603. $ispostactionok = -1;
  604. }
  605. }
  606. }
  607. }
  608. if (!$error) {
  609. $db->commit();
  610. } else {
  611. $db->rollback();
  612. }
  613. // Send email to member
  614. if (!$error) {
  615. dol_syslog("Send email to customer to ".$object->email." if we have to (sendalsoemail = ".$sendalsoemail.")", LOG_DEBUG, 0, '_payment');
  616. // Send confirmation Email
  617. if ($object->email && $sendalsoemail) {
  618. $subject = '';
  619. $msg = '';
  620. // Send subscription email
  621. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  622. $formmail = new FormMail($db);
  623. // Load traductions files required by page
  624. $outputlangs->loadLangs(array("main", "members"));
  625. // Get email content from template
  626. $arraydefaultmessage = null;
  627. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  628. if (!empty($labeltouse)) {
  629. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  630. }
  631. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  632. $subject = $arraydefaultmessage->topic;
  633. $msg = $arraydefaultmessage->content;
  634. }
  635. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  636. // Create external user
  637. if (!empty($conf->global->ADHERENT_CREATE_EXTERNAL_USER_LOGIN)) {
  638. $infouserlogin = '';
  639. $nuser = new User($db);
  640. $tmpuser = dol_clone($object);
  641. $result = $nuser->create_from_member($tmpuser, $object->login);
  642. $newpassword = $nuser->setPassword($user, '');
  643. if ($result < 0) {
  644. $outputlangs->load("errors");
  645. $postactionmessages[] = 'Error in create external user : '.$nuser->error;
  646. } else {
  647. $infouserlogin = $outputlangs->trans("Login").': '.$nuser->login.' '."\n".$outputlangs->trans("Password").': '.$newpassword;
  648. $postactionmessages[] = $langs->trans("NewUserCreated", $nuser->login);
  649. }
  650. $substitutionarray['__MEMBER_USER_LOGIN_INFORMATION__'] = $infouserlogin;
  651. }
  652. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  653. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  654. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  655. // Attach a file ?
  656. $file = '';
  657. $listofpaths = array();
  658. $listofnames = array();
  659. $listofmimes = array();
  660. if (is_object($object->invoice)) {
  661. $invoicediroutput = $conf->facture->dir_output;
  662. $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
  663. $file = $fileparams['fullname'];
  664. $listofpaths = array($file);
  665. $listofnames = array(basename($file));
  666. $listofmimes = array(dol_mimetype($file));
  667. }
  668. $moreinheader = 'X-Dolibarr-Info: send_an_email by public/payment/paymentok.php'."\r\n";
  669. $result = $object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, "", $moreinheader);
  670. if ($result < 0) {
  671. $errmsg = $object->error;
  672. $postactionmessages[] = $errmsg;
  673. $ispostactionok = -1;
  674. } else {
  675. if ($file) {
  676. $postactionmessages[] = 'Email sent to member (with invoice document attached)';
  677. } else {
  678. $postactionmessages[] = 'Email sent to member (without any attached document)';
  679. }
  680. // TODO Add actioncomm event
  681. }
  682. }
  683. }
  684. } else {
  685. $postactionmessages[] = 'Failed to get a valid value for "amount paid" or "payment type" to record the payment of subscription for member '.$tmptag['MEM'].'. May be payment was already recorded.';
  686. $ispostactionok = -1;
  687. }
  688. } else {
  689. $postactionmessages[] = 'Member '.$tmptag['MEM'].' for subscription paid was not found';
  690. $ispostactionok = -1;
  691. }
  692. } elseif (array_key_exists('INV', $tmptag) && $tmptag['INV'] > 0) {
  693. // Record payment
  694. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  695. $object = new Facture($db);
  696. $result = $object->fetch((int) $tmptag['INV']);
  697. if ($result) {
  698. $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
  699. $paymentTypeId = 0;
  700. if ($paymentmethod === 'paybox') {
  701. $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
  702. }
  703. if ($paymentmethod === 'paypal') {
  704. $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
  705. }
  706. if ($paymentmethod === 'stripe') {
  707. $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
  708. }
  709. if (empty($paymentTypeId)) {
  710. dol_syslog("paymentType = ".$paymentType, LOG_DEBUG, 0, '_payment');
  711. if (empty($paymentType)) {
  712. $paymentType = 'CB';
  713. }
  714. // May return nothing when paymentType means nothing
  715. // (for example when paymentType is 'Mark', 'Sole', 'Sale', for paypal)
  716. $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
  717. // If previous line has returned nothing, we force to get the ID of payment of Credit Card (hard coded code 'CB').
  718. if (empty($paymentTypeId) || $paymentTypeId < 0) {
  719. $paymentTypeId = dol_getIdFromCode($db, 'CB', 'c_paiement', 'code', 'id', 1);
  720. }
  721. }
  722. dol_syslog("FinalPaymentAmt = ".$FinalPaymentAmt." paymentTypeId = ".$paymentTypeId, LOG_DEBUG, 0, '_payment');
  723. // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
  724. if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
  725. $db->begin();
  726. // Creation of payment line
  727. include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  728. $paiement = new Paiement($db);
  729. $paiement->datepaye = $now;
  730. if ($currencyCodeType == $conf->currency) {
  731. $paiement->amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id
  732. } else {
  733. $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching
  734. $postactionmessages[] = 'Payment was done in a different currency that currency expected of company';
  735. $ispostactionok = -1;
  736. $error++; // Not yet supported
  737. }
  738. $paiement->paiementid = $paymentTypeId;
  739. $paiement->num_payment = '';
  740. $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress;
  741. $paiement->ext_payment_id = $TRANSACTIONID; // TODO LDR May be we should store py_... instead of pi_... but we started with pi_... so we continue.
  742. //$paiement->ext_payment_id = $TRANSACTIONID.':'.$customer->id.'@'.$stripearrayofkeysbyenv[$servicestatus]['publishable_key']; // TODO LDR It would be better if we could store this. Do we have customer->id and publishable_key ?
  743. $paiement->ext_payment_site = $service;
  744. if (!$error) {
  745. $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents
  746. if ($paiement_id < 0) {
  747. $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
  748. $ispostactionok = -1;
  749. $error++;
  750. } else {
  751. $postactionmessages[] = 'Payment created';
  752. $ispostactionok = 1;
  753. }
  754. }
  755. if (!$error && isModEnabled("banque")) {
  756. $bankaccountid = 0;
  757. if ($paymentmethod == 'paybox') {
  758. $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
  759. } elseif ($paymentmethod == 'paypal') {
  760. $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
  761. } elseif ($paymentmethod == 'stripe') {
  762. $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
  763. }
  764. if ($bankaccountid > 0) {
  765. $label = '(CustomerInvoicePayment)';
  766. if ($object->type == Facture::TYPE_CREDIT_NOTE) {
  767. $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
  768. }
  769. $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
  770. if ($result < 0) {
  771. $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
  772. $ispostactionok = -1;
  773. $error++;
  774. } else {
  775. $postactionmessages[] = 'Bank transaction of payment created';
  776. $ispostactionok = 1;
  777. }
  778. } else {
  779. $postactionmessages[] = 'Setup of bank account to use in module '.$paymentmethod.' was not set. Your payment was really executed but we failed to record it. Please contact us.';
  780. $ispostactionok = -1;
  781. $error++;
  782. }
  783. }
  784. if (!$error) {
  785. $db->commit();
  786. } else {
  787. $db->rollback();
  788. }
  789. } else {
  790. $postactionmessages[] = 'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.') or "payment type id" ('.$paymentTypeId.') to record the payment of invoice '.$tmptag['INV'].'. May be payment was already recorded.';
  791. $ispostactionok = -1;
  792. }
  793. } else {
  794. $postactionmessages[] = 'Invoice paid '.$tmptag['INV'].' was not found';
  795. $ispostactionok = -1;
  796. }
  797. } elseif (array_key_exists('ORD', $tmptag) && $tmptag['ORD'] > 0) {
  798. include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
  799. $object = new Commande($db);
  800. $result = $object->fetch((int) $tmptag['ORD']);
  801. if ($result) {
  802. $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
  803. $paymentTypeId = 0;
  804. if ($paymentmethod == 'paybox') {
  805. $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
  806. }
  807. if ($paymentmethod == 'paypal') {
  808. $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
  809. }
  810. if ($paymentmethod == 'stripe') {
  811. $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
  812. }
  813. if (empty($paymentTypeId)) {
  814. dol_syslog("paymentType = ".$paymentType, LOG_DEBUG, 0, '_payment');
  815. if (empty($paymentType)) {
  816. $paymentType = 'CB';
  817. }
  818. // May return nothing when paymentType means nothing
  819. // (for example when paymentType is 'Mark', 'Sole', 'Sale', for paypal)
  820. $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
  821. // If previous line has returned nothing, we force to get the ID of payment of Credit Card (hard coded code 'CB').
  822. if (empty($paymentTypeId) || $paymentTypeId < 0) {
  823. $paymentTypeId = dol_getIdFromCode($db, 'CB', 'c_paiement', 'code', 'id', 1);
  824. }
  825. }
  826. // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
  827. if (isModEnabled('facture')) {
  828. if (!empty($FinalPaymentAmt) && $paymentTypeId > 0 ) {
  829. include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
  830. $invoice = new Facture($db);
  831. $result = $invoice->createFromOrder($object, $user);
  832. if ($result > 0) {
  833. $object->classifyBilled($user);
  834. $invoice->validate($user);
  835. // Creation of payment line
  836. include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
  837. $paiement = new Paiement($db);
  838. $paiement->datepaye = $now;
  839. if ($currencyCodeType == $conf->currency) {
  840. $paiement->amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id
  841. } else {
  842. $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching
  843. $postactionmessages[] = 'Payment was done in a different currency that currency expected of company';
  844. $ispostactionok = -1;
  845. $error++;
  846. }
  847. $paiement->paiementid = $paymentTypeId;
  848. $paiement->num_payment = '';
  849. $paiement->note_public = 'Online payment ' . dol_print_date($now, 'standard') . ' from ' . $ipaddress;
  850. $paiement->ext_payment_id = $TRANSACTIONID; // pi_... for Stripe, ...
  851. $paiement->ext_payment_site = $service; // 'StripeLive' or 'Stripe', or ...
  852. if (!$error) {
  853. $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents
  854. if ($paiement_id < 0) {
  855. $postactionmessages[] = $paiement->error . ' ' . join("<br>\n", $paiement->errors);
  856. $ispostactionok = -1;
  857. $error++;
  858. } else {
  859. $postactionmessages[] = 'Payment created';
  860. $ispostactionok = 1;
  861. }
  862. }
  863. if (!$error && isModEnabled("banque")) {
  864. $bankaccountid = 0;
  865. if ($paymentmethod == 'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
  866. elseif ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
  867. elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
  868. if ($bankaccountid > 0) {
  869. $label = '(CustomerInvoicePayment)';
  870. if ($object->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
  871. $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
  872. if ($result < 0) {
  873. $postactionmessages[] = $paiement->error . ' ' . join("<br>\n", $paiement->errors);
  874. $ispostactionok = -1;
  875. $error++;
  876. } else {
  877. $postactionmessages[] = 'Bank transaction of payment created';
  878. $ispostactionok = 1;
  879. }
  880. } else {
  881. $postactionmessages[] = 'Setup of bank account to use in module ' . $paymentmethod . ' was not set. No way to record the payment.';
  882. $ispostactionok = -1;
  883. $error++;
  884. }
  885. }
  886. if (!$error) {
  887. $db->commit();
  888. } else {
  889. $db->rollback();
  890. }
  891. } else {
  892. $postactionmessages[] = 'Failed to create invoice form order ' . $tmptag['ORD'] . '.';
  893. $ispostactionok = -1;
  894. }
  895. } else {
  896. $postactionmessages[] = 'Failed to get a valid value for "amount paid" (' . $FinalPaymentAmt . ') or "payment type id" (' . $paymentTypeId . ') to record the payment of order ' . $tmptag['ORD'] . '. May be payment was already recorded.';
  897. $ispostactionok = -1;
  898. }
  899. } else {
  900. $postactionmessages[] = 'Invoice module is not enable';
  901. $ispostactionok = -1;
  902. }
  903. } else {
  904. $postactionmessages[] = 'Order paid ' . $tmptag['ORD'] . ' was not found';
  905. $ispostactionok = -1;
  906. }
  907. } elseif (array_key_exists('DON', $tmptag) && $tmptag['DON'] > 0) {
  908. include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  909. $don = new Don($db);
  910. $result = $don->fetch((int) $tmptag['DON']);
  911. if ($result) {
  912. $paymentTypeId = 0;
  913. if ($paymentmethod == 'paybox') {
  914. $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
  915. }
  916. if ($paymentmethod == 'paypal') {
  917. $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
  918. }
  919. if ($paymentmethod == 'stripe') {
  920. $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
  921. }
  922. if (empty($paymentTypeId)) {
  923. dol_syslog("paymentType = ".$paymentType, LOG_DEBUG, 0, '_payment');
  924. if (empty($paymentType)) {
  925. $paymentType = 'CB';
  926. }
  927. // May return nothing when paymentType means nothing
  928. // (for example when paymentType is 'Mark', 'Sole', 'Sale', for paypal)
  929. $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
  930. // If previous line has returned nothing, we force to get the ID of payment of Credit Card (hard coded code 'CB').
  931. if (empty($paymentTypeId) || $paymentTypeId < 0) {
  932. $paymentTypeId = dol_getIdFromCode($db, 'CB', 'c_paiement', 'code', 'id', 1);
  933. }
  934. }
  935. // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
  936. if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
  937. $db->begin();
  938. // Creation of paiement line for donation
  939. include_once DOL_DOCUMENT_ROOT.'/don/class/paymentdonation.class.php';
  940. $paiement = new PaymentDonation($db);
  941. $totalpaid = $FinalPaymentAmt;
  942. if ($currencyCodeType == $conf->currency) {
  943. $paiement->amounts = array($object->id => $totalpaid); // Array with all payments dispatching with donation
  944. } else {
  945. // PaymentDonation does not support multi currency
  946. $postactionmessages[] = 'Payment donation can\'t be payed with diffent currency than '.$conf->currency;
  947. $ispostactionok = -1;
  948. $error++; // Not yet supported
  949. }
  950. $paiement->fk_donation = $don->id;
  951. $paiement->datep = $now;
  952. $paiement->paymenttype = $paymentTypeId;
  953. $paiement->num_payment = '';
  954. $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress;
  955. $paiement->ext_payment_id = $TRANSACTIONID;
  956. $paiement->ext_payment_site = $service;
  957. if (!$error) {
  958. $paiement_id = $paiement->create($user, 1);
  959. if ($paiement_id < 0) {
  960. $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
  961. $ispostactionok = -1;
  962. $error++;
  963. } else {
  964. $postactionmessages[] = 'Payment created';
  965. $ispostactionok = 1;
  966. if ($totalpaid >= $don->getRemainToPay()) {
  967. $don->setPaid($don->id);
  968. }
  969. }
  970. }
  971. if (!$error && isModEnabled("banque")) {
  972. $bankaccountid = 0;
  973. if ($paymentmethod == 'paybox') {
  974. $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
  975. } elseif ($paymentmethod == 'paypal') {
  976. $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
  977. } elseif ($paymentmethod == 'stripe') {
  978. $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
  979. }
  980. if ($bankaccountid > 0) {
  981. $result = $paiement->addPaymentToBank($user, 'payment_donation', '(DonationPayment)', $bankaccountid, '', '');
  982. if ($result < 0) {
  983. $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
  984. $ispostactionok = -1;
  985. $error++;
  986. } else {
  987. $postactionmessages[] = 'Bank transaction of payment created';
  988. $ispostactionok = 1;
  989. }
  990. } else {
  991. $postactionmessages[] = 'Setup of bank account to use in module '.$paymentmethod.' was not set. Your payment was really executed but we failed to record it. Please contact us.';
  992. $ispostactionok = -1;
  993. $error++;
  994. }
  995. }
  996. if (!$error) {
  997. $db->commit();
  998. } else {
  999. $db->rollback();
  1000. }
  1001. } else {
  1002. $postactionmessages[] = 'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.') or "payment type id" ('.$paymentTypeId.') to record the payment of donation '.$tmptag['DON'].'. May be payment was already recorded.';
  1003. $ispostactionok = -1;
  1004. }
  1005. } else {
  1006. $postactionmessages[] = 'Donation paid '.$tmptag['DON'].' was not found';
  1007. $ispostactionok = -1;
  1008. }
  1009. // TODO send email with acknowledgment for the donation
  1010. // (we need first that the donation module is able to generate a pdf document for the cerfa with pre filled content)
  1011. } elseif (array_key_exists('ATT', $tmptag) && $tmptag['ATT'] > 0) {
  1012. // Record payment for registration to an event for an attendee
  1013. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
  1014. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
  1015. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  1016. $object = new Facture($db);
  1017. $result = $object->fetch($ref);
  1018. if ($result) {
  1019. $paymentTypeId = 0;
  1020. if ($paymentmethod == 'paybox') {
  1021. $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
  1022. }
  1023. if ($paymentmethod == 'paypal') {
  1024. $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
  1025. }
  1026. if ($paymentmethod == 'stripe') {
  1027. $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
  1028. }
  1029. if (empty($paymentTypeId)) {
  1030. dol_syslog("paymentType = ".$paymentType, LOG_DEBUG, 0, '_payment');
  1031. if (empty($paymentType)) {
  1032. $paymentType = 'CB';
  1033. }
  1034. // May return nothing when paymentType means nothing
  1035. // (for example when paymentType is 'Mark', 'Sole', 'Sale', for paypal)
  1036. $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
  1037. // If previous line has returned nothing, we force to get the ID of payment of Credit Card (hard coded code 'CB').
  1038. if (empty($paymentTypeId) || $paymentTypeId < 0) {
  1039. $paymentTypeId = dol_getIdFromCode($db, 'CB', 'c_paiement', 'code', 'id', 1);
  1040. }
  1041. }
  1042. // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
  1043. if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
  1044. $resultvalidate = $object->validate($user);
  1045. if ($resultvalidate < 0) {
  1046. $postactionmessages[] = 'Cannot validate invoice';
  1047. $ispostactionok = -1;
  1048. $error++; // Not yet supported
  1049. } else {
  1050. $db->begin();
  1051. // Creation of payment line
  1052. include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  1053. $paiement = new Paiement($db);
  1054. $paiement->datepaye = $now;
  1055. if ($currencyCodeType == $conf->currency) {
  1056. $paiement->amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id
  1057. } else {
  1058. $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching
  1059. $postactionmessages[] = 'Payment was done in a different currency that currency expected of company';
  1060. $ispostactionok = -1;
  1061. $error++; // Not yet supported
  1062. }
  1063. $paiement->paiementid = $paymentTypeId;
  1064. $paiement->num_payment = '';
  1065. $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress.' for event registration';
  1066. $paiement->ext_payment_id = $TRANSACTIONID;
  1067. $paiement->ext_payment_site = $service;
  1068. if (!$error) {
  1069. $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents
  1070. if ($paiement_id < 0) {
  1071. $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
  1072. $ispostactionok = -1;
  1073. $error++;
  1074. } else {
  1075. $postactionmessages[] = 'Payment created';
  1076. $ispostactionok = 1;
  1077. }
  1078. }
  1079. if (!$error && isModEnabled("banque")) {
  1080. $bankaccountid = 0;
  1081. if ($paymentmethod == 'paybox') {
  1082. $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
  1083. } elseif ($paymentmethod == 'paypal') {
  1084. $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
  1085. } elseif ($paymentmethod == 'stripe') {
  1086. $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
  1087. }
  1088. if ($bankaccountid > 0) {
  1089. $label = '(CustomerInvoicePayment)';
  1090. if ($object->type == Facture::TYPE_CREDIT_NOTE) {
  1091. $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
  1092. }
  1093. $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
  1094. if ($result < 0) {
  1095. $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
  1096. $ispostactionok = -1;
  1097. $error++;
  1098. } else {
  1099. $postactionmessages[] = 'Bank transaction of payment created';
  1100. $ispostactionok = 1;
  1101. }
  1102. } else {
  1103. $postactionmessages[] = 'Setup of bank account to use in module '.$paymentmethod.' was not set. Your payment was really executed but we failed to record it. Please contact us.';
  1104. $ispostactionok = -1;
  1105. $error++;
  1106. }
  1107. }
  1108. if (!$error) {
  1109. // Validating the attendee
  1110. $attendeetovalidate = new ConferenceOrBoothAttendee($db);
  1111. $resultattendee = $attendeetovalidate->fetch((int) $tmptag['ATT']);
  1112. if ($resultattendee < 0) {
  1113. $error++;
  1114. setEventMessages(null, $attendeetovalidate->errors, "errors");
  1115. } else {
  1116. $attendeetovalidate->validate($user);
  1117. $attendeetovalidate->amount = $FinalPaymentAmt;
  1118. $attendeetovalidate->date_subscription = dol_now();
  1119. $attendeetovalidate->update($user);
  1120. }
  1121. }
  1122. if (!$error) {
  1123. $db->commit();
  1124. } else {
  1125. setEventMessages(null, $postactionmessages, 'warnings');
  1126. $db->rollback();
  1127. }
  1128. if (! $error) {
  1129. // Sending mail
  1130. $thirdparty = new Societe($db);
  1131. $resultthirdparty = $thirdparty->fetch($attendeetovalidate->fk_soc);
  1132. if ($resultthirdparty < 0) {
  1133. setEventMessages($resultthirdparty->error, $resultthirdparty->errors, "errors");
  1134. } else {
  1135. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  1136. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  1137. $formmail = new FormMail($db);
  1138. // Set output language
  1139. $outputlangs = new Translate('', $conf);
  1140. $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
  1141. // Load traductions files required by page
  1142. $outputlangs->loadLangs(array("main", "members", "eventorganization"));
  1143. // Get email content from template
  1144. $arraydefaultmessage = null;
  1145. $idoftemplatetouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT; // Email to send for Event organization registration
  1146. if (!empty($idoftemplatetouse)) {
  1147. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1, '');
  1148. }
  1149. if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  1150. $subject = $arraydefaultmessage->topic;
  1151. $msg = $arraydefaultmessage->content;
  1152. } else {
  1153. $subject = '['.$appli.'] '.$object->ref.' - '.$outputlangs->trans("NewRegistration").']';
  1154. $msg = $outputlangs->trans("OrganizationEventPaymentOfRegistrationWasReceived");
  1155. }
  1156. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
  1157. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  1158. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  1159. $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
  1160. $sendto = $attendeetovalidate->email;
  1161. $cc = '';
  1162. if ($thirdparty->email) {
  1163. $cc = $thirdparty->email;
  1164. }
  1165. if ($attendeetovalidate->email_company && $attendeetovalidate->email_company != $thirdparty->email) {
  1166. $cc = ($cc ? ', ' : '').$attendeetovalidate->email_company;
  1167. }
  1168. $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM : getDolGlobalString("MAIN_MAIL_EMAIL_FROM");
  1169. $urlback = $_SERVER["REQUEST_URI"];
  1170. $ishtml = dol_textishtml($texttosend); // May contain urls
  1171. // Attach a file ?
  1172. $file = '';
  1173. $listofpaths = array();
  1174. $listofnames = array();
  1175. $listofmimes = array();
  1176. if (is_object($object)) {
  1177. $invoicediroutput = $conf->facture->dir_output;
  1178. $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->ref, preg_quote($object->ref, '/').'[^\-]+');
  1179. $file = $fileparams['fullname'];
  1180. $listofpaths = array($file);
  1181. $listofnames = array(basename($file));
  1182. $listofmimes = array(dol_mimetype($file));
  1183. }
  1184. $mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, $listofpaths, $listofmimes, $listofnames, $cc, '', 0, $ishtml);
  1185. $result = $mailfile->sendfile();
  1186. if ($result) {
  1187. dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
  1188. } else {
  1189. dol_syslog("Failed to send EMail to ".$sendto.' - '.$mailfile->error, LOG_ERR, 0, '_payment');
  1190. }
  1191. }
  1192. }
  1193. }
  1194. } else {
  1195. $postactionmessages[] = 'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.') or "payment type id" ('.$paymentTypeId.') to record the payment of invoice '.$tmptag['ATT'].'. May be payment was already recorded.';
  1196. $ispostactionok = -1;
  1197. }
  1198. } else {
  1199. $postactionmessages[] = 'Invoice paid '.$tmptag['ATT'].' was not found';
  1200. $ispostactionok = -1;
  1201. }
  1202. } elseif (array_key_exists('BOO', $tmptag) && $tmptag['BOO'] > 0) {
  1203. // Record payment for booth or conference
  1204. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
  1205. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
  1206. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  1207. $object = new Facture($db);
  1208. $result = $object->fetch($ref);
  1209. if ($result) {
  1210. $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
  1211. $paymentTypeId = 0;
  1212. if ($paymentmethod == 'paybox') {
  1213. $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
  1214. }
  1215. if ($paymentmethod == 'paypal') {
  1216. $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
  1217. }
  1218. if ($paymentmethod == 'stripe') {
  1219. $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
  1220. }
  1221. if (empty($paymentTypeId)) {
  1222. dol_syslog("paymentType = ".$paymentType, LOG_DEBUG, 0, '_payment');
  1223. if (empty($paymentType)) {
  1224. $paymentType = 'CB';
  1225. }
  1226. // May return nothing when paymentType means nothing
  1227. // (for example when paymentType is 'Mark', 'Sole', 'Sale', for paypal)
  1228. $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
  1229. // If previous line has returned nothing, we force to get the ID of payment of Credit Card (hard coded code 'CB').
  1230. if (empty($paymentTypeId) || $paymentTypeId < 0) {
  1231. $paymentTypeId = dol_getIdFromCode($db, 'CB', 'c_paiement', 'code', 'id', 1);
  1232. }
  1233. }
  1234. // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
  1235. if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
  1236. $resultvalidate = $object->validate($user);
  1237. if ($resultvalidate < 0) {
  1238. $postactionmessages[] = 'Cannot validate invoice';
  1239. $ispostactionok = -1;
  1240. $error++; // Not yet supported
  1241. } else {
  1242. $db->begin();
  1243. // Creation of payment line
  1244. include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  1245. $paiement = new Paiement($db);
  1246. $paiement->datepaye = $now;
  1247. if ($currencyCodeType == $conf->currency) {
  1248. $paiement->amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id
  1249. } else {
  1250. $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching
  1251. $postactionmessages[] = 'Payment was done in a different currency that currency expected of company';
  1252. $ispostactionok = -1;
  1253. $error++; // Not yet supported
  1254. }
  1255. $paiement->paiementid = $paymentTypeId;
  1256. $paiement->num_payment = '';
  1257. $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress;
  1258. $paiement->ext_payment_id = $TRANSACTIONID;
  1259. $paiement->ext_payment_site = $service;
  1260. if (!$error) {
  1261. $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents
  1262. if ($paiement_id < 0) {
  1263. $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
  1264. $ispostactionok = -1;
  1265. $error++;
  1266. } else {
  1267. $postactionmessages[] = 'Payment created';
  1268. $ispostactionok = 1;
  1269. }
  1270. }
  1271. if (!$error && isModEnabled("banque")) {
  1272. $bankaccountid = 0;
  1273. if ($paymentmethod == 'paybox') {
  1274. $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
  1275. } elseif ($paymentmethod == 'paypal') {
  1276. $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
  1277. } elseif ($paymentmethod == 'stripe') {
  1278. $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
  1279. }
  1280. if ($bankaccountid > 0) {
  1281. $label = '(CustomerInvoicePayment)';
  1282. if ($object->type == Facture::TYPE_CREDIT_NOTE) {
  1283. $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
  1284. }
  1285. $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
  1286. if ($result < 0) {
  1287. $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
  1288. $ispostactionok = -1;
  1289. $error++;
  1290. } else {
  1291. $postactionmessages[] = 'Bank transaction of payment created';
  1292. $ispostactionok = 1;
  1293. }
  1294. } else {
  1295. $postactionmessages[] = 'Setup of bank account to use in module '.$paymentmethod.' was not set. Your payment was really executed but we failed to record it. Please contact us.';
  1296. $ispostactionok = -1;
  1297. $error++;
  1298. }
  1299. }
  1300. if (!$error) {
  1301. // Putting the booth to "suggested" state
  1302. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
  1303. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
  1304. $booth = new ConferenceOrBooth($db);
  1305. $resultbooth = $booth->fetch((int) $tmptag['BOO']);
  1306. if ($resultbooth < 0) {
  1307. $error++;
  1308. setEventMessages(null, $booth->errors, "errors");
  1309. } else {
  1310. $booth->status = CONFERENCEORBOOTH::STATUS_SUGGESTED;
  1311. $resultboothupdate = $booth->update($user);
  1312. if ($resultboothupdate<0) {
  1313. // Finding the thirdparty by getting the invoice
  1314. $invoice = new Facture($db);
  1315. $resultinvoice = $invoice->fetch($ref);
  1316. if ($resultinvoice<0) {
  1317. $postactionmessages[] = 'Could not find the associated invoice.';
  1318. $ispostactionok = -1;
  1319. $error++;
  1320. } else {
  1321. $thirdparty = new Societe($db);
  1322. $resultthirdparty = $thirdparty->fetch($invoice->socid);
  1323. if ($resultthirdparty<0) {
  1324. $error++;
  1325. setEventMessages(null, $thirdparty->errors, "errors");
  1326. } else {
  1327. // Sending mail
  1328. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  1329. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  1330. $formmail = new FormMail($db);
  1331. // Set output language
  1332. $outputlangs = new Translate('', $conf);
  1333. $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
  1334. // Load traductions files required by page
  1335. $outputlangs->loadLangs(array("main", "members", "eventorganization"));
  1336. // Get email content from template
  1337. $arraydefaultmessage = null;
  1338. $idoftemplatetouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_BOOTH; // Email sent after registration for a Booth
  1339. if (!empty($idoftemplatetouse)) {
  1340. $arraydefaultmessage = $formmail->getEMailTemplate($db, 'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1, '');
  1341. }
  1342. if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
  1343. $subject = $arraydefaultmessage->topic;
  1344. $msg = $arraydefaultmessage->content;
  1345. } else {
  1346. $subject = '['.$appli.'] '.$booth->ref.' - '.$outputlangs->trans("NewRegistration").']';
  1347. $msg = $outputlangs->trans("OrganizationEventPaymentOfBoothWasReceived");
  1348. }
  1349. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
  1350. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  1351. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  1352. $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
  1353. $sendto = $thirdparty->email;
  1354. $from = $conf->global->MAILING_EMAIL_FROM;
  1355. $urlback = $_SERVER["REQUEST_URI"];
  1356. $ishtml = dol_textishtml($texttosend); // May contain urls
  1357. $mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml);
  1358. $result = $mailfile->sendfile();
  1359. if ($result) {
  1360. dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
  1361. } else {
  1362. dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
  1363. }
  1364. }
  1365. }
  1366. }
  1367. }
  1368. }
  1369. if (!$error) {
  1370. $db->commit();
  1371. } else {
  1372. $db->rollback();
  1373. }
  1374. }
  1375. } else {
  1376. $postactionmessages[] = 'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.') or "payment type id" ('.$paymentTypeId.') to record the payment of invoice '.$tmptag['ATT'].'. May be payment was already recorded.';
  1377. $ispostactionok = -1;
  1378. }
  1379. } else {
  1380. $postactionmessages[] = 'Invoice paid '.$tmptag['ATT'].' was not found';
  1381. $ispostactionok = -1;
  1382. }
  1383. } else {
  1384. // Nothing done
  1385. }
  1386. }
  1387. // Set $appli for emails title
  1388. $appli = $mysoc->name;
  1389. if ($ispaymentok) {
  1390. // Get on url call
  1391. $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
  1392. $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
  1393. // Set by newpayment.php
  1394. $currencyCodeType = $_SESSION['currencyCodeType'];
  1395. $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
  1396. $paymentType = $_SESSION['PaymentType']; // Seems used by paypal only
  1397. if (is_object($object) && method_exists($object, 'call_trigger')) {
  1398. // Call trigger
  1399. $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_OK', $user);
  1400. if ($result < 0) {
  1401. $error++;
  1402. }
  1403. // End call triggers
  1404. } elseif (get_class($object) == 'stdClass') {
  1405. //In some case $object is not instanciate (for paiement on custom object) We need to deal with payment
  1406. include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  1407. $paiement = new Paiement($db);
  1408. $result = $paiement->call_trigger('PAYMENTONLINE_PAYMENT_OK', $user);
  1409. if ($result < 0) $error++;
  1410. }
  1411. print $langs->trans("YourPaymentHasBeenRecorded")."<br>\n";
  1412. if ($TRANSACTIONID) {
  1413. print $langs->trans("ThisIsTransactionId", $TRANSACTIONID)."<br><br>\n";
  1414. }
  1415. $key = 'ONLINE_PAYMENT_MESSAGE_OK';
  1416. if (!empty($conf->global->$key)) {
  1417. print '<br>';
  1418. print $conf->global->$key;
  1419. }
  1420. $sendemail = '';
  1421. if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
  1422. $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
  1423. }
  1424. $tmptag = dolExplodeIntoArray($fulltag, '.', '=');
  1425. dol_syslog("Send email to admins if we have to (sendemail = ".$sendemail.")", LOG_DEBUG, 0, '_payment');
  1426. // Send an email to admins
  1427. if ($sendemail) {
  1428. $companylangs = new Translate('', $conf);
  1429. $companylangs->setDefaultLang($mysoc->default_lang);
  1430. $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
  1431. $sendto = $sendemail;
  1432. $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM : getDolGlobalString("MAIN_MAIL_EMAIL_FROM");
  1433. // Define $urlwithroot
  1434. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  1435. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  1436. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  1437. // Define link to login card
  1438. $urlback = $_SERVER["REQUEST_URI"];
  1439. $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentReceived");
  1440. $content = "";
  1441. if (array_key_exists('MEM', $tmptag)) {
  1442. $url = $urlwithroot."/adherents/subscription.php?rowid=".((int) $tmptag['MEM']);
  1443. $content .= '<strong>'.$companylangs->trans("PaymentSubscription")."</strong><br><br>\n";
  1444. $content .= $companylangs->trans("MemberId").': <strong>'.$tmptag['MEM']."</strong><br>\n";
  1445. $content .= $companylangs->trans("Link").': <a href="'.$url.'">'.$url.'</a>'."<br>\n";
  1446. } elseif (array_key_exists('INV', $tmptag)) {
  1447. $url = $urlwithroot."/compta/facture/card.php?id=".((int) $tmptag['INV']);
  1448. $content .= '<strong>'.$companylangs->trans("Payment")."</strong><br><br>\n";
  1449. $content .= $companylangs->trans("InvoiceId").': <strong>'.$tmptag['INV']."</strong><br>\n";
  1450. //$content.=$companylangs->trans("ThirdPartyId").': '.$tmptag['CUS']."<br>\n";
  1451. $content .= $companylangs->trans("Link").': <a href="'.$url.'">'.$url.'</a>'."<br>\n";
  1452. } else {
  1453. $content .= $companylangs->transnoentitiesnoconv("NewOnlinePaymentReceived")."<br>\n";
  1454. }
  1455. $content .= $companylangs->transnoentities("PostActionAfterPayment").' : ';
  1456. if ($ispostactionok > 0) {
  1457. //$topic.=' ('.$companylangs->transnoentitiesnoconv("Status").' '.$companylangs->transnoentitiesnoconv("OK").')';
  1458. $content .= '<span style="color: green">'.$companylangs->transnoentitiesnoconv("OK").'</span>';
  1459. } elseif ($ispostactionok == 0) {
  1460. $content .= $companylangs->transnoentitiesnoconv("None");
  1461. } else {
  1462. $topic .= ($ispostactionok ? '' : ' ('.$companylangs->trans("WarningPostActionErrorAfterPayment").')');
  1463. $content .= '<span class="star">'.$companylangs->transnoentitiesnoconv("Error").'</span>';
  1464. }
  1465. $content .= '<br>'."\n";
  1466. foreach ($postactionmessages as $postactionmessage) {
  1467. $content .= ' * '.$postactionmessage.'<br>'."\n";
  1468. }
  1469. if ($ispostactionok < 0) {
  1470. $content .= $langs->transnoentities("ARollbackWasPerformedOnPostActions");
  1471. }
  1472. $content .= '<br>'."\n";
  1473. $content .= "<br>\n";
  1474. $content .= '<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
  1475. $content .= $companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
  1476. $content .= $companylangs->transnoentitiesnoconv("ThisIsTransactionId").': <strong>'.$TRANSACTIONID."</strong><br>\n";
  1477. $content .= $companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
  1478. $content .= "<br>\n";
  1479. $content .= "tag=".$fulltag."<br>\ntoken=".$onlinetoken."<br>\npaymentType=".$paymentType."<br>\ncurrencycodeType=".$currencyCodeType."<br>\npayerId=".$payerID."<br>\nipaddress=".$ipaddress."<br>\nFinalPaymentAmt=".$FinalPaymentAmt."<br>\n";
  1480. if (!empty($ErrorCode)) {
  1481. $content .= "ErrorCode = ".$ErrorCode."<br>\n";
  1482. }
  1483. if (!empty($ErrorShortMsg)) {
  1484. $content .= "ErrorShortMsg = ".$ErrorShortMsg."<br>\n";
  1485. }
  1486. if (!empty($ErrorLongMsg)) {
  1487. $content .= "ErrorLongMsg = ".$ErrorLongMsg."<br>\n";
  1488. }
  1489. if (!empty($ErrorSeverityCode)) {
  1490. $content .= "ErrorSeverityCode = ".$ErrorSeverityCode."<br>\n";
  1491. }
  1492. $ishtml = dol_textishtml($content); // May contain urls
  1493. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  1494. $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
  1495. $result = $mailfile->sendfile();
  1496. if ($result) {
  1497. dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
  1498. //dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0);
  1499. } else {
  1500. dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
  1501. //dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0);
  1502. }
  1503. }
  1504. } else {
  1505. // Get on url call
  1506. $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
  1507. $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
  1508. // Set by newpayment.php
  1509. $paymentType = $_SESSION['PaymentType'];
  1510. $currencyCodeType = $_SESSION['currencyCodeType'];
  1511. $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
  1512. if (is_object($object) && method_exists($object, 'call_trigger')) {
  1513. // Call trigger
  1514. $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_KO', $user);
  1515. if ($result < 0) {
  1516. $error++;
  1517. }
  1518. // End call triggers
  1519. }
  1520. print $langs->trans('DoExpressCheckoutPaymentAPICallFailed')."<br>\n";
  1521. print $langs->trans('DetailedErrorMessage').": ".$ErrorLongMsg."<br>\n";
  1522. print $langs->trans('ShortErrorMessage').": ".$ErrorShortMsg."<br>\n";
  1523. print $langs->trans('ErrorCode').": ".$ErrorCode."<br>\n";
  1524. print $langs->trans('ErrorSeverityCode').": ".$ErrorSeverityCode."<br>\n";
  1525. if ($mysoc->email) {
  1526. print "\nPlease, send a screenshot of this page to ".$mysoc->email."<br>\n";
  1527. }
  1528. $sendemail = '';
  1529. if (!empty($conf->global->PAYMENTONLINE_SENDEMAIL)) {
  1530. $sendemail = $conf->global->PAYMENTONLINE_SENDEMAIL;
  1531. }
  1532. // TODO Remove local option to keep only the generic one ?
  1533. if ($paymentmethod == 'paypal' && !empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) {
  1534. $sendemail = $conf->global->PAYPAL_PAYONLINE_SENDEMAIL;
  1535. } elseif ($paymentmethod == 'paybox' && !empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) {
  1536. $sendemail = $conf->global->PAYBOX_PAYONLINE_SENDEMAIL;
  1537. } elseif ($paymentmethod == 'stripe' && !empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) {
  1538. $sendemail = $conf->global->STRIPE_PAYONLINE_SENDEMAIL;
  1539. }
  1540. // Send warning of error to administrator
  1541. if ($sendemail) {
  1542. $companylangs = new Translate('', $conf);
  1543. $companylangs->setDefaultLang($mysoc->default_lang);
  1544. $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
  1545. $sendto = $sendemail;
  1546. $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM : getDolGlobalString("MAIN_MAIL_EMAIL_FROM");
  1547. // Define $urlwithroot
  1548. $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
  1549. $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  1550. //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
  1551. $urlback = $_SERVER["REQUEST_URI"];
  1552. $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("ValidationOfPaymentFailed");
  1553. $content = "";
  1554. $content .= '<span style="color: orange">'.$companylangs->transnoentitiesnoconv("PaymentSystemConfirmPaymentPageWasCalledButFailed")."</span>\n";
  1555. $content .= "<br><br>\n";
  1556. $content .= '<u>'.$companylangs->transnoentitiesnoconv("TechnicalInformation").":</u><br>\n";
  1557. $content .= $companylangs->transnoentitiesnoconv("OnlinePaymentSystem").': <strong>'.$paymentmethod."</strong><br>\n";
  1558. $content .= $companylangs->transnoentitiesnoconv("ReturnURLAfterPayment").': '.$urlback."<br>\n";
  1559. $content .= "<br>\n";
  1560. $content .= "tag=".$fulltag."<br>\ntoken=".$onlinetoken."<br>\npaymentType=".$paymentType."<br>\ncurrencycodeType=".$currencyCodeType."<br>\npayerId=".$payerID."<br>\nipaddress=".$ipaddress."<br>\nFinalPaymentAmt=".$FinalPaymentAmt."<br>\n";
  1561. $ishtml = dol_textishtml($content); // May contain urls
  1562. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  1563. $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
  1564. $result = $mailfile->sendfile();
  1565. if ($result) {
  1566. dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
  1567. } else {
  1568. dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
  1569. }
  1570. }
  1571. }
  1572. print "\n</div>\n";
  1573. print "<!-- Info for payment: FinalPaymentAmt=".dol_escape_htmltag($FinalPaymentAmt)." paymentTypeId=".dol_escape_htmltag($paymentTypeId)." currencyCodeType=".dol_escape_htmltag($currencyCodeType)." -->\n";
  1574. htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix);
  1575. // Clean session variables to avoid duplicate actions if post is resent
  1576. unset($_SESSION["FinalPaymentAmt"]);
  1577. unset($_SESSION["TRANSACTIONID"]);
  1578. llxFooter('', 'public');
  1579. $db->close();