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