newpayment.php 106 KB

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