paymentok.php 73 KB

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