newpayment.php 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2018 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2018-2021 Thibault FOUCART <support@ptibogxiv.net>
  7. * Copyright (C) 2021 Waël Almoman <info@almoman.com>
  8. * Copyright (C) 2021 Dorian Vabre <dorian.vabre@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. *
  23. * For Paypal test: https://developer.paypal.com/
  24. * For Paybox test: ???
  25. * For Stripe test: Use credit card 4242424242424242 .More example on https://stripe.com/docs/testing
  26. *
  27. * Variants:
  28. * - When option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION is on, we use the new PaymentIntent API
  29. * - When option STRIPE_USE_NEW_CHECKOUT is on, we use the new checkout API
  30. * - If no option set, we use old APIS (charge)
  31. */
  32. /**
  33. * \file htdocs/public/payment/newpayment.php
  34. * \ingroup core
  35. * \brief File to offer a way to make a payment for a particular Dolibarr object
  36. */
  37. if (!defined('NOLOGIN')) {
  38. define("NOLOGIN", 1); // This means this output page does not require to be logged.
  39. }
  40. if (!defined('NOCSRFCHECK')) {
  41. define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
  42. }
  43. if (!defined('NOIPCHECK')) {
  44. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  45. }
  46. if (!defined('NOBROWSERNOTIF')) {
  47. define('NOBROWSERNOTIF', '1');
  48. }
  49. // For MultiCompany module.
  50. // Do not use GETPOST here, function is not defined and get of entity must be done before including main.inc.php
  51. $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : (!empty($_GET['e']) ? (int) $_GET['e'] : (!empty($_POST['e']) ? (int) $_POST['e'] : 1))));
  52. if (is_numeric($entity)) {
  53. define("DOLENTITY", $entity);
  54. }
  55. require '../../main.inc.php';
  56. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  57. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  58. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  59. require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
  60. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  61. require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
  62. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  63. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  64. // Hook to be used by external payment modules (ie Payzen, ...)
  65. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  66. $hookmanager = new HookManager($db);
  67. $hookmanager->initHooks(array('newpayment'));
  68. // Load translation files
  69. $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "paybox", "paypal", "stripe")); // File with generic data
  70. // Security check
  71. // No check on module enabled. Done later according to $validpaymentmethod
  72. $action = GETPOST('action', 'aZ09');
  73. // Input are:
  74. // type ('invoice','order','contractline'),
  75. // id (object id),
  76. // amount (required if id is empty),
  77. // tag (a free text, required if type is empty)
  78. // currency (iso code)
  79. $suffix = GETPOST("suffix", 'aZ09');
  80. $amount = price2num(GETPOST("amount", 'alpha'));
  81. if (!GETPOST("currency", 'alpha')) {
  82. $currency = $conf->currency;
  83. } else {
  84. $currency = GETPOST("currency", 'aZ09');
  85. }
  86. $source = GETPOST("s", 'aZ09') ?GETPOST("s", 'aZ09') : GETPOST("source", 'aZ09');
  87. //$download = GETPOST('d', 'int') ?GETPOST('d', 'int') : GETPOST('download', 'int');
  88. if (!$action) {
  89. if (!GETPOST("amount", 'alpha') && !$source) {
  90. print $langs->trans('ErrorBadParameters')." - amount or source";
  91. exit;
  92. }
  93. if (is_numeric($amount) && !GETPOST("tag", 'alpha') && !$source) {
  94. print $langs->trans('ErrorBadParameters')." - tag or source";
  95. exit;
  96. }
  97. if ($source && !GETPOST("ref", 'alpha')) {
  98. print $langs->trans('ErrorBadParameters')." - ref";
  99. exit;
  100. }
  101. }
  102. if ($source == 'organizedeventregistration') {
  103. // Finding the Attendee
  104. $attendee = new ConferenceOrBoothAttendee($db);
  105. $invoiceid = GETPOST('ref', 'int');
  106. $invoice = new Facture($db);
  107. $resultinvoice = $invoice->fetch($invoiceid);
  108. if ($resultinvoice <= 0) {
  109. setEventMessages(null, $invoice->errors, "errors");
  110. } else {
  111. /*
  112. $attendeeid = 0;
  113. $invoice->fetchObjectLinked();
  114. $linkedAttendees = $invoice->linkedObjectsIds['conferenceorboothattendee'];
  115. if (is_array($linkedAttendees)) {
  116. $linkedAttendees = array_values($linkedAttendees);
  117. $attendeeid = $linkedAttendees[0];
  118. }*/
  119. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee";
  120. $sql .= " WHERE fk_invoice = ".((int) $invoiceid);
  121. $resql = $db->query($sql);
  122. if ($resql) {
  123. $obj = $db->fetch_object($resql);
  124. if ($obj) {
  125. $attendeeid = $obj->rowid;
  126. }
  127. }
  128. if ($attendeeid > 0) {
  129. $resultattendee = $attendee->fetch($attendeeid);
  130. if ($resultattendee <= 0) {
  131. setEventMessages(null, $attendee->errors, "errors");
  132. } else {
  133. $attendee->fetch_projet();
  134. $amount = price2num($invoice->total_ttc);
  135. // Finding the associated thirdparty
  136. $thirdparty = new Societe($db);
  137. $resultthirdparty = $thirdparty->fetch($invoice->socid);
  138. if ($resultthirdparty <= 0) {
  139. setEventMessages(null, $thirdparty->errors, "errors");
  140. }
  141. $object = $thirdparty;
  142. }
  143. }
  144. }
  145. } elseif ($source == 'boothlocation') {
  146. // Getting the amount to pay, the invoice, finding the thirdparty
  147. $invoiceid = GETPOST('ref');
  148. $invoice = new Facture($db);
  149. $resultinvoice = $invoice->fetch($invoiceid);
  150. if ($resultinvoice <= 0) {
  151. setEventMessages(null, $invoice->errors, "errors");
  152. } else {
  153. $amount = price2num($invoice->total_ttc);
  154. // Finding the associated thirdparty
  155. $thirdparty = new Societe($db);
  156. $resultthirdparty = $thirdparty->fetch($invoice->socid);
  157. if ($resultthirdparty <= 0) {
  158. setEventMessages(null, $thirdparty->errors, "errors");
  159. }
  160. $object = $thirdparty;
  161. }
  162. }
  163. $paymentmethod = GETPOST('paymentmethod', 'alphanohtml') ? GETPOST('paymentmethod', 'alphanohtml') : ''; // Empty in most cases. Defined when a payment mode is forced
  164. $validpaymentmethod = array();
  165. // Detect $paymentmethod
  166. foreach ($_POST as $key => $val) {
  167. $reg = array();
  168. if (preg_match('/^dopayment_(.*)$/', $key, $reg)) {
  169. $paymentmethod = $reg[1];
  170. break;
  171. }
  172. }
  173. // Define $urlwithroot
  174. //$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
  175. //$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
  176. $urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
  177. $urlok = $urlwithroot.'/public/payment/paymentok.php?';
  178. $urlko = $urlwithroot.'/public/payment/paymentko.php?';
  179. // Complete urls for post treatment
  180. $ref = $REF = GETPOST('ref', 'alpha');
  181. $TAG = GETPOST("tag", 'alpha');
  182. $FULLTAG = GETPOST("fulltag", 'alpha'); // fulltag is tag with more informations
  183. $SECUREKEY = GETPOST("securekey"); // Secure key
  184. if ($paymentmethod && !preg_match('/'.preg_quote('PM='.$paymentmethod, '/').'/', $FULLTAG)) {
  185. $FULLTAG .= ($FULLTAG ? '.' : '').'PM='.$paymentmethod;
  186. }
  187. if (!empty($suffix)) {
  188. $urlok .= 'suffix='.urlencode($suffix).'&';
  189. $urlko .= 'suffix='.urlencode($suffix).'&';
  190. }
  191. if ($source) {
  192. $urlok .= 's='.urlencode($source).'&';
  193. $urlko .= 's='.urlencode($source).'&';
  194. }
  195. if (!empty($REF)) {
  196. $urlok .= 'ref='.urlencode($REF).'&';
  197. $urlko .= 'ref='.urlencode($REF).'&';
  198. }
  199. if (!empty($TAG)) {
  200. $urlok .= 'tag='.urlencode($TAG).'&';
  201. $urlko .= 'tag='.urlencode($TAG).'&';
  202. }
  203. if (!empty($FULLTAG)) {
  204. $urlok .= 'fulltag='.urlencode($FULLTAG).'&';
  205. $urlko .= 'fulltag='.urlencode($FULLTAG).'&';
  206. }
  207. if (!empty($SECUREKEY)) {
  208. $urlok .= 'securekey='.urlencode($SECUREKEY).'&';
  209. $urlko .= 'securekey='.urlencode($SECUREKEY).'&';
  210. }
  211. if (!empty($entity)) {
  212. $urlok .= 'e='.urlencode($entity).'&';
  213. $urlko .= 'e='.urlencode($entity).'&';
  214. }
  215. $urlok = preg_replace('/&$/', '', $urlok); // Remove last &
  216. $urlko = preg_replace('/&$/', '', $urlko); // Remove last &
  217. // Make special controls
  218. if ((empty($paymentmethod) || $paymentmethod == 'paypal') && !empty($conf->paypal->enabled)) {
  219. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
  220. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
  221. // Check parameters
  222. $PAYPAL_API_OK = "";
  223. if ($urlok) {
  224. $PAYPAL_API_OK = $urlok;
  225. }
  226. $PAYPAL_API_KO = "";
  227. if ($urlko) {
  228. $PAYPAL_API_KO = $urlko;
  229. }
  230. if (empty($PAYPAL_API_USER)) {
  231. dol_print_error('', "Paypal setup param PAYPAL_API_USER not defined");
  232. return -1;
  233. }
  234. if (empty($PAYPAL_API_PASSWORD)) {
  235. dol_print_error('', "Paypal setup param PAYPAL_API_PASSWORD not defined");
  236. return -1;
  237. }
  238. if (empty($PAYPAL_API_SIGNATURE)) {
  239. dol_print_error('', "Paypal setup param PAYPAL_API_SIGNATURE not defined");
  240. return -1;
  241. }
  242. }
  243. if ((empty($paymentmethod) || $paymentmethod == 'paybox') && !empty($conf->paybox->enabled)) {
  244. // No specific test for the moment
  245. }
  246. if ((empty($paymentmethod) || $paymentmethod == 'stripe') && !empty($conf->stripe->enabled)) {
  247. require_once DOL_DOCUMENT_ROOT.'/stripe/config.php'; // This include also /stripe/lib/stripe.lib.php, /includes/stripe/stripe-php/init.php, ...
  248. }
  249. // Initialize $validpaymentmethod
  250. $validpaymentmethod = getValidOnlinePaymentMethods($paymentmethod);
  251. // This hook is used to push to $validpaymentmethod by external payment modules (ie Payzen, ...)
  252. $parameters = [
  253. 'paymentmethod' => $paymentmethod,
  254. 'validpaymentmethod' => &$validpaymentmethod
  255. ];
  256. $reshook = $hookmanager->executeHooks('doValidatePayment', $parameters, $object, $action);
  257. if ($reshook < 0) {
  258. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  259. } elseif ($reshook > 0) {
  260. print $hookmanager->resPrint;
  261. }
  262. // Check security token
  263. $tmpsource = $source;
  264. if ($tmpsource == 'membersubscription') {
  265. $tmpsource = 'member';
  266. }
  267. $valid = true;
  268. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
  269. $tokenisok = false;
  270. if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
  271. if ($tmpsource && $REF) {
  272. // Use the source in the hash to avoid duplicates if the references are identical
  273. $tokenisok = dol_verifyHash($conf->global->PAYMENT_SECURITY_TOKEN.$tmpsource.$REF, $SECUREKEY, '2');
  274. // Do a second test for retro-compatibility (token may have been hashed with membersubscription in external module)
  275. if ($tmpsource != $source) {
  276. $tokenisok = dol_verifyHash($conf->global->PAYMENT_SECURITY_TOKEN.$source.$REF, $SECUREKEY, '2');
  277. }
  278. } else {
  279. $tokenisok = dol_verifyHash($conf->global->PAYMENT_SECURITY_TOKEN, $SECUREKEY, '2');
  280. }
  281. } else {
  282. $tokenisok = ($conf->global->PAYMENT_SECURITY_TOKEN == $SECUREKEY);
  283. }
  284. if (! $tokenisok) {
  285. if (empty($conf->global->PAYMENT_SECURITY_ACCEPT_ANY_TOKEN)) {
  286. $valid = false; // PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is for backward compatibility
  287. } else {
  288. dol_syslog("Warning: PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is on", LOG_WARNING);
  289. }
  290. }
  291. if (!$valid) {
  292. print '<div class="error">Bad value for key.</div>';
  293. //print 'SECUREKEY='.$SECUREKEY.' valid='.$valid;
  294. exit;
  295. }
  296. }
  297. if (!empty($paymentmethod) && empty($validpaymentmethod[$paymentmethod])) {
  298. print 'Payment module for payment method '.$paymentmethod.' is not active';
  299. exit;
  300. }
  301. if (empty($validpaymentmethod)) {
  302. print 'No active payment module (Paypal, Stripe, Paybox, ...)';
  303. exit;
  304. }
  305. // Common variables
  306. $creditor = $mysoc->name;
  307. $paramcreditor = 'ONLINE_PAYMENT_CREDITOR';
  308. $paramcreditorlong = 'ONLINE_PAYMENT_CREDITOR_'.$suffix;
  309. if (!empty($conf->global->$paramcreditorlong)) {
  310. $creditor = $conf->global->$paramcreditorlong;
  311. } elseif (!empty($conf->global->$paramcreditor)) {
  312. $creditor = $conf->global->$paramcreditor;
  313. }
  314. $mesg = '';
  315. /*
  316. * Actions
  317. */
  318. // Action dopayment is called after clicking/choosing the payment mode
  319. if ($action == 'dopayment') {
  320. if ($paymentmethod == 'paypal') {
  321. $PAYPAL_API_PRICE = price2num(GETPOST("newamount", 'alpha'), 'MT');
  322. $PAYPAL_PAYMENT_TYPE = 'Sale';
  323. // Vars that are used as global var later in print_paypal_redirect()
  324. $origfulltag = GETPOST("fulltag", 'alpha');
  325. $shipToName = GETPOST("shipToName", 'alpha');
  326. $shipToStreet = GETPOST("shipToStreet", 'alpha');
  327. $shipToCity = GETPOST("shipToCity", 'alpha');
  328. $shipToState = GETPOST("shipToState", 'alpha');
  329. $shipToCountryCode = GETPOST("shipToCountryCode", 'alpha');
  330. $shipToZip = GETPOST("shipToZip", 'alpha');
  331. $shipToStreet2 = GETPOST("shipToStreet2", 'alpha');
  332. $phoneNum = GETPOST("phoneNum", 'alpha');
  333. $email = GETPOST("email", 'alpha');
  334. $desc = GETPOST("desc", 'alpha');
  335. $thirdparty_id = GETPOST('thirdparty_id', 'int');
  336. // Special case for Paypal-Indonesia
  337. if ($shipToCountryCode == 'ID' && !preg_match('/\-/', $shipToState)) {
  338. $shipToState = 'ID-'.$shipToState;
  339. }
  340. if (empty($PAYPAL_API_PRICE) || !is_numeric($PAYPAL_API_PRICE)) {
  341. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount"));
  342. $action = '';
  343. // } elseif (empty($EMAIL)) { $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail"));
  344. // } elseif (! isValidEMail($EMAIL)) { $mesg=$langs->trans("ErrorBadEMail",$EMAIL);
  345. } elseif (!$origfulltag) {
  346. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentCode"));
  347. $action = '';
  348. }
  349. //var_dump($_POST);
  350. if (empty($mesg)) {
  351. dol_syslog("newpayment.php call paypal api and do redirect", LOG_DEBUG);
  352. // Other
  353. $PAYPAL_API_DEVISE = "USD";
  354. if (!empty($currency)) {
  355. $PAYPAL_API_DEVISE = $currency;
  356. }
  357. // Show var initialized by include fo paypal lib at begin of this file
  358. dol_syslog("Submit Paypal form", LOG_DEBUG);
  359. dol_syslog("PAYPAL_API_USER: $PAYPAL_API_USER", LOG_DEBUG);
  360. dol_syslog("PAYPAL_API_PASSWORD: ".preg_replace('/./', '*', $PAYPAL_API_PASSWORD), LOG_DEBUG); // No password into log files
  361. dol_syslog("PAYPAL_API_SIGNATURE: $PAYPAL_API_SIGNATURE", LOG_DEBUG);
  362. dol_syslog("PAYPAL_API_SANDBOX: $PAYPAL_API_SANDBOX", LOG_DEBUG);
  363. dol_syslog("PAYPAL_API_OK: $PAYPAL_API_OK", LOG_DEBUG);
  364. dol_syslog("PAYPAL_API_KO: $PAYPAL_API_KO", LOG_DEBUG);
  365. dol_syslog("PAYPAL_API_PRICE: $PAYPAL_API_PRICE", LOG_DEBUG);
  366. dol_syslog("PAYPAL_API_DEVISE: $PAYPAL_API_DEVISE", LOG_DEBUG);
  367. // All those fields may be empty when making a payment for a free amount for example
  368. dol_syslog("shipToName: $shipToName", LOG_DEBUG);
  369. dol_syslog("shipToStreet: $shipToStreet", LOG_DEBUG);
  370. dol_syslog("shipToCity: $shipToCity", LOG_DEBUG);
  371. dol_syslog("shipToState: $shipToState", LOG_DEBUG);
  372. dol_syslog("shipToCountryCode: $shipToCountryCode", LOG_DEBUG);
  373. dol_syslog("shipToZip: $shipToZip", LOG_DEBUG);
  374. dol_syslog("shipToStreet2: $shipToStreet2", LOG_DEBUG);
  375. dol_syslog("phoneNum: $phoneNum", LOG_DEBUG);
  376. dol_syslog("email: $email", LOG_DEBUG);
  377. dol_syslog("desc: $desc", LOG_DEBUG);
  378. dol_syslog("SCRIPT_URI: ".(empty($_SERVER["SCRIPT_URI"]) ? '' : $_SERVER["SCRIPT_URI"]), LOG_DEBUG); // If defined script uri must match domain of PAYPAL_API_OK and PAYPAL_API_KO
  379. // A redirect is added if API call successfull
  380. $mesg = print_paypal_redirect($PAYPAL_API_PRICE, $PAYPAL_API_DEVISE, $PAYPAL_PAYMENT_TYPE, $PAYPAL_API_OK, $PAYPAL_API_KO, $FULLTAG);
  381. // If we are here, it means the Paypal redirect was not done, so we show error message
  382. $action = '';
  383. }
  384. }
  385. if ($paymentmethod == 'paybox') {
  386. $PRICE = price2num(GETPOST("newamount"), 'MT');
  387. $email = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
  388. $thirdparty_id = GETPOST('thirdparty_id', 'int');
  389. $origfulltag = GETPOST("fulltag", 'alpha');
  390. // Securekey into back url useless for back url and we need an url lower than 150.
  391. $urlok = preg_replace('/securekey=[^&]+&?/', '', $urlok);
  392. $urlko = preg_replace('/securekey=[^&]+&?/', '', $urlko);
  393. if (empty($PRICE) || !is_numeric($PRICE)) {
  394. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount"));
  395. } elseif (empty($email)) {
  396. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ONLINE_PAYMENT_SENDEMAIL"));
  397. } elseif (!isValidEMail($email)) {
  398. $mesg = $langs->trans("ErrorBadEMail", $email);
  399. } elseif (!$origfulltag) {
  400. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentCode"));
  401. } elseif (dol_strlen($urlok) > 150) {
  402. $mesg = 'Error urlok too long '.$urlok.' (Paybox requires 150, found '.strlen($urlok).')';
  403. } elseif (dol_strlen($urlko) > 150) {
  404. $mesg = 'Error urlko too long '.$urlko.' (Paybox requires 150, found '.strlen($urlok).')';
  405. }
  406. if (empty($mesg)) {
  407. dol_syslog("newpayment.php call paybox api and do redirect", LOG_DEBUG);
  408. include_once DOL_DOCUMENT_ROOT.'/paybox/lib/paybox.lib.php';
  409. print_paybox_redirect($PRICE, $conf->currency, $email, $urlok, $urlko, $FULLTAG);
  410. session_destroy();
  411. exit;
  412. }
  413. }
  414. if ($paymentmethod == 'stripe') {
  415. if (GETPOST('newamount', 'alpha')) {
  416. $amount = price2num(GETPOST('newamount', 'alpha'), 'MT');
  417. } else {
  418. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
  419. $action = '';
  420. }
  421. }
  422. }
  423. // Called when choosing Stripe mode.
  424. // When using the old Charge API architecture, this code is called after clicking the 'dopayment' with the Charge API architecture.
  425. // When using the PaymentIntent API architecture, the Stripe customer was already created when creating PaymentIntent when showing payment page, and the payment is already ok when action=charge.
  426. if ($action == 'charge' && !empty($conf->stripe->enabled)) {
  427. $amountstripe = $amount;
  428. // Correct the amount according to unit of currency
  429. // See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
  430. $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
  431. if (!in_array($currency, $arrayzerounitcurrency)) {
  432. $amountstripe = $amountstripe * 100;
  433. }
  434. dol_syslog("--- newpayment.php Execute action = ".$action." STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION=".getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION'), LOG_DEBUG, 0, '_stripe');
  435. dol_syslog("GET=".var_export($_GET, true), LOG_DEBUG, 0, '_stripe');
  436. dol_syslog("POST=".var_export($_POST, true), LOG_DEBUG, 0, '_stripe');
  437. $stripeToken = GETPOST("stripeToken", 'alpha');
  438. $email = GETPOST("email", 'alpha');
  439. $thirdparty_id = GETPOST('thirdparty_id', 'int'); // Note that for payment following online registration for members, this is empty because thirdparty is created once payment is confirmed by paymentok.php
  440. $dol_type = (GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha'));
  441. $dol_id = GETPOST('dol_id', 'int');
  442. $vatnumber = GETPOST('vatnumber', 'alpha');
  443. $savesource = GETPOSTISSET('savesource') ? GETPOST('savesource', 'int') : 1;
  444. dol_syslog("POST stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_stripe');
  445. dol_syslog("POST email = ".$email, LOG_DEBUG, 0, '_stripe');
  446. dol_syslog("POST thirdparty_id = ".$thirdparty_id, LOG_DEBUG, 0, '_stripe');
  447. dol_syslog("POST vatnumber = ".$vatnumber, LOG_DEBUG, 0, '_stripe');
  448. $error = 0;
  449. $errormessage = '';
  450. // When using the old Charge API architecture
  451. if (!getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) {
  452. try {
  453. $metadata = array(
  454. 'dol_version' => DOL_VERSION,
  455. 'dol_entity' => $conf->entity,
  456. 'dol_company' => $mysoc->name, // Usefull when using multicompany
  457. 'dol_tax_num' => $vatnumber,
  458. 'ipaddress'=> getUserRemoteIP()
  459. );
  460. if (!empty($thirdparty_id)) {
  461. $metadata["dol_thirdparty_id"] = $thirdparty_id;
  462. }
  463. if ($thirdparty_id > 0) {
  464. dol_syslog("Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0, '_stripe');
  465. $service = 'StripeTest';
  466. $servicestatus = 0;
  467. if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'int')) {
  468. $service = 'StripeLive';
  469. $servicestatus = 1;
  470. }
  471. $thirdparty = new Societe($db);
  472. $thirdparty->fetch($thirdparty_id);
  473. // Create Stripe customer
  474. include_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
  475. $stripe = new Stripe($db);
  476. $stripeacc = $stripe->getStripeAccount($service);
  477. $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
  478. if (empty($customer)) {
  479. $error++;
  480. dol_syslog('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, LOG_ERR, 0, '_stripe');
  481. setEventMessages('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, null, 'errors');
  482. $action = '';
  483. }
  484. // Create Stripe card from Token
  485. if (!$error) {
  486. if ($savesource) {
  487. $card = $customer->sources->create(array("source" => $stripeToken, "metadata" => $metadata));
  488. } else {
  489. $card = $stripeToken;
  490. }
  491. if (empty($card)) {
  492. $error++;
  493. dol_syslog('Failed to create card record', LOG_WARNING, 0, '_stripe');
  494. setEventMessages('Failed to create card record', null, 'errors');
  495. $action = '';
  496. } else {
  497. if (!empty($FULLTAG)) {
  498. $metadata["FULLTAG"] = $FULLTAG;
  499. }
  500. if (!empty($dol_id)) {
  501. $metadata["dol_id"] = $dol_id;
  502. }
  503. if (!empty($dol_type)) {
  504. $metadata["dol_type"] = $dol_type;
  505. }
  506. dol_syslog("Create charge on card ".$card->id, LOG_DEBUG, 0, '_stripe');
  507. $charge = \Stripe\Charge::create(array(
  508. 'amount' => price2num($amountstripe, 'MU'),
  509. 'currency' => $currency,
  510. 'capture' => true, // Charge immediatly
  511. 'description' => 'Stripe payment: '.$FULLTAG.' ref='.$ref,
  512. 'metadata' => $metadata,
  513. 'customer' => $customer->id,
  514. 'source' => $card,
  515. 'statement_descriptor_suffix' => dol_trunc($FULLTAG, 10, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt (company + description)
  516. ), array("idempotency_key" => "$FULLTAG", "stripe_account" => "$stripeacc"));
  517. // Return $charge = array('id'=>'ch_XXXX', 'status'=>'succeeded|pending|failed', 'failure_code'=>, 'failure_message'=>...)
  518. if (empty($charge)) {
  519. $error++;
  520. dol_syslog('Failed to charge card', LOG_WARNING, 0, '_stripe');
  521. setEventMessages('Failed to charge card', null, 'errors');
  522. $action = '';
  523. }
  524. }
  525. }
  526. } else {
  527. $vatcleaned = $vatnumber ? $vatnumber : null;
  528. /*$taxinfo = array('type'=>'vat');
  529. if ($vatcleaned)
  530. {
  531. $taxinfo["tax_id"] = $vatcleaned;
  532. }
  533. // We force data to "null" if not defined as expected by Stripe
  534. if (empty($vatcleaned)) $taxinfo=null;
  535. */
  536. dol_syslog("Create anonymous customer card profile", LOG_DEBUG, 0, '_stripe');
  537. $customer = \Stripe\Customer::create(array(
  538. 'email' => $email,
  539. 'description' => ($email ? 'Anonymous customer for '.$email : 'Anonymous customer'),
  540. 'metadata' => $metadata,
  541. 'source' => $stripeToken // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?)
  542. ));
  543. // Return $customer = array('id'=>'cus_XXXX', ...)
  544. // Create the VAT record in Stripe
  545. /* We don't know country of customer, so we can't create tax
  546. if (! empty($conf->global->STRIPE_SAVE_TAX_IDS)) // We setup to save Tax info on Stripe side. Warning: This may result in error when saving customer
  547. {
  548. if (! empty($vatcleaned))
  549. {
  550. $isineec=isInEEC($object);
  551. if ($object->country_code && $isineec)
  552. {
  553. //$taxids = $customer->allTaxIds($customer->id);
  554. $customer->createTaxId($customer->id, array('type'=>'eu_vat', 'value'=>$vatcleaned));
  555. }
  556. }
  557. }*/
  558. if (!empty($FULLTAG)) {
  559. $metadata["FULLTAG"] = $FULLTAG;
  560. }
  561. if (!empty($dol_id)) {
  562. $metadata["dol_id"] = $dol_id;
  563. }
  564. if (!empty($dol_type)) {
  565. $metadata["dol_type"] = $dol_type;
  566. }
  567. // The customer was just created with a source, so we can make a charge
  568. // with no card defined, the source just used for customer creation will be used.
  569. dol_syslog("Create charge", LOG_DEBUG, 0, '_stripe');
  570. $charge = \Stripe\Charge::create(array(
  571. 'customer' => $customer->id,
  572. 'amount' => price2num($amountstripe, 'MU'),
  573. 'currency' => $currency,
  574. 'capture' => true, // Charge immediatly
  575. 'description' => 'Stripe payment: '.$FULLTAG.' ref='.$ref,
  576. 'metadata' => $metadata,
  577. 'statement_descriptor' => dol_trunc($FULLTAG, 10, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt (company + description)
  578. ), array("idempotency_key" => "$FULLTAG", "stripe_account" => "$stripeacc"));
  579. // Return $charge = array('id'=>'ch_XXXX', 'status'=>'succeeded|pending|failed', 'failure_code'=>, 'failure_message'=>...)
  580. if (empty($charge)) {
  581. $error++;
  582. dol_syslog('Failed to charge card', LOG_WARNING, 0, '_stripe');
  583. setEventMessages('Failed to charge card', null, 'errors');
  584. $action = '';
  585. }
  586. }
  587. } catch (\Stripe\Error\Card $e) {
  588. // Since it's a decline, \Stripe\Error\Card will be caught
  589. $body = $e->getJsonBody();
  590. $err = $body['error'];
  591. print('Status is:'.$e->getHttpStatus()."\n");
  592. print('Type is:'.$err['type']."\n");
  593. print('Code is:'.$err['code']."\n");
  594. // param is '' in this case
  595. print('Param is:'.$err['param']."\n");
  596. print('Message is:'.$err['message']."\n");
  597. $error++;
  598. $errormessage = "ErrorCard ".$e->getMessage()." err=".var_export($err, true);
  599. dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
  600. setEventMessages($e->getMessage(), null, 'errors');
  601. $action = '';
  602. } catch (\Stripe\Error\RateLimit $e) {
  603. // Too many requests made to the API too quickly
  604. $error++;
  605. $errormessage = "ErrorRateLimit ".$e->getMessage();
  606. dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
  607. setEventMessages($e->getMessage(), null, 'errors');
  608. $action = '';
  609. } catch (\Stripe\Error\InvalidRequest $e) {
  610. // Invalid parameters were supplied to Stripe's API
  611. $error++;
  612. $errormessage = "ErrorInvalidRequest ".$e->getMessage();
  613. dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
  614. setEventMessages($e->getMessage(), null, 'errors');
  615. $action = '';
  616. } catch (\Stripe\Error\Authentication $e) {
  617. // Authentication with Stripe's API failed
  618. // (maybe you changed API keys recently)
  619. $error++;
  620. $errormessage = "ErrorAuthentication ".$e->getMessage();
  621. dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
  622. setEventMessages($e->getMessage(), null, 'errors');
  623. $action = '';
  624. } catch (\Stripe\Error\ApiConnection $e) {
  625. // Network communication with Stripe failed
  626. $error++;
  627. $errormessage = "ErrorApiConnection ".$e->getMessage();
  628. dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
  629. setEventMessages($e->getMessage(), null, 'errors');
  630. $action = '';
  631. } catch (\Stripe\Error\Base $e) {
  632. // Display a very generic error to the user, and maybe send
  633. // yourself an email
  634. $error++;
  635. $errormessage = "ErrorBase ".$e->getMessage();
  636. dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
  637. setEventMessages($e->getMessage(), null, 'errors');
  638. $action = '';
  639. } catch (Exception $e) {
  640. // Something else happened, completely unrelated to Stripe
  641. $error++;
  642. $errormessage = "ErrorException ".$e->getMessage();
  643. dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
  644. setEventMessages($e->getMessage(), null, 'errors');
  645. $action = '';
  646. }
  647. }
  648. // When using the PaymentIntent API architecture (mode set on by default into conf.class.php)
  649. if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) {
  650. $service = 'StripeTest';
  651. $servicestatus = 0;
  652. if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'int')) {
  653. $service = 'StripeLive';
  654. $servicestatus = 1;
  655. }
  656. include_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
  657. $stripe = new Stripe($db);
  658. $stripeacc = $stripe->getStripeAccount($service);
  659. // We go here if $conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION is set.
  660. // In such a case, payment is always ok when we call the "charge" action.
  661. $paymentintent_id = GETPOST("paymentintent_id", "alpha");
  662. // Force to use the correct API key
  663. global $stripearrayofkeysbyenv;
  664. \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']);
  665. try {
  666. if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
  667. $paymentintent = \Stripe\PaymentIntent::retrieve($paymentintent_id);
  668. } else {
  669. $paymentintent = \Stripe\PaymentIntent::retrieve($paymentintent_id, array("stripe_account" => $stripeacc));
  670. }
  671. } catch (Exception $e) {
  672. $error++;
  673. $errormessage = "CantRetrievePaymentIntent ".$e->getMessage();
  674. dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
  675. setEventMessages($e->getMessage(), null, 'errors');
  676. $action = '';
  677. }
  678. if ($paymentintent->status != 'succeeded') {
  679. $error++;
  680. $errormessage = "StatusOfRetrievedIntent is not succeeded: ".$paymentintent->status;
  681. dol_syslog($errormessage, LOG_WARNING, 0, '_stripe');
  682. setEventMessages($paymentintent->status, null, 'errors');
  683. $action = '';
  684. } else {
  685. // TODO We can also record the payment mode into llx_societe_rib with stripe $paymentintent->payment_method
  686. // Note that with other old Stripe architecture (using Charge API), the payment mode was not recorded, so it is not mandatory to do it here.
  687. //dol_syslog("Create payment_method for ".$paymentintent->payment_method, LOG_DEBUG, 0, '_stripe');
  688. // Get here amount and currency used for payment and force value into $amount and $currency so the real amount is saved into session instead
  689. // of the amount and currency retreived from the POST.
  690. if (!empty($paymentintent->currency) && !empty($paymentintent->amount)) {
  691. $currency = strtoupper($paymentintent->currency);
  692. $amount = $paymentintent->amount;
  693. // Correct the amount according to unit of currency
  694. // See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
  695. $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
  696. if (!in_array($currency, $arrayzerounitcurrency)) {
  697. $amount = $amount / 100;
  698. }
  699. }
  700. }
  701. }
  702. $remoteip = getUserRemoteIP();
  703. $_SESSION["onlinetoken"] = $stripeToken;
  704. $_SESSION["FinalPaymentAmt"] = $amount; // amount really paid (coming from Stripe). Will be used for check in paymentok.php.
  705. $_SESSION["currencyCodeType"] = $currency; // currency really used for payment (coming from Stripe). Will be used for check in paymentok.php.
  706. $_SESSION["paymentType"] = '';
  707. $_SESSION['ipaddress'] = ($remoteip ? $remoteip : 'unknown'); // Payer ip
  708. $_SESSION['payerID'] = is_object($customer) ? $customer->id : '';
  709. $_SESSION['TRANSACTIONID'] = (is_object($charge) ? $charge->id : (is_object($paymentintent) ? $paymentintent->id : ''));
  710. $_SESSION['errormessage'] = $errormessage;
  711. dol_syslog("Action charge stripe STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION=".getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')." ip=".$remoteip, LOG_DEBUG, 0, '_stripe');
  712. dol_syslog("onlinetoken=".$_SESSION["onlinetoken"]." FinalPaymentAmt=".$_SESSION["FinalPaymentAmt"]." currencyCodeType=".$_SESSION["currencyCodeType"]." payerID=".$_SESSION['payerID']." TRANSACTIONID=".$_SESSION['TRANSACTIONID'], LOG_DEBUG, 0, '_stripe');
  713. dol_syslog("FULLTAG=".$FULLTAG, LOG_DEBUG, 0, '_stripe');
  714. dol_syslog("error=".$error." errormessage=".$errormessage, LOG_DEBUG, 0, '_stripe');
  715. dol_syslog("Now call the redirect to paymentok or paymentko, URL = ".($error ? $urlko : $urlok), LOG_DEBUG, 0, '_stripe');
  716. if ($error) {
  717. header("Location: ".$urlko);
  718. exit;
  719. } else {
  720. header("Location: ".$urlok);
  721. exit;
  722. }
  723. }
  724. /*
  725. * View
  726. */
  727. $form = new Form($db);
  728. $head = '';
  729. if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
  730. $head = '<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
  731. }
  732. $conf->dol_hide_topmenu = 1;
  733. $conf->dol_hide_leftmenu = 1;
  734. $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
  735. llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
  736. // Check link validity
  737. if ($source && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', 'donation_ref', ''))) {
  738. $langs->load("errors");
  739. dol_print_error_email('BADREFINPAYMENTFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $source, $ref));
  740. // End of page
  741. llxFooter();
  742. $db->close();
  743. exit;
  744. }
  745. // Show sandbox warning
  746. if ((empty($paymentmethod) || $paymentmethod == 'paypal') && !empty($conf->paypal->enabled) && (!empty($conf->global->PAYPAL_API_SANDBOX) || GETPOST('forcesandbox', 'int'))) { // We can force sand box with param 'forcesandbox'
  747. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Paypal'), '', 'warning');
  748. }
  749. if ((empty($paymentmethod) || $paymentmethod == 'stripe') && !empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'int'))) {
  750. dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
  751. }
  752. print '<span id="dolpaymentspan"></span>'."\n";
  753. print '<div class="center">'."\n";
  754. print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
  755. print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  756. print '<input type="hidden" name="action" value="dopayment">'."\n";
  757. print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
  758. print '<input type="hidden" name="suffix" value="'.dol_escape_htmltag($suffix).'">'."\n";
  759. print '<input type="hidden" name="securekey" value="'.dol_escape_htmltag($SECUREKEY).'">'."\n";
  760. print '<input type="hidden" name="e" value="'.$entity.'" />';
  761. print '<input type="hidden" name="forcesandbox" value="'.GETPOST('forcesandbox', 'int').'" />';
  762. print "\n";
  763. // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
  764. // Define logo and logosmall
  765. $logosmall = $mysoc->logo_small;
  766. $logo = $mysoc->logo;
  767. $paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
  768. if (!empty($conf->global->$paramlogo)) {
  769. $logosmall = $conf->global->$paramlogo;
  770. } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
  771. $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
  772. }
  773. //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
  774. // Define urllogo
  775. $urllogo = '';
  776. $urllogofull = '';
  777. if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
  778. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
  779. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
  780. } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
  781. $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
  782. $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
  783. }
  784. // Output html code for logo
  785. if ($urllogo) {
  786. print '<div class="backgreypublicpayment">';
  787. print '<div class="logopublicpayment">';
  788. print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
  789. print '>';
  790. print '</div>';
  791. if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
  792. 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>';
  793. }
  794. print '</div>';
  795. }
  796. if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
  797. print '<div class="backimagepublicpayment">';
  798. print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.'">';
  799. print '</div>';
  800. }
  801. print '<!-- Form to send a payment -->'."\n";
  802. print '<!-- creditor = '.dol_escape_htmltag($creditor).' -->'."\n";
  803. // Additionnal information for each payment system
  804. if (!empty($conf->paypal->enabled)) {
  805. print '<!-- PAYPAL_API_SANDBOX = '.$conf->global->PAYPAL_API_SANDBOX.' -->'."\n";
  806. print '<!-- PAYPAL_API_INTEGRAL_OR_PAYPALONLY = '.$conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY.' -->'."\n";
  807. }
  808. if (!empty($conf->paybox->enabled)) {
  809. print '<!-- PAYBOX_CGI_URL = '.$conf->global->PAYBOX_CGI_URL_V2.' -->'."\n";
  810. }
  811. if (!empty($conf->stripe->enabled)) {
  812. print '<!-- STRIPE_LIVE = '.$conf->global->STRIPE_LIVE.' -->'."\n";
  813. }
  814. print '<!-- urlok = '.$urlok.' -->'."\n";
  815. print '<!-- urlko = '.$urlko.' -->'."\n";
  816. print "\n";
  817. // Section with payment informationsummary
  818. print '<table id="dolpublictable" summary="Payment form" class="center">'."\n";
  819. // Output introduction text
  820. $text = '';
  821. if (!empty($conf->global->PAYMENT_NEWFORM_TEXT)) {
  822. $langs->load("members");
  823. if (preg_match('/^\((.*)\)$/', $conf->global->PAYMENT_NEWFORM_TEXT, $reg)) {
  824. $text .= $langs->trans($reg[1])."<br>\n";
  825. } else {
  826. $text .= $conf->global->PAYMENT_NEWFORM_TEXT."<br>\n";
  827. }
  828. $text = '<tr><td align="center"><br>'.$text.'<br></td></tr>'."\n";
  829. }
  830. if (empty($text)) {
  831. $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnPaymentPage").'</strong></td></tr>'."\n";
  832. $text .= '<tr><td class="textpublicpayment">'.$langs->trans("ThisScreenAllowsYouToPay", $creditor).'<br><br></td></tr>'."\n";
  833. }
  834. print $text;
  835. // Output payment summary form
  836. print '<tr><td align="center">';
  837. print '<table with="100%" id="tablepublicpayment">';
  838. print '<tr><td align="left" colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnPayment").' :</td></tr>'."\n";
  839. $found = false;
  840. $error = 0;
  841. $object = null;
  842. // Free payment
  843. if (!$source) {
  844. $found = true;
  845. $tag = GETPOST("tag", 'alpha');
  846. if (GETPOST('fulltag', 'alpha')) {
  847. $fulltag = GETPOST('fulltag', 'alpha');
  848. } else {
  849. $fulltag = "TAG=".$tag;
  850. }
  851. // Creditor
  852. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  853. print '</td><td class="CTableRow2">';
  854. print img_picto('', 'company', 'class="pictofixedwidth"');
  855. print '<b>'.$creditor.'</b>';
  856. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  857. print '</td></tr>'."\n";
  858. // Amount
  859. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
  860. if (empty($amount)) {
  861. print ' ('.$langs->trans("ToComplete").')';
  862. }
  863. print '</td><td class="CTableRow2">';
  864. if (empty($amount) || !is_numeric($amount)) {
  865. print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
  866. print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
  867. // Currency
  868. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  869. } else {
  870. print '<b class="amount">'.price($amount, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
  871. print '<input type="hidden" name="amount" value="'.$amount.'">';
  872. print '<input type="hidden" name="newamount" value="'.$amount.'">';
  873. }
  874. print '<input type="hidden" name="currency" value="'.$currency.'">';
  875. print '</td></tr>'."\n";
  876. // Tag
  877. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
  878. print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
  879. print '<input type="hidden" name="tag" value="'.$tag.'">';
  880. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  881. print '</td></tr>'."\n";
  882. // We do not add fields shipToName, shipToStreet, shipToCity, shipToState, shipToCountryCode, shipToZip, shipToStreet2, phoneNum
  883. // as they don't exists (buyer is unknown, tag is free).
  884. }
  885. // Added by MMI Mathieu Moulin iProspective
  886. // Payment on customer propal
  887. if ($source == 'propal') {
  888. $found = true;
  889. $langs->load("propal");
  890. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  891. $propal = new Propal($db);
  892. $result = $propal->fetch('', $ref);
  893. if ($result <= 0) {
  894. $mesg = $propal->error;
  895. $error++;
  896. } else {
  897. $result = $propal->fetch_thirdparty($propal->socid);
  898. }
  899. $object = $propal;
  900. if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
  901. $dejaregle = $propal->getSommePaiement();
  902. $amount = max(0, $propal->total_ttc - $dejaregle);
  903. $paye = $propal->paye();
  904. if (GETPOST("amount", 'alpha')) {
  905. $amount = GETPOST("amount", 'alpha');
  906. }
  907. $amount = price2num($amount);
  908. }
  909. if (GETPOST('fulltag', 'alpha')) {
  910. $fulltag = GETPOST('fulltag', 'alpha');
  911. } else {
  912. $fulltag = 'PRO='.$propal->id.'.CUS='.$propal->thirdparty->id;
  913. if (!empty($TAG)) {
  914. $tag = $TAG; $fulltag .= '.TAG='.$TAG;
  915. }
  916. }
  917. $fulltag = dol_string_unaccent($fulltag);
  918. // Creditor
  919. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  920. print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
  921. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  922. print '</td></tr>'."\n";
  923. // Debitor
  924. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
  925. print '</td><td class="CTableRow2"><b>'.$propal->thirdparty->name.'</b>';
  926. print '</td></tr>'."\n";
  927. // Object
  928. $text = '<b>'.$langs->trans("PaymentPropalRef", $propal->ref).'</b>';
  929. if (GETPOST('desc', 'alpha')) {
  930. $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
  931. }
  932. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  933. print '</td><td class="CTableRow2">'.$text;
  934. print '<input type="hidden" name="s" value="'.dol_escape_htmltag($source).'">';
  935. print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($propal->ref).'">';
  936. print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag($propal->id).'">';
  937. $directdownloadlink = $propal->getLastMainDocLink('propal');
  938. if ($directdownloadlink) {
  939. print '<br><a href="'.$directdownloadlink.'" rel="nofollow noopener">';
  940. print img_mime($propal->last_main_doc, '');
  941. print $langs->trans("DownloadDocument").'</a>';
  942. }
  943. print '</td></tr>'."\n";
  944. // MMI
  945. if ($dejaregle) {
  946. // Total
  947. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountTotal");
  948. print '</td><td class="CTableRow2">';
  949. print '<b>'.price2num($propal->total_ttc).'</b>';
  950. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  951. print '</td></tr>'."\n";
  952. // Déjà réglé
  953. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountAlreadyPaid");
  954. print '</td><td class="CTableRow2">';
  955. print '<b>'.price2num($dejaregle).'</b>';
  956. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  957. print '</td></tr>'."\n";
  958. }
  959. if (! $paye) {
  960. // Amount
  961. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountPayment");
  962. if (empty($amount)) {
  963. print ' ('.$langs->trans("ToComplete").')';
  964. }
  965. print '</td><td class="CTableRow2">';
  966. if (empty($amount) || !is_numeric($amount)) {
  967. print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
  968. print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
  969. } else {
  970. print '<b>'.price($amount).'</b>';
  971. print '<input type="hidden" name="amount" value="'.$amount.'">';
  972. print '<input type="hidden" name="newamount" value="'.$amount.'">';
  973. }
  974. // Currency
  975. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  976. print '<input type="hidden" name="currency" value="'.$currency.'">';
  977. print '</td></tr>'."\n";
  978. // Tag
  979. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
  980. print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
  981. print '<input type="hidden" name="tag" value="'.dol_escape_htmltag($tag).'">';
  982. print '<input type="hidden" name="fulltag" value="'.dol_escape_htmltag($fulltag).'">';
  983. print '</td></tr>'."\n";
  984. }
  985. // Shipping address
  986. $shipToName = $propal->thirdparty->name;
  987. $shipToStreet = $propal->thirdparty->address;
  988. $shipToCity = $propal->thirdparty->town;
  989. $shipToState = $propal->thirdparty->state_code;
  990. $shipToCountryCode = $propal->thirdparty->country_code;
  991. $shipToZip = $propal->thirdparty->zip;
  992. $shipToStreet2 = '';
  993. $phoneNum = $propal->thirdparty->phone;
  994. if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
  995. print '<input type="hidden" name="shipToName" value="'.dol_escape_htmltag($shipToName).'">'."\n";
  996. print '<input type="hidden" name="shipToStreet" value="'.dol_escape_htmltag($shipToStreet).'">'."\n";
  997. print '<input type="hidden" name="shipToCity" value="'.dol_escape_htmltag($shipToCity).'">'."\n";
  998. print '<input type="hidden" name="shipToState" value="'.dol_escape_htmltag($shipToState).'">'."\n";
  999. print '<input type="hidden" name="shipToCountryCode" value="'.dol_escape_htmltag($shipToCountryCode).'">'."\n";
  1000. print '<input type="hidden" name="shipToZip" value="'.dol_escape_htmltag($shipToZip).'">'."\n";
  1001. print '<input type="hidden" name="shipToStreet2" value="'.dol_escape_htmltag($shipToStreet2).'">'."\n";
  1002. print '<input type="hidden" name="phoneNum" value="'.dol_escape_htmltag($phoneNum).'">'."\n";
  1003. } else {
  1004. print '<!-- Shipping address not complete, so we don t use it -->'."\n";
  1005. }
  1006. if (is_object($propal->thirdparty)) {
  1007. print '<input type="hidden" name="thirdparty_id" value="'.$propal->thirdparty->id.'">'."\n";
  1008. }
  1009. print '<input type="hidden" name="email" value="'.$propal->thirdparty->email.'">'."\n";
  1010. print '<input type="hidden" name="vatnumber" value="'.dol_escape_htmltag($propal->thirdparty->tva_intra).'">'."\n";
  1011. $labeldesc = $langs->trans("Propal").' '.$propal->ref;
  1012. if (GETPOST('desc', 'alpha')) {
  1013. $labeldesc = GETPOST('desc', 'alpha');
  1014. }
  1015. print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
  1016. }
  1017. // Payment on customer order
  1018. if ($source == 'order') {
  1019. $found = true;
  1020. $langs->load("orders");
  1021. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  1022. $order = new Commande($db);
  1023. $result = $order->fetch('', $ref);
  1024. if ($result <= 0) {
  1025. $mesg = $order->error;
  1026. $error++;
  1027. } else {
  1028. $result = $order->fetch_thirdparty($order->socid);
  1029. }
  1030. $object = $order;
  1031. if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
  1032. // Added by MMI Mathieu Moulin iProspective
  1033. $dejaregle = $order->getSommePaiement();
  1034. $amount = max(0, $order->total_ttc - $dejaregle);
  1035. $paye = $order->paye();
  1036. if (GETPOST("amount", 'alpha')) {
  1037. $amount = GETPOST("amount", 'alpha');
  1038. }
  1039. $amount = price2num($amount);
  1040. }
  1041. if (GETPOST('fulltag', 'alpha')) {
  1042. $fulltag = GETPOST('fulltag', 'alpha');
  1043. } else {
  1044. $fulltag = 'ORD='.$order->id.'.CUS='.$order->thirdparty->id;
  1045. if (!empty($TAG)) {
  1046. $tag = $TAG; $fulltag .= '.TAG='.$TAG;
  1047. }
  1048. }
  1049. $fulltag = dol_string_unaccent($fulltag);
  1050. // Creditor
  1051. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  1052. print '</td><td class="CTableRow2">';
  1053. print img_picto('', 'company', 'class="pictofixedwidth"');
  1054. print '<b>'.$creditor.'</b>';
  1055. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  1056. print '</td></tr>'."\n";
  1057. // Debitor
  1058. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
  1059. print '</td><td class="CTableRow2">';
  1060. print img_picto('', 'company', 'class="pictofixedwidth"');
  1061. print '<b>'.$order->thirdparty->name.'</b>';
  1062. print '</td></tr>'."\n";
  1063. // Object
  1064. $text = '<b>'.$langs->trans("PaymentOrderRef", $order->ref).'</b>';
  1065. if (GETPOST('desc', 'alpha')) {
  1066. $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
  1067. }
  1068. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  1069. print '</td><td class="CTableRow2">'.$text;
  1070. print '<input type="hidden" name="s" value="'.dol_escape_htmltag($source).'">';
  1071. print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($order->ref).'">';
  1072. print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag($order->id).'">';
  1073. $directdownloadlink = $order->getLastMainDocLink('commande');
  1074. if ($directdownloadlink) {
  1075. print '<br><a href="'.$directdownloadlink.'" rel="nofollow noopener">';
  1076. print img_mime($order->last_main_doc, '');
  1077. print $langs->trans("DownloadDocument").'</a>';
  1078. }
  1079. print '</td></tr>'."\n";
  1080. // Added by MMI Mathieu Moulin iProspective
  1081. if ($dejaregle) {
  1082. // Total
  1083. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountTotal");
  1084. print '</td><td class="CTableRow2">';
  1085. print '<b>'.price2num($order->total_ttc).'</b>';
  1086. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  1087. print '</td></tr>'."\n";
  1088. // Déjà réglé
  1089. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountAlreadyPaid");
  1090. print '</td><td class="CTableRow2">';
  1091. print '<b>'.price2num($dejaregle).'</b>';
  1092. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  1093. print '</td></tr>'."\n";
  1094. }
  1095. if (! $paye) {
  1096. // Amount
  1097. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("AmountPayment");
  1098. if (empty($amount)) {
  1099. print ' ('.$langs->trans("ToComplete").')';
  1100. }
  1101. print '</td><td class="CTableRow2">';
  1102. if (empty($amount) || !is_numeric($amount)) {
  1103. print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
  1104. print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
  1105. // Currency
  1106. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  1107. } else {
  1108. print '<b class="amount">'.price($amount, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
  1109. print '<input type="hidden" name="amount" value="'.$amount.'">';
  1110. print '<input type="hidden" name="newamount" value="'.$amount.'">';
  1111. }
  1112. print '<input type="hidden" name="currency" value="'.$currency.'">';
  1113. print '</td></tr>'."\n";
  1114. // Tag
  1115. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
  1116. print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
  1117. print '<input type="hidden" name="tag" value="'.dol_escape_htmltag($tag).'">';
  1118. print '<input type="hidden" name="fulltag" value="'.dol_escape_htmltag($fulltag).'">';
  1119. print '</td></tr>'."\n";
  1120. }
  1121. // Shipping address
  1122. $shipToName = $order->thirdparty->name;
  1123. $shipToStreet = $order->thirdparty->address;
  1124. $shipToCity = $order->thirdparty->town;
  1125. $shipToState = $order->thirdparty->state_code;
  1126. $shipToCountryCode = $order->thirdparty->country_code;
  1127. $shipToZip = $order->thirdparty->zip;
  1128. $shipToStreet2 = '';
  1129. $phoneNum = $order->thirdparty->phone;
  1130. if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
  1131. print '<input type="hidden" name="shipToName" value="'.dol_escape_htmltag($shipToName).'">'."\n";
  1132. print '<input type="hidden" name="shipToStreet" value="'.dol_escape_htmltag($shipToStreet).'">'."\n";
  1133. print '<input type="hidden" name="shipToCity" value="'.dol_escape_htmltag($shipToCity).'">'."\n";
  1134. print '<input type="hidden" name="shipToState" value="'.dol_escape_htmltag($shipToState).'">'."\n";
  1135. print '<input type="hidden" name="shipToCountryCode" value="'.dol_escape_htmltag($shipToCountryCode).'">'."\n";
  1136. print '<input type="hidden" name="shipToZip" value="'.dol_escape_htmltag($shipToZip).'">'."\n";
  1137. print '<input type="hidden" name="shipToStreet2" value="'.dol_escape_htmltag($shipToStreet2).'">'."\n";
  1138. print '<input type="hidden" name="phoneNum" value="'.dol_escape_htmltag($phoneNum).'">'."\n";
  1139. } else {
  1140. print '<!-- Shipping address not complete, so we don t use it -->'."\n";
  1141. }
  1142. if (is_object($order->thirdparty)) {
  1143. print '<input type="hidden" name="thirdparty_id" value="'.$order->thirdparty->id.'">'."\n";
  1144. }
  1145. print '<input type="hidden" name="email" value="'.$order->thirdparty->email.'">'."\n";
  1146. print '<input type="hidden" name="vatnumber" value="'.dol_escape_htmltag($order->thirdparty->tva_intra).'">'."\n";
  1147. $labeldesc = $langs->trans("Order").' '.$order->ref;
  1148. if (GETPOST('desc', 'alpha')) {
  1149. $labeldesc = GETPOST('desc', 'alpha');
  1150. }
  1151. print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
  1152. }
  1153. // Payment on customer invoice
  1154. if ($source == 'invoice') {
  1155. $found = true;
  1156. $langs->load("bills");
  1157. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  1158. $invoice = new Facture($db);
  1159. $result = $invoice->fetch('', $ref);
  1160. if ($result <= 0) {
  1161. $mesg = $invoice->error;
  1162. $error++;
  1163. } else {
  1164. $result = $invoice->fetch_thirdparty($invoice->socid);
  1165. }
  1166. $object = $invoice;
  1167. if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
  1168. $amount = price2num($invoice->total_ttc - ($invoice->getSommePaiement() + $invoice->getSumCreditNotesUsed() + $invoice->getSumDepositsUsed()));
  1169. if (GETPOST("amount", 'alpha')) {
  1170. $amount = GETPOST("amount", 'alpha');
  1171. }
  1172. $amount = price2num($amount);
  1173. }
  1174. if (GETPOST('fulltag', 'alpha')) {
  1175. $fulltag = GETPOST('fulltag', 'alpha');
  1176. } else {
  1177. $fulltag = 'INV='.$invoice->id.'.CUS='.$invoice->thirdparty->id;
  1178. if (!empty($TAG)) {
  1179. $tag = $TAG; $fulltag .= '.TAG='.$TAG;
  1180. }
  1181. }
  1182. $fulltag = dol_string_unaccent($fulltag);
  1183. // Creditor
  1184. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  1185. print '</td><td class="CTableRow2">';
  1186. print img_picto('', 'company', 'class="pictofixedwidth"');
  1187. print '<b>'.$creditor.'</b>';
  1188. print '<input type="hidden" name="creditor" value="'.dol_escape_htmltag($creditor).'">';
  1189. print '</td></tr>'."\n";
  1190. // Debitor
  1191. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
  1192. print '</td><td class="CTableRow2">';
  1193. print img_picto('', 'company', 'class="pictofixedwidth"');
  1194. print '<b>'.$invoice->thirdparty->name.'</b>';
  1195. print '</td></tr>'."\n";
  1196. // Object
  1197. $text = '<b>'.$langs->trans("PaymentInvoiceRef", $invoice->ref).'</b>';
  1198. if (GETPOST('desc', 'alpha')) {
  1199. $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
  1200. }
  1201. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  1202. print '</td><td class="CTableRow2">'.$text;
  1203. print '<input type="hidden" name="s" value="'.dol_escape_htmltag($source).'">';
  1204. print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($invoice->ref).'">';
  1205. print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag($invoice->id).'">';
  1206. $directdownloadlink = $invoice->getLastMainDocLink('facture');
  1207. if ($directdownloadlink) {
  1208. print '<br><a href="'.$directdownloadlink.'">';
  1209. print img_mime($invoice->last_main_doc, '');
  1210. print $langs->trans("DownloadDocument").'</a>';
  1211. }
  1212. print '</td></tr>'."\n";
  1213. // Amount
  1214. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentAmount");
  1215. if (empty($amount) && empty($object->paye)) {
  1216. print ' ('.$langs->trans("ToComplete").')';
  1217. }
  1218. print '</td><td class="CTableRow2">';
  1219. if ($object->type == $object::TYPE_CREDIT_NOTE) {
  1220. print '<b>'.$langs->trans("CreditNote").'</b>';
  1221. } elseif (empty($object->paye)) {
  1222. if (empty($amount) || !is_numeric($amount)) {
  1223. print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
  1224. print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
  1225. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  1226. } else {
  1227. print '<b class="amount">'.price($amount, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
  1228. print '<input type="hidden" name="amount" value="'.$amount.'">';
  1229. print '<input type="hidden" name="newamount" value="'.$amount.'">';
  1230. }
  1231. } else {
  1232. print '<b class="amount">'.price($object->total_ttc, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
  1233. }
  1234. print '<input type="hidden" name="currency" value="'.$currency.'">';
  1235. print '</td></tr>'."\n";
  1236. // Tag
  1237. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
  1238. print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
  1239. print '<input type="hidden" name="tag" value="'.$tag.'">';
  1240. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  1241. print '</td></tr>'."\n";
  1242. // Shipping address
  1243. $shipToName = $invoice->thirdparty->name;
  1244. $shipToStreet = $invoice->thirdparty->address;
  1245. $shipToCity = $invoice->thirdparty->town;
  1246. $shipToState = $invoice->thirdparty->state_code;
  1247. $shipToCountryCode = $invoice->thirdparty->country_code;
  1248. $shipToZip = $invoice->thirdparty->zip;
  1249. $shipToStreet2 = '';
  1250. $phoneNum = $invoice->thirdparty->phone;
  1251. if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
  1252. print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
  1253. print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
  1254. print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
  1255. print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
  1256. print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
  1257. print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
  1258. print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
  1259. print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
  1260. } else {
  1261. print '<!-- Shipping address not complete, so we don t use it -->'."\n";
  1262. }
  1263. if (is_object($invoice->thirdparty)) {
  1264. print '<input type="hidden" name="thirdparty_id" value="'.$invoice->thirdparty->id.'">'."\n";
  1265. }
  1266. print '<input type="hidden" name="email" value="'.$invoice->thirdparty->email.'">'."\n";
  1267. print '<input type="hidden" name="vatnumber" value="'.$invoice->thirdparty->tva_intra.'">'."\n";
  1268. $labeldesc = $langs->trans("Invoice").' '.$invoice->ref;
  1269. if (GETPOST('desc', 'alpha')) {
  1270. $labeldesc = GETPOST('desc', 'alpha');
  1271. }
  1272. print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
  1273. }
  1274. // Payment on contract line
  1275. if ($source == 'contractline') {
  1276. $found = true;
  1277. $langs->load("contracts");
  1278. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  1279. $contract = new Contrat($db);
  1280. $contractline = new ContratLigne($db);
  1281. $result = $contractline->fetch('', $ref);
  1282. if ($result <= 0) {
  1283. $mesg = $contractline->error;
  1284. $error++;
  1285. } else {
  1286. if ($contractline->fk_contrat > 0) {
  1287. $result = $contract->fetch($contractline->fk_contrat);
  1288. if ($result > 0) {
  1289. $result = $contract->fetch_thirdparty($contract->socid);
  1290. } else {
  1291. $mesg = $contract->error;
  1292. $error++;
  1293. }
  1294. } else {
  1295. $mesg = 'ErrorRecordNotFound';
  1296. $error++;
  1297. }
  1298. }
  1299. $object = $contractline;
  1300. if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
  1301. $amount = $contractline->total_ttc;
  1302. if ($contractline->fk_product && !empty($conf->global->PAYMENT_USE_NEW_PRICE_FOR_CONTRACTLINES)) {
  1303. $product = new Product($db);
  1304. $result = $product->fetch($contractline->fk_product);
  1305. // We define price for product (TODO Put this in a method in product class)
  1306. if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
  1307. $pu_ht = $product->multiprices[$contract->thirdparty->price_level];
  1308. $pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level];
  1309. $price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level];
  1310. } else {
  1311. $pu_ht = $product->price;
  1312. $pu_ttc = $product->price_ttc;
  1313. $price_base_type = $product->price_base_type;
  1314. }
  1315. $amount = $pu_ttc;
  1316. if (empty($amount)) {
  1317. dol_print_error('', 'ErrorNoPriceDefinedForThisProduct');
  1318. exit;
  1319. }
  1320. }
  1321. if (GETPOST("amount", 'alpha')) {
  1322. $amount = GETPOST("amount", 'alpha');
  1323. }
  1324. $amount = price2num($amount);
  1325. }
  1326. if (GETPOST('fulltag', 'alpha')) {
  1327. $fulltag = GETPOST('fulltag', 'alpha');
  1328. } else {
  1329. $fulltag = 'COL='.$contractline->id.'.CON='.$contract->id.'.CUS='.$contract->thirdparty->id.'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
  1330. if (!empty($TAG)) {
  1331. $tag = $TAG; $fulltag .= '.TAG='.$TAG;
  1332. }
  1333. }
  1334. $fulltag = dol_string_unaccent($fulltag);
  1335. $qty = 1;
  1336. if (GETPOST('qty')) {
  1337. $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
  1338. }
  1339. // Creditor
  1340. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  1341. print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
  1342. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  1343. print '</td></tr>'."\n";
  1344. // Debitor
  1345. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
  1346. print '</td><td class="CTableRow2"><b>'.$contract->thirdparty->name.'</b>';
  1347. print '</td></tr>'."\n";
  1348. // Object
  1349. $text = '<b>'.$langs->trans("PaymentRenewContractId", $contract->ref, $contractline->ref).'</b>';
  1350. if ($contractline->fk_product > 0) {
  1351. $contractline->fetch_product();
  1352. $text .= '<br>'.$contractline->product->ref.($contractline->product->label ? ' - '.$contractline->product->label : '');
  1353. }
  1354. if ($contractline->description) {
  1355. $text .= '<br>'.dol_htmlentitiesbr($contractline->description);
  1356. }
  1357. //if ($contractline->date_fin_validite) {
  1358. // $text.='<br>'.$langs->trans("DateEndPlanned").': ';
  1359. // $text.=dol_print_date($contractline->date_fin_validite);
  1360. //}
  1361. if ($contractline->date_end) {
  1362. $text .= '<br>'.$langs->trans("ExpiredSince").': '.dol_print_date($contractline->date_end);
  1363. }
  1364. if (GETPOST('desc', 'alpha')) {
  1365. $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
  1366. }
  1367. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  1368. print '</td><td class="CTableRow2">'.$text;
  1369. print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
  1370. print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($contractline->ref).'">';
  1371. print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag($contractline->id).'">';
  1372. $directdownloadlink = $contract->getLastMainDocLink('contract');
  1373. if ($directdownloadlink) {
  1374. print '<br><a href="'.$directdownloadlink.'">';
  1375. print img_mime($contract->last_main_doc, '');
  1376. print $langs->trans("DownloadDocument").'</a>';
  1377. }
  1378. print '</td></tr>'."\n";
  1379. // Quantity
  1380. $label = $langs->trans("Quantity");
  1381. $qty = 1;
  1382. $duration = '';
  1383. if ($contractline->fk_product) {
  1384. if ($contractline->product->isService() && $contractline->product->duration_value > 0) {
  1385. $label = $langs->trans("Duration");
  1386. // TODO Put this in a global method
  1387. if ($contractline->product->duration_value > 1) {
  1388. $dur = array("h"=>$langs->trans("Hours"), "d"=>$langs->trans("DurationDays"), "w"=>$langs->trans("DurationWeeks"), "m"=>$langs->trans("DurationMonths"), "y"=>$langs->trans("DurationYears"));
  1389. } else {
  1390. $dur = array("h"=>$langs->trans("Hour"), "d"=>$langs->trans("DurationDay"), "w"=>$langs->trans("DurationWeek"), "m"=>$langs->trans("DurationMonth"), "y"=>$langs->trans("DurationYear"));
  1391. }
  1392. $duration = $contractline->product->duration_value.' '.$dur[$contractline->product->duration_unit];
  1393. }
  1394. }
  1395. print '<tr class="CTableRow2"><td class="CTableRow2">'.$label.'</td>';
  1396. print '<td class="CTableRow2"><b>'.($duration ? $duration : $qty).'</b>';
  1397. print '<input type="hidden" name="newqty" value="'.dol_escape_htmltag($qty).'">';
  1398. print '</b></td></tr>'."\n";
  1399. // Amount
  1400. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
  1401. if (empty($amount)) {
  1402. print ' ('.$langs->trans("ToComplete").')';
  1403. }
  1404. print '</td><td class="CTableRow2">';
  1405. if (empty($amount) || !is_numeric($amount)) {
  1406. print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
  1407. print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
  1408. // Currency
  1409. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  1410. } else {
  1411. print '<b class="amount">'.price($amount, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
  1412. print '<input type="hidden" name="amount" value="'.$amount.'">';
  1413. print '<input type="hidden" name="newamount" value="'.$amount.'">';
  1414. }
  1415. print '<input type="hidden" name="currency" value="'.$currency.'">';
  1416. print '</td></tr>'."\n";
  1417. // Tag
  1418. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
  1419. print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
  1420. print '<input type="hidden" name="tag" value="'.$tag.'">';
  1421. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  1422. print '</td></tr>'."\n";
  1423. // Shipping address
  1424. $shipToName = $contract->thirdparty->name;
  1425. $shipToStreet = $contract->thirdparty->address;
  1426. $shipToCity = $contract->thirdparty->town;
  1427. $shipToState = $contract->thirdparty->state_code;
  1428. $shipToCountryCode = $contract->thirdparty->country_code;
  1429. $shipToZip = $contract->thirdparty->zip;
  1430. $shipToStreet2 = '';
  1431. $phoneNum = $contract->thirdparty->phone;
  1432. if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
  1433. print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
  1434. print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
  1435. print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
  1436. print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
  1437. print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
  1438. print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
  1439. print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
  1440. print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
  1441. } else {
  1442. print '<!-- Shipping address not complete, so we don t use it -->'."\n";
  1443. }
  1444. if (is_object($contract->thirdparty)) {
  1445. print '<input type="hidden" name="thirdparty_id" value="'.$contract->thirdparty->id.'">'."\n";
  1446. }
  1447. print '<input type="hidden" name="email" value="'.$contract->thirdparty->email.'">'."\n";
  1448. print '<input type="hidden" name="vatnumber" value="'.$contract->thirdparty->tva_intra.'">'."\n";
  1449. $labeldesc = $langs->trans("Contract").' '.$contract->ref;
  1450. if (GETPOST('desc', 'alpha')) {
  1451. $labeldesc = GETPOST('desc', 'alpha');
  1452. }
  1453. print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
  1454. }
  1455. // Payment on member subscription
  1456. if ($source == 'member' || $source == 'membersubscription') {
  1457. $newsource = 'member';
  1458. $found = true;
  1459. $langs->load("members");
  1460. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  1461. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  1462. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  1463. $member = new Adherent($db);
  1464. $adht = new AdherentType($db);
  1465. $result = $member->fetch('', $ref);
  1466. if ($result <= 0) {
  1467. $mesg = $member->error;
  1468. $error++;
  1469. } else {
  1470. $member->fetch_thirdparty();
  1471. $subscription = new Subscription($db);
  1472. $adht->fetch($member->typeid);
  1473. }
  1474. $object = $member;
  1475. if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
  1476. $amount = $subscription->total_ttc;
  1477. if (GETPOST("amount", 'alpha')) {
  1478. $amount = GETPOST("amount", 'alpha');
  1479. }
  1480. // If amount still not defined, we take amount of the type of member
  1481. if (empty($amount)) {
  1482. $amount = $adht->amount;
  1483. }
  1484. $amount = price2num($amount, 'MT');
  1485. }
  1486. if (GETPOST('fulltag', 'alpha')) {
  1487. $fulltag = GETPOST('fulltag', 'alpha');
  1488. } else {
  1489. $fulltag = 'MEM='.$member->id.'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
  1490. if (!empty($TAG)) {
  1491. $tag = $TAG; $fulltag .= '.TAG='.$TAG;
  1492. }
  1493. }
  1494. $fulltag = dol_string_unaccent($fulltag);
  1495. // Creditor
  1496. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  1497. print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
  1498. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  1499. print '</td></tr>'."\n";
  1500. // Debitor
  1501. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Member");
  1502. print '</td><td class="CTableRow2">';
  1503. print '<b>';
  1504. if ($member->morphy == 'mor' && !empty($member->company)) {
  1505. print img_picto('', 'company', 'class="pictofixedwidth"');
  1506. print $member->company;
  1507. } else {
  1508. print img_picto('', 'member', 'class="pictofixedwidth"');
  1509. print $member->getFullName($langs);
  1510. }
  1511. print '</b>';
  1512. print '</td></tr>'."\n";
  1513. // Object
  1514. $text = '<b>'.$langs->trans("PaymentSubscription").'</b>';
  1515. if (GETPOST('desc', 'alpha')) {
  1516. $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
  1517. }
  1518. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  1519. print '</td><td class="CTableRow2">'.$text;
  1520. print '<input type="hidden" name="source" value="'.dol_escape_htmltag($newsource).'">';
  1521. print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($member->ref).'">';
  1522. print '</td></tr>'."\n";
  1523. if ($object->datefin > 0) {
  1524. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("DateEndSubscription");
  1525. print '</td><td class="CTableRow2">'.dol_print_date($member->datefin, 'day');
  1526. print '</td></tr>'."\n";
  1527. }
  1528. if ($member->last_subscription_date || $member->last_subscription_amount) {
  1529. // Last subscription date
  1530. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("LastSubscriptionDate");
  1531. print '</td><td class="CTableRow2">'.dol_print_date($member->last_subscription_date, 'day');
  1532. print '</td></tr>'."\n";
  1533. // Last subscription amount
  1534. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("LastSubscriptionAmount");
  1535. print '</td><td class="CTableRow2">'.price($member->last_subscription_amount);
  1536. print '</td></tr>'."\n";
  1537. if (empty($amount) && !GETPOST('newamount', 'alpha')) {
  1538. $_GET['newamount'] = $member->last_subscription_amount;
  1539. }
  1540. }
  1541. if ($member->type) {
  1542. $oldtypeid = $member->typeid;
  1543. $newtypeid = (int) (GETPOSTISSET("typeid") ? GETPOST("typeid", 'int') : $member->typeid);
  1544. if (!empty($conf->global->MEMBER_ALLOW_CHANGE_OF_TYPE)) {
  1545. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  1546. $adht = new AdherentType($db);
  1547. // Amount by member type
  1548. $amountbytype = $adht->amountByType(1);
  1549. // Last member type
  1550. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("LastMemberType");
  1551. print '</td><td class="CTableRow2">'.dol_escape_htmltag($member->type);
  1552. print "</td></tr>\n";
  1553. // Set the new member type
  1554. $member->typeid = $newtypeid;
  1555. $member->type = dol_getIdFromCode($db, $newtypeid, 'adherent_type', 'rowid', 'libelle');
  1556. // list member type
  1557. if (!$action) {
  1558. // Set amount for the subscription
  1559. $amount = (!empty($amountbytype[$member->typeid])) ? $amountbytype[$member->typeid] : $member->last_subscription_amount;
  1560. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("NewSubscription");
  1561. print '</td><td class="CTableRow2">';
  1562. print $form->selectarray("typeid", $adht->liste_array(1), $member->typeid, 0, 0, 0, 'onchange="window.location.replace(\''.$urlwithroot.'/public/payment/newpayment.php?source='.urlencode($source).'&ref='.urlencode($ref).'&amount='.urlencode($amount).'&typeid=\' + this.value + \'&securekey='.urlencode($SECUREKEY).'\');"', 0, 0, 0, '', '', 1);
  1563. print "</td></tr>\n";
  1564. } elseif ($action == 'dopayment') {
  1565. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("NewMemberType");
  1566. print '</td><td class="CTableRow2">'.dol_escape_htmltag($member->type);
  1567. print '<input type="hidden" name="membertypeid" value="'.$member->typeid.'">';
  1568. print "</td></tr>\n";
  1569. }
  1570. } else {
  1571. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("MemberType");
  1572. print '</td><td class="CTableRow2">'.dol_escape_htmltag($member->type);
  1573. print "</td></tr>\n";
  1574. }
  1575. }
  1576. // Amount
  1577. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
  1578. if (empty($amount)) {
  1579. if (empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  1580. print ' ('.$langs->trans("ToComplete");
  1581. }
  1582. if (!empty($conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO)) {
  1583. print ' - <a href="'.$conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO.'" rel="external" target="_blank" rel="noopener noreferrer">'.$langs->trans("SeeHere").'</a>';
  1584. }
  1585. if (empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  1586. print ')';
  1587. }
  1588. }
  1589. print '</td><td class="CTableRow2">';
  1590. $valtoshow = '';
  1591. if (empty($amount) || !is_numeric($amount)) {
  1592. $valtoshow = price2num(GETPOST("newamount", 'alpha'), 'MT');
  1593. // force default subscription amount to value defined into constant...
  1594. if (empty($valtoshow)) {
  1595. if (!empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT)) {
  1596. if (!empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  1597. $valtoshow = $conf->global->MEMBER_NEWFORM_AMOUNT;
  1598. }
  1599. } else {
  1600. if (!empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  1601. $amount = $conf->global->MEMBER_NEWFORM_AMOUNT;
  1602. }
  1603. }
  1604. }
  1605. }
  1606. if (empty($amount) || !is_numeric($amount)) {
  1607. //$valtoshow=price2num(GETPOST("newamount",'alpha'),'MT');
  1608. if (!empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) {
  1609. $valtoshow = max($conf->global->MEMBER_MIN_AMOUNT, $valtoshow);
  1610. }
  1611. print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
  1612. if (empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT)) {
  1613. print '<input class="flat maxwidth75" type="text" name="newamountbis" value="'.$valtoshow.'" disabled="disabled">';
  1614. print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
  1615. } else {
  1616. print '<input class="flat maxwidth75" type="text" name="newamount" value="'.$valtoshow.'">';
  1617. }
  1618. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  1619. } else {
  1620. $valtoshow = $amount;
  1621. if (!empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) {
  1622. $valtoshow = max($conf->global->MEMBER_MIN_AMOUNT, $valtoshow);
  1623. $amount = $valtoshow;
  1624. }
  1625. print '<b class="amount">'.price($valtoshow, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
  1626. print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
  1627. print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
  1628. }
  1629. print '<input type="hidden" name="currency" value="'.$currency.'">';
  1630. print '</td></tr>'."\n";
  1631. // Tag
  1632. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
  1633. print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
  1634. print '<input type="hidden" name="tag" value="'.$tag.'">';
  1635. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  1636. print '</td></tr>'."\n";
  1637. // Shipping address
  1638. $shipToName = $member->getFullName($langs);
  1639. $shipToStreet = $member->address;
  1640. $shipToCity = $member->town;
  1641. $shipToState = $member->state_code;
  1642. $shipToCountryCode = $member->country_code;
  1643. $shipToZip = $member->zip;
  1644. $shipToStreet2 = '';
  1645. $phoneNum = $member->phone;
  1646. if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
  1647. print '<!-- Shipping address information -->';
  1648. print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
  1649. print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
  1650. print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
  1651. print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
  1652. print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
  1653. print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
  1654. print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
  1655. print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
  1656. } else {
  1657. print '<!-- Shipping address not complete, so we don t use it -->'."\n";
  1658. }
  1659. if (is_object($member->thirdparty)) {
  1660. print '<input type="hidden" name="thirdparty_id" value="'.$member->thirdparty->id.'">'."\n";
  1661. }
  1662. print '<input type="hidden" name="email" value="'.$member->email.'">'."\n";
  1663. $labeldesc = $langs->trans("PaymentSubscription");
  1664. if (GETPOST('desc', 'alpha')) {
  1665. $labeldesc = GETPOST('desc', 'alpha');
  1666. }
  1667. print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
  1668. }
  1669. // Payment on donation
  1670. if ($source == 'donation') {
  1671. $found = true;
  1672. $langs->load("don");
  1673. require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  1674. $don = new Don($db);
  1675. $result = $don->fetch($ref);
  1676. if ($result <= 0) {
  1677. $mesg = $don->error;
  1678. $error++;
  1679. } else {
  1680. $don->fetch_thirdparty();
  1681. }
  1682. $object = $don;
  1683. if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
  1684. if (GETPOST("amount", 'alpha')) {
  1685. $amount = GETPOST("amount", 'alpha');
  1686. } else {
  1687. $amount = $don->getRemainToPay();
  1688. }
  1689. $amount = price2num($amount);
  1690. }
  1691. if (GETPOST('fulltag', 'alpha')) {
  1692. $fulltag = GETPOST('fulltag', 'alpha');
  1693. } else {
  1694. $fulltag = 'DON='.$don->ref.'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
  1695. if (!empty($TAG)) {
  1696. $tag = $TAG; $fulltag .= '.TAG='.$TAG;
  1697. }
  1698. }
  1699. $fulltag = dol_string_unaccent($fulltag);
  1700. // Creditor
  1701. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  1702. print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
  1703. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  1704. print '</td></tr>'."\n";
  1705. // Debitor
  1706. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
  1707. print '</td><td class="CTableRow2"><b>';
  1708. if ($don->morphy == 'mor' && !empty($don->societe)) {
  1709. print $don->societe;
  1710. } else {
  1711. print $don->getFullName($langs);
  1712. }
  1713. print '</b>';
  1714. print '</td></tr>'."\n";
  1715. // Object
  1716. $text = '<b>'.$langs->trans("PaymentDonation").'</b>';
  1717. if (GETPOST('desc', 'alpha')) {
  1718. $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
  1719. }
  1720. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  1721. print '</td><td class="CTableRow2">'.$text;
  1722. print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
  1723. print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($don->ref).'">';
  1724. print '</td></tr>'."\n";
  1725. // Amount
  1726. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
  1727. if (empty($amount)) {
  1728. if (empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  1729. print ' ('.$langs->trans("ToComplete");
  1730. }
  1731. if (!empty($conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO)) {
  1732. print ' - <a href="'.$conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO.'" rel="external" target="_blank" rel="noopener noreferrer">'.$langs->trans("SeeHere").'</a>';
  1733. }
  1734. if (empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  1735. print ')';
  1736. }
  1737. }
  1738. print '</td><td class="CTableRow2">';
  1739. $valtoshow = '';
  1740. if (empty($amount) || !is_numeric($amount)) {
  1741. $valtoshow = price2num(GETPOST("newamount", 'alpha'), 'MT');
  1742. // force default subscription amount to value defined into constant...
  1743. if (empty($valtoshow)) {
  1744. if (!empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT)) {
  1745. if (!empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  1746. $valtoshow = $conf->global->MEMBER_NEWFORM_AMOUNT;
  1747. }
  1748. } else {
  1749. if (!empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
  1750. $amount = $conf->global->MEMBER_NEWFORM_AMOUNT;
  1751. }
  1752. }
  1753. }
  1754. }
  1755. if (empty($amount) || !is_numeric($amount)) {
  1756. //$valtoshow=price2num(GETPOST("newamount",'alpha'),'MT');
  1757. if (!empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) {
  1758. $valtoshow = max($conf->global->MEMBER_MIN_AMOUNT, $valtoshow);
  1759. }
  1760. print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
  1761. print '<input class="flat maxwidth75" type="text" name="newamount" value="'.$valtoshow.'">';
  1762. // Currency
  1763. print ' <b>'.$langs->trans("Currency".$currency).'</b>';
  1764. } else {
  1765. $valtoshow = $amount;
  1766. if (!empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) {
  1767. $valtoshow = max($conf->global->MEMBER_MIN_AMOUNT, $valtoshow);
  1768. $amount = $valtoshow;
  1769. }
  1770. print '<b class="amount">'.price($valtoshow, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
  1771. print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
  1772. print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
  1773. }
  1774. print '<input type="hidden" name="currency" value="'.$currency.'">';
  1775. print '</td></tr>'."\n";
  1776. // Tag
  1777. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
  1778. print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
  1779. print '<input type="hidden" name="tag" value="'.$tag.'">';
  1780. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  1781. print '</td></tr>'."\n";
  1782. // Shipping address
  1783. $shipToName = $don->getFullName($langs);
  1784. $shipToStreet = $don->address;
  1785. $shipToCity = $don->town;
  1786. $shipToState = $don->state_code;
  1787. $shipToCountryCode = $don->country_code;
  1788. $shipToZip = $don->zip;
  1789. $shipToStreet2 = '';
  1790. $phoneNum = $don->phone;
  1791. if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
  1792. print '<!-- Shipping address information -->';
  1793. print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
  1794. print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
  1795. print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
  1796. print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
  1797. print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
  1798. print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
  1799. print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
  1800. print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
  1801. } else {
  1802. print '<!-- Shipping address not complete, so we don t use it -->'."\n";
  1803. }
  1804. if (is_object($don->thirdparty)) {
  1805. print '<input type="hidden" name="thirdparty_id" value="'.$don->thirdparty->id.'">'."\n";
  1806. }
  1807. print '<input type="hidden" name="email" value="'.$don->email.'">'."\n";
  1808. $labeldesc = $langs->trans("PaymentSubscription");
  1809. if (GETPOST('desc', 'alpha')) {
  1810. $labeldesc = GETPOST('desc', 'alpha');
  1811. }
  1812. print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
  1813. }
  1814. if ($source == 'organizedeventregistration') {
  1815. $found = true;
  1816. $langs->loadLangs(array("members", "eventorganization"));
  1817. if (GETPOST('fulltag', 'alpha')) {
  1818. $fulltag = GETPOST('fulltag', 'alpha');
  1819. } else {
  1820. $fulltag = 'ATT='.$attendee->id.'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
  1821. if (!empty($TAG)) {
  1822. $tag = $TAG; $fulltag .= '.TAG='.$TAG;
  1823. }
  1824. }
  1825. $fulltag = dol_string_unaccent($fulltag);
  1826. // Creditor
  1827. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  1828. print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
  1829. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  1830. print '</td></tr>'."\n";
  1831. // Debitor
  1832. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Attendee");
  1833. print '</td><td class="CTableRow2"><b>';
  1834. print $attendee->email;
  1835. print ($thirdparty->name ? ' ('.$thirdparty->name.')' : '');
  1836. print '</b>';
  1837. print '</td></tr>'."\n";
  1838. if (! is_object($attendee->project)) {
  1839. $text = 'ErrorProjectNotFound';
  1840. } else {
  1841. $text = $langs->trans("PaymentEvent").' - '.$attendee->project->title;
  1842. }
  1843. // Object
  1844. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  1845. print '</td><td class="CTableRow2"><b>'.$text.'</b>';
  1846. print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
  1847. print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($invoice->id).'">';
  1848. print '</td></tr>'."\n";
  1849. // Amount
  1850. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
  1851. print '</td><td class="CTableRow2">';
  1852. $valtoshow = $amount;
  1853. print '<b class="amount">'.price($valtoshow, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
  1854. print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
  1855. print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
  1856. print '<input type="hidden" name="currency" value="'.$currency.'">';
  1857. print '</td></tr>'."\n";
  1858. // Tag
  1859. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
  1860. print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
  1861. print '<input type="hidden" name="tag" value="'.$tag.'">';
  1862. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  1863. print '</td></tr>'."\n";
  1864. // Shipping address
  1865. $shipToName = $thirdparty->getFullName($langs);
  1866. $shipToStreet = $thirdparty->address;
  1867. $shipToCity = $thirdparty->town;
  1868. $shipToState = $thirdparty->state_code;
  1869. $shipToCountryCode = $thirdparty->country_code;
  1870. $shipToZip = $thirdparty->zip;
  1871. $shipToStreet2 = '';
  1872. $phoneNum = $thirdparty->phone;
  1873. if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
  1874. print '<!-- Shipping address information -->';
  1875. print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
  1876. print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
  1877. print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
  1878. print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
  1879. print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
  1880. print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
  1881. print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
  1882. print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
  1883. } else {
  1884. print '<!-- Shipping address not complete, so we don t use it -->'."\n";
  1885. }
  1886. print '<input type="hidden" name="thirdparty_id" value="'.$thirdparty->id.'">'."\n";
  1887. print '<input type="hidden" name="email" value="'.$thirdparty->email.'">'."\n";
  1888. $labeldesc = $langs->trans("PaymentSubscription");
  1889. if (GETPOST('desc', 'alpha')) {
  1890. $labeldesc = GETPOST('desc', 'alpha');
  1891. }
  1892. print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
  1893. }
  1894. if ($source == 'boothlocation') {
  1895. $found = true;
  1896. $langs->load("members");
  1897. if (GETPOST('fulltag', 'alpha')) {
  1898. $fulltag = GETPOST('fulltag', 'alpha');
  1899. } else {
  1900. $fulltag = 'BOO='.GETPOST("booth").'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
  1901. if (!empty($TAG)) {
  1902. $tag = $TAG; $fulltag .= '.TAG='.$TAG;
  1903. }
  1904. }
  1905. $fulltag = dol_string_unaccent($fulltag);
  1906. // Creditor
  1907. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
  1908. print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
  1909. print '<input type="hidden" name="creditor" value="'.$creditor.'">';
  1910. print '</td></tr>'."\n";
  1911. // Debitor
  1912. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Attendee");
  1913. print '</td><td class="CTableRow2"><b>';
  1914. print $thirdparty->name;
  1915. print '</b>';
  1916. print '</td></tr>'."\n";
  1917. // Object
  1918. $text = '<b>'.$langs->trans("PaymentBoothLocation").'</b>';
  1919. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
  1920. print '</td><td class="CTableRow2">'.$text;
  1921. print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
  1922. print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($invoice->id).'">';
  1923. print '</td></tr>'."\n";
  1924. // Amount
  1925. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
  1926. print '</td><td class="CTableRow2">';
  1927. $valtoshow = $amount;
  1928. print '<b class="amount">'.price($valtoshow, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
  1929. print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
  1930. print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
  1931. print '<input type="hidden" name="currency" value="'.$currency.'">';
  1932. print '</td></tr>'."\n";
  1933. // Tag
  1934. print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
  1935. print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
  1936. print '<input type="hidden" name="tag" value="'.$tag.'">';
  1937. print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
  1938. print '</td></tr>'."\n";
  1939. // Shipping address
  1940. $shipToName = $thirdparty->getFullName($langs);
  1941. $shipToStreet = $thirdparty->address;
  1942. $shipToCity = $thirdparty->town;
  1943. $shipToState = $thirdparty->state_code;
  1944. $shipToCountryCode = $thirdparty->country_code;
  1945. $shipToZip = $thirdparty->zip;
  1946. $shipToStreet2 = '';
  1947. $phoneNum = $thirdparty->phone;
  1948. if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
  1949. print '<!-- Shipping address information -->';
  1950. print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
  1951. print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
  1952. print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
  1953. print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
  1954. print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
  1955. print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
  1956. print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
  1957. print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
  1958. } else {
  1959. print '<!-- Shipping address not complete, so we don t use it -->'."\n";
  1960. }
  1961. print '<input type="hidden" name="thirdparty_id" value="'.$thirdparty->id.'">'."\n";
  1962. print '<input type="hidden" name="email" value="'.$thirdparty->email.'">'."\n";
  1963. $labeldesc = $langs->trans("PaymentSubscription");
  1964. if (GETPOST('desc', 'alpha')) {
  1965. $labeldesc = GETPOST('desc', 'alpha');
  1966. }
  1967. print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
  1968. }
  1969. if (!$found && !$mesg) {
  1970. $mesg = $langs->trans("ErrorBadParameters");
  1971. }
  1972. if ($mesg) {
  1973. print '<tr><td align="center" colspan="2"><br><div class="warning">'.dol_escape_htmltag($mesg, 1, 1, 'br').'</div></td></tr>'."\n";
  1974. }
  1975. print '</table>'."\n";
  1976. print "\n";
  1977. // Show all payment mode buttons (Stripe, Paypal, ...)
  1978. if ($action != 'dopayment') {
  1979. if ($found && !$error) { // We are in a management option and no error
  1980. // Check status of the object (Invoice) to verify if it is paid by external payment modules (ie Payzen, ...)
  1981. $parameters = [
  1982. 'source' => $source,
  1983. 'object' => $object
  1984. ];
  1985. $reshook = $hookmanager->executeHooks('doCheckStatus', $parameters, $object, $action);
  1986. if ($reshook < 0) {
  1987. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1988. } elseif ($reshook > 0) {
  1989. print $hookmanager->resPrint;
  1990. }
  1991. // Added by MMI Mathieu Moulin iProspective
  1992. if ($source == 'propal' && $object->paye()) {
  1993. print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("PropalPaid").'</span>';
  1994. } elseif ($source == 'order' && $object->billed) {
  1995. print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("OrderBilled").'</span>';
  1996. } elseif ($source == 'invoice' && $object->paye) {
  1997. print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("InvoicePaid").'</span>';
  1998. } elseif ($source == 'donation' && $object->paid) {
  1999. print '<br><br><span class="amountpaymentcomplete size15x">'.$langs->trans("DonationPaid").'</span>';
  2000. } else {
  2001. // Membership can be paid and we still allow to make renewal
  2002. if (($source == 'member' || $source == 'membersubscription') && $object->datefin > dol_now()) {
  2003. $langs->load("members");
  2004. print '<br><span class="amountpaymentcomplete size15x">'.$langs->trans("MembershipPaid", dol_print_date($object->datefin, 'day')).'</span><br>';
  2005. print '<div class="opacitymedium margintoponly">'.$langs->trans("PaymentWillBeRecordedForNextPeriod").'</div>';
  2006. }
  2007. // Buttons for all payments registration methods
  2008. // This hook is used to add Button to newpayment.php for external payment modules (ie Payzen, ...)
  2009. $parameters = [
  2010. 'paymentmethod' => $paymentmethod,
  2011. 'amount' => price2num(GETPOST("amount", 'alpha')),
  2012. ];
  2013. $reshook = $hookmanager->executeHooks('doAddButton', $parameters, $object, $action);
  2014. if ($reshook < 0) {
  2015. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  2016. } elseif ($reshook > 0) {
  2017. print $hookmanager->resPrint;
  2018. }
  2019. if ((empty($paymentmethod) || $paymentmethod == 'paybox') && !empty($conf->paybox->enabled)) {
  2020. print '<div class="button buttonpayment" id="div_dopayment_paybox"><span class="fa fa-credit-card"></span> <input class="" type="submit" id="dopayment_paybox" name="dopayment_paybox" value="'.$langs->trans("PayBoxDoPayment").'">';
  2021. print '<br>';
  2022. print '<span class="buttonpaymentsmall">'.$langs->trans("CreditOrDebitCard").'</span>';
  2023. print '</div>';
  2024. print '<script>
  2025. $( document ).ready(function() {
  2026. $("#div_dopayment_paybox").click(function(){
  2027. $("#dopayment_paybox").click();
  2028. });
  2029. $("#dopayment_paybox").click(function(e){
  2030. $("#div_dopayment_paybox").css( \'cursor\', \'wait\' );
  2031. e.stopPropagation();
  2032. });
  2033. });
  2034. </script>
  2035. ';
  2036. }
  2037. if ((empty($paymentmethod) || $paymentmethod == 'stripe') && !empty($conf->stripe->enabled)) {
  2038. print '<div class="button buttonpayment" id="div_dopayment_stripe"><span class="fa fa-credit-card"></span> <input class="" type="submit" id="dopayment_stripe" name="dopayment_stripe" value="'.$langs->trans("StripeDoPayment").'">';
  2039. print '<input type="hidden" name="noidempotency" value="'.GETPOST('noidempotency', 'int').'">';
  2040. print '<br>';
  2041. print '<span class="buttonpaymentsmall">'.$langs->trans("CreditOrDebitCard").'</span>';
  2042. print '</div>';
  2043. print '<script>
  2044. $( document ).ready(function() {
  2045. $("#div_dopayment_stripe").click(function(){
  2046. $("#dopayment_stripe").click();
  2047. });
  2048. $("#dopayment_stripe").click(function(e){
  2049. $("#div_dopayment_stripe").css( \'cursor\', \'wait\' );
  2050. e.stopPropagation();
  2051. return true;
  2052. });
  2053. });
  2054. </script>
  2055. ';
  2056. }
  2057. if ((empty($paymentmethod) || $paymentmethod == 'paypal') && !empty($conf->paypal->enabled)) {
  2058. if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) {
  2059. $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY = 'integral';
  2060. }
  2061. print '<div class="button buttonpayment" id="div_dopayment_paypal">';
  2062. if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY != 'integral') {
  2063. print '<div style="line-height: 1em">&nbsp;</div>';
  2064. }
  2065. print '<span class="fa fa-paypal"></span> <input class="" type="submit" id="dopayment_paypal" name="dopayment_paypal" value="'.$langs->trans("PaypalDoPayment").'">';
  2066. if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral') {
  2067. print '<br>';
  2068. print '<span class="buttonpaymentsmall">'.$langs->trans("CreditOrDebitCard").'</span><span class="buttonpaymentsmall"> - </span>';
  2069. print '<span class="buttonpaymentsmall">'.$langs->trans("PayPalBalance").'</span>';
  2070. }
  2071. if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly') {
  2072. //print '<br>';
  2073. //print '<span class="buttonpaymentsmall">'.$langs->trans("PayPalBalance").'"></span>';
  2074. }
  2075. print '</div>';
  2076. print '<script>
  2077. $( document ).ready(function() {
  2078. $("#div_dopayment_paypal").click(function(){
  2079. $("#dopayment_paypal").click();
  2080. });
  2081. $("#dopayment_paypal").click(function(e){
  2082. $("#div_dopayment_paypal").css( \'cursor\', \'wait\' );
  2083. e.stopPropagation();
  2084. return true;
  2085. });
  2086. });
  2087. </script>
  2088. ';
  2089. }
  2090. }
  2091. } else {
  2092. dol_print_error_email('ERRORNEWPAYMENT');
  2093. }
  2094. } else {
  2095. // Print
  2096. }
  2097. print '</td></tr>'."\n";
  2098. print '</table>'."\n";
  2099. print '</form>'."\n";
  2100. print '</div>'."\n";
  2101. print '<br>';
  2102. // Add more content on page for some services
  2103. if (preg_match('/^dopayment/', $action)) { // If we choosed/click on the payment mode
  2104. // Save some data for the paymentok
  2105. $remoteip = getUserRemoteIP();
  2106. $_SESSION["currencyCodeType"] = $currency;
  2107. $_SESSION["FinalPaymentAmt"] = $amount;
  2108. $_SESSION['ipaddress'] = ($remoteip ? $remoteip : 'unknown'); // Payer ip
  2109. $_SESSION["paymentType"] = '';
  2110. // For Stripe
  2111. if (GETPOST('dopayment_stripe', 'alpha')) {
  2112. // Personalized checkout
  2113. print '<style>
  2114. /**
  2115. * The CSS shown here will not be introduced in the Quickstart guide, but shows
  2116. * how you can use CSS to style your Element s container.
  2117. */
  2118. .StripeElement {
  2119. background-color: white;
  2120. padding: 8px 12px;
  2121. border-radius: 4px;
  2122. border: 1px solid transparent;
  2123. box-shadow: 0 1px 3px 0 #e6ebf1;
  2124. -webkit-transition: box-shadow 150ms ease;
  2125. transition: box-shadow 150ms ease;
  2126. }
  2127. .StripeElement--focus {
  2128. box-shadow: 0 1px 3px 0 #cfd7df;
  2129. }
  2130. .StripeElement--invalid {
  2131. border-color: #fa755a;
  2132. }
  2133. .StripeElement--webkit-autofill {
  2134. background-color: #fefde5 !important;
  2135. }
  2136. </style>';
  2137. //print '<br>';
  2138. print '<!-- Form payment-form STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = '.$conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION.' STRIPE_USE_NEW_CHECKOUT = '.$conf->global->STRIPE_USE_NEW_CHECKOUT.' -->'."\n";
  2139. print '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" id="payment-form">'."\n";
  2140. print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  2141. print '<input type="hidden" name="dopayment_stripe" value="1">'."\n";
  2142. print '<input type="hidden" name="action" value="charge">'."\n";
  2143. print '<input type="hidden" name="tag" value="'.$TAG.'">'."\n";
  2144. print '<input type="hidden" name="s" value="'.$source.'">'."\n";
  2145. print '<input type="hidden" name="ref" value="'.$REF.'">'."\n";
  2146. print '<input type="hidden" name="fulltag" value="'.$FULLTAG.'">'."\n";
  2147. print '<input type="hidden" name="suffix" value="'.$suffix.'">'."\n";
  2148. print '<input type="hidden" name="securekey" value="'.$SECUREKEY.'">'."\n";
  2149. print '<input type="hidden" name="e" value="'.$entity.'" />';
  2150. print '<input type="hidden" name="amount" value="'.$amount.'">'."\n";
  2151. print '<input type="hidden" name="currency" value="'.$currency.'">'."\n";
  2152. print '<input type="hidden" name="forcesandbox" value="'.GETPOST('forcesandbox', 'int').'" />';
  2153. print '<input type="hidden" name="email" value="'.GETPOST('email', 'alpha').'" />';
  2154. print '<input type="hidden" name="thirdparty_id" value="'.GETPOST('thirdparty_id', 'int').'" />';
  2155. if (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION) || !empty($conf->global->STRIPE_USE_NEW_CHECKOUT)) { // Use a SCA ready method
  2156. require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
  2157. $service = 'StripeLive';
  2158. $servicestatus = 1;
  2159. if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha')) {
  2160. $service = 'StripeTest';
  2161. $servicestatus = 0;
  2162. }
  2163. $stripe = new Stripe($db);
  2164. $stripeacc = $stripe->getStripeAccount($service);
  2165. $stripecu = null;
  2166. if (is_object($object) && is_object($object->thirdparty)) {
  2167. $stripecu = $stripe->customerStripe($object->thirdparty, $stripeacc, $servicestatus, 1);
  2168. }
  2169. if (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) {
  2170. $noidempotency_key = (GETPOSTISSET('noidempotency') ? GETPOST('noidempotency', 'int') : 0); // By default noidempotency is unset, so we must use a different tag/ref for each payment. If set, we can pay several times the same tag/ref.
  2171. $paymentintent = $stripe->getPaymentIntent($amount, $currency, $tag, 'Stripe payment: '.$fulltag.(is_object($object) ? ' ref='.$object->ref : ''), $object, $stripecu, $stripeacc, $servicestatus, 0, 'automatic', false, null, 0, $noidempotency_key);
  2172. // The paymentintnent has status 'requires_payment_method' (even if paymentintent was already paid)
  2173. //var_dump($paymentintent);
  2174. if ($stripe->error) {
  2175. setEventMessages($stripe->error, null, 'errors');
  2176. }
  2177. }
  2178. }
  2179. // Note:
  2180. // $conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = 1 = use intent (default value)
  2181. // $conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = 2 = use payment
  2182. //if (empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION) || ! empty($paymentintent))
  2183. //{
  2184. print '
  2185. <table id="dolpaymenttable" summary="Payment form" class="center centpercent">
  2186. <tbody><tr><td class="textpublicpayment">';
  2187. if (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) {
  2188. print '<div id="payment-request-button"><!-- A Stripe Element will be inserted here. --></div>';
  2189. }
  2190. print '<div class="form-row '.(getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2 ? 'center' : 'left').'">';
  2191. if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 1) {
  2192. print '<label for="card-element">'.$langs->trans("CreditOrDebitCard").'</label>';
  2193. print '<br><input id="cardholder-name" class="marginbottomonly" name="cardholder-name" value="" type="text" placeholder="'.$langs->trans("CardOwner").'" autocomplete="off" autofocus required>';
  2194. }
  2195. if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 1) {
  2196. print '<div id="card-element">
  2197. <!-- a Stripe Element will be inserted here. -->
  2198. </div>';
  2199. }
  2200. if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2) {
  2201. print '<div id="payment-element">
  2202. <!-- a Stripe Element will be inserted here. -->
  2203. </div>';
  2204. }
  2205. print '<!-- Used to display form errors -->
  2206. <div id="card-errors" role="alert"></div>
  2207. </div>';
  2208. print '<br>';
  2209. print '<button class="button buttonpayment" style="text-align: center; padding-left: 0; padding-right: 0;" id="buttontopay" data-secret="'.(is_object($paymentintent) ? $paymentintent->client_secret : '').'">'.$langs->trans("ValidatePayment").'</button>';
  2210. print '<img id="hourglasstopay" class="hidden" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/working.gif">';
  2211. print '</td></tr></tbody>';
  2212. print '</table>';
  2213. //}
  2214. if (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) {
  2215. if (empty($paymentintent)) {
  2216. print '<center>'.$langs->trans("Error").'</center>';
  2217. } else {
  2218. print '<input type="hidden" name="paymentintent_id" value="'.$paymentintent->id.'">';
  2219. //$_SESSION["paymentintent_id"] = $paymentintent->id;
  2220. }
  2221. }
  2222. print '</form>'."\n";
  2223. // JS Code for Stripe
  2224. if (empty($stripearrayofkeys['publishable_key'])) {
  2225. $langs->load("errors");
  2226. print info_admin($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Stripe")), 0, 0, 'error');
  2227. } else {
  2228. print '<!-- JS Code for Stripe components -->';
  2229. print '<script src="https://js.stripe.com/v3/"></script>'."\n";
  2230. print '<!-- urllogofull = '.$urllogofull.' -->'."\n";
  2231. // Code to ask the credit card. This use the default "API version". No way to force API version when using JS code.
  2232. print '<script type="text/javascript">'."\n";
  2233. if (!empty($conf->global->STRIPE_USE_NEW_CHECKOUT)) {
  2234. $amountstripe = $amount;
  2235. // Correct the amount according to unit of currency
  2236. // See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
  2237. $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
  2238. if (!in_array($currency, $arrayzerounitcurrency)) {
  2239. $amountstripe = $amountstripe * 100;
  2240. }
  2241. $ipaddress = getUserRemoteIP();
  2242. $metadata = array('dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>$ipaddress);
  2243. if (is_object($object)) {
  2244. $metadata['dol_type'] = $object->element;
  2245. $metadata['dol_id'] = $object->id;
  2246. $ref = $object->ref;
  2247. }
  2248. try {
  2249. $arrayforpaymentintent = array(
  2250. 'description'=>'Stripe payment: '.$FULLTAG.($ref ? ' ref='.$ref : ''),
  2251. "metadata" => $metadata
  2252. );
  2253. if ($TAG) {
  2254. $arrayforpaymentintent["statement_descriptor"] = dol_trunc($TAG, 10, 'right', 'UTF-8', 1); // 22 chars that appears on bank receipt (company + description)
  2255. }
  2256. $arrayforcheckout = array(
  2257. 'payment_method_types' => array('card'),
  2258. 'line_items' => array(array(
  2259. 'name' => $langs->transnoentitiesnoconv("Payment").' '.$TAG, // Label of product line
  2260. 'description' => 'Stripe payment: '.$FULLTAG.($ref ? ' ref='.$ref : ''),
  2261. 'amount' => $amountstripe,
  2262. 'currency' => $currency,
  2263. //'images' => array($urllogofull),
  2264. 'quantity' => 1,
  2265. )),
  2266. 'client_reference_id' => $FULLTAG,
  2267. 'success_url' => $urlok,
  2268. 'cancel_url' => $urlko,
  2269. 'payment_intent_data' => $arrayforpaymentintent
  2270. );
  2271. if ($stripecu) {
  2272. $arrayforcheckout['customer'] = $stripecu;
  2273. } elseif (GETPOST('email', 'alpha') && isValidEmail(GETPOST('email', 'alpha'))) {
  2274. $arrayforcheckout['customer_email'] = GETPOST('email', 'alpha');
  2275. }
  2276. $sessionstripe = \Stripe\Checkout\Session::create($arrayforcheckout);
  2277. $remoteip = getUserRemoteIP();
  2278. // Save some data for the paymentok
  2279. $_SESSION["currencyCodeType"] = $currency;
  2280. $_SESSION["paymentType"] = '';
  2281. $_SESSION["FinalPaymentAmt"] = $amount;
  2282. $_SESSION['ipaddress'] = ($remoteip ? $remoteip : 'unknown'); // Payer ip
  2283. $_SESSION['payerID'] = is_object($stripecu) ? $stripecu->id : '';
  2284. $_SESSION['TRANSACTIONID'] = $sessionstripe->id;
  2285. } catch (Exception $e) {
  2286. print $e->getMessage();
  2287. }
  2288. ?>
  2289. // Code for payment with option STRIPE_USE_NEW_CHECKOUT set
  2290. // Create a Stripe client.
  2291. <?php
  2292. if (empty($stripeacc)) {
  2293. ?>
  2294. var stripe = Stripe('<?php echo $stripearrayofkeys['publishable_key']; // Defined into config.php ?>');
  2295. <?php
  2296. } else {
  2297. ?>
  2298. var stripe = Stripe('<?php echo $stripearrayofkeys['publishable_key']; // Defined into config.php ?>', { stripeAccount: '<?php echo $stripeacc; ?>' });
  2299. <?php
  2300. }
  2301. ?>
  2302. // Create an instance of Elements
  2303. var elements = stripe.elements();
  2304. // Custom styling can be passed to options when creating an Element.
  2305. // (Note that this demo uses a wider set of styles than the guide below.)
  2306. var style = {
  2307. base: {
  2308. color: '#32325d',
  2309. lineHeight: '24px',
  2310. fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
  2311. fontSmoothing: 'antialiased',
  2312. fontSize: '16px',
  2313. '::placeholder': {
  2314. color: '#aab7c4'
  2315. }
  2316. },
  2317. invalid: {
  2318. color: '#fa755a',
  2319. iconColor: '#fa755a'
  2320. }
  2321. };
  2322. var cardElement = elements.create('card', {style: style});
  2323. // Comment this to avoid the redirect
  2324. stripe.redirectToCheckout({
  2325. // Make the id field from the Checkout Session creation API response
  2326. // available to this file, so you can provide it as parameter here
  2327. // instead of the {{CHECKOUT_SESSION_ID}} placeholder.
  2328. sessionId: '<?php print $sessionstripe->id; ?>'
  2329. }).then(function (result) {
  2330. // If `redirectToCheckout` fails due to a browser or network
  2331. // error, display the localized error message to your customer
  2332. // using `result.error.message`.
  2333. });
  2334. <?php
  2335. } elseif (!empty($conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION)) {
  2336. ?>
  2337. // Code for payment with option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION set to 1 or 2
  2338. // Create a Stripe client.
  2339. <?php
  2340. if (empty($stripeacc)) {
  2341. ?>
  2342. var stripe = Stripe('<?php echo $stripearrayofkeys['publishable_key']; // Defined into config.php ?>');
  2343. <?php
  2344. } else {
  2345. ?>
  2346. var stripe = Stripe('<?php echo $stripearrayofkeys['publishable_key']; // Defined into config.php ?>', { stripeAccount: '<?php echo $stripeacc; ?>' });
  2347. <?php
  2348. }
  2349. ?>
  2350. <?php
  2351. if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2) {
  2352. ?>
  2353. var cardButton = document.getElementById('buttontopay');
  2354. var clientSecret = cardButton.dataset.secret;
  2355. var options = { clientSecret: clientSecret,};
  2356. // Create an instance of Elements
  2357. var elements = stripe.elements(options);
  2358. <?php
  2359. } else {
  2360. ?>
  2361. // Create an instance of Elements
  2362. var elements = stripe.elements();
  2363. <?php
  2364. }
  2365. ?>
  2366. // Custom styling can be passed to options when creating an Element.
  2367. // (Note that this demo uses a wider set of styles than the guide below.)
  2368. var style = {
  2369. base: {
  2370. color: '#32325d',
  2371. lineHeight: '24px',
  2372. fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
  2373. fontSmoothing: 'antialiased',
  2374. fontSize: '16px',
  2375. '::placeholder': {
  2376. color: '#aab7c4'
  2377. }
  2378. },
  2379. invalid: {
  2380. color: '#fa755a',
  2381. iconColor: '#fa755a'
  2382. }
  2383. };
  2384. <?php
  2385. if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2) {
  2386. ?>
  2387. var paymentElement = elements.create("payment");
  2388. // Add an instance of the card Element into the `card-element` <div>
  2389. paymentElement.mount("#payment-element");
  2390. // Handle form submission
  2391. var cardButton = document.getElementById('buttontopay');
  2392. cardButton.addEventListener('click', function(event) {
  2393. console.log("We click on buttontopay");
  2394. event.preventDefault();
  2395. /* Disable button to pay and show hourglass cursor */
  2396. jQuery('#hourglasstopay').show();
  2397. jQuery('#buttontopay').hide();
  2398. stripe.confirmPayment({
  2399. elements,confirmParams: {
  2400. return_url: '<?php echo $urlok; ?>',
  2401. payment_method_data: {
  2402. billing_details: {
  2403. name: 'test'
  2404. <?php if (GETPOST('email', 'alpha') || (is_object($object) && is_object($object->thirdparty) && !empty($object->thirdparty->email))) {
  2405. ?>, email: '<?php echo dol_escape_js(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $object->thirdparty->email); ?>'<?php
  2406. } ?>
  2407. <?php if (is_object($object) && is_object($object->thirdparty) && !empty($object->thirdparty->phone)) {
  2408. ?>, phone: '<?php echo dol_escape_js($object->thirdparty->phone); ?>'<?php
  2409. } ?>
  2410. <?php if (is_object($object) && is_object($object->thirdparty)) {
  2411. ?>, address: {
  2412. city: '<?php echo dol_escape_js($object->thirdparty->town); ?>',
  2413. <?php if ($object->thirdparty->country_code) {
  2414. ?>country: '<?php echo dol_escape_js($object->thirdparty->country_code); ?>',<?php
  2415. } ?>
  2416. line1: '<?php echo dol_escape_js(preg_replace('/\s\s+/', ' ', $object->thirdparty->address)); ?>',
  2417. postal_code: '<?php echo dol_escape_js($object->thirdparty->zip); ?>'
  2418. }
  2419. <?php } ?>
  2420. }
  2421. },
  2422. save_payment_method:<?php if ($stripecu) {
  2423. print 'true';
  2424. } else {
  2425. print 'false';
  2426. } ?> /* true when a customer was provided when creating payment intent. true ask to save the card */
  2427. },
  2428. }
  2429. ).then(function(result) {
  2430. console.log(result);
  2431. if (result.error) {
  2432. console.log("Error on result of handleCardPayment");
  2433. jQuery('#buttontopay').show();
  2434. jQuery('#hourglasstopay').hide();
  2435. // Inform the user if there was an error
  2436. var errorElement = document.getElementById('card-errors');
  2437. console.log(result);
  2438. errorElement.textContent = result.error.message;
  2439. } else {
  2440. // The payment has succeeded. Display a success message.
  2441. console.log("No error on result of handleCardPayment, so we submit the form");
  2442. // Submit the form
  2443. jQuery('#buttontopay').hide();
  2444. jQuery('#hourglasstopay').show();
  2445. // Send form (action=charge that will do nothing)
  2446. jQuery('#payment-form').submit();
  2447. }
  2448. });
  2449. });
  2450. <?php
  2451. } else {
  2452. ?>
  2453. var cardElement = elements.create('card', {style: style});
  2454. // Add an instance of the card Element into the `card-element` <div>
  2455. cardElement.mount('#card-element');
  2456. // Handle real-time validation errors from the card Element.
  2457. cardElement.addEventListener('change', function(event) {
  2458. var displayError = document.getElementById('card-errors');
  2459. if (event.error) {
  2460. console.log("Show event error (like 'Incorrect card number', ...)");
  2461. displayError.textContent = event.error.message;
  2462. } else {
  2463. console.log("Reset error message");
  2464. displayError.textContent = '';
  2465. }
  2466. });
  2467. // Handle form submission
  2468. var cardholderName = document.getElementById('cardholder-name');
  2469. var cardButton = document.getElementById('buttontopay');
  2470. var clientSecret = cardButton.dataset.secret;
  2471. cardButton.addEventListener('click', function(event) {
  2472. console.log("We click on buttontopay");
  2473. event.preventDefault();
  2474. if (cardholderName.value == '')
  2475. {
  2476. console.log("Field Card holder is empty");
  2477. var displayError = document.getElementById('card-errors');
  2478. displayError.textContent = '<?php print dol_escape_js($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardOwner"))); ?>';
  2479. }
  2480. else
  2481. {
  2482. /* Disable button to pay and show hourglass cursor */
  2483. jQuery('#hourglasstopay').show();
  2484. jQuery('#buttontopay').hide();
  2485. stripe.handleCardPayment(
  2486. clientSecret, cardElement, {
  2487. payment_method_data: {
  2488. billing_details: {
  2489. name: cardholderName.value
  2490. <?php if (GETPOST('email', 'alpha') || (is_object($object) && is_object($object->thirdparty) && !empty($object->thirdparty->email))) {
  2491. ?>, email: '<?php echo dol_escape_js(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $object->thirdparty->email); ?>'<?php
  2492. } ?>
  2493. <?php if (is_object($object) && is_object($object->thirdparty) && !empty($object->thirdparty->phone)) {
  2494. ?>, phone: '<?php echo dol_escape_js($object->thirdparty->phone); ?>'<?php
  2495. } ?>
  2496. <?php if (is_object($object) && is_object($object->thirdparty)) {
  2497. ?>, address: {
  2498. city: '<?php echo dol_escape_js($object->thirdparty->town); ?>',
  2499. <?php if ($object->thirdparty->country_code) {
  2500. ?>country: '<?php echo dol_escape_js($object->thirdparty->country_code); ?>',<?php
  2501. } ?>
  2502. line1: '<?php echo dol_escape_js(preg_replace('/\s\s+/', ' ', $object->thirdparty->address)); ?>',
  2503. postal_code: '<?php echo dol_escape_js($object->thirdparty->zip); ?>'
  2504. }
  2505. <?php } ?>
  2506. }
  2507. },
  2508. save_payment_method:<?php if ($stripecu) {
  2509. print 'true';
  2510. } else {
  2511. print 'false';
  2512. } ?> /* true when a customer was provided when creating payment intent. true ask to save the card */
  2513. }
  2514. ).then(function(result) {
  2515. console.log(result);
  2516. if (result.error) {
  2517. console.log("Error on result of handleCardPayment");
  2518. jQuery('#buttontopay').show();
  2519. jQuery('#hourglasstopay').hide();
  2520. // Inform the user if there was an error
  2521. var errorElement = document.getElementById('card-errors');
  2522. errorElement.textContent = result.error.message;
  2523. } else {
  2524. // The payment has succeeded. Display a success message.
  2525. console.log("No error on result of handleCardPayment, so we submit the form");
  2526. // Submit the form
  2527. jQuery('#buttontopay').hide();
  2528. jQuery('#hourglasstopay').show();
  2529. // Send form (action=charge that will do nothing)
  2530. jQuery('#payment-form').submit();
  2531. }
  2532. });
  2533. }
  2534. });
  2535. <?php
  2536. }
  2537. ?>
  2538. <?php
  2539. }
  2540. print '</script>';
  2541. }
  2542. }
  2543. // For any other payment services
  2544. // This hook can be used to show the embedded form to make payments with external payment modules (ie Payzen, ...)
  2545. $parameters = [
  2546. 'paymentmethod' => $paymentmethod,
  2547. 'amount' => $amount,
  2548. 'currency' => $currency,
  2549. 'tag' => GETPOST("tag", 'alpha'),
  2550. 'dopayment' => GETPOST('dopayment', 'alpha')
  2551. ];
  2552. $reshook = $hookmanager->executeHooks('doPayment', $parameters, $object, $action);
  2553. if ($reshook < 0) {
  2554. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  2555. } elseif ($reshook > 0) {
  2556. print $hookmanager->resPrint;
  2557. }
  2558. }
  2559. htmlPrintOnlinePaymentFooter($mysoc, $langs, 1, $suffix, $object);
  2560. llxFooter('', 'public');
  2561. $db->close();