newpayment.php 107 KB

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