paymentok.php 73 KB

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