newpayment.php 107 KB

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