dolibarr 25.0.0-alpha
newpayment.php
Go to the documentation of this file.
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 *
25 * For Paypal test: https://developer.paypal.com/
26 * For Paybox test: ???
27 * For Stripe test: Use credit card 4242424242424242 .More example on https://stripe.com/docs/testing
28 *
29 * Variants:
30 * - When option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION is on, we use the new PaymentIntent API
31 * - When option STRIPE_USE_NEW_CHECKOUT is on, we use the new checkout API
32 * - If no option set, we use old APIS (charge)
33 */
34
41if (!defined('NOLOGIN')) {
42 define("NOLOGIN", 1); // This means this output page does not require to be logged.
43}
44if (!defined('NOCSRFCHECK')) {
45 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
46}
47if (!defined('NOIPCHECK')) {
48 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
49}
50if (!defined('NOBROWSERNOTIF')) {
51 define('NOBROWSERNOTIF', '1');
52}
53
54if (!defined('XFRAMEOPTIONS_ALLOWALL')) {
55 define('XFRAMEOPTIONS_ALLOWALL', '1');
56}
57
58// For MultiCompany module.
59// Do not use GETPOST here, function is not defined and get of entity must be done before including main.inc.php
60// Because 2 entities can have the same ref.
61$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))));
62if (is_numeric($entity)) {
63 define("DOLENTITY", $entity);
64}
65
66// Load Dolibarr environment
67require '../../main.inc.php';
78require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
79require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
80require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
81require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
82require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
83require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
84require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
85require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
86require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
87require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
88
89// Load translation files
90$langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paypal", "stripe")); // File with generic data
91
92// Hook to be used by external payment modules (ie Payzen, ...)
93$hookmanager = new HookManager($db);
94$hookmanager->initHooks(array('newpayment'));
95
96
97// Security check
98// No check on module enabled. Done later according to $validpaymentmethod
99
100$action = GETPOST('action', 'aZ09');
101
102// Input are:
103// type ('invoice','order','contractline'),
104// id (object id),
105// amount (required if id is empty),
106// tag (a free text, required if type is empty)
107// currency (iso code)
108
109$suffix = GETPOST("suffix", 'aZ09');
110$amount = price2num(GETPOST("amount", 'alpha'));
111if (!GETPOST("currency", 'alpha')) {
112 $currency = getDolCurrency();
113} else {
114 $currency = GETPOST("currency", 'aZ09');
115}
116$source = GETPOST("s", 'aZ09') ? GETPOST("s", 'aZ09') : GETPOST("source", 'aZ09');
117$getpostlang = GETPOST('lang', 'aZ09');
118$ws = GETPOST("ws", "aZ09"); // Website reference where the newpayment page is embedded or from where the newpayment page is called
119
120if (!$action) {
121 if (!GETPOST("amount", 'alpha') && !$source) {
122 $langs->load('errors');
123 print $langs->trans('ErrorBadParameters')." - amount or source";
124 exit;
125 }
126 if (is_numeric($amount) && !GETPOST("tag", 'alpha') && !$source) {
127 $langs->load('errors');
128 print $langs->trans('ErrorBadParameters')." - tag or source";
129 exit;
130 }
131 if ($source && !GETPOST("ref", 'alpha')) {
132 $langs->load('errors');
133 print $langs->trans('ErrorBadParameters')." - ref";
134 exit;
135 }
136}
137
138
139$thirdparty = null; // Init for static analysis
140$attendee = null; // Init for static analysis
141$invoice = null; // Init for static analysis
142$stripecu = null; // Init for static analysis
143$paymentintent = null; // Init for static analysis
144
145// Load data required later for actions and view
146
147if ($source == 'organizedeventregistration') { // Test on permission not required here (anonymous action protected by mitigation of /public/... urls)
148 // Finding the Attendee
149 $attendee = new ConferenceOrBoothAttendee($db);
150
151 $invoiceid = GETPOSTINT('ref');
152 $invoice = new Facture($db);
153
154 $resultinvoice = $invoice->fetch($invoiceid);
155
156 if ($resultinvoice <= 0) {
157 setEventMessages(null, $invoice->errors, "errors");
158 } else {
159 /*
160 $attendeeid = 0;
161
162 $invoice->fetchObjectLinked();
163 $linkedAttendees = $invoice->linkedObjectsIds['conferenceorboothattendee'];
164
165 if (is_array($linkedAttendees)) {
166 $linkedAttendees = array_values($linkedAttendees);
167 $attendeeid = $linkedAttendees[0];
168 }*/
169 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee";
170 $sql .= " WHERE fk_invoice = ".((int) $invoiceid);
171 $attendeeid = 0;
172 $resql = $db->query($sql);
173 if ($resql) {
174 $obj = $db->fetch_object($resql);
175 if ($obj) {
176 $attendeeid = $obj->rowid;
177 }
178 }
179
180 if ($attendeeid > 0) {
181 $resultattendee = $attendee->fetch($attendeeid);
182
183 if ($resultattendee <= 0) {
184 setEventMessages(null, $attendee->errors, "errors");
185 } else {
186 $attendee->fetch_projet();
187
188 $amount = price2num($invoice->total_ttc);
189 // Finding the associated thirdparty
190 $thirdparty = new Societe($db);
191 $resultthirdparty = $thirdparty->fetch($invoice->socid);
192 if ($resultthirdparty <= 0) {
193 setEventMessages(null, $thirdparty->errors, "errors");
194 }
195 $object = $thirdparty;
196 }
197 }
198 }
199} elseif ($source == 'boothlocation') { // Test on permission not required here (anonymous action protected by mitigation of /public/... urls)
200 // Getting the amount to pay, the invoice, finding the thirdparty
201 $invoiceid = GETPOSTINT('ref');
202 $invoice = new Facture($db);
203 $resultinvoice = $invoice->fetch($invoiceid);
204 if ($resultinvoice <= 0) {
205 setEventMessages(null, $invoice->errors, "errors");
206 } else {
207 $amount = price2num($invoice->total_ttc);
208 // Finding the associated thirdparty
209 $thirdparty = new Societe($db);
210 $resultthirdparty = $thirdparty->fetch($invoice->socid);
211 if ($resultthirdparty <= 0) {
212 setEventMessages(null, $thirdparty->errors, "errors");
213 }
214 $object = $thirdparty;
215 }
216}
217
218
219$paymentmethod = GETPOST('paymentmethod', 'alphanohtml') ? GETPOST('paymentmethod', 'alphanohtml') : ''; // Empty in most cases. Defined when a payment mode is forced
220$validpaymentmethod = array();
221
222// Detect $paymentmethod
223foreach ($_POST as $key => $val) {
224 $reg = array();
225 if (preg_match('/^dopayment_(.*)$/', $key, $reg)) {
226 $paymentmethod = $reg[1];
227 break;
228 }
229}
230
231// Complete urls for post treatment
232$ref = $REF = GETPOST('ref', 'alpha');
233$TAG = GETPOST("tag", 'alpha');
234$FULLTAG = GETPOST("fulltag", 'alpha'); // fulltag is tag with more information
235$SECUREKEY = GETPOST("securekey"); // Secure key
236$PAYPAL_API_OK = "";
237$PAYPAL_API_KO = "";
238$PAYPAL_API_SANDBOX = "";
239$PAYPAL_API_USER = "";
240$PAYPAL_API_PASSWORD = "";
241$PAYPAL_API_SIGNATURE = "";
242
243$reg = array();
244if (empty($ws) && preg_match('/WS=([^=&]+)/', $FULLTAG, $reg)) {
245 $ws = $reg[1];
246}
247
248// Define $urlwithroot
249//$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
250//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
251$urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
252
253$urlok = $urlwithroot.'/public/payment/paymentok.php?';
254$urlko = $urlwithroot.'/public/payment/paymentko.php?';
255
256if ($ws && !defined('USEDOLIBARRSERVER') && !defined('USEDOLIBARREDITOR')) { // So defined('USEEXTERNALSERVER') should be set but is not always
257 if (!empty($_SERVER["HTTP_X_FORWARDED_HOST"])) {
258 // Page is called after a proxy
259 $tmphosts = explode(',', $_SERVER["HTTP_X_FORWARDED_HOST"]);
260 $tmphosts = array_map('trim', $tmphosts);
261 $lastproxy = end($tmphosts);
262
263 include_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
264 $tmpwebsite = new Website($db);
265 $tmpwebsite->fetch(0, $ws);
266
267 if (preg_replace('/https?:\/\//i', '', $tmpwebsite->virtualhost) == $lastproxy) {
268 // If the newpayment.php page was called from a proxy with same domain than the website virtual host, we must use this one as the redirect domain url.
269 $urlok = $tmpwebsite->virtualhost.'/public/payment/paymentok.php?';
270 $urlko = $tmpwebsite->virtualhost.'/public/payment/paymentko.php?';
271 }
272 }
273}
274
275if ($paymentmethod && !preg_match('/'.preg_quote('PM='.$paymentmethod, '/').'/', $FULLTAG)) {
276 $FULLTAG .= ($FULLTAG ? '.' : '').'PM='.$paymentmethod;
277}
278
279if ($ws && !preg_match('/'.preg_quote('WS='.$ws, '/').'/', $FULLTAG)) {
280 $FULLTAG .= ($FULLTAG ? '.' : '').'WS='.$ws;
281}
282
283if (!empty($suffix)) {
284 $urlok .= 'suffix='.urlencode($suffix).'&';
285 $urlko .= 'suffix='.urlencode($suffix).'&';
286}
287if ($source) {
288 $urlok .= 's='.urlencode($source).'&';
289 $urlko .= 's='.urlencode($source).'&';
290}
291if (!empty($REF)) {
292 $urlok .= 'ref='.urlencode($REF).'&';
293 $urlko .= 'ref='.urlencode($REF).'&';
294}
295if (!empty($TAG)) {
296 $urlok .= 'tag='.urlencode($TAG).'&';
297 $urlko .= 'tag='.urlencode($TAG).'&';
298}
299if (!empty($FULLTAG)) {
300 $urlok .= 'fulltag='.urlencode($FULLTAG).'&';
301 $urlko .= 'fulltag='.urlencode($FULLTAG).'&';
302}
303if (!empty($SECUREKEY)) {
304 $urlok .= 'securekey='.urlencode($SECUREKEY).'&';
305 $urlko .= 'securekey='.urlencode($SECUREKEY).'&';
306}
307if (!empty($entity)) {
308 $urlok .= 'e='.urlencode((string) ($entity)).'&';
309 $urlko .= 'e='.urlencode((string) ($entity)).'&';
310}
311if (!empty($getpostlang)) {
312 $urlok .= 'lang='.urlencode($getpostlang).'&';
313 $urlko .= 'lang='.urlencode($getpostlang).'&';
314}
315$urlok = preg_replace('/&$/', '', $urlok); // Remove last &
316$urlko = preg_replace('/&$/', '', $urlko); // Remove last &
317
318
319// Make special controls
320
321// From paypal.lib - reused across 'if' bodies
322'
323@phan-var-force string $PAYPAL_API_SANDBOX
324@phan-var-force string $PAYPAL_API_OK
325@phan-var-force string $PAYPAL_API_KO
326';
327
328if ((empty($paymentmethod) || $paymentmethod == 'paypal') && isModEnabled('paypal')) {
329 global $PAYPAL_API_SANDBOX, $PAYPAL_API_OK, $PAYPAL_API_KO, $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
330 require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
331 require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
332
333
334 // Check parameters
335 $PAYPAL_API_OK = "";
336 if ($urlok) {
337 $PAYPAL_API_OK = $urlok;
338 }
339 $PAYPAL_API_KO = "";
340 if ($urlko) {
341 $PAYPAL_API_KO = $urlko;
342 }
343 if (empty($PAYPAL_API_USER)) {
344 print 'Paypal parameter PAYPAL_API_USER is not defined. Please <a href="'.DOL_URL_ROOT.'/paypal/admin/paypal.php">complete the setup of module PayPal first</a>.';
345 exit;
346 }
347 if (empty($PAYPAL_API_PASSWORD)) {
348 print 'Paypal parameter PAYPAL_API_PASSWORD is not defined. Please <a href="'.DOL_URL_ROOT.'/paypal/admin/paypal.php">complete the setup of module PayPal first</a>.';
349 exit;
350 }
351 if (empty($PAYPAL_API_SIGNATURE)) {
352 print 'Paypal parameter PAYPAL_API_SIGNATURE is not defined. Please <a href="'.DOL_URL_ROOT.'/paypal/admin/paypal.php">complete the setup of module PayPal first</a>.';
353 exit;
354 }
355}
356if ((empty($paymentmethod) || $paymentmethod == 'stripe') && isModEnabled('stripe')) {
357 require_once DOL_DOCUMENT_ROOT.'/stripe/config.php'; // This include also /stripe/lib/stripe.lib.php, /includes/stripe/stripe-php/init.php, ...
362}
363
364// Initialize $validpaymentmethod
365// The list can be complete by the hook 'doValidatePayment' executed inside getValidOnlinePaymentMethods()
366$validpaymentmethod = getValidOnlinePaymentMethods($paymentmethod);
367
368// Check security token
369$tmpsource = $source;
370if ($tmpsource == 'membersubscription') {
371 $tmpsource = 'member';
372}
373$valid = true;
374if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
375 $tokenisok = false;
376 if ($tmpsource && $REF) {
377 // Use the source in the hash to avoid duplicates if the references are identical
378 $tokenisok = dol_verifyHash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $tmpsource.$REF, $SECUREKEY, '2');
379 // Do a second test for retro-compatibility (token may have been hashed with membersubscription in external module)
380 if ($tmpsource != $source) {
381 $tokenisok = dol_verifyHash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $source.$REF, $SECUREKEY, '2');
382 }
383 }
384
385 if (! $tokenisok) {
386 if (!getDolGlobalString('PAYMENT_SECURITY_ACCEPT_ANY_TOKEN')) {
387 $valid = false; // PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is for backward compatibility
388 } else {
389 dol_syslog("Warning: PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is on", LOG_WARNING);
390 dol_syslog("Warning: PAYMENT_SECURITY_ACCEPT_ANY_TOKEN is on", LOG_WARNING, 0, '_payment');
391 }
392 }
393
394 if (!$valid) {
395 print '<div class="error">Bad value for key.</div>';
396 //print 'SECUREKEY='.$SECUREKEY.' valid='.$valid;
397 exit;
398 }
399}
400
401if (!empty($paymentmethod) && empty($validpaymentmethod[$paymentmethod])) {
402 print 'Payment module for payment method '.$paymentmethod.' is not active';
403 exit;
404}
405if (empty($validpaymentmethod)) {
406 print 'No active payment module (Paypal, Stripe, Paybox, ...)';
407 exit;
408}
409
410// Common variables
411$creditor = $mysoc->name;
412$paramcreditor = 'ONLINE_PAYMENT_CREDITOR';
413$paramcreditorlong = 'ONLINE_PAYMENT_CREDITOR_'.$suffix;
414if (getDolGlobalString($paramcreditorlong)) {
415 $creditor = getDolGlobalString($paramcreditorlong); // use label long of the seller to show
416} elseif (getDolGlobalString($paramcreditor)) {
417 $creditor = getDolGlobalString($paramcreditor); // use label short of the seller to show
418}
419
420$mesg = '';
421
422
423/*
424 * Actions
425 */
426
427// First log into the dolibarr_payment.log file
428dol_syslog("--- newpayment.php action=".$action." paymentmethod=".$paymentmethod.' amount='.$amount.' newamount='.GETPOST("newamount", 'alpha'), LOG_DEBUG, 0, '_payment');
429
430dol_syslog("fulltag=".GETPOST("fulltag", 'alpha')." ws=".$ws." urlok=".$urlok, LOG_DEBUG, 0, '_payment');
431
432// Action dopayment is called after clicking/choosing the payment mode
433if ($action == 'dopayment') { // Test on permission not required here (anonymous action protected by mitigation of /public/... urls)
434 // Payment account information
435 $accountid = 0;
436 if ($paymentmethod == 'paybox') {
437 $accountid = getDolGlobalString('PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS');
438 }
439 if ($paymentmethod == 'paypal') {
440 $accountid = getDolGlobalString('PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS');
441 }
442 if ($paymentmethod == 'stripe') {
443 $accountid = getDolGlobalString('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS');
444 }
445 // Get bank account for a specific paymentmedthod
446 $parameters = [
447 'paymentmethod' => $paymentmethod,
448 ];
449 $reshook = $hookmanager->executeHooks('getBankAccountPaymentMethod', $parameters, $object, $action);
450 if ($reshook >= 0) {
451 if (isset($hookmanager->resArray['bankaccountid'])) {
452 dol_syslog('accountid overwrite by hook return with value='.$hookmanager->resArray['bankaccountid'], LOG_DEBUG, 0, '_payment');
453 $accountid = $hookmanager->resArray['bankaccountid'];
454 }
455 }
456 if (isModEnabled('bank') && $accountid < 0) {
457 $mesg = 'Setup of bank account to use for payment is not correctly done for payment method '.$paymentmethod;
458 $action = '';
459 }
460
461 if ($paymentmethod == 'paypal') {
462 $PAYPAL_API_PRICE = price2num(GETPOST("newamount", 'alpha'), 'MT');
463 $PAYPAL_PAYMENT_TYPE = 'Sale';
464
465 // Vars that are used as global var later in print_paypal_redirect()
466 $origfulltag = GETPOST("fulltag", 'alpha');
467 $shipToName = GETPOST("shipToName", 'alpha');
468 $shipToStreet = GETPOST("shipToStreet", 'alpha');
469 $shipToCity = GETPOST("shipToCity", 'alpha');
470 $shipToState = GETPOST("shipToState", 'alpha');
471 $shipToCountryCode = GETPOST("shipToCountryCode", 'alpha');
472 $shipToZip = GETPOST("shipToZip", 'alpha');
473 $shipToStreet2 = GETPOST("shipToStreet2", 'alpha');
474 $phoneNum = GETPOST("phoneNum", 'alpha');
475 $email = GETPOST("email", 'alpha');
476 $desc = GETPOST("desc", 'alpha');
477 $thirdparty_id = GETPOSTINT('thirdparty_id');
478
479 // Special case for Paypal-Indonesia
480 if ($shipToCountryCode == 'ID' && !preg_match('/\-/', $shipToState)) {
481 $shipToState = 'ID-'.$shipToState;
482 }
483
484 if (empty($PAYPAL_API_PRICE) || !is_numeric($PAYPAL_API_PRICE)) {
485 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount"));
486 $action = '';
487 // } elseif (empty($EMAIL)) { $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail"));
488 // } elseif (! isValidEmail($EMAIL)) { $mesg=$langs->trans("ErrorBadEMail",$EMAIL);
489 } elseif (!$origfulltag) {
490 $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentCode"));
491 $action = '';
492 }
493
494 if (empty($mesg)) {
495 dol_syslog("newpayment.php call paypal api and do redirect", LOG_DEBUG);
496 dol_syslog("newpayment.php call paypal api and do redirect", LOG_DEBUG, 0, '_payment');
497
498 // Other
499 $PAYPAL_API_DEVISE = "USD";
500 if (!empty($currency)) {
501 $PAYPAL_API_DEVISE = $currency;
502 }
503
504 // Show var initialized by inclusion of paypal lib at start of this file
505 dol_syslog("Submit Paypal form", LOG_DEBUG);
506 dol_syslog("Submit Paypal form", LOG_DEBUG, 0, '_payment');
507
508 dol_syslog("PAYPAL_API_USER: $PAYPAL_API_USER", LOG_DEBUG, 0, '_payment');
509 dol_syslog("PAYPAL_API_PASSWORD: ".preg_replace('/./', '*', $PAYPAL_API_PASSWORD), LOG_DEBUG, 0, '_payment'); // No password into log files
510 dol_syslog("PAYPAL_API_SIGNATURE: $PAYPAL_API_SIGNATURE", LOG_DEBUG, 0, '_payment');
511 dol_syslog("PAYPAL_API_SANDBOX: $PAYPAL_API_SANDBOX", LOG_DEBUG, 0, '_payment');
512 dol_syslog("PAYPAL_API_OK: $PAYPAL_API_OK", LOG_DEBUG, 0, '_payment');
513 dol_syslog("PAYPAL_API_KO: $PAYPAL_API_KO", LOG_DEBUG, 0, '_payment');
514 dol_syslog("PAYPAL_API_PRICE: $PAYPAL_API_PRICE", LOG_DEBUG, 0, '_payment');
515 dol_syslog("PAYPAL_API_DEVISE: $PAYPAL_API_DEVISE", LOG_DEBUG, 0, '_payment');
516 // All those fields may be empty when making a payment for a free amount for example
517 dol_syslog("shipToName: $shipToName", LOG_DEBUG, 0, '_payment');
518 dol_syslog("shipToStreet: $shipToStreet", LOG_DEBUG, 0, '_payment');
519 dol_syslog("shipToCity: $shipToCity", LOG_DEBUG, 0, '_payment');
520 dol_syslog("shipToState: $shipToState", LOG_DEBUG, 0, '_payment');
521 dol_syslog("shipToCountryCode: $shipToCountryCode", LOG_DEBUG, 0, '_payment');
522 dol_syslog("shipToZip: $shipToZip", LOG_DEBUG, 0, '_payment');
523 dol_syslog("shipToStreet2: $shipToStreet2", LOG_DEBUG, 0, '_payment');
524 dol_syslog("phoneNum: $phoneNum", LOG_DEBUG, 0, '_payment');
525 dol_syslog("email: $email", LOG_DEBUG, 0, '_payment');
526 dol_syslog("desc: $desc", LOG_DEBUG, 0, '_payment');
527
528 dol_syslog("SCRIPT_URI: ".(empty($_SERVER["SCRIPT_URI"]) ? '' : $_SERVER["SCRIPT_URI"]), LOG_DEBUG, 0, '_payment'); // If defined script uri must match domain of PAYPAL_API_OK and PAYPAL_API_KO
529
530 // A redirect is added if API call successful
531 $mesg = print_paypal_redirect((float) $PAYPAL_API_PRICE, $PAYPAL_API_DEVISE, $PAYPAL_PAYMENT_TYPE, $PAYPAL_API_OK, $PAYPAL_API_KO, $FULLTAG);
532
533 // If we are here, it means the Paypal redirect was not done, so we show error message
534 $action = '';
535 }
536 }
537
538 if ($paymentmethod == 'stripe') {
539 if (GETPOST('newamount', 'alpha')) {
540 $amount = price2num(GETPOST('newamount', 'alpha'), 'MT');
541 } else {
542 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
543 $action = '';
544 }
545 }
546}
547
548
549// Called when choosing Stripe mode.
550// When using the old Charge API architecture, this code is called after clicking the 'dopayment' with the Charge API architecture.
551// 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.
552if ($action == 'charge' && isModEnabled('stripe')) { // Test on permission not required here (anonymous action protected by mitigation of /public/... urls)
553 $amountstripe = (float) $amount;
554
555 // Correct the amount according to unit of currency
556 // See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
557 $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
558 if (!in_array($currency, $arrayzerounitcurrency)) {
559 $amountstripe *= 100;
560 }
561
562 dol_syslog("newpayment.php execute action = ".$action." STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION=".getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION'), LOG_DEBUG, 0, '_payment');
563 dol_syslog("GET=".formatLogObject($_GET), LOG_DEBUG, 0, '_payment');
564 dol_syslog("POST=".formatLogObject($_POST), LOG_DEBUG, 0, '_payment');
565
566 $stripeToken = GETPOST("stripeToken", 'alpha');
567 $email = GETPOST("email", 'alpha');
568 $thirdparty_id = GETPOSTINT('thirdparty_id'); // Note that for payment following online registration for members, this is empty because thirdparty is created once payment is confirmed by paymentok.php
569 $dol_type = (GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha'));
570 $dol_id = GETPOSTINT('dol_id');
571 $vatnumber = GETPOST('vatnumber', 'alpha');
572 $savesource = GETPOSTISSET('savesource') ? GETPOSTINT('savesource') : 1;
573
574 dol_syslog("POST stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_payment');
575 dol_syslog("POST email = ".$email, LOG_DEBUG, 0, '_payment');
576 dol_syslog("POST thirdparty_id = ".$thirdparty_id, LOG_DEBUG, 0, '_payment');
577 dol_syslog("POST vatnumber = ".$vatnumber, LOG_DEBUG, 0, '_payment');
578
579 $error = 0;
580 $errormessage = '';
581 $stripeacc = null;
582 $customer = null;
583 $charge = null;
584 $paymentintent = null;
585
586 // When using the old Charge API architecture
587 if (!getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) {
588 try {
589 $metadata = array(
590 'dol_version' => DOL_VERSION,
591 'dol_entity' => $conf->entity,
592 'dol_company' => $mysoc->name, // Useful when using multicompany
593 'dol_tax_num' => $vatnumber,
594 'ipaddress' => getUserRemoteIP()
595 );
596
597 if (!empty($thirdparty_id)) {
598 $metadata["dol_thirdparty_id"] = $thirdparty_id;
599 }
600
601 if ($thirdparty_id > 0) {
602 dol_syslog("Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0, '_payment');
603
604 $service = 'StripeTest';
605 $servicestatus = 0;
606 if (getDolGlobalString('STRIPE_LIVE')/* && !GETPOSTINT('forcesandbox') */) {
607 $service = 'StripeLive';
608 $servicestatus = 1;
609 }
610
611 $thirdparty = new Societe($db);
612 $thirdparty->fetch($thirdparty_id);
613
614 // Create Stripe customer
615 include_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
616 $stripe = new Stripe($db);
617 $stripeacc = $stripe->getStripeAccount($service);
618 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
619 if (empty($customer)) {
620 $error++;
621 dol_syslog('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, LOG_ERR, 0, '_payment');
622 setEventMessages('Failed to get/create stripe customer for thirdparty id = '.$thirdparty_id.' and servicestatus = '.$servicestatus.': '.$stripe->error, null, 'errors');
623 $action = '';
624 }
625
626 // Create Stripe card from Token
627 if (!$error) {
628 if ($savesource) {
629 $card = $customer->sources->create(array("source" => $stripeToken, "metadata" => $metadata));
630 } else {
631 $card = $stripeToken;
632 }
633
634 if (empty($card)) {
635 $error++;
636 dol_syslog('Failed to create card record', LOG_WARNING, 0, '_payment');
637 setEventMessages('Failed to create card record', null, 'errors');
638 $action = '';
639 } else {
640 if (!empty($FULLTAG)) {
641 $metadata["FULLTAG"] = $FULLTAG;
642 }
643 if (!empty($dol_id)) {
644 $metadata["dol_id"] = $dol_id;
645 }
646 if (!empty($dol_type)) {
647 $metadata["dol_type"] = $dol_type;
648 }
649
650 dol_syslog("Create charge on card ".$card->id, LOG_DEBUG, 0, '_payment');
651 $charge = \Stripe\Charge::create(array(
652 'amount' => price2num($amountstripe, 'MU'),
653 'currency' => $currency,
654 'capture' => true, // Charge immediately
655 'description' => 'Stripe payment: '.$FULLTAG.' ref='.$ref,
656 'metadata' => $metadata,
657 'customer' => $customer->id,
658 'source' => $card,
659 'statement_descriptor' => dol_trunc($FULLTAG, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt for SEPA
660 'statement_descriptor_suffix' => dol_trunc($FULLTAG, 12, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt for CARD (company + description)
661 ), array("idempotency_key" => "$FULLTAG", "stripe_account" => "$stripeacc"));
662 // Return $charge = array('id'=>'ch_XXXX', 'status'=>'succeeded|pending|failed', 'failure_code'=>, 'failure_message'=>...)
663 if (empty($charge)) {
664 $error++;
665 dol_syslog('Failed to charge card', LOG_WARNING, 0, '_payment');
666 setEventMessages('Failed to charge card', null, 'errors');
667 $action = '';
668 }
669 }
670 }
671 } else {
672 $vatcleaned = $vatnumber ? $vatnumber : null;
673
674 /*$taxinfo = array('type'=>'vat');
675 if ($vatcleaned)
676 {
677 $taxinfo["tax_id"] = $vatcleaned;
678 }
679 // We force data to "null" if not defined as expected by Stripe
680 if (empty($vatcleaned)) $taxinfo=null;
681 */
682
683 dol_syslog("Create anonymous customer card profile", LOG_DEBUG, 0, '_payment');
684
685 $customer = \Stripe\Customer::create(array(
686 'email' => $email,
687 'description' => ($email ? 'Anonymous customer for '.$email : 'Anonymous customer'),
688 'metadata' => $metadata,
689 '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 ?)
690 ));
691 // Return $customer = array('id'=>'cus_XXXX', ...)
692
693 // Create the VAT record in Stripe
694 /* We don't know country of customer, so we can't create tax
695 if (getDolGlobalString('STRIPE_SAVE_TAX_IDS')) { // We setup to save Tax info on Stripe side. Warning: This may result in error when saving customer
696 if (!empty($vatcleaned))
697 {
698 $isineec=isInEEC($object);
699 if ($object->country_code && $isineec)
700 {
701 //$taxids = $customer->allTaxIds($customer->id);
702 $customer->createTaxId($customer->id, array('type'=>'eu_vat', 'value'=>$vatcleaned));
703 }
704 }
705 }*/
706
707 if (!empty($FULLTAG)) {
708 $metadata["FULLTAG"] = $FULLTAG;
709 }
710 if (!empty($dol_id)) {
711 $metadata["dol_id"] = $dol_id;
712 }
713 if (!empty($dol_type)) {
714 $metadata["dol_type"] = $dol_type;
715 }
716
717 // The customer was just created with a source, so we can make a charge
718 // with no card defined, the source just used for customer creation will be used.
719 dol_syslog("Create charge", LOG_DEBUG, 0, '_payment');
720 $charge = \Stripe\Charge::create(array(
721 'customer' => $customer->id,
722 'amount' => price2num($amountstripe, 'MU'),
723 'currency' => $currency,
724 'capture' => true, // Charge immediately
725 'description' => 'Stripe payment: '.$FULLTAG.' ref='.$ref,
726 'metadata' => $metadata,
727 'statement_descriptor' => dol_trunc($FULLTAG, 22, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt for SEPA
728 'statement_descriptor_suffix' => dol_trunc($FULLTAG, 12, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt for CARD (company + description)
729 ), array("idempotency_key" => (string) $FULLTAG, "stripe_account" => (string) $stripeacc));
730 // Return $charge = array('id'=>'ch_XXXX', 'status'=>'succeeded|pending|failed', 'failure_code'=>, 'failure_message'=>...)
731 if (empty($charge)) {
732 $error++;
733 dol_syslog('Failed to charge card', LOG_WARNING, 0, '_payment');
734 setEventMessages('Failed to charge card', null, 'errors');
735 $action = '';
736 }
737 }
738 } catch (\Stripe\Exception\CardException $e) {
739 // Since it's a decline, \Stripe\Exception\Card will be caught
740 $body = $e->getJsonBody();
741 $err = $body['error'];
742
743 print('Status is:'.$e->getHttpStatus()."\n");
744 print('Type is:'.$err['type']."\n");
745 print('Code is:'.$err['code']."\n");
746 // param is '' in this case
747 print('Param is:'.$err['param']."\n");
748 print('Message is:'.$err['message']."\n");
749
750 $error++;
751 $errormessage = "ErrorCard ".$e->getMessage()." err=".formatLogObject($err);
752 dol_syslog($errormessage, LOG_WARNING, 0, '_payment');
753 setEventMessages($e->getMessage(), null, 'errors');
754 $action = '';
755 } catch (\Stripe\Exception\RateLimitException $e) {
756 // Too many requests made to the API too quickly
757 $error++;
758 $errormessage = "ErrorRateLimit ".$e->getMessage();
759 dol_syslog($errormessage, LOG_WARNING, 0, '_payment');
760 setEventMessages($e->getMessage(), null, 'errors');
761 $action = '';
762 } catch (\Stripe\Exception\InvalidRequestException $e) {
763 // Invalid parameters were supplied to Stripe's API
764 $error++;
765 $errormessage = "ErrorInvalidRequest ".$e->getMessage();
766 dol_syslog($errormessage, LOG_WARNING, 0, '_payment');
767 setEventMessages($e->getMessage(), null, 'errors');
768 $action = '';
769 } catch (\Stripe\Exception\AuthenticationException $e) {
770 // Authentication with Stripe's API failed
771 // (maybe you changed API keys recently)
772 $error++;
773 $errormessage = "ErrorAuthentication ".$e->getMessage();
774 dol_syslog($errormessage, LOG_WARNING, 0, '_payment');
775 setEventMessages($e->getMessage(), null, 'errors');
776 $action = '';
777 } catch (\Stripe\Exception\ApiConnectionException $e) {
778 // Network communication with Stripe failed
779 $error++;
780 $errormessage = "ErrorApiConnection ".$e->getMessage();
781 dol_syslog($errormessage, LOG_WARNING, 0, '_payment');
782 setEventMessages($e->getMessage(), null, 'errors');
783 $action = '';
784 } catch (\Stripe\Exception\ExceptionInterface $e) {
785 // Display a very generic error to the user, and maybe send
786 // yourself an email
787 $error++;
788 $errormessage = "ErrorBase ".$e->getMessage();
789 dol_syslog($errormessage, LOG_WARNING, 0, '_payment');
790 setEventMessages($e->getMessage(), null, 'errors');
791 $action = '';
792 } catch (Exception $e) {
793 // Something else happened, completely unrelated to Stripe
794 $error++;
795 $errormessage = "ErrorException ".$e->getMessage();
796 dol_syslog($errormessage, LOG_WARNING, 0, '_payment');
797 setEventMessages($e->getMessage(), null, 'errors');
798 $action = '';
799 }
800
801 if ($error) {
802 $randomseckey = getRandomPassword(true, null, 20); // TODO Generate a key including fulltag to avoid forging URL.
803 $_SESSION['paymentkosessioncode'] = $randomseckey; // key between newpayment.php to paymentko.php
804
805 $urlko .= '&paymentkosessioncode='.urlencode($randomseckey);
806 } else {
807 $randomseckey = getRandomPassword(true, null, 20); // TODO Generate a key including fulltag to avoid forging URL.
808 $_SESSION['paymentoksessioncode'] = $randomseckey; // key between newpayment.php to paymentok.php
809
810 $urlok .= '&paymentoksessioncode='.urlencode($randomseckey);
811 }
812 }
813
814 // When using the PaymentIntent API architecture (mode set on by default into conf.class.php)
815 if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) {
816 $service = 'StripeTest';
817 $servicestatus = 0;
818 if (getDolGlobalString('STRIPE_LIVE')/* && !GETPOSTINT('forcesandbox') */) {
819 $service = 'StripeLive';
820 $servicestatus = 1;
821 }
822 include_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
823 $stripe = new Stripe($db);
824 $stripeacc = $stripe->getStripeAccount($service);
825
826 // We go here if getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') is set.
827 // In such a case, payment is always ok when we call the "charge" action.
828 $paymentintent_id = GETPOST("paymentintent_id", "alpha");
829
830 // Force to use the correct API key
831 global $stripearrayofkeysbyenv;
832 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']);
833
834 try {
835 if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
836 $paymentintent = \Stripe\PaymentIntent::retrieve($paymentintent_id);
837 } else {
838 $paymentintent = \Stripe\PaymentIntent::retrieve($paymentintent_id, array("stripe_account" => $stripeacc));
839 }
840 } catch (Exception $e) {
841 $error++;
842 $errormessage = "CantRetrievePaymentIntent ".$e->getMessage();
843 dol_syslog($errormessage, LOG_WARNING, 0, '_payment');
844 setEventMessages($e->getMessage(), null, 'errors');
845 $action = '';
846 }
847
848 // Security: a succeeded PaymentIntent must not be reusable to record a payment on more than one Dolibarr object.
849 // Without this check, a PaymentIntent id obtained for one invoice/order/... could be resubmitted here with a
850 // different fulltag/ref to fraudulently record (and validate) a payment on a different object that was never
851 // really paid for, since Dolibarr never re-checks that a "succeeded" PaymentIntent is bound to a specific target.
852 $paymentintentalreadyused = 0;
853 if (!$error && is_object($paymentintent) && $paymentintent->status == 'succeeded') {
854 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."paiement";
855 $sql .= " WHERE ext_payment_id = '".$db->escape($paymentintent_id)."'";
856 $sql .= " OR ext_payment_id LIKE '".$db->escape($paymentintent_id).":%'";
857 $resql = $db->query($sql);
858 if ($resql) {
859 if ($db->num_rows($resql) > 0) {
860 $paymentintentalreadyused = 1;
861 }
862 $db->free($resql);
863 }
864 }
865
866 if ($paymentintent->status != 'succeeded' || $paymentintentalreadyused) {
867 $error++;
868 if ($paymentintentalreadyused) {
869 $errormessage = "PaymentIntent ".$paymentintent_id." was already used to record a payment, it cannot be reused for another object";
870 } else {
871 $errormessage = "StatusOfRetrievedIntent is not succeeded: ".$paymentintent->status;
872 }
873 dol_syslog($errormessage, LOG_WARNING, 0, '_payment');
874 setEventMessages($errormessage, null, 'errors');
875 $action = '';
876
877 $randomseckey = getRandomPassword(true, null, 20); // TODO Generate a key including fulltag to avoid forging URL.
878 $_SESSION['paymentkosessioncode'] = $randomseckey; // key between newpayment.php to paymentko.php
879
880 $urlko .= '&paymentkosessioncode='.urlencode($randomseckey);
881 } else {
882 // We can also record the payment mode into llx_societe_rib with stripe $paymentintent->payment_method
883 // 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.
884 // dol_syslog("Create payment_method for ".$paymentintent->payment_method, LOG_DEBUG, 0, '_payment');
885
886 // Get here amount and currency used for payment and force value into $amount and $currency so the real amount is saved into session instead
887 // of the amount and currency retrieved from the POST.
888 $amount = $paymentintent->amount;
889 $currency = '';
890
891 if (!empty($paymentintent->currency)) {
892 $currency = strtoupper($paymentintent->currency);
893
894 // Correct the amount according to unit of currency
895 // See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
896 $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
897 if (!in_array($currency, $arrayzerounitcurrency)) {
898 $amount /= 100;
899 }
900 }
901
902 dol_syslog("StatusOfRetrievedIntent is succeeded for amount = ".$amount." currency = ".$currency, LOG_DEBUG, 0, '_payment');
903
904 $randomseckey = getRandomPassword(true, null, 20); // TODO Generate a key including fulltag to avoid forging URL.
905 $_SESSION['paymentoksessioncode'] = $randomseckey; // key between newpayment.php to paymentok.php
906
907 $urlok .= '&paymentoksessioncode='.urlencode($randomseckey);
908 }
909 }
910
911
912 $remoteip = getUserRemoteIP();
913
914 $_SESSION["onlinetoken"] = $stripeToken;
915 $_SESSION["FinalPaymentAmt"] = $amount; // amount really paid (coming from Stripe). Will be used for check in paymentok.php.
916 $_SESSION["currencyCodeType"] = $currency; // currency really used for payment (coming from Stripe). Will be used for check in paymentok.php.
917 $_SESSION["paymentType"] = '';
918 $_SESSION['ipaddress'] = ($remoteip ? $remoteip : 'unknown'); // Payer ip
919 $_SESSION['TRANSACTIONID'] = (($charge && is_object($charge)) ? $charge->id : (is_object($paymentintent) ? $paymentintent->id : ''));
920 $_SESSION['errormessage'] = $errormessage;
921 if (!getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) {
922 $_SESSION['payerID'] = is_object($customer) ? $customer->id : '';
923 } else {
924 $_SESSION['payerID'] = '';
925 }
926
927 // Save in database the data of the session (key = id of the charge or PaymentIntent), paymentok.php reads them from there first
928 if (!$error && !empty($_SESSION['TRANSACTIONID'])) {
929 onlinePaymentSessionSave(getDolGlobalString('STRIPE_LIVE') ? 'StripeLive' : 'StripeTest', $_SESSION['TRANSACTIONID'], array(
930 'fulltag' => $FULLTAG,
931 'FinalPaymentAmt' => $amount,
932 'currencyCodeType' => $currency,
933 'ipaddress' => $_SESSION['ipaddress'],
934 'payerID' => $_SESSION['payerID'],
935 'paymentType' => ''
936 ));
937 }
938
939 dol_syslog("Action charge stripe STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION=".getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')." ip=".$remoteip, LOG_DEBUG, 0, '_payment');
940 dol_syslog("_SERVER[HTTP_X_FORWARDED_HOST] = ".(empty($_SERVER["HTTP_X_FORWARDED_HOST"]) ? '' : dol_escape_htmltag($_SERVER["HTTP_X_FORWARDED_HOST"])), LOG_DEBUG, 0, '_payment');
941 dol_syslog("_SERVER[SERVER_NAME] = ".(empty($_SERVER["SERVER_NAME"]) ? '' : dol_escape_htmltag($_SERVER["SERVER_NAME"])), LOG_DEBUG, 0, '_payment');
942 dol_syslog("_SERVER[SERVER_ADDR] = ".(empty($_SERVER["SERVER_ADDR"]) ? '' : dol_escape_htmltag($_SERVER["SERVER_ADDR"])), LOG_DEBUG, 0, '_payment');
943 dol_syslog("session_id=".session_id(), LOG_DEBUG, 0, '_payment');
944 dol_syslog("onlinetoken=".$_SESSION["onlinetoken"]." paymentoksessioncode=".$_SESSION["paymentoksessioncode"]." paymentkosessioncode=".($_SESSION["paymentkosessioncode"] ?? ''), LOG_DEBUG, 0, '_payment');
945 dol_syslog("FinalPaymentAmt=".$_SESSION["FinalPaymentAmt"]." currencyCodeType=".$_SESSION["currencyCodeType"]." payerID=".$_SESSION['payerID']." TRANSACTIONID=".$_SESSION['TRANSACTIONID'], LOG_DEBUG, 0, '_payment');
946 dol_syslog("FULLTAG=".$FULLTAG, LOG_DEBUG, 0, '_payment');
947 dol_syslog("error=".$error." errormessage=".$errormessage, LOG_DEBUG, 0, '_payment');
948 dol_syslog("Now call the redirect to paymentok or paymentko, URL = ".($error ? $urlko : $urlok), LOG_DEBUG, 0, '_payment');
949
950 if ($error) {
951 header("Location: ".$urlko);
952 exit;
953 } else {
954 header("Location: ".$urlok);
955 exit;
956 }
957}
958
959// This hook is used to push to $validpaymentmethod by external payment modules (ie Payzen, ...)
960$parameters = array(
961 'paymentmethod' => $paymentmethod,
962 'validpaymentmethod' => &$validpaymentmethod
963);
964$reshook = $hookmanager->executeHooks('doPayment', $parameters, $object, $action);
965if ($reshook < 0) {
966 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
967} elseif ($reshook > 0) {
968 print $hookmanager->resPrint;
969}
970
971
972
973/*
974 * View
975 */
976
977$form = new Form($db);
978
979$head = '';
980if (getDolGlobalString('ONLINE_PAYMENT_CSS_URL')) {
981 $head = '<link rel="stylesheet" type="text/css" href="' . getDolGlobalString('ONLINE_PAYMENT_CSS_URL').'?lang='.(!empty($getpostlang) ? $getpostlang : $langs->defaultlang).'">'."\n";
982}
983
984$conf->dol_hide_topmenu = 1;
985$conf->dol_hide_leftmenu = 1;
986
987$replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
988llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
989
990dol_syslog("newpayment.php show page source=".$source." paymentmethod=".$paymentmethod.' amount='.$amount.' newamount='.GETPOST("newamount", 'alpha')." ref=".$ref, LOG_DEBUG, 0, '_payment');
991dol_syslog("_SERVER[HTTP_X_FORWARDED_HOST] = ".(empty($_SERVER["HTTP_X_FORWARDED_HOST"]) ? '' : dol_escape_htmltag($_SERVER["HTTP_X_FORWARDED_HOST"])), LOG_DEBUG, 0, '_payment');
992dol_syslog("_SERVER[SERVER_NAME] = ".(empty($_SERVER["SERVER_NAME"]) ? '' : dol_escape_htmltag($_SERVER["SERVER_NAME"])), LOG_DEBUG, 0, '_payment');
993dol_syslog("_SERVER[SERVER_ADDR] = ".(empty($_SERVER["SERVER_ADDR"]) ? '' : dol_escape_htmltag($_SERVER["SERVER_ADDR"])), LOG_DEBUG, 0, '_payment');
994dol_syslog("session_id=".session_id(), LOG_DEBUG, 0, '_payment');
995
996// Check link validity
997if ($source && in_array($ref, array('member_ref', 'contractline_ref', 'invoice_ref', 'order_ref', 'donation_ref', ''))) {
998 $langs->load("errors");
999 dol_print_error_email('BADREFINPAYMENTFORM', $langs->trans("ErrorBadLinkSourceSetButBadValueForRef", $source, $ref));
1000 // End of page
1001 llxFooter();
1002 $db->close();
1003 exit;
1004}
1005
1006
1007// Show sandbox warning
1008if ((empty($paymentmethod) || $paymentmethod == 'paypal') && isModEnabled('paypal') && (getDolGlobalString('PAYPAL_API_SANDBOX')/* || GETPOSTINT('forcesandbox')*/)) { // We can force sand box with param 'forcesandbox'
1009 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Paypal'), array(), 'warning');
1010}
1011if ((empty($paymentmethod) || $paymentmethod == 'stripe') && isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE')/* || GETPOSTINT('forcesandbox')*/)) {
1012 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), array(), 'warning');
1013}
1014
1015
1016print '<span id="dolpaymentspan"></span>'."\n";
1017print '<div class="center">'."\n";
1018print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
1019print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
1020print '<input type="hidden" name="action" value="dopayment">'."\n";
1021print '<input type="hidden" name="tag" value="'.GETPOST("tag", 'alpha').'">'."\n";
1022print '<input type="hidden" name="suffix" value="'.dol_escape_htmltag($suffix).'">'."\n";
1023print '<input type="hidden" name="securekey" value="'.dol_escape_htmltag($SECUREKEY).'">'."\n";
1024print '<input type="hidden" name="e" value="'.$entity.'" />';
1025//print '<input type="hidden" name="forcesandbox" value="'.GETPOSTINT('forcesandbox').'" />';
1026print '<input type="hidden" name="lang" value="'.$getpostlang.'">';
1027print '<input type="hidden" name="ws" value="'.$ws.'">';
1028print '<input type="hidden" name="reload" id="reload" value="0">';
1029print "\n";
1030
1031
1032// Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
1033// Define logo and logosmall
1034$logosmall = $mysoc->logo_small;
1035$logo = $mysoc->logo;
1036$paramlogo = 'ONLINE_PAYMENT_LOGO_'.$suffix;
1037if (getDolGlobalString($paramlogo)) {
1038 $logosmall = getDolGlobalString($paramlogo);
1039} elseif (getDolGlobalString('ONLINE_PAYMENT_LOGO')) {
1040 $logosmall = getDolGlobalString('ONLINE_PAYMENT_LOGO');
1041}
1042//print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
1043// Define urllogo
1044$urllogo = '';
1045$urllogofull = '';
1046if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall)) {
1047 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$logosmall);
1048 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/thumbs/'.$logosmall);
1049} elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo)) {
1050 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
1051 $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
1052}
1053
1054// Output html code for logo
1055if ($ws) {
1056 // Look for a personalized header file (htmlheaderpayment.html) if the payment system is called from a website
1057 $filehtmlheader = dol_sanitizePathName(DOL_DATA_ROOT . ($conf->entity > 1 ? '/' . $conf->entity : '') . '/website/' . $ws . '/htmlheaderpayment.html');
1058 if (dol_is_file($filehtmlheader)) {
1059 print file_get_contents(dol_osencode($filehtmlheader));
1060 }
1061}
1062
1063if ($urllogo && !$ws) {
1064 print '<div class="backgreypublicpayment">';
1065 print '<div class="logopublicpayment">';
1066 print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
1067 print '>';
1068 print '</div>';
1069 if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
1070 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>';
1071 }
1072 print '</div>';
1073} elseif ($creditor && !$ws) {
1074 print '<div class="backgreypublicpayment">';
1075 print '<div class="logopublicpayment">';
1076 print $creditor;
1077 print '</div>';
1078 print '</div>';
1079}
1080if (getDolGlobalString('MAIN_IMAGE_PUBLIC_PAYMENT')) {
1081 print '<div class="backimagepublicpayment">';
1082 print '<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.getDolGlobalString('MAIN_IMAGE_PUBLIC_PAYMENT').'">';
1083 print '</div>';
1084}
1085
1086
1087
1088
1089print '<!-- Form to send a payment -->'."\n";
1090print '<!-- creditor = '.dol_escape_htmltag((string) $creditor).' -->'."\n";
1091// Additional information for each payment system
1092if (isModEnabled('paypal')) {
1093 print '<!-- PAYPAL_API_SANDBOX = '.getDolGlobalString('PAYPAL_API_SANDBOX').' -->'."\n";
1094 print '<!-- PAYPAL_API_INTEGRAL_OR_PAYPALONLY = '.getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY').' -->'."\n";
1095}
1096if (isModEnabled('stripe')) {
1097 print '<!-- STRIPE_LIVE = '.getDolGlobalString('STRIPE_LIVE').' -->'."\n";
1098 print '<!-- STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = '.getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION').' -->'."\n";
1099}
1100print '<!-- urlok = '.$urlok.' -->'."\n";
1101print '<!-- urlko = '.$urlko.' -->'."\n";
1102print "\n";
1103
1104// Section with payment informationsummary
1105print '<table id="dolpublictable" summary="Payment form" class="center">'."\n";
1106
1107// Output introduction text
1108$text = '';
1109if (getDolGlobalString('PAYMENT_NEWFORM_TEXT')) {
1110 $langs->load("members");
1111 $reg = array();
1112 if (preg_match('/^\‍((.*)\‍)$/', getDolGlobalString('PAYMENT_NEWFORM_TEXT'), $reg)) {
1113 $text .= $langs->trans($reg[1])."<br>\n";
1114 } else {
1115 $text .= getDolGlobalString('PAYMENT_NEWFORM_TEXT') . "<br>\n";
1116 }
1117 $text = '<tr><td class="center"><br>'.$text.'<br></td></tr>'."\n";
1118}
1119if (empty($text)) {
1120 $text .= '<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnPaymentPage").'</strong></td></tr>'."\n";
1121 $text .= '<tr><td class="textpublicpayment"><span class="opacitymedium">'.$langs->trans("ThisScreenAllowsYouToPay", (string) $creditor).'</span><br><br></td></tr>'."\n";
1122}
1123print $text;
1124
1125// Output payment summary form
1126print '<tr><td align="center">'; // class=center does not have the payment button centered so we keep align here.
1127print '<table class="centpercent left" id="tablepublicpayment">';
1128print '<tr class="hideonsmartphone"><td colspan="2" class="opacitymedium">'.$langs->trans("ThisIsInformationOnPayment").'...<br><br></td></tr>'."\n";
1129
1130$found = false;
1131$error = 0;
1132
1133$object = null;
1134$tag = null;
1135$fulltag = null;
1136
1137
1138// Free payment
1139if (!$source) {
1140 dol_syslog("newpayment.php no source", LOG_DEBUG);
1141
1142 $found = true;
1143 $tag = GETPOST("tag", 'alpha');
1144 if (GETPOST('fulltag', 'alpha')) {
1145 $fulltag = GETPOST('fulltag', 'alpha');
1146 } else {
1147 $fulltag = "TAG=".$tag;
1148 }
1149
1150 // Creditor
1151 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
1152 print '</td><td class="CTableRow2">';
1153 print img_picto('', 'company', 'class="pictofixedwidth"');
1154 print '<b>'.$creditor.'</b>';
1155 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
1156 print '</td></tr>'."\n";
1157
1158 // Amount
1159 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
1160 if (empty($amount)) {
1161 print ' ('.$langs->trans("ToComplete").')';
1162 }
1163 print '</td><td class="CTableRow2">';
1164 if (empty($amount) || !is_numeric($amount)) {
1165 print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
1166 print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
1167 // Currency
1168 print ' <b>'.$langs->trans("Currency".$currency).'</b>';
1169 } else {
1170 print '<b class="amount">'.price($amount, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
1171 print '<input type="hidden" name="amount" value="'.$amount.'">';
1172 print '<input type="hidden" name="newamount" value="'.$amount.'">';
1173 }
1174 print '<input type="hidden" name="currency" value="'.$currency.'">';
1175 print '</td></tr>'."\n";
1176
1177 // Tag
1178 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
1179 print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
1180 print '<input type="hidden" name="tag" value="'.$tag.'">';
1181 print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
1182 print '</td></tr>'."\n";
1183
1184 // We do not add fields shipToName, shipToStreet, shipToCity, shipToState, shipToCountryCode, shipToZip, shipToStreet2, phoneNum
1185 // as they don't exists (buyer is unknown, tag is free).
1186}
1187
1188
1189// Payment on a Sale Order
1190if ($source == 'order') {
1191 dol_syslog("newpayment.php source=order", LOG_DEBUG);
1192
1193 $found = true;
1194 $langs->load("orders");
1195
1196 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
1197
1198 $order = new Commande($db);
1199 $result = $order->fetch(0, $ref);
1200 if ($result <= 0) {
1201 $mesg = $order->error;
1202 $error++;
1203 } else {
1204 $result = $order->fetch_thirdparty($order->socid);
1205 }
1206 $object = $order;
1207
1208 if ($object->billed) {
1209 $action = "";
1210 }
1211
1212 if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
1213 $amount = $order->total_ttc;
1214 if (GETPOST("amount", 'alpha')) {
1215 $amount = GETPOST("amount", 'alpha');
1216 }
1217 $amount = price2num($amount);
1218 }
1219
1220 $tag = '';
1221 if (GETPOST('fulltag', 'alpha')) {
1222 $fulltag = GETPOST('fulltag', 'alpha');
1223 } else {
1224 $fulltag = 'ORD='.$order->id.'.CUS='.$order->thirdparty->id;
1225 if (!empty($TAG)) {
1226 $tag = $TAG;
1227 $fulltag .= '.TAG='.$TAG;
1228 }
1229 }
1230 $fulltag = dol_string_unaccent($fulltag);
1231
1232 // Creditor
1233 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
1234 print '</td><td class="CTableRow2"';
1235 print ' title="'.dolPrintHTMLForAttribute($langs->transnoentitiesnoconv("Country").'='.$mysoc->country_code.' - '.$langs->transnoentitiesnoconv("VATIntra").'='.$mysoc->tva_intra).'"';
1236 print '>';
1237 print img_picto('', 'company', 'class="pictofixedwidth"');
1238 print '<b>'.$creditor.'</b>';
1239 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
1240 print '</td></tr>'."\n";
1241
1242 // Debitor
1243 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
1244 print '</td><td class="CTableRow2"';
1245 print ' title="'.dolPrintHTMLForAttribute($langs->transnoentitiesnoconv("Country").'='.$order->thirdparty->country_code.' - '.$langs->transnoentitiesnoconv("VATIntra").'='.$order->thirdparty->tva_intra).'"';
1246 print '>';
1247 print img_picto('', 'company', 'class="pictofixedwidth"');
1248 print '<b>'.$order->thirdparty->name.'</b>';
1249 print '</td></tr>'."\n";
1250
1251 // Object
1252 $text = '<b>'.$langs->trans("PaymentOrderRef", $order->ref).'</b>';
1253 if (GETPOST('desc', 'alpha')) {
1254 $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
1255 }
1256 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
1257 print '</td><td class="CTableRow2">'.$text;
1258 print '<input type="hidden" name="s" value="'.dol_escape_htmltag($source).'">';
1259 print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($order->ref).'">';
1260 print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag((string) $order->id).'">';
1261 $directdownloadlink = $order->getLastMainDocLink('commande');
1262 if ($directdownloadlink) {
1263 print '<br><a href="'.$directdownloadlink.'" rel="nofollow noopener">';
1264 print img_mime($order->last_main_doc, '');
1265 print $langs->trans("DownloadDocument").'</a>';
1266 }
1267 print '</td></tr>'."\n";
1268
1269 // Amount
1270 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
1271 if (empty($amount)) {
1272 print ' ('.$langs->trans("ToComplete").')';
1273 }
1274 print '</td><td class="CTableRow2">';
1275 if (empty($amount) || !is_numeric($amount)) {
1276 print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
1277 print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
1278 // Currency
1279 print ' <b>'.$langs->trans("Currency".$currency).'</b>';
1280 } else {
1281 print '<b class="amount">'.price($amount, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
1282 print '<input type="hidden" name="amount" value="'.$amount.'">';
1283 print '<input type="hidden" name="newamount" value="'.$amount.'">';
1284 }
1285 print '<input type="hidden" name="currency" value="'.$currency.'">';
1286 print '</td></tr>'."\n";
1287
1288 // Tag
1289 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
1290 print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
1291 print '<input type="hidden" name="tag" value="'.dol_escape_htmltag($tag).'">';
1292 print '<input type="hidden" name="fulltag" value="'.dol_escape_htmltag($fulltag).'">';
1293 print '</td></tr>'."\n";
1294
1295 // Shipping address
1296 $shipToName = $order->thirdparty->name;
1297 $shipToStreet = $order->thirdparty->address;
1298 $shipToCity = $order->thirdparty->town;
1299 $shipToState = $order->thirdparty->state_code;
1300 $shipToCountryCode = $order->thirdparty->country_code;
1301 $shipToZip = $order->thirdparty->zip;
1302 $shipToStreet2 = '';
1303 $phoneNum = $order->thirdparty->phone;
1304 if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
1305 print '<input type="hidden" name="shipToName" value="'.dol_escape_htmltag($shipToName).'">'."\n";
1306 print '<input type="hidden" name="shipToStreet" value="'.dol_escape_htmltag($shipToStreet).'">'."\n";
1307 print '<input type="hidden" name="shipToCity" value="'.dol_escape_htmltag($shipToCity).'">'."\n";
1308 print '<input type="hidden" name="shipToState" value="'.dol_escape_htmltag($shipToState).'">'."\n";
1309 print '<input type="hidden" name="shipToCountryCode" value="'.dol_escape_htmltag($shipToCountryCode).'">'."\n";
1310 print '<input type="hidden" name="shipToZip" value="'.dol_escape_htmltag($shipToZip).'">'."\n";
1311 print '<input type="hidden" name="shipToStreet2" value="'.dol_escape_htmltag($shipToStreet2).'">'."\n";
1312 print '<input type="hidden" name="phoneNum" value="'.dol_escape_htmltag($phoneNum).'">'."\n";
1313 } else {
1314 print '<!-- Shipping address not complete, so we don t use it -->'."\n";
1315 }
1316 if (is_object($order->thirdparty)) {
1317 print '<input type="hidden" name="thirdparty_id" value="'.$order->thirdparty->id.'">'."\n";
1318 }
1319 print '<input type="hidden" name="email" value="'.$order->thirdparty->email.'">'."\n";
1320 print '<input type="hidden" name="vatnumber" value="'.dol_escape_htmltag($order->thirdparty->tva_intra).'">'."\n";
1321 $labeldesc = $langs->trans("Order").' '.$order->ref;
1322 if (GETPOST('desc', 'alpha')) {
1323 $labeldesc = GETPOST('desc', 'alpha');
1324 }
1325 print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
1326}
1327
1328
1329// Payment on a Customer Invoice
1330if ($source == 'invoice') {
1331 dol_syslog("newpayment.php source=invoice", LOG_DEBUG);
1332
1333 $found = true;
1334 $langs->load("bills");
1335 $form->load_cache_types_paiements();
1336
1337 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1338
1339 $invoice = new Facture($db);
1340 $result = $invoice->fetch(0, $ref);
1341 if ($result <= 0) {
1342 $mesg = $invoice->error;
1343 $error++;
1344 } else {
1345 $result = $invoice->fetch_thirdparty($invoice->socid);
1346 }
1347 $object = $invoice;
1348
1349 if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
1350 $amount = price2num($invoice->total_ttc - ($invoice->getSommePaiement() + $invoice->getSumCreditNotesUsed() + $invoice->getSumDepositsUsed()));
1351 if (GETPOST("amount", 'alpha')) {
1352 $amount = GETPOST("amount", 'alpha');
1353 }
1354 $amount = price2num($amount);
1355 }
1356
1357 if (GETPOST('fulltag', 'alpha')) {
1358 $fulltag = GETPOST('fulltag', 'alpha');
1359 } else {
1360 $fulltag = 'INV='.$invoice->id.'.CUS='.$invoice->thirdparty->id;
1361 if (!empty($TAG)) {
1362 $tag = $TAG;
1363 $fulltag .= '.TAG='.$TAG;
1364 }
1365 }
1366 $fulltag = dol_string_unaccent($fulltag);
1367
1368 // Creditor (seller)
1369 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
1370 print '</td><td class="CTableRow2"';
1371 print ' title="'.dolPrintHTMLForAttribute($langs->transnoentitiesnoconv("Country").'='.$mysoc->country_code.' - '.$langs->transnoentitiesnoconv("VATIntra").'='.$mysoc->tva_intra).'"';
1372 print '>';
1373 print img_picto('', 'company', 'class="pictofixedwidth"');
1374 print '<b>'.$creditor.'</b>';
1375 print '<input type="hidden" name="creditor" value="'.dol_escape_htmltag((string) $creditor).'">';
1376 print '</td></tr>'."\n";
1377
1378 // Debitor (buyer)
1379 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
1380 print '</td><td class="CTableRow2"';
1381 print ' title="'.dolPrintHTMLForAttribute($langs->transnoentitiesnoconv("Country").'='.$invoice->thirdparty->country_code.' - '.$langs->transnoentitiesnoconv("VATIntra").'='.$invoice->thirdparty->tva_intra).'"';
1382 print '>';
1383 print img_picto('', 'company', 'class="pictofixedwidth"');
1384 print '<b>'.$invoice->thirdparty->name.'</b>';
1385 print '</td></tr>'."\n";
1386
1387 // Object
1388 $text = '<b>'.$langs->trans("PaymentInvoiceRef", $invoice->ref).'</b>';
1389 if (GETPOST('desc', 'alpha')) {
1390 $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
1391 }
1392 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
1393 print '</td><td class="CTableRow2">'.$text;
1394 print '<input type="hidden" name="s" value="'.dol_escape_htmltag($source).'">';
1395 print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($invoice->ref).'">';
1396 print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag((string) $invoice->id).'">';
1397 $directdownloadlink = $invoice->getLastMainDocLink('facture');
1398 if ($directdownloadlink) {
1399 print '<br><a href="'.$directdownloadlink.'">';
1400 print img_mime($invoice->last_main_doc, '');
1401 print $langs->trans("DownloadDocument").'</a>';
1402 }
1403 print '</td></tr>'."\n";
1404
1405 // Amount
1406 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentAmount");
1407 if (empty($amount) && empty($object->paye)) {
1408 print ' ('.$langs->trans("ToComplete").')';
1409 }
1410 print '</td><td class="CTableRow2">';
1411 if ($object->type == $object::TYPE_CREDIT_NOTE) {
1412 print '<b>'.$langs->trans("CreditNote").'</b>';
1413 } elseif (empty($object->paye)) {
1414 if (empty($amount) || !is_numeric($amount)) {
1415 print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
1416 print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
1417 print ' <b>'.$langs->trans("Currency".$currency).'</b>';
1418 } else {
1419 print '<b class="amount">'.price($amount, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
1420 print '<input type="hidden" name="amount" value="'.$amount.'">';
1421 print '<input type="hidden" name="newamount" value="'.$amount.'">';
1422 }
1423 } else {
1424 print '<b class="amount">'.price($object->total_ttc, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
1425 }
1426 print '<input type="hidden" name="currency" value="'.$currency.'">';
1427 print '</td></tr>'."\n";
1428
1429 // Tag
1430 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
1431 print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
1432 print '<input type="hidden" name="tag" value="'.(empty($tag) ? '' : $tag).'">';
1433 print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
1434 print '</td></tr>'."\n";
1435
1436 // Add a warning if we try to pay an invoice set to be paid in credit transfer
1437 if ($invoice->status == $invoice::STATUS_VALIDATED && $invoice->mode_reglement_id > 0 && $form->cache_types_paiements[$invoice->mode_reglement_id]["code"] == "VIR") {
1438 print '<tr class="CTableRow2 center"><td class="CTableRow2" colspan="2">';
1439 print '<div class="warning maxwidth1000">';
1440 print $langs->trans("PayOfBankTransferInvoice");
1441 print '</div>';
1442 print '</td></tr>'."\n";
1443 }
1444
1445 // Shipping address
1446 $shipToName = $invoice->thirdparty->name;
1447 $shipToStreet = $invoice->thirdparty->address;
1448 $shipToCity = $invoice->thirdparty->town;
1449 $shipToState = $invoice->thirdparty->state_code;
1450 $shipToCountryCode = $invoice->thirdparty->country_code;
1451 $shipToZip = $invoice->thirdparty->zip;
1452 $shipToStreet2 = '';
1453 $phoneNum = $invoice->thirdparty->phone;
1454 if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
1455 print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
1456 print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
1457 print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
1458 print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
1459 print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
1460 print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
1461 print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
1462 print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
1463 } else {
1464 print '<!-- Shipping address not complete, so we don t use it -->'."\n";
1465 }
1466 if (is_object($invoice->thirdparty)) {
1467 print '<input type="hidden" name="thirdparty_id" value="'.$invoice->thirdparty->id.'">'."\n";
1468 }
1469 print '<input type="hidden" name="email" value="'.$invoice->thirdparty->email.'">'."\n";
1470 print '<input type="hidden" name="vatnumber" value="'.$invoice->thirdparty->tva_intra.'">'."\n";
1471 $labeldesc = $langs->trans("Invoice").' '.$invoice->ref;
1472 if (GETPOST('desc', 'alpha')) {
1473 $labeldesc = GETPOST('desc', 'alpha');
1474 }
1475 print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
1476}
1477
1478// Payment on a Contract line
1479if ($source == 'contractline') {
1480 dol_syslog("newpayment.php source=contractline", LOG_DEBUG);
1481
1482 $found = true;
1483 $langs->load("contracts");
1484
1485 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
1486
1487 $contract = new Contrat($db);
1488 $contractline = new ContratLigne($db);
1489
1490 $result = $contractline->fetch(0, $ref);
1491 if ($result <= 0) {
1492 $mesg = $contractline->error;
1493 $error++;
1494 } else {
1495 if ($contractline->fk_contrat > 0) {
1496 $result = $contract->fetch($contractline->fk_contrat);
1497 if ($result > 0) {
1498 $result = $contract->fetch_thirdparty($contract->socid);
1499 } else {
1500 $mesg = $contract->error;
1501 $error++;
1502 }
1503 } else {
1504 $mesg = 'ErrorRecordNotFound';
1505 $error++;
1506 }
1507 }
1508 $object = $contractline;
1509
1510 if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
1511 $amount = $contractline->total_ttc;
1512
1513 if ($contractline->fk_product && getDolGlobalString('PAYMENT_USE_NEW_PRICE_FOR_CONTRACTLINES')) {
1514 $product = new Product($db);
1515 $result = $product->fetch($contractline->fk_product);
1516
1517 // We define price for product (TODO Put this in a method in product class)
1518 if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
1519 $pu_ht = $product->multiprices[$contract->thirdparty->price_level];
1520 $pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level];
1521 $price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level];
1522 } else {
1523 $pu_ht = $product->price;
1524 $pu_ttc = $product->price_ttc;
1525 $price_base_type = $product->price_base_type;
1526 }
1527
1528 $amount = $pu_ttc;
1529 if (empty($amount)) {
1530 dol_print_error(null, 'ErrorNoPriceDefinedForThisProduct');
1531 exit;
1532 }
1533 }
1534
1535 if (GETPOST("amount", 'alpha')) {
1536 $amount = GETPOST("amount", 'alpha');
1537 }
1538 $amount = price2num($amount);
1539 }
1540
1541 if (GETPOST('fulltag', 'alpha')) {
1542 $fulltag = GETPOST('fulltag', 'alpha');
1543 } else {
1544 $fulltag = 'COL='.$contractline->id.'.CON='.$contract->id.'.CUS='.$contract->thirdparty->id.'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
1545 if (!empty($TAG)) {
1546 $tag = $TAG;
1547 $fulltag .= '.TAG='.$TAG;
1548 }
1549 }
1550 $fulltag = dol_string_unaccent($fulltag);
1551
1552 $qty = 1;
1553 if (GETPOST('qty')) {
1554 $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
1555 }
1556
1557 // Creditor
1558 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
1559 print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
1560 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
1561 print '</td></tr>'."\n";
1562
1563 // Debitor
1564 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
1565 print '</td><td class="CTableRow2"><b>'.$contract->thirdparty->name.'</b>';
1566 print '</td></tr>'."\n";
1567
1568 // Object
1569 $text = '<b>'.$langs->trans("PaymentRenewContractId", $contract->ref, $contractline->ref).'</b>';
1570 if ($contractline->fk_product > 0) {
1571 $contractline->fetch_product();
1572 $text .= '<br>'.$contractline->product->ref.($contractline->product->label ? ' - '.$contractline->product->label : '');
1573 }
1574 if ($contractline->description) {
1575 $text .= '<br>'.dol_htmlentitiesbr($contractline->description);
1576 }
1577 if ($contractline->date_end) {
1578 $text .= '<br>'.$langs->trans("ExpiredSince").': '.dol_print_date($contractline->date_end);
1579 }
1580 if (GETPOST('desc', 'alpha')) {
1581 $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
1582 }
1583 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
1584 print '</td><td class="CTableRow2">'.$text;
1585 print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
1586 print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($contractline->ref).'">';
1587 print '<input type="hidden" name="dol_id" value="'.dol_escape_htmltag((string) $contractline->id).'">';
1588 $directdownloadlink = $contract->getLastMainDocLink('contract');
1589 if ($directdownloadlink) {
1590 print '<br><a href="'.$directdownloadlink.'">';
1591 print img_mime($contract->last_main_doc, '');
1592 print $langs->trans("DownloadDocument").'</a>';
1593 }
1594 print '</td></tr>'."\n";
1595
1596 // Quantity
1597 $label = $langs->trans("Quantity");
1598 $qty = 1;
1599 $duration = '';
1600 if ($contractline->fk_product) {
1601 if ($contractline->product->isService() && $contractline->product->duration_value > 0) {
1602 $label = $langs->trans("Duration");
1603
1604 // TODO Put this in a global method
1605 if ($contractline->product->duration_value > 1) {
1606 $dur = array("h" => $langs->trans("Hours"), "d" => $langs->trans("DurationDays"), "w" => $langs->trans("DurationWeeks"), "m" => $langs->trans("DurationMonths"), "y" => $langs->trans("DurationYears"));
1607 } else {
1608 $dur = array("h" => $langs->trans("Hour"), "d" => $langs->trans("DurationDay"), "w" => $langs->trans("DurationWeek"), "m" => $langs->trans("DurationMonth"), "y" => $langs->trans("DurationYear"));
1609 }
1610 $duration = $contractline->product->duration_value.' '.$dur[$contractline->product->duration_unit];
1611 }
1612 }
1613 print '<tr class="CTableRow2"><td class="CTableRow2">'.$label.'</td>';
1614 print '<td class="CTableRow2"><b>'.($duration ? $duration : $qty).'</b>';
1615 print '<input type="hidden" name="newqty" value="'.dol_escape_htmltag((string) $qty).'">';
1616 print '</b></td></tr>'."\n";
1617
1618 // Amount
1619 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
1620 if (empty($amount)) {
1621 print ' ('.$langs->trans("ToComplete").')';
1622 }
1623 print '</td><td class="CTableRow2">';
1624 if (empty($amount) || !is_numeric($amount)) {
1625 print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
1626 print '<input class="flat maxwidth75" type="text" name="newamount" value="'.price2num(GETPOST("newamount", "alpha"), 'MT').'">';
1627 // Currency
1628 print ' <b>'.$langs->trans("Currency".$currency).'</b>';
1629 } else {
1630 print '<b class="amount">'.price($amount, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
1631 print '<input type="hidden" name="amount" value="'.$amount.'">';
1632 print '<input type="hidden" name="newamount" value="'.$amount.'">';
1633 }
1634 print '<input type="hidden" name="currency" value="'.$currency.'">';
1635 print '</td></tr>'."\n";
1636
1637 // Tag
1638 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
1639 print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
1640 print '<input type="hidden" name="tag" value="'.$tag.'">';
1641 print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
1642 print '</td></tr>'."\n";
1643
1644 // Shipping address
1645 $shipToName = $contract->thirdparty->name;
1646 $shipToStreet = $contract->thirdparty->address;
1647 $shipToCity = $contract->thirdparty->town;
1648 $shipToState = $contract->thirdparty->state_code;
1649 $shipToCountryCode = $contract->thirdparty->country_code;
1650 $shipToZip = $contract->thirdparty->zip;
1651 $shipToStreet2 = '';
1652 $phoneNum = $contract->thirdparty->phone;
1653 if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
1654 print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
1655 print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
1656 print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
1657 print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
1658 print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
1659 print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
1660 print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
1661 print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
1662 } else {
1663 print '<!-- Shipping address not complete, so we don t use it -->'."\n";
1664 }
1665 if (is_object($contract->thirdparty)) {
1666 print '<input type="hidden" name="thirdparty_id" value="'.$contract->thirdparty->id.'">'."\n";
1667 }
1668 print '<input type="hidden" name="email" value="'.$contract->thirdparty->email.'">'."\n";
1669 print '<input type="hidden" name="vatnumber" value="'.$contract->thirdparty->tva_intra.'">'."\n";
1670 $labeldesc = $langs->trans("Contract").' '.$contract->ref;
1671 if (GETPOST('desc', 'alpha')) {
1672 $labeldesc = GETPOST('desc', 'alpha');
1673 }
1674 print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
1675}
1676
1677// Payment on a Member subscription
1678if ($source == 'member' || $source == 'membersubscription') {
1679 dol_syslog("newpayment.php source=".$source, LOG_DEBUG);
1680
1681 $newsource = 'member';
1682
1683 $tag = "";
1684 $found = true;
1685 $langs->load("members");
1686
1687 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
1688 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
1689 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1690
1691 $member = new Adherent($db);
1692 $adht = new AdherentType($db);
1693
1694 $result = $member->fetch(0, $ref, 0, '', true, true); // This fetch also ->last_subscription_amount
1695 if ($result <= 0) {
1696 $mesg = $member->error;
1697 $error++;
1698 } else {
1699 $member->fetch_thirdparty();
1700
1701 $adht->fetch($member->typeid);
1702 }
1703 $object = $member;
1704
1705 if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
1706 $amount = $member->last_subscription_amount;
1707 if (GETPOST("amount", 'alpha')) {
1708 $amount = price2num(GETPOST("amount", 'alpha'), 'MT', 2);
1709 }
1710 // If amount still not defined, we take amount of the type of member
1711 if (empty($amount)) {
1712 $amount = $adht->amount;
1713 }
1714
1715 $amount = max(0, price2num($amount, 'MT'));
1716 }
1717
1718 if (GETPOST('fulltag', 'alpha')) {
1719 $fulltag = GETPOST('fulltag', 'alpha');
1720 } else {
1721 $fulltag = 'MEM='.$member->id.'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
1722 if (!empty($TAG)) {
1723 $tag = $TAG;
1724 $fulltag .= '.TAG='.$TAG;
1725 }
1726 }
1727 $fulltag = dol_string_unaccent($fulltag);
1728
1729 // Creditor
1730 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
1731 print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
1732 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
1733 print '</td></tr>'."\n";
1734
1735 // Debitor
1736 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Member");
1737 print '</td><td class="CTableRow2">';
1738 print '<b>';
1739 if ($member->morphy == 'mor' && !empty($member->company)) {
1740 print img_picto('', 'company', 'class="pictofixedwidth"');
1741 print $member->company;
1742 } else {
1743 print img_picto('', 'member', 'class="pictofixedwidth"');
1744 print $member->getFullName($langs);
1745 }
1746 print '</b>';
1747 print '</td></tr>'."\n";
1748
1749 // Object
1750 $text = '<b>'.$langs->trans("PaymentSubscription").'</b>';
1751 if (GETPOST('desc', 'alpha')) {
1752 $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
1753 }
1754 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
1755 print '</td><td class="CTableRow2">'.$text;
1756 print '<input type="hidden" name="source" value="'.dol_escape_htmltag($newsource).'">';
1757 print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($member->ref).'">';
1758 print '</td></tr>'."\n";
1759
1760 if ($object->datefin > 0) {
1761 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("DateEndSubscription");
1762 print '</td><td class="CTableRow2">'.dol_print_date($member->datefin, 'day');
1763 print '</td></tr>'."\n";
1764 }
1765
1766 if ($member->last_subscription_date || $member->last_subscription_amount) {
1767 // Last subscription date
1768
1769 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("LastSubscriptionDate");
1770 print '</td><td class="CTableRow2">'.dol_print_date($member->last_subscription_date, 'day');
1771 print '</td></tr>'."\n";
1772
1773 // Last subscription amount
1774
1775 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("LastSubscriptionAmount");
1776 print '</td><td class="CTableRow2">'.price($member->last_subscription_amount);
1777 print '</td></tr>'."\n";
1778
1779 if (empty($amount) && !GETPOST('newamount', 'alpha')) {
1780 $_GET['newamount'] = $member->last_subscription_amount;
1781 $_GET['amount'] = $member->last_subscription_amount;
1782 }
1783 if (!empty($member->last_subscription_amount) && !GETPOSTISSET('newamount') && is_numeric($amount)) {
1784 $amount = max($member->last_subscription_amount, $amount);
1785 }
1786 }
1787
1788 $amountbytype = $adht->amountByType(1);
1789
1790 $typeid = $adht->id;
1791 $caneditamount = $adht->caneditamount;
1792
1793 if ($member->type) {
1794 $oldtypeid = $member->typeid;
1795 $newtypeid = (int) (GETPOSTISSET("typeid") ? GETPOSTINT("typeid") : $member->typeid);
1796 if (getDolGlobalString('MEMBER_ALLOW_CHANGE_OF_TYPE')) {
1797 $typeid = $newtypeid;
1798 $adht->fetch($typeid); // Reload with the new type id
1799 }
1800
1801 $caneditamount = $adht->caneditamount;
1802
1803 if (getDolGlobalString('MEMBER_ALLOW_CHANGE_OF_TYPE')) {
1804 // Last member type
1805 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("LastMemberType");
1806 print '</td><td class="CTableRow2">'.dol_escape_htmltag($member->type);
1807 print "</td></tr>\n";
1808
1809 // Set the new member type
1810 $member->typeid = $newtypeid;
1811 $member->type = (string) dol_getIdFromCode($db, $newtypeid, 'adherent_type', 'rowid', 'libelle');
1812
1813 // list member type
1814 if (!$action) {
1815 // Set amount for the subscription.
1816 // If we change the type, we use the amount of the new type and not the amount of last subscription.
1817 $amount = (!empty($amountbytype[$member->typeid])) ? $amountbytype[$member->typeid] : $member->last_subscription_amount;
1818
1819 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("NewSubscription");
1820 print '</td><td class="CTableRow2">';
1821 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);
1822 print "</td></tr>\n";
1823 } elseif ($action == 'dopayment') {
1824 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("NewMemberType");
1825 print '</td><td class="CTableRow2">'.dol_escape_htmltag($member->type);
1826 print '<input type="hidden" name="membertypeid" value="'.$member->typeid.'">';
1827 print "</td></tr>\n";
1828 }
1829 } else {
1830 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("MemberType");
1831 print '</td><td class="CTableRow2">'.dol_escape_htmltag($member->type);
1832 print "</td></tr>\n";
1833 }
1834 }
1835
1836
1837 // Add hook to complete the form
1838 $parameters = array('mode' => 'renewal');
1839 $reshook = $hookmanager->executeHooks('membershipNewSubscriptionPublicForm', $parameters, $object, $action);
1840 if ($reshook < 0) {
1841 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1842 $error++;
1843 }
1844
1845 // TODO Move this into previous hook
1846 if (getDolGlobalString('MEMBER_NEWFORM_DOLIBARRTURNOVER') && $action != 'dopayment') {
1847 $country_id = 0;
1848 if ($member->thirdparty instanceof Societe) {
1849 $country_id = $member->thirdparty->country_id;
1850 }
1851 $checkednature = $member->morphy;
1852 print '<input type="hidden" name="moralinput" id="moralinput" value="'.$checkednature.'">';
1853
1854 // Is it a Preferred Partner
1855 $pp = 0;
1856 include_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
1857 $partnership = new Partnership($db);
1858 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1859 $result = $partnership->fetch(0, '', 0, (int) $member->thirdparty->id);
1860 if ($result > 0) {
1861 $pp = 1;
1862 }
1863
1864 $s = $langs->trans("AreYouAPreferredPartner", '<a href="https://partners.dolibarr.org" target="_blank">{s1}</a>');
1865 $s = str_replace('{s1}', 'Preferred Partner', $s);
1866 print '<tr id="trbudget" class="trcompany"><td><label for="pp" class="small">'.$s.'</label></td><td>';
1867 print '<input type="checkbox" name="pp" id="pp" value="1"'.((GETPOST('reload') ? GETPOST('pp') : $pp) ? ' checked="checked"' : '').' class="reposition">';
1868 print '</td></tr>';
1869
1870 print '<tr id="trbudget" class="trcompany"><td class=""><span class="small">'.$langs->trans("TurnoverOrBudget").'</span></td><td>';
1871
1872 $country_code = dol_getIdFromCode($db, $country_id, 'c_country', 'rowid', 'code');
1873 if ($country_code === 'FR' && $checkednature === 'mor' && (GETPOST('reload') ? GETPOST('pp') : $pp)) {
1874 print '<input type="text" name="budget" id="budget" class="flat turnover right width100" value="'.GETPOST('budget').'"'.($action != 'dopayment' ? ' required autofocus' : '').'>';
1875 } else {
1876 $arraybudget = array('50' => '<= 100 000', '100' => '<= 200 000', '200' => '<= 500 000', '300' => '<= 1 500 000', '600' => '<= 3 000 000', '1000' => '<= 5 000 000', '2000' => '5 000 000+');
1877 print $form->selectarray('budget', $arraybudget, GETPOSTINT('budget'), 1, 0, 0, ($checkednature === 'mor' ? 'required' : ''), 0, 0, 0, '');
1878 }
1879 print ' € or $';
1880
1881 print '<script type="text/javascript">
1882 jQuery(document).ready(function() {
1883 firstload = true;
1884
1885 newamount = initturnover();
1886 jQuery("#amount").val(newamount);
1887 jQuery("#newamount").val(newamount);
1888
1889 firstload = false;
1890
1891 jQuery("#selectcountry_id").change(function() {
1892 console.log("We change country (code added for association, replace common code), so we reload page");
1893 jQuery("#budget").val(\'\');
1894 jQuery("#amount").val(\'\');
1895 jQuery("#newamount").val(\'\');
1896 jQuery("#amounthidden").val(\'\');
1897 });
1898 jQuery("#pp").change(function() {
1899 console.log("We change the preferred partner status");
1900 selectcountry_id = jQuery("#selectcountry_id").val();
1901 morphy = jQuery("#moralinput").is(\':checked\') ? \'mor\' : \'phy\';
1902 jQuery("#budget").val(\'\');
1903 jQuery("#amount").val(\'\');
1904 jQuery("#amounthidden").val(\'\');
1905 jQuery("#newamount").val(\'\');
1906 jQuery("#reload").val(\'1\');
1907 document.paymentform.action.value="";
1908 jQuery("#dolpaymentform").submit();
1909 });
1910 jQuery("#budget").change(function() {
1911 console.log("Turnover amount has been modified on change");
1912 newamount = initturnover();
1913 jQuery("#amount").val(newamount);
1914 jQuery("#amounthidden").val(newamount);
1915 jQuery("#newamount").val(newamount);
1916 });
1917 jQuery("#budget").keyup(function() {
1918 console.log("Turnover amount has been modified on keyup");
1919 newamount = initturnover();
1920 jQuery("#amount").val(newamount);
1921 jQuery("#amounthidden").val(newamount);
1922 jQuery("#newamount").val(newamount);
1923 });
1924
1925 function initturnover() {
1926 newamount = 0;
1927
1928 //morphy = jQuery("#moralinput").is(\':checked\') ? \'mor\' : \'phy\';
1929 morphy = jQuery("#moralinput").val();
1930 selectcountry_id = '.((int) $country_id).';
1931 pp = jQuery("#pp").is(\':checked\') ? true : false;
1932 console.log("Set fields according to nature and other properties");
1933 console.log("morphy="+morphy);
1934 console.log("selectcountry_id="+selectcountry_id);
1935 console.log("pp="+pp);
1936
1937 if (morphy == \'phy\') {
1938 jQuery(".amount").val('.((float) $amount).');
1939 jQuery("#trbirth").show();
1940 jQuery(".trcompany").hide();
1941 jQuery(".trbudget").hide();
1942 newamount = '.((float) $amount).';
1943 } else {
1944 jQuery(".amount").val(\'\');
1945 jQuery("#trbirth").hide();
1946 jQuery(".trcompany").show();
1947 jQuery(".trbudget").show();
1948 jQuery(".hideifautoturnover").hide();
1949 if (firstload) {
1950 jQuery("#budget").val(\'\');
1951 }
1952
1953 if (selectcountry_id == 1) {
1954 if (jQuery("#budget").val() == \'\') {
1955 return null;
1956 }
1957 if (pp) {
1958 console.log("value selected in input text field is "+jQuery("#budget").val());
1959 newamount = Math.max(Math.round(price2numjs(jQuery("#budget").val()) * 0.005), 50);
1960 console.log("newamount = "+newamount);
1961 } else {
1962 console.log("not a pp");
1963 if (jQuery("#budget").val() > 0) {
1964 console.log("value found in budget is "+jQuery("#budget").val());
1965 newamount = jQuery("#budget").val();
1966 } else {
1967 jQuery("#budget").val(\'\');
1968 newamount = \'\';
1969 }
1970 }
1971 } else {
1972 if (jQuery("#budget").val() > 0) {
1973 newamount = jQuery("#budget").val();
1974 } else {
1975 jQuery("#budget").val(\'\');
1976 newamount = \'\';
1977 }
1978 }
1979 }
1980
1981 return newamount;
1982 }
1983 });
1984 </script>';
1985 print '</td></tr>'."\n";
1986 }
1987
1988
1989 // Set amount for the subscription from the the type and options:
1990 // - First check the amount of the member type if there is no previous payment.
1991 $amount = ($member->last_subscription_amount ? $member->last_subscription_amount : (empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid]));
1992
1993 // - If an amount was posted from the form (for example from page with types of membership)
1994 if ($caneditamount && !GETPOST('reload') && GETPOSTISSET('amount') && GETPOSTFLOAT('amount', 'MT') > 0) {
1995 $amount = GETPOSTFLOAT('amount', 'MT');
1996 }
1997 // - If a new amount was posted from the form
1998 if ($caneditamount && !GETPOST('reload') && GETPOSTISSET('newamount') && GETPOSTFLOAT('newamount', 'MT') > 0) {
1999 $amount = GETPOSTFLOAT('newamount', 'MT');
2000 }
2001 // - If a min is set or an amount from the posted form, we take them into account
2002 $amount = max(0, (float) $amount, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT"));
2003
2004 // Amount
2005 $caneditamount = $adht->caneditamount;
2006 $minimumamount = !getDolGlobalString('MEMBER_MIN_AMOUNT') ? $adht->amount : max(getDolGlobalString('MEMBER_MIN_AMOUNT'), $adht->amount, $amount);
2007 $amountformuladescriptionbytype = $adht->amountformuladescriptionbytype(1); // Load the array of amount ormula description per type
2008 $amountformuladescription = $amountformuladescriptionbytype[$typeid];
2009 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
2010 // This place no longer allows amount edition
2011 if (getDolGlobalString('MEMBER_EXT_URL_SUBSCRIPTION_INFO')) {
2012 print ' - <a href="' . getDolGlobalString('MEMBER_EXT_URL_SUBSCRIPTION_INFO').'" rel="external" target="_blank" rel="noopener noreferrer">'.img_picto('', 'url', 'class="pictofixedwidth"').$langs->trans("SeeHere").'</a>';
2013 }
2014 if ($amountformuladescription) {
2015 print '</td><td class="CTableRow2">'.$amountformuladescription;
2016 print '</td></tr>'."\n";
2017 print '<tr class="CTableRow2"><td class="CTableRow2">';
2018 print '</td><td class="CTableRow2">';
2019 } else {
2020 print '</td><td class="CTableRow2">';
2021 }
2022
2023 if ($caneditamount && ($action != 'dopayment' || GETPOST('reload'))) {
2024 if (GETPOSTISSET('newamount')) {
2025 print '<input type="text" class="width75 amount" name="newamount" id="newamount" value="'.price(price2num(GETPOST('newamount'), '', 2), 1, $langs, 1, -1, -1).'">';
2026 } else {
2027 print '<input type="text" class="width75 amount" name="newamount" id="newamount" value="'.price($amount, 1, $langs, 1, -1, -1).'">';
2028 }
2029 print $langs->trans("Currency".$conf->currency);
2030 } else {
2031 print '<b class="amount">'.price($amount, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
2032 if ($minimumamount > $amount) {
2033 print ' &nbsp; <span class="opacitymedium small">'. $langs->trans("AmountIsLowerToMinimumNotice", price($minimumamount, 1, $langs, 1, -1, -1, $currency)).'</span>';
2034 }
2035 print '<input type="hidden" name="newamount" value="'.$amount.'">';
2036 }
2037 print '<input type="hidden" name="amount" value="'.$amount.'">';
2038 print '<input type="hidden" name="currency" value="'.$currency.'">';
2039 print '</td></tr>'."\n";
2040
2041 // Tag
2042 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
2043 print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
2044 print '<input type="hidden" name="tag" value="'.$tag.'">';
2045 print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
2046 print '</td></tr>'."\n";
2047
2048 // Shipping address
2049 $shipToName = $member->getFullName($langs);
2050 $shipToStreet = $member->address;
2051 $shipToCity = $member->town;
2052 $shipToState = $member->state_code;
2053 $shipToCountryCode = $member->country_code;
2054 $shipToZip = $member->zip;
2055 $shipToStreet2 = '';
2056 $phoneNum = $member->phone;
2057 if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
2058 print '<!-- Shipping address information -->';
2059 print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
2060 print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
2061 print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
2062 print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
2063 print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
2064 print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
2065 print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
2066 print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
2067 } else {
2068 print '<!-- Shipping address not complete, so we don t use it -->'."\n";
2069 }
2070 if (is_object($member->thirdparty)) {
2071 print '<input type="hidden" name="thirdparty_id" value="'.$member->thirdparty->id.'">'."\n";
2072 }
2073 print '<input type="hidden" name="email" value="'.$member->email.'">'."\n";
2074 $labeldesc = $langs->trans("PaymentSubscription");
2075 if (GETPOST('desc', 'alpha')) {
2076 $labeldesc = GETPOST('desc', 'alpha');
2077 }
2078 print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
2079}
2080
2081// Payment on donation
2082if ($source == 'donation') {
2083 dol_syslog("newpayment.php source=donation", LOG_DEBUG);
2084
2085 $found = true;
2086 $langs->load("don");
2087
2088 require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
2089
2090 $don = new Don($db);
2091 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2092 $result = $don->fetch((int) $ref);
2093 if ($result <= 0) {
2094 $mesg = $don->error;
2095 $error++;
2096 } else {
2097 $don->fetch_thirdparty();
2098 }
2099 $object = $don;
2100
2101 if ($action != 'dopayment') { // Do not change amount if we just click on first dopayment
2102 if (GETPOST("amount", 'alpha')) {
2103 $amount = GETPOST("amount", 'alpha');
2104 } else {
2105 $amount = $don->getRemainToPay();
2106 }
2107 $amount = price2num($amount);
2108 }
2109
2110 if (GETPOST('fulltag', 'alpha')) {
2111 $fulltag = GETPOST('fulltag', 'alpha');
2112 } else {
2113 $fulltag = 'DON='.$don->ref.'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
2114 if (!empty($TAG)) {
2115 $tag = $TAG;
2116 $fulltag .= '.TAG='.$TAG;
2117 }
2118 }
2119 $fulltag = dol_string_unaccent($fulltag);
2120
2121 // Creditor
2122 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
2123 print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
2124 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
2125 print '</td></tr>'."\n";
2126
2127 // Debitor
2128 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("ThirdParty");
2129 print '</td><td class="CTableRow2"><b>';
2130 if (!empty($don->societe)) {
2131 print $don->societe;
2132 } else {
2133 print $don->getFullName($langs);
2134 }
2135 print '</b>';
2136 print '</td></tr>'."\n";
2137
2138 // Object
2139 $text = '<b>'.$langs->trans("PaymentDonation").'</b>';
2140 if (GETPOST('desc', 'alpha')) {
2141 $text = '<b>'.$langs->trans(GETPOST('desc', 'alpha')).'</b>';
2142 }
2143 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
2144 print '</td><td class="CTableRow2">'.$text;
2145 print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
2146 print '<input type="hidden" name="ref" value="'.dol_escape_htmltag($don->ref).'">';
2147 print '</td></tr>'."\n";
2148
2149 // Amount
2150 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
2151 if (empty($amount)) {
2152 if (!getDolGlobalString('DONATION_NEWFORM_AMOUNT')) {
2153 print ' ('.$langs->trans("ToComplete");
2154 }
2155 if (getDolGlobalString('DONATION_EXT_URL_SUBSCRIPTION_INFO')) {
2156 print ' - <a href="' . getDolGlobalString('DONATION_EXT_URL_SUBSCRIPTION_INFO').'" rel="external" target="_blank" rel="noopener noreferrer">'.$langs->trans("SeeHere").'</a>';
2157 }
2158 if (!getDolGlobalString('DONATION_NEWFORM_AMOUNT')) {
2159 print ')';
2160 }
2161 }
2162 print '</td><td class="CTableRow2">';
2163 $valtoshow = '';
2164 if (empty($amount) || !is_numeric($amount)) {
2165 $valtoshow = price2num(GETPOST("newamount", 'alpha'), 'MT');
2166 // force default subscription amount to value defined into constant...
2167 if (empty($valtoshow)) {
2168 if (getDolGlobalString('DONATION_NEWFORM_EDITAMOUNT')) {
2169 if (getDolGlobalString('DONATION_NEWFORM_AMOUNT')) {
2170 $valtoshow = getDolGlobalString('DONATION_NEWFORM_AMOUNT');
2171 }
2172 } else {
2173 if (getDolGlobalString('DONATION_NEWFORM_AMOUNT')) {
2174 $amount = getDolGlobalString('DONATION_NEWFORM_AMOUNT');
2175 }
2176 }
2177 }
2178 }
2179 if (empty($amount) || !is_numeric($amount)) {
2180 //$valtoshow=price2num(GETPOST("newamount",'alpha'),'MT');
2181 if (getDolGlobalString('DONATION_MIN_AMOUNT') && $valtoshow) {
2182 $valtoshow = max(getDolGlobalString('DONATION_MIN_AMOUNT'), $valtoshow);
2183 }
2184 print '<input type="hidden" name="amount" value="'.price2num(GETPOST("amount", 'alpha'), 'MT').'">';
2185 print '<input class="flat maxwidth75" type="text" name="newamount" value="'.$valtoshow.'">';
2186 // Currency
2187 print ' <b>'.$langs->trans("Currency".$currency).'</b>';
2188 } else {
2189 $valtoshow = $amount;
2190 if (getDolGlobalString('DONATION_MIN_AMOUNT') && $valtoshow) {
2191 $valtoshow = max(getDolGlobalString('DONATION_MIN_AMOUNT'), $valtoshow);
2192 $amount = $valtoshow;
2193 }
2194 print '<b class="amount">'.price($valtoshow, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
2195 print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
2196 print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
2197 }
2198 print '<input type="hidden" name="currency" value="'.$currency.'">';
2199 print '</td></tr>'."\n";
2200
2201 // Tag
2202 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
2203 print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
2204 print '<input type="hidden" name="tag" value="'.$tag.'">';
2205 print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
2206 print '</td></tr>'."\n";
2207
2208 // Shipping address
2209 $shipToName = $don->getFullName($langs);
2210 $shipToStreet = $don->address;
2211 $shipToCity = $don->town;
2212 $shipToState = $don->state_code;
2213 $shipToCountryCode = $don->country_code;
2214 $shipToZip = $don->zip;
2215 $shipToStreet2 = '';
2216 $phoneNum = $don->phone;
2217 if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
2218 print '<!-- Shipping address information -->';
2219 print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
2220 print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
2221 print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
2222 print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
2223 print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
2224 print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
2225 print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
2226 print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
2227 } else {
2228 print '<!-- Shipping address not complete, so we don t use it -->'."\n";
2229 }
2230 if (is_object($don->thirdparty)) {
2231 print '<input type="hidden" name="thirdparty_id" value="'.$don->thirdparty->id.'">'."\n";
2232 }
2233 print '<input type="hidden" name="email" value="'.$don->email.'">'."\n";
2234 $labeldesc = $langs->trans("PaymentSubscription");
2235 if (GETPOST('desc', 'alpha')) {
2236 $labeldesc = GETPOST('desc', 'alpha');
2237 }
2238 print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
2239}
2240
2241if ($source == 'organizedeventregistration' && is_object($thirdparty) && is_object($attendee) && is_object($invoice)) {
2242 dol_syslog("newpayment.php source=organizedeventregistration", LOG_DEBUG);
2243
2244 $found = true;
2245 $langs->loadLangs(array("members", "eventorganization"));
2246
2247 if (GETPOST('fulltag', 'alpha')) {
2248 $fulltag = GETPOST('fulltag', 'alpha');
2249 } else {
2250 $fulltag = 'ATT='.$attendee->id.'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
2251 if (!empty($TAG)) {
2252 $tag = $TAG;
2253 $fulltag .= '.TAG='.$TAG;
2254 }
2255 }
2256 $fulltag = dol_string_unaccent($fulltag);
2257
2258 // Creditor
2259 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
2260 print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
2261 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
2262 print '</td></tr>'."\n";
2263
2264 // Debitor
2265 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Attendee");
2266 print '</td><td class="CTableRow2"><b>';
2267 print $attendee->email;
2268 print($thirdparty->name ? ' ('.$thirdparty->name.')' : '');
2269 print '</b>';
2270 print '</td></tr>'."\n";
2271
2272 if (! is_object($attendee->project)) {
2273 $text = 'ErrorProjectNotFound';
2274 } else {
2275 $text = $langs->trans("PaymentEvent").' - '.$attendee->project->title;
2276 }
2277
2278 // Object
2279 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
2280 print '</td><td class="CTableRow2"><b>'.$text.'</b>';
2281 print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
2282 print '<input type="hidden" name="ref" value="'.dol_escape_htmltag((string) $invoice->id).'">';
2283 print '</td></tr>'."\n";
2284
2285 // Amount
2286 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
2287 print '</td><td class="CTableRow2">';
2288 $valtoshow = $amount;
2289 print '<b class="amount">'.price($valtoshow, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
2290 print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
2291 print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
2292 print '<input type="hidden" name="currency" value="'.$currency.'">';
2293 print '</td></tr>'."\n";
2294
2295 // Tag
2296 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
2297 print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
2298 print '<input type="hidden" name="tag" value="'.$tag.'">';
2299 print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
2300 print '</td></tr>'."\n";
2301
2302 // Shipping address
2303 $shipToName = $thirdparty->getFullName($langs);
2304 $shipToStreet = $thirdparty->address;
2305 $shipToCity = $thirdparty->town;
2306 $shipToState = $thirdparty->state_code;
2307 $shipToCountryCode = $thirdparty->country_code;
2308 $shipToZip = $thirdparty->zip;
2309 $shipToStreet2 = '';
2310 $phoneNum = $thirdparty->phone;
2311 if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
2312 print '<!-- Shipping address information -->';
2313 print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
2314 print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
2315 print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
2316 print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
2317 print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
2318 print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
2319 print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
2320 print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
2321 } else {
2322 print '<!-- Shipping address not complete, so we don t use it -->'."\n";
2323 }
2324 print '<input type="hidden" name="thirdparty_id" value="'.$thirdparty->id.'">'."\n";
2325 print '<input type="hidden" name="email" value="'.$thirdparty->email.'">'."\n";
2326 $labeldesc = $langs->trans("PaymentSubscription");
2327 if (GETPOST('desc', 'alpha')) {
2328 $labeldesc = GETPOST('desc', 'alpha');
2329 }
2330 print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
2331}
2332
2333if ($source == 'boothlocation' && is_object($invoice)) {
2334 dol_syslog("newpayment.php source=boothlocation", LOG_DEBUG);
2335
2336 $found = true;
2337 $langs->load("members");
2338
2339 if (GETPOST('fulltag', 'alpha')) {
2340 $fulltag = GETPOST('fulltag', 'alpha');
2341 } else {
2342 $fulltag = 'BOO='.GETPOST("booth").'.DAT='.dol_print_date(dol_now(), '%Y%m%d%H%M%S');
2343 if (!empty($TAG)) {
2344 $tag = $TAG;
2345 $fulltag .= '.TAG='.$TAG;
2346 }
2347 }
2348 $fulltag = dol_string_unaccent($fulltag);
2349
2350 // Creditor
2351 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Creditor");
2352 print '</td><td class="CTableRow2"><b>'.$creditor.'</b>';
2353 print '<input type="hidden" name="creditor" value="'.$creditor.'">';
2354 print '</td></tr>'."\n";
2355
2356 // Debitor
2357 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Attendee");
2358 print '</td><td class="CTableRow2"><b>';
2359 print $thirdparty->name;
2360 print '</b>';
2361 print '</td></tr>'."\n";
2362
2363 // Object
2364 $text = '<b>'.$langs->trans("PaymentBoothLocation").'</b>';
2365 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Designation");
2366 print '</td><td class="CTableRow2">'.$text;
2367 print '<input type="hidden" name="source" value="'.dol_escape_htmltag($source).'">';
2368 print '<input type="hidden" name="ref" value="'.dol_escape_htmltag((string) $invoice->id).'">';
2369 print '</td></tr>'."\n";
2370
2371 // Amount
2372 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("Amount");
2373 print '</td><td class="CTableRow2">';
2374 $valtoshow = $amount;
2375 print '<b class="amount">'.price($valtoshow, 1, $langs, 1, -1, -1, $currency).'</b>'; // Price with currency
2376 print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
2377 print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
2378 print '<input type="hidden" name="currency" value="'.$currency.'">';
2379 print '</td></tr>'."\n";
2380
2381 // Tag
2382 print '<tr class="CTableRow2"><td class="CTableRow2">'.$langs->trans("PaymentCode");
2383 print '</td><td class="CTableRow2"><b style="word-break: break-all;">'.$fulltag.'</b>';
2384 print '<input type="hidden" name="tag" value="'.$tag.'">';
2385 print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
2386 print '</td></tr>'."\n";
2387
2388 // Shipping address
2389 $shipToName = $thirdparty->getFullName($langs);
2390 $shipToStreet = $thirdparty->address;
2391 $shipToCity = $thirdparty->town;
2392 $shipToState = $thirdparty->state_code;
2393 $shipToCountryCode = $thirdparty->country_code;
2394 $shipToZip = $thirdparty->zip;
2395 $shipToStreet2 = '';
2396 $phoneNum = $thirdparty->phone;
2397 if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip) {
2398 print '<!-- Shipping address information -->';
2399 print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
2400 print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
2401 print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
2402 print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
2403 print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
2404 print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
2405 print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
2406 print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
2407 } else {
2408 print '<!-- Shipping address not complete, so we don t use it -->'."\n";
2409 }
2410 print '<input type="hidden" name="thirdparty_id" value="'.$thirdparty->id.'">'."\n";
2411 print '<input type="hidden" name="email" value="'.$thirdparty->email.'">'."\n";
2412 $labeldesc = $langs->trans("PaymentSubscription");
2413 if (GETPOST('desc', 'alpha')) {
2414 $labeldesc = GETPOST('desc', 'alpha');
2415 }
2416 print '<input type="hidden" name="desc" value="'.dol_escape_htmltag($labeldesc).'">'."\n";
2417}
2418
2419if (!$found && !$mesg) {
2420 $langs->load('errors');
2421 $mesg = $langs->trans("ErrorBadParameters");
2422}
2423
2424if ($mesg) {
2425 print '<tr><td align="center" colspan="2"><br><div class="warning">'.dol_escape_htmltag($mesg, 1, 1, 'br').'</div></td></tr>'."\n";
2426}
2427
2428print '</table>'."\n";
2429print "\n";
2430
2431
2432// Show all payment mode buttons (Stripe, Paypal, ...)
2433if ($action != 'dopayment') {
2434 dol_syslog("newpayment.php action is not dopayment so we show all payment modes", LOG_DEBUG);
2435
2436 if ($found && !$error) { // We are in a management option and no error
2437 // Check status of the object (Invoice) to verify if it is paid by external payment modules (ie Payzen, ...)
2438 $parameters = [
2439 'source' => $source,
2440 'object' => $object
2441 ];
2442 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable
2443 $reshook = $hookmanager->executeHooks('doCheckStatus', $parameters, $object, $action);
2444 if ($reshook < 0) {
2445 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2446 } elseif ($reshook > 0) {
2447 print $hookmanager->resPrint;
2448 }
2449
2450 if ($source == 'order' && $object->billed) {
2451 print '<br><br><div class="amountpaymentcomplete size12x wrapimp">'.$langs->trans("OrderBilled").'</div>';
2452 } elseif ($source == 'invoice' && $object->paye) {
2453 print '<br><br><div class="amountpaymentcomplete size12x wrapimp">'.$langs->trans("InvoicePaid").'</div>';
2454 } elseif ($source == 'invoice' && $object->status == Facture::STATUS_ABANDONED && ($object->close_code == Facture::CLOSECODE_REPLACED || getDolGlobalString('INVOICE_ONLINE_PAYMENT_REFUSED_WHATEVER_IS_ABANDON_REASON'))) {
2455 // Only refuse the payment when the invoice was closed because it has been replaced: the amount is
2456 // then claimed by the replacement invoice and paying this link would pay it twice. An invoice
2457 // abandoned for any other reason, a bad debt for instance, keeps its link usable, since a customer
2458 // paying it anyway is a good outcome.
2459 // INVOICE_ONLINE_PAYMENT_REFUSED_WHATEVER_IS_ABANDON_REASON extends the refusal to every
2460 // abandoned invoice, for jurisdictions where collecting is no longer allowed once a
2461 // receivable has been written off or sent to collections (#39327).
2462 print '<br><br><div class="amountpaymentcomplete size12x wrapimp">'.$langs->trans("Abandoned").'</div>';
2463 } elseif ($source == 'donation' && $object->paid) {
2464 print '<br><br><div class="amountpaymentcomplete size12x wrapimp">'.$langs->trans("DonationPaid").'</div>';
2465 } else {
2466 // Membership can be paid and we still allow to make renewal
2467 if (($source == 'member' || $source == 'membersubscription') && $object->datefin > dol_now()) {
2468 $langs->load("members");
2469 print '<br><div class="amountpaymentcomplete size12x wrapimp">';
2470 $s = $langs->trans("MembershipPaid", '{s1}');
2471 print str_replace('{s1}', '<span class="nobold">'.dol_print_date($object->datefin, 'day').'</span>', $s);
2472 print '</div>';
2473 print '<div class="opacitymedium margintoponly">'.$langs->trans("PaymentWillBeRecordedForNextPeriod").'</div>';
2474 print '<br>';
2475 }
2476
2477 // Buttons for all payments registration methods
2478
2479 // This hook is used to add Button to newpayment.php for external payment modules (ie Payzen, ...)
2480 $parameters = [
2481 'paymentmethod' => $paymentmethod
2482 ];
2483 $reshook = $hookmanager->executeHooks('doAddButton', $parameters, $object, $action);
2484 if ($reshook < 0) {
2485 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2486 } elseif ($reshook >= 0) {
2487 print $hookmanager->resPrint;
2488 }
2489
2490 if ((empty($paymentmethod) || $paymentmethod == 'stripe') && isModEnabled('stripe')) {
2491 $showbutton = 1;
2492 if (getDolGlobalString(strtoupper($source).'_FORCE_DISABLE_STRIPE')) { // Example: MEMBER_FORCE_DISABLE_STRIPE
2493 $showbutton = 0;
2494 }
2495
2496 if ($showbutton) {
2497 // By default noidempotency is set to 1, to avoid the error "Keys for idempotant requests...". It means we can try to pay several times the same tag/ref.
2498 // If STRIPE_USE_IDEMPOTENCY_BY_DEFAULT is set or param noidempotency=0 is added, then we add an idempotent key, so we must use a different tag/ref for each payment (if not we will get an error).
2499 $noidempotency_key = (GETPOSTISSET('noidempotency') ? GETPOSTINT('noidempotency') : (getDolGlobalInt('STRIPE_USE_IDEMPOTENCY_BY_DEFAULT') ? 0 : 1));
2500
2501 print '<div class="button buttonpayment" id="div_dopayment_stripe">';
2502 print '<span class="fa fa-credit-card"></span> ';
2503 print '<input class="" type="submit" id="dopayment_stripe" name="dopayment_stripe" value="'.$langs->trans("StripeDoPayment").'">';
2504 print '<input type="hidden" name="noidempotency" value="'.$noidempotency_key.'">';
2505 print '<br>';
2506 print '<span class="buttonpaymentsmall">'.$langs->trans("CreditOrDebitCard").'</span>';
2507 print '</div>';
2508 print '<script>
2509 $( document ).ready(function() {
2510 $("#div_dopayment_stripe").click(function(){
2511 $("#dopayment_stripe").click();
2512 });
2513 $("#dopayment_stripe").click(function(e){
2514 $("#div_dopayment_stripe").css( \'cursor\', \'wait\' );
2515 e.stopPropagation();
2516 return true;
2517 });
2518 });
2519 </script>
2520 ';
2521 }
2522 }
2523
2524 if ((empty($paymentmethod) || $paymentmethod == 'paypal') && isModEnabled('paypal')) {
2525 if (!getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY')) {
2526 $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY = 'integral';
2527 }
2528
2529 $showbutton = 1;
2530 if (getDolGlobalString(strtoupper($source).'_FORCE_DISABLE_PAYPAL')) { // Example: MEMBER_FORCE_DISABLE_PAYPAL
2531 $showbutton = 0;
2532 }
2533
2534 if ($showbutton) {
2535 print '<div class="button buttonpayment" id="div_dopayment_paypal">';
2536 if (getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY') != 'integral') {
2537 print '<div style="line-height: 1em">&nbsp;</div>';
2538 }
2539 print '<span class="fab fa-paypal"></span> <input class="" type="submit" id="dopayment_paypal" name="dopayment_paypal" value="'.$langs->trans("PaypalDoPayment").'">';
2540 if (getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY') == 'integral') {
2541 print '<br>';
2542 print '<span class="buttonpaymentsmall">'.$langs->trans("CreditOrDebitCard").'</span><span class="buttonpaymentsmall"> - </span>';
2543 print '<span class="buttonpaymentsmall">'.$langs->trans("PayPalBalance").'</span>';
2544 }
2545 //if (getDolGlobalString('PAYPAL_API_INTEGRAL_OR_PAYPALONLY') == 'paypalonly') {
2546 //print '<br>';
2547 //print '<span class="buttonpaymentsmall">'.$langs->trans("PayPalBalance").'"></span>';
2548 //}
2549 print '</div>';
2550 print '<script>
2551 $( document ).ready(function() {
2552 $("#div_dopayment_paypal").click(function(){
2553 $("#dopayment_paypal").click();
2554 });
2555 $("#dopayment_paypal").click(function(e){
2556 $("#div_dopayment_paypal").css( \'cursor\', \'wait\' );
2557 e.stopPropagation();
2558 return true;
2559 });
2560 });
2561 </script>
2562 ';
2563 }
2564 }
2565 }
2566 } else {
2567 dol_print_error_email('ERRORNEWPAYMENT');
2568 }
2569} else {
2570 // Print
2571}
2572
2573print '</td></tr>'."\n";
2574
2575print '</table>'."\n";
2576
2577print '</form>'."\n";
2578print '</div>'."\n";
2579
2580print '<br>';
2581
2582
2583
2584// Add more content on page for some services
2585if (preg_match('/^dopayment/', $action)) { // If we choose/clicked on the payment mode
2586 dol_syslog("newpayment.php action is dopayment... because we clicked on a payment mode - amount = ".$amount);
2587
2588 // Save some data for the paymentok
2589 $remoteip = getUserRemoteIP();
2590 $_SESSION["currencyCodeType"] = $currency;
2591 $_SESSION["FinalPaymentAmt"] = $amount;
2592 $_SESSION['ipaddress'] = ($remoteip ? $remoteip : 'unknown'); // Payer ip
2593 $_SESSION["paymentType"] = '';
2594
2595 $stripecu = null;
2596
2597 // For Stripe
2598 if (GETPOST('dopayment_stripe', 'alpha')) {
2599 // Personalized checkout
2600 print '<style>
2605 .StripeElement {
2606 background-color: white;
2607 padding: 8px 12px;
2608 border-radius: 4px;
2609 border: 1px solid transparent;
2610 box-shadow: 0 1px 3px 0 #e6ebf1;
2611 -webkit-transition: box-shadow 150ms ease;
2612 transition: box-shadow 150ms ease;
2613 }
2614
2615 .StripeElement--focus {
2616 box-shadow: 0 1px 3px 0 #cfd7df;
2617 }
2618
2619 .StripeElement--invalid {
2620 border-color: #fa755a;
2621 }
2622
2623 .StripeElement--webkit-autofill {
2624 background-color: #fefde5 !important;
2625 }
2626 </style>';
2627
2628 //print '<br>';
2629
2630 print '<!-- Show Stripe form payment-form STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = ' . getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION').' STRIPE_USE_NEW_CHECKOUT = ' . getDolGlobalString('STRIPE_USE_NEW_CHECKOUT').' -->'."\n";
2631 print '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST" id="payment-form">'."\n";
2632
2633 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
2634 print '<input type="hidden" name="dopayment_stripe" value="1">'."\n";
2635 print '<input type="hidden" name="action" value="charge">'."\n";
2636 print '<input type="hidden" name="tag" value="'.$TAG.'">'."\n";
2637 print '<input type="hidden" name="s" value="'.$source.'">'."\n";
2638 print '<input type="hidden" name="ref" value="'.$REF.'">'."\n";
2639 print '<input type="hidden" name="fulltag" value="'.$FULLTAG.'">'."\n";
2640 print '<input type="hidden" name="suffix" value="'.$suffix.'">'."\n";
2641 print '<input type="hidden" name="securekey" value="'.$SECUREKEY.'">'."\n";
2642 print '<input type="hidden" name="e" value="'.$entity.'" />'."\n";
2643 print '<input type="hidden" name="amount" value="'.$amount.'">'."\n";
2644 print '<input type="hidden" name="currency" value="'.$currency.'">'."\n";
2645 //print '<input type="hidden" name="forcesandbox" value="'.GETPOSTINT('forcesandbox').'" />';
2646 print '<input type="hidden" name="email" value="'.GETPOST('email', 'alpha').'" />';
2647 print '<input type="hidden" name="thirdparty_id" value="'.GETPOSTINT('thirdparty_id').'" />';
2648 print '<input type="hidden" name="lang" value="'.$getpostlang.'">';
2649
2650 // Make some check on amount: We accept an amount that is different to allow to pay an existing invoice partially or
2651 // to allow to pay a membership with open amount, but for a payment of an order, we have no reason to accept partial payment.
2652 $checkamount = 1;
2653 $tmptag = dolExplodeIntoArray($fulltag, '.', '=');
2654 if (array_key_exists('ORD', $tmptag) && (int) $tmptag['ORD'] > 0) {
2655 include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
2656 $object = new Commande($db);
2657 $result = $object->fetch((int) $tmptag['ORD']);
2658 if ($result > 0) {
2659 if ($object->total_ttc != $amount) {
2660 $checkamount = 0;
2661 }
2662 } else {
2663 $checkamount = 0;
2664 }
2665 }
2666 if (!$checkamount) {
2667 dol_syslog("Hack attempt detected", LOG_WARNING);
2668 setEventMessages('Bad value for amount. Reported as a hack attempt.', null, 'errors');
2669 }
2670
2671
2672 $service = 'StripeLive';
2673 $servicestatus = 1;
2674 if (!getDolGlobalString('STRIPE_LIVE')/* || GETPOST('forcesandbox', 'alpha') */) {
2675 $service = 'StripeTest';
2676 $servicestatus = 0;
2677 }
2678
2679 if ($checkamount && (getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') || getDolGlobalString('STRIPE_USE_NEW_CHECKOUT'))) { // Use a SCA ready method
2680 require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
2681
2682 $stripe = new Stripe($db);
2683 $stripeacc = $stripe->getStripeAccount($service);
2684 if (is_object($object) && is_object($object->thirdparty)) {
2685 $stripecu = $stripe->customerStripe($object->thirdparty, $stripeacc, $servicestatus, 1);
2686 }
2687
2688 if (getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) {
2689 dol_syslog("newpayment.php Create a Paymentintent for amount=".$amount, LOG_DEBUG);
2690
2691 // By default noidempotency is set to 1, to avoid the error "Keys for idempotant requests...". It means we can pay several times the same tag/ref.
2692 // If STRIPE_USE_IDEMPOTENCY_BY_DEFAULT is set or param noidempotency=0 is added, then with add an idempotent key, so we must use a different tag/ref for each payment (if not we will get an error).
2693 $noidempotency_key = (GETPOSTISSET('noidempotency') ? GETPOSTINT('noidempotency') : (getDolGlobalInt('STRIPE_USE_IDEMPOTENCY_BY_DEFAULT') ? 0 : 1));
2694
2695 $paymentintent = $stripe->getPaymentIntent($amount, $currency, ($tag ? $tag : $fulltag), 'Stripe payment: '.$fulltag.(is_object($object) ? ' ref='.$object->ref : ''), $object, $stripecu, $stripeacc, $servicestatus, 0, 'automatic', false, null, 0, $noidempotency_key);
2696 // The paymentintnent has status 'requires_payment_method' (even if paymentintent was already paid)
2697 //var_dump($paymentintent);
2698 if ($stripe->error) {
2699 setEventMessages($stripe->error, null, 'errors');
2700 }
2701
2702 // Save the data needed by paymentok.php in database (key = PaymentIntent id), so they are found even if the session cookie is lost on the return from Stripe
2703 if (is_object($paymentintent) && !empty($paymentintent->id)) {
2704 $resultsave = onlinePaymentSessionSave($service, $paymentintent->id, array(
2705 'fulltag' => $FULLTAG,
2706 'FinalPaymentAmt' => $amount,
2707 'currencyCodeType' => $currency,
2708 'ipaddress' => getUserRemoteIP() ? getUserRemoteIP() : 'unknown',
2709 'payerID' => is_object($stripecu) ? $stripecu->id : '',
2710 'paymentType' => ''
2711 ));
2712 if ($resultsave < 0) {
2713 dol_syslog("Failed to save the data of the payment ".$paymentintent->id." into llx_onlinepayment_session", LOG_ERR, 0, '_payment');
2714 }
2715 }
2716 }
2717 }
2718
2719 // Note:
2720 // $conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = 1 = use intent object (default value, suggest card payment mode only)
2721 // $conf->global->STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = 2 = use payment object (suggest both card payment mode but also sepa, ...)
2722
2723 print '
2724 <table id="dolpaymenttable" summary="Payment form" class="center centpercent">
2725 <tbody><tr><td class="textpublicpayment">';
2726
2727 if (getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) {
2728 print '<div id="payment-request-button"><!-- A Stripe Element will be inserted here. --></div>';
2729 }
2730
2731 print '<div class="form-row '.(getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2 ? 'center' : 'left').'">';
2732 if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 1) {
2733 print '<label for="card-element">'.$langs->trans("CreditOrDebitCard").'</label>';
2734 print '<br><input id="cardholder-name" class="marginbottomonly" name="cardholder-name" value="" type="text" placeholder="'.$langs->trans("CardOwner").'" autocomplete="off" spellcheck="false" autofocus required>';
2735 }
2736
2737 if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 1) {
2738 print '<div id="card-element">
2739 <!-- a Stripe Element will be inserted here. -->
2740 </div>';
2741 }
2742 if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2) {
2743 print '<div id="payment-element">
2744 <!-- a Stripe Element will be inserted here. -->
2745 </div>';
2746 }
2747
2748 print '<!-- Used to display form errors -->
2749 <div id="card-errors" role="alert"></div>
2750 </div>';
2751
2752 print '<br>';
2753 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>';
2754 print '<img id="hourglasstopay" class="hidden" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/working.gif">';
2755
2756 print '</td></tr></tbody>';
2757 print '</table>';
2758 //}
2759
2760 if (getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) {
2761 if (empty($paymentintent)) {
2762 print '<center>'.$langs->trans("Error").' - Failed to get PaymentIntent</center>';
2763 } else {
2764 print '<input type="hidden" name="paymentintent_id" value="'.$paymentintent->id.'">';
2765 //$_SESSION["paymentintent_id"] = $paymentintent->id;
2766 }
2767 }
2768
2769 print '</form>'."\n";
2770
2771
2772 // JS Code for Stripe
2773 if (empty($stripearrayofkeys['publishable_key'])) {
2774 $langs->load("errors");
2775 print info_admin($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Stripe")), 0, 0, 'error marginleftonly marginrightonly');
2776 } else {
2777 print '<!-- JS Code for Stripe components -->';
2778 print '<script src="https://js.stripe.com/v3/"></script>'."\n";
2779 print '<!-- urllogofull = '.$urllogofull.' -->'."\n";
2780
2781 // Code to ask the credit card. This use the default "API version". No way to force API version when using JS code.
2782 print '<script type="text/javascript">'."\n";
2783
2784 if (getDolGlobalString('STRIPE_USE_NEW_CHECKOUT')) {
2785 $amountstripe = $amount;
2786
2787 // Correct the amount according to unit of currency
2788 // See https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support
2789 $arrayzerounitcurrency = array('BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VND', 'VUV', 'XAF', 'XOF', 'XPF');
2790 if (!in_array($currency, $arrayzerounitcurrency)) {
2791 $amountstripe *= 100;
2792 }
2793
2794 $ipaddress = getUserRemoteIP();
2795 $metadata = array('dol_version' => DOL_VERSION, 'dol_entity' => $conf->entity, 'ipaddress' => $ipaddress);
2796 if (is_object($object)) {
2797 $metadata['dol_type'] = $object->element;
2798 $metadata['dol_id'] = $object->id;
2799
2800 $ref = $object->ref;
2801 }
2802
2803 try {
2804 $arrayforpaymentintent = array(
2805 'description' => 'Stripe payment: '.$FULLTAG.($ref ? ' ref='.$ref : ''),
2806 "metadata" => $metadata
2807 );
2808 if ($TAG) {
2809 $arrayforpaymentintent["statement_descriptor"] = dol_trunc($TAG, 22, 'right', 'UTF-8', 1); // 22 chars that appears on bank receipt (company + description)
2810 }
2811
2812 $arrayforcheckout = array(
2813 'payment_method_types' => array('card'),
2814 'line_items' => array(array(
2815 'price_data' => array(
2816 'currency' => $currency,
2817 'unit_amount' => $amountstripe,
2818 'product_data' => array(
2819 'name' => $langs->transnoentitiesnoconv("Payment").' '.$TAG, // Label of product line
2820 'description' => 'Stripe payment: '.$FULLTAG.($ref ? ' ref='.$ref : ''),
2821 //'images' => array($urllogofull),
2822 ),
2823 ),
2824 'quantity' => 1,
2825 )),
2826 'mode' => 'payment',
2827 'client_reference_id' => $FULLTAG,
2828 'success_url' => $urlok.'&session_id={CHECKOUT_SESSION_ID}', // Stripe replaces the placeholder by the Checkout Session id, used by paymentok.php to find the session saved data
2829 'cancel_url' => $urlko,
2830 'payment_intent_data' => $arrayforpaymentintent
2831 );
2832 if ($stripecu) {
2833 $arrayforcheckout['customer'] = $stripecu;
2834 } elseif (GETPOST('email', 'alpha') && isValidEmail(GETPOST('email', 'alpha'))) {
2835 $arrayforcheckout['customer_email'] = GETPOST('email', 'alpha');
2836 }
2837
2838 dol_syslog("We create a stripe session with \Stripe\Checkout\Session::create for amountstripe=".$amountstripe);
2839
2840 $sessionstripe = \Stripe\Checkout\Session::create($arrayforcheckout);
2841
2842 dol_syslog("sessionstripe=".$sessionstripe->id);
2843
2844
2845 $remoteip = getUserRemoteIP();
2846
2847 // Save some data for the paymentok
2848 $_SESSION["currencyCodeType"] = $currency;
2849 $_SESSION["paymentType"] = '';
2850 $_SESSION["FinalPaymentAmt"] = $amount;
2851 $_SESSION['ipaddress'] = ($remoteip ? $remoteip : 'unknown'); // Payer ip
2852 $_SESSION['payerID'] = is_object($stripecu) ? $stripecu->id : '';
2853 $_SESSION['TRANSACTIONID'] = $sessionstripe->id;
2854
2855 // Save the data needed by paymentok.php in database (key = Checkout Session id), so they are found even if the session cookie is lost
2856 onlinePaymentSessionSave($service, $sessionstripe->id, array(
2857 'fulltag' => $FULLTAG,
2858 'FinalPaymentAmt' => $amount,
2859 'currencyCodeType' => $currency,
2860 'ipaddress' => ($remoteip ? $remoteip : 'unknown'),
2861 'payerID' => is_object($stripecu) ? $stripecu->id : '',
2862 'paymentType' => ''
2863 ));
2864 } catch (Exception $e) {
2865 print $e->getMessage();
2866 } ?>
2867 // Code for payment with option STRIPE_USE_NEW_CHECKOUT set
2868
2869 // Create a Stripe client.
2870 <?php
2871 if (empty($stripeacc)) {
2872 ?>
2873 var stripe = Stripe('<?php echo $stripearrayofkeys['publishable_key']; // Defined into config.php?>');
2874 <?php
2875 } else {
2876 ?>
2877 var stripe = Stripe('<?php echo $stripearrayofkeys['publishable_key']; // Defined into config.php?>', { stripeAccount: '<?php echo $stripeacc; ?>' });
2878 <?php
2879 } ?>
2880
2881 // Create an instance of Elements
2882 var elements = stripe.elements();
2883
2884 // Custom styling can be passed to options when creating an Element.
2885 // (Note that this demo uses a wider set of styles than the guide below.)
2886 var style = {
2887 base: {
2888 color: '#32325d',
2889 lineHeight: '24px',
2890 fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
2891 fontSmoothing: 'antialiased',
2892 fontSize: '16px',
2893 '::placeholder': {
2894 color: '#aab7c4'
2895 }
2896 },
2897 invalid: {
2898 color: '#fa755a',
2899 iconColor: '#fa755a'
2900 }
2901 }
2902
2903 var cardElement = elements.create('card', {style: style});
2904
2905 <?php if (!empty($sessionstripe)) { ?>
2906 // Comment this to avoid the redirect
2907 stripe.redirectToCheckout({
2908 // Make the id field from the Checkout Session creation API response
2909 // available to this file, so you can provide it as parameter here
2910 // instead of the {{CHECKOUT_SESSION_ID}} placeholder.
2911 sessionId: '<?php print $sessionstripe->id; ?>'
2912 }).then(function (result) {
2913 // If `redirectToCheckout` fails due to a browser or network
2914 // error, display the localized error message to your customer
2915 // using `result.error.message`.
2916 });
2917 <?php } else { ?>
2918 // $sessionstripe was not created (Stripe API call failed, see the error message printed above)
2919 console.error('Failed to create Stripe Checkout Session');
2920 <?php } ?>
2921
2922
2923 <?php
2924 } elseif (getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) { // default value is 1
2925 ?>
2926 // Code for payment with option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION set to 1 or 2
2927
2928 // Create a Stripe client.
2929 <?php
2930 if (empty($stripeacc)) {
2931 ?>
2932 var stripe = Stripe('<?php echo $stripearrayofkeys['publishable_key']; // Defined into config.php?>');
2933 <?php
2934 } else {
2935 ?>
2936 var stripe = Stripe('<?php echo $stripearrayofkeys['publishable_key']; // Defined into config.php?>', { stripeAccount: '<?php echo $stripeacc; ?>' });
2937 <?php
2938 } ?>
2939
2940 <?php
2941 if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2) { // default is 1
2942 ?>
2943 var cardButton = document.getElementById('buttontopay');
2944 var clientSecret = cardButton.dataset.secret;
2945 var options = { clientSecret: clientSecret };
2946
2947 // Create an instance of Elements
2948 var elements = stripe.elements(options);
2949 <?php
2950 } else {
2951 ?>
2952 // Create an instance of Elements
2953 var elements = stripe.elements();
2954 <?php
2955 } ?>
2956
2957 // Custom styling can be passed to options when creating an Element.
2958 // (Note that this demo uses a wider set of styles than the guide below.)
2959 var style = {
2960 base: {
2961 color: '#32325d',
2962 lineHeight: '24px',
2963 fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
2964 fontSmoothing: 'antialiased',
2965 fontSize: '16px',
2966 '::placeholder': {
2967 color: '#aab7c4'
2968 }
2969 },
2970 invalid: {
2971 color: '#fa755a',
2972 iconColor: '#fa755a'
2973 }
2974 }
2975
2976 <?php
2977 if (getDolGlobalInt('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') == 2) { // Default is 1.
2978 ?>
2979 var paymentElement = elements.create("payment");
2980
2981 // Add an instance of the card Element into the div #payment-element
2982 paymentElement.mount("#payment-element");
2983
2984 // Handle form submission
2985 var cardButton = document.getElementById('buttontopay');
2986
2987 cardButton.addEventListener('click', function(event) {
2988 console.log("We click on buttontopay");
2989 event.preventDefault();
2990
2991 /* Disable button to pay and show hourglass cursor */
2992 jQuery('#hourglasstopay').show();
2993 jQuery('#buttontopay').hide();
2994
2995 stripe.confirmPayment({
2996 elements,confirmParams: {
2997 return_url: '<?php echo $urlok; ?>',
2998 payment_method_data: {
2999 billing_details: {
3000 name: 'test'
3001 <?php if (GETPOST('email', 'alpha') || (is_object($object) && is_object($object->thirdparty) && !empty($object->thirdparty->email))) {
3002 ?>, email: <?php echo "'".dol_escape_js(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $object->thirdparty->email)."'" ; ?><?php
3003 } ?>
3004 <?php if (is_object($object) && is_object($object->thirdparty) && !empty($object->thirdparty->phone)) {
3005 ?>, phone: <?php echo "'".dol_escape_js($object->thirdparty->phone)."'" ; ?><?php
3006 } ?>
3007 <?php if (is_object($object) && is_object($object->thirdparty)) {
3008 ?>, address: {
3009 city: <?php echo "'".dol_escape_js($object->thirdparty->town)."'" ; ?>,
3010 <?php if ($object->thirdparty->country_code) {
3011 ?>country: <?php echo "'".dol_escape_js($object->thirdparty->country_code)."'" ; ?>,<?php
3012 } ?>
3013 line1: <?php echo "'".dol_escape_js(preg_replace('/\s\s+/', ' ', $object->thirdparty->address))."'" ; ?>,
3014 postal_code: <?php echo "'".dol_escape_js($object->thirdparty->zip)."'" ; ?>
3015 }
3016 <?php
3017 } ?>
3018 }
3019 },
3020 save_payment_method:<?php if ($stripecu) {
3021 print 'true';
3022 } else {
3023 print 'false';
3024 } ?> /* true when a customer was provided when creating payment intent. true ask to save the card */
3025 },
3026 }
3027 ).then(function(result) {
3028 console.log(result);
3029 if (result.error) {
3030 console.log("Error on result of handleCardPayment");
3031 jQuery('#buttontopay').show();
3032 jQuery('#hourglasstopay').hide();
3033 // Inform the user if there was an error
3034 var errorElement = document.getElementById('card-errors');
3035 console.log(result);
3036 errorElement.textContent = result.error.message;
3037 } else {
3038 // The payment has succeeded. Display a success message.
3039 console.log("No error on result of handleCardPayment, so we submit the form");
3040 // Submit the form
3041 jQuery('#buttontopay').hide();
3042 jQuery('#hourglasstopay').show();
3043 // Send form (action=charge that will do nothing)
3044 jQuery('#payment-form').submit();
3045 }
3046 });
3047
3048 });
3049 <?php
3050 } else {
3051 ?>
3052 var cardElement = elements.create('card', {style: style});
3053
3054 // Add an instance of the card Element into the div #card-element
3055 cardElement.mount('#card-element');
3056
3057 // Handle real-time validation errors from the card Element.
3058 cardElement.addEventListener('change', function(event) {
3059 var displayError = document.getElementById('card-errors');
3060 if (event.error) {
3061 console.log("Show event error (like 'Incorrect card number', ...)");
3062 displayError.textContent = event.error.message;
3063 } else {
3064 console.log("Reset error message");
3065 displayError.textContent = '';
3066 }
3067 });
3068
3069 // Handle form submission
3070 var cardholderName = document.getElementById('cardholder-name');
3071 var cardButton = document.getElementById('buttontopay');
3072 var clientSecret = cardButton.dataset.secret;
3073
3074 cardButton.addEventListener('click', function(event) {
3075 console.log("We click on buttontopay");
3076 event.preventDefault();
3077
3078 if (cardholderName.value == '')
3079 {
3080 console.log("Field Card holder is empty");
3081 var displayError = document.getElementById('card-errors');
3082 displayError.textContent = <?php print "'".dol_escape_js($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CardOwner")))."'" ; ?>;
3083 }
3084 else
3085 {
3086 /* Disable button to pay and show hourglass cursor */
3087 jQuery('#hourglasstopay').show();
3088 jQuery('#buttontopay').hide();
3089
3090 stripe.handleCardPayment(
3091 clientSecret, cardElement, {
3092 payment_method_data: {
3093 billing_details: {
3094 name: cardholderName.value
3095 <?php if (GETPOST('email', 'alpha') || (is_object($object) && is_object($object->thirdparty) && !empty($object->thirdparty->email))) {
3096 ?>, email: <?php echo "'".dol_escape_js(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : $object->thirdparty->email)."'" ; ?><?php
3097 } ?>
3098 <?php if (is_object($object) && is_object($object->thirdparty) && !empty($object->thirdparty->phone)) {
3099 ?>, phone: <?php echo "'".dol_escape_js($object->thirdparty->phone)."'" ; ?><?php
3100 } ?>
3101 <?php if (is_object($object) && is_object($object->thirdparty)) {
3102 ?>, address: {
3103 city: <?php echo "'".dol_escape_js($object->thirdparty->town)."'" ; ?>,
3104 <?php if ($object->thirdparty->country_code) {
3105 ?>country: <?php echo "'".dol_escape_js($object->thirdparty->country_code)."'" ; ?>,<?php
3106 } ?>
3107 line1: <?php echo "'".dol_escape_js(preg_replace('/\s\s+/', ' ', $object->thirdparty->address))."'" ; ?>,
3108 postal_code: <?php echo "'".dol_escape_js($object->thirdparty->zip)."'" ; ?>
3109 }
3110 <?php
3111 } ?>
3112 }
3113 },
3114 save_payment_method:<?php if ($stripecu) {
3115 print 'true';
3116 } else {
3117 print 'false';
3118 } ?> /* true when a customer was provided when creating payment intent. true ask to save the card */
3119 }
3120 ).then(function(result) {
3121 console.log(result);
3122 if (result.error) {
3123 console.log("Error on result of handleCardPayment");
3124 jQuery('#buttontopay').show();
3125 jQuery('#hourglasstopay').hide();
3126 // Inform the user if there was an error
3127 var errorElement = document.getElementById('card-errors');
3128 errorElement.textContent = result.error.message;
3129 } else {
3130 // The payment has succeeded. Display a success message.
3131 console.log("No error on result of handleCardPayment, so we submit the form");
3132 // Submit the form
3133 jQuery('#buttontopay').hide();
3134 jQuery('#hourglasstopay').show();
3135 // Send form (action=charge that will do nothing)
3136 jQuery('#payment-form').submit();
3137 }
3138 });
3139 }
3140 });
3141 <?php
3142 } ?>
3143
3144 <?php
3145 }
3146
3147 print '</script>';
3148 }
3149 }
3150
3151 // For any other payment services
3152 // This hook can be used to show the embedded form to make payments with external payment modules (ie Payzen, ...)
3153 $parameters = [
3154 'paymentmethod' => $paymentmethod,
3155 'amount' => $amount,
3156 'currency' => $currency,
3157 'tag' => GETPOST("tag", 'alpha'),
3158 'dopayment' => GETPOST('dopayment', 'alpha')
3159 ];
3160 // @phan-suppress-next-line PhanTypeMismatchArgumentNullable
3161 $reshook = $hookmanager->executeHooks('doPayment', $parameters, $object, $action);
3162 if ($reshook < 0) {
3163 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
3164 } elseif ($reshook > 0) {
3165 print $hookmanager->resPrint;
3166 }
3167}
3168
3169if (!$ws) {
3170 htmlPrintOnlineFooter($mysoc, $langs, 1, $suffix, $object);
3171}
3172
3173llxFooter('', 'public');
3174
3175$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage members of a foundation.
Class to manage members type.
Class to manage customers orders.
Class for ConferenceOrBoothAttendee.
Class to manage lines of contracts.
Class to manage donations.
Definition don.class.php:42
Class to manage invoices.
const STATUS_ABANDONED
Classified abandoned and no payment done.
Class to manage generation of HTML components Only common components must be here.
Class to manage hooks.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Stripe class @TODO No reason to extend CommonObject.
Class Website.
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML public pages.
global $mysoc
dol_is_file($pathoffile)
Return if path is a file.
dol_now($mode='gmt')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_sanitizePathName($str, $newstr='_', $unaccent=0, $allowdash=0)
Clean a string to use it as a path name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) formatLogObject($data)
Return a string serialized to be output on log with dol_syslog() An option allow to output log in one...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
dol_print_error_email($prefixcode, $errormessage='', $errormessages=array(), $morecss='error', $email='')
Show a public email and error code to contact if technical error.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Build the customer statement lines (invoices and payments) with running balance.
print_paypal_redirect($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag)
Send redirect to paypal to browser.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...