34if (!defined(
'NOLOGIN')) {
37if (!defined(
'NOCSRFCHECK')) {
38 define(
"NOCSRFCHECK", 1);
40if (!defined(
'NOIPCHECK')) {
41 define(
'NOIPCHECK',
'1');
43if (!defined(
'NOBROWSERNOTIF')) {
44 define(
'NOBROWSERNOTIF',
'1');
46if (!defined(
'XFRAMEOPTIONS_ALLOWALL')) {
47 define(
'XFRAMEOPTIONS_ALLOWALL',
'1');
53$entity = (!empty($_GET[
'e']) ? (int) $_GET[
'e'] : (!empty($_POST[
'e']) ? (int) $_POST[
'e'] : 1));
54if (is_numeric($entity)) {
55 define(
"DOLENTITY", $entity);
59require
'../../main.inc.php';
70require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
71require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
72require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
74 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypal.lib.php';
75 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypalfunctions.lib.php';
81$hookmanager->initHooks(array(
'newpayment'));
83$langs->loadLangs(array(
"main",
"other",
"dict",
"bills",
"companies",
"paypal",
"stripe"));
87$PAYPAL_API_PASSWORD =
"";
88$PAYPAL_API_SIGNATURE =
"";
89$PAYPAL_API_SANDBOX =
"";
98 $PAYPALTOKEN =
GETPOST(
'TOKEN');
99 if (empty($PAYPALTOKEN)) {
100 $PAYPALTOKEN =
GETPOST(
'token');
102 $PAYPALPAYERID =
GETPOST(
'PAYERID');
103 if (empty($PAYPALPAYERID)) {
104 $PAYPALPAYERID =
GETPOST(
'PayerID');
109if (empty($FULLTAG)) {
115$suffix =
GETPOST(
"suffix",
'aZ09');
122if (preg_match(
'/PM=([^\.]+)/', $FULLTAG, $reg)) {
123 $paymentmethod = $reg[1];
125if (empty($paymentmethod)) {
129 dol_syslog(
"***** paymentok.php was called with a non valid parameter FULLTAG=".$FULLTAG, LOG_WARNING, 0,
'_payment');
130 http_response_code(400);
131 print
'Bad request: the callback url does not contain a valid fulltag parameter, required to find the payment method used.';
135dol_syslog(
"***** paymentok.php is called paymentmethod=".$paymentmethod.
" FULLTAG=".$FULLTAG.
" REQUEST_URI=".$_SERVER[
"REQUEST_URI"], LOG_DEBUG, 0,
'_payment');
139$ws = preg_match(
'/WS=([^\.]+)/', $FULLTAG, $reg_ws) ? $reg_ws[1] : 0;
141 dol_syslog(
"paymentok.php page is invoked from a website with ref ".$ws.
". It performs actions and then redirects back to this website. A page with ref paymentok must be created for this website.", LOG_DEBUG, 0,
'_payment');
144$validpaymentmethod = getValidOnlinePaymentMethods($paymentmethod);
147if (empty($validpaymentmethod)) {
153$paramcreditor =
'ONLINE_PAYMENT_CREDITOR';
154$paramcreditorlong =
'ONLINE_PAYMENT_CREDITOR_'.$suffix;
163$onlinepaymentsession =
null;
164$onlinepaymentsessionid = $onlinepaymentsessionservice =
'';
166$PAYMENTSTATUS = $TRANSACTIONID = $LONGTRANSACTIONID = $TAXAMT = $NOTE =
'';
168$ErrorCode = $ErrorShortMsg = $ErrorLongMsg = $ErrorSeverityCode =
'';
176$ws_virtuelhost =
null;
178$doactionsthenredirect = 0;
180 $doactionsthenredirect = 1;
181 include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
183 $result = $website->fetch(0, $ws);
185 $ws_virtuelhost = $website->virtualhost;
186 $ws_id = $website->id;
203dol_syslog(
"Callback url when a payment was done. doactionsthenredirect=".$doactionsthenredirect.
" query_string=".(empty($_SERVER[
"QUERY_STRING"]) ?
'' :
dol_escape_htmltag($_SERVER[
"QUERY_STRING"])).
" script_uri=".(empty($_SERVER[
"SCRIPT_URI"]) ?
'' :
dol_escape_htmltag($_SERVER[
"SCRIPT_URI"])), LOG_DEBUG, 0,
'_payment');
204dol_syslog(
"_SERVER[SERVER_NAME] = ".(empty($_SERVER[
"SERVER_NAME"]) ?
'' :
dol_escape_htmltag($_SERVER[
"SERVER_NAME"])), LOG_DEBUG, 0,
'_payment');
205dol_syslog(
"_SERVER[SERVER_ADDR] = ".(empty($_SERVER[
"SERVER_ADDR"]) ?
'' :
dol_escape_htmltag($_SERVER[
"SERVER_ADDR"])), LOG_DEBUG, 0,
'_payment');
208foreach ($_POST as $k => $v) {
209 if (is_scalar($k) && is_scalar($v)) {
210 $tracepost .=
"$k=$v\n";
213dol_syslog(
"POST: ".$tracepost, LOG_DEBUG, 0,
'_payment');
216foreach ($_SESSION as $k => $v) {
217 if (is_scalar($k) && is_scalar($v) && in_array($k, array(
'currencyCodeType',
'errormessage',
'FinalPaymentAmt',
'ipaddress',
'onlinetoken',
'payerID',
'paymentType',
'TRANSACTIONID',
'paymentoksessionkey',
'paymentkosessionkey'))) {
218 $tracesession .=
"$k=$v\n";
221dol_syslog(
"session_id=".session_id().
" SESSION: ".$tracesession, LOG_DEBUG, 0,
'_payment');
223dol_syslog(
"paymentoksessioncode=".
GETPOST(
'paymentoksessioncode').
" SESSION['paymentoksessioncode']=".$_SESSION[
'paymentoksessioncode'], LOG_DEBUG, 0,
'_payment');
227 $head =
'<link rel="stylesheet" type="text/css" href="' .
getDolGlobalString(
'ONLINE_PAYMENT_CSS_URL').
'?lang='.$langs->defaultlang.
'">'.
"\n";
230$conf->dol_hide_topmenu = 1;
231$conf->dol_hide_leftmenu = 1;
235if (empty($doactionsthenredirect)) {
236 $replacemainarea = (empty(
$conf->dol_hide_leftmenu) ?
'<div>' :
'').
'<div>';
237 llxHeader($head, $langs->trans(
"PaymentForm"),
'',
'', 0, 0,
'',
'',
'',
'onlinepaymentbody', $replacemainarea);
241 print
'<span id="dolpaymentspan"></span>'.
"\n";
242 print
'<div id="dolpaymentdiv" class="center">'.
"\n";
247 $logosmall =
$mysoc->logo_small;
249 $paramlogo =
'ONLINE_PAYMENT_LOGO_'.$suffix;
259 if (!empty($logosmall) && is_readable(
$conf->mycompany->dir_output.
'/logos/thumbs/'.$logosmall)) {
260 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.
$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
261 $urllogofull =
$dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.
$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
262 } elseif (!empty($logo) && is_readable(
$conf->mycompany->dir_output.
'/logos/'.$logo)) {
263 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.
$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
269 print
'<div class="backgreypublicpayment">';
270 print
'<div class="logopublicpayment">';
271 print
'<img id="dolpaymentlogo" src="'.$urllogo.
'"';
275 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>';
278 } elseif ($creditor) {
279 print
'<div class="backgreypublicpayment">';
280 print
'<div class="logopublicpayment">';
286 print
'<div class="backimagepublicpayment">';
287 print
'<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="' .
getDolGlobalString(
'MAIN_IMAGE_PUBLIC_PAYMENT').
'">';
292 print
'<br><br><br>';
297$service = $paymentmethod;
300if (
isModEnabled(
'paypal') && $paymentmethod ===
'paypal') {
301 if (!empty($PAYPALTOKEN)) {
304 $onlinetoken = $PAYPALTOKEN;
306 $payerID = !empty($PAYPALPAYERID) ? $PAYPALPAYERID :
'';
308 $ipaddress = $_SESSION[
'ipaddress'];
309 $currencyCodeType = $_SESSION[
'currencyCodeType'];
310 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
311 $paymentType = $_SESSION[
'PaymentType'];
313 dol_syslog(
"Call paymentok with token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
316 if (!empty($paymentType)) {
317 dol_syslog(
"We call GetExpressCheckoutDetails", LOG_DEBUG, 0,
'_payment');
321 $ack = strtoupper($resArray[
"ACK"]);
322 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
324 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
329 dol_syslog(
"We call DoExpressCheckoutPayment token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
330 $resArray2 =
confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag);
333 $ack = strtoupper($resArray2[
"ACK"]);
334 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
335 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
341 $object->resArray = $resArray2;
345 $PAYMENTSTATUS = urldecode($resArray2[
"PAYMENTSTATUS"]);
346 $TRANSACTIONID = urldecode($resArray2[
"TRANSACTIONID"]);
347 $TAXAMT = urldecode($resArray2[
"TAXAMT"]);
348 $NOTE = urldecode($resArray2[
"NOTE"]);
355 $ErrorCode = urldecode($resArray2[
"L_ERRORCODE0"]);
356 $ErrorShortMsg = urldecode($resArray2[
"L_SHORTMESSAGE0"]);
357 $ErrorLongMsg = urldecode($resArray2[
"L_LONGMESSAGE0"]);
358 $ErrorSeverityCode = urldecode($resArray2[
"L_SEVERITYCODE0"]);
361 $ErrorCode =
"SESSIONEXPIRED";
362 $ErrorLongMsg =
"Session expired. Can't retrieve PaymentType. Payment has not been validated.";
363 $ErrorShortMsg =
"Session expired";
365 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
366 dol_print_error(
null,
'Session expired');
369 $ErrorCode =
"PAYPALTOKENNOTDEFINED";
370 $ErrorLongMsg =
"The parameter PAYPALTOKEN was not defined. Payment has not been validated.";
371 $ErrorShortMsg =
"Parameter PAYPALTOKEN not defined";
373 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
374 dol_print_error(
null,
'PAYPALTOKEN not defined');
379if (
isModEnabled(
'stripe') && $paymentmethod ===
'stripe') {
381 if (empty($TRANSACTIONID)) {
382 $TRANSACTIONID = empty($_SESSION[
'TRANSACTIONID']) ?
'' : $_SESSION[
'TRANSACTIONID'];
383 if (empty($TRANSACTIONID) &&
GETPOST(
'payment_intent',
'alphanohtml')) {
385 $TRANSACTIONID =
GETPOST(
'payment_intent',
'alphanohtml');
387 if (empty($TRANSACTIONID) &&
GETPOST(
'session_id',
'alphanohtml')) {
389 $TRANSACTIONID =
GETPOST(
'session_id',
'alphanohtml');
392 $FinalPaymentAmt = empty($_SESSION[
"FinalPaymentAmt"]) ?
'' : $_SESSION[
"FinalPaymentAmt"];
393 $currencyCodeType = empty($_SESSION[
'currencyCodeType']) ?
'' : $_SESSION[
'currencyCodeType'];
395 $service =
'StripeTest';
398 $service =
'StripeLive';
403 $onlinepaymentsessionservice = $service;
404 $onlinepaymentsessionid =
GETPOST(
'session_id',
'alphanohtml') ?
GETPOST(
'session_id',
'alphanohtml') : $TRANSACTIONID;
405 if ($onlinepaymentsessionid) {
406 $onlinepaymentsession = onlinePaymentSessionFetch($onlinepaymentsessionservice, $onlinepaymentsessionid);
409 if (is_object($onlinepaymentsession)) {
411 if (empty($onlinepaymentsession->fulltag) || $onlinepaymentsession->fulltag !== $FULLTAG) {
413 $errmsg =
'Stripe payment verification failed: the payment was not created for fulltag '.$FULLTAG;
416 $FinalPaymentAmt = empty($onlinepaymentsession->FinalPaymentAmt) ?
'' : $onlinepaymentsession->FinalPaymentAmt;
417 $currencyCodeType = empty($onlinepaymentsession->currencyCodeType) ?
'' : $onlinepaymentsession->currencyCodeType;
418 $ipaddress = empty($onlinepaymentsession->ipaddress) ?
'' : $onlinepaymentsession->ipaddress;
419 $paymentType = empty($onlinepaymentsession->paymentType) ?
'' : $onlinepaymentsession->paymentType;
420 } elseif (!
GETPOST(
'payment_intent',
'alphanohtml') &&
GETPOST(
'paymentoksessioncode') !== $_SESSION[
'paymentoksessioncode']) {
427 $errmsg =
'Attempted direct access to the paymentok page without a valid session.';
432 if (!$error && $TRANSACTIONID) {
435 include_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
436 $stripe =
new Stripe($db);
437 $stripeacc = $stripe->getStripeAccount($service);
440 global $stripearrayofkeysbyenv;
441 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
445 if (preg_match(
'/^cs_/', $TRANSACTIONID)) {
446 if (empty($stripeacc)) {
447 $checkoutsession = \Stripe\Checkout\Session::retrieve($TRANSACTIONID);
449 $checkoutsession = \Stripe\Checkout\Session::retrieve($TRANSACTIONID, array(
"stripe_account" => $stripeacc));
451 $TRANSACTIONID = (string) $checkoutsession->payment_intent;
454 if (empty($stripeacc)) {
455 $paymentIntent = \Stripe\PaymentIntent::retrieve($TRANSACTIONID);
457 $paymentIntent = \Stripe\PaymentIntent::retrieve($TRANSACTIONID, array(
"stripe_account" => $stripeacc));
462 $zeroDecimalCurrencies = array(
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF');
463 if (in_array(strtoupper($currencyCodeType), $zeroDecimalCurrencies)) {
464 $expectedAmount = (int) round($FinalPaymentAmt);
466 $expectedAmount = (int) round($FinalPaymentAmt * 100);
468 $expectedCurrency = strtolower($currencyCodeType);
470 if ((
int) $paymentIntent->amount !== $expectedAmount || strtolower($paymentIntent->currency) !== $expectedCurrency) {
472 $errmsg =
'Stripe payment information mismatch: expected amount ' . $expectedAmount .
' and currency ' . $expectedCurrency .
', got amount ' . $paymentIntent->amount .
' and currency ' . $paymentIntent->currency;
475 if ($paymentIntent->status !==
'succeeded') {
477 $errmsg =
'Stripe payment not succeeded. Status: ' . $paymentIntent->status;
484 if ($paymentIntent instanceof \
Stripe\PaymentIntent) {
485 $customerid = $paymentIntent->customer;
487 if (isset($stripearrayofkeysbyenv[$servicestatus][
'publishable_key'])) {
488 $pkey = $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
491 if ($customerid && $pkey) {
492 $LONGTRANSACTIONID = $TRANSACTIONID.
':'.$customerid.
'@'.$pkey;
496 $errormessage =
"Stripe API error: ".$e->getMessage();
497 dol_syslog($errormessage, LOG_ERR, 0,
'_payment');
498 setEventMessages($e->getMessage(),
null,
'errors');
501 $errormessage =
"CantRetrievePaymentIntent: ".$e->getMessage();
502 dol_syslog($errormessage, LOG_ERR, 0,
'_payment');
503 setEventMessages($e->getMessage(),
null,
'errors');
507 $errmsg =
'Stripe API error: ' . $e->getMessage();
512 $errmsg =
'Stripe payment verification failed: TRANSACTIONID is not set or session key does not match.';
514 setEventMessages($errmsg,
null,
'errors');
520 $ispaymentok =
false;
525if (!in_array($paymentmethod, array(
'paypal',
'paybox',
'stripe'))) {
529 'paymentmethod' => $paymentmethod,
531 $reshook = $hookmanager->executeHooks(
'isPaymentOK', $parameters, $object, $action);
533 if (isset($hookmanager->resArray[
'ispaymentok'])) {
534 dol_syslog(
'ispaymentok overwrite by hook return with value='.$hookmanager->resArray[
'ispaymentok'], LOG_DEBUG, 0,
'_payment');
535 $ispaymentok = $hookmanager->resArray[
'ispaymentok'];
538 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
544if (empty($ipaddress)) {
545 $ipaddress = $_SESSION[
'ipaddress'];
547if (empty($FinalPaymentAmt)) {
548 $FinalPaymentAmt = empty($_SESSION[
"FinalPaymentAmt"]) ?
'' : $_SESSION[
"FinalPaymentAmt"];
550if (empty($currencyCodeType)) {
551 $currencyCodeType = empty($_SESSION[
'currencyCodeType']) ?
'' : $_SESSION[
'currencyCodeType'];
553if (empty($paymentType)) {
554 $paymentType = empty($_SESSION[
"paymentType"]) ?
'' : $_SESSION[
"paymentType"];
557if (empty($TRANSACTIONID)) {
558 $TRANSACTIONID = empty($_SESSION[
'TRANSACTIONID']) ?
'' : $_SESSION[
'TRANSACTIONID'];
559 if (empty($TRANSACTIONID) &&
GETPOST(
'payment_intent',
'alphanohtml')) {
561 $TRANSACTIONID =
GETPOST(
'payment_intent',
'alphanohtml');
576if ($ispaymentok && !empty($TRANSACTIONID)) {
577 $sqltransaction =
"SELECT p.rowid FROM ".MAIN_DB_PREFIX.
"paiement as p";
578 $sqltransaction .=
" WHERE p.ext_payment_id = '".$db->escape($TRANSACTIONID).
"' OR p.ext_payment_id LIKE '".$db->escape($db->escapeforlike($TRANSACTIONID)).
":%'";
579 $sqltransaction .=
" UNION";
580 $sqltransaction .=
" SELECT pd.rowid FROM ".MAIN_DB_PREFIX.
"payment_donation as pd";
581 $sqltransaction .=
" WHERE pd.ext_payment_id = '".$db->escape($TRANSACTIONID).
"' OR pd.ext_payment_id LIKE '".$db->escape($db->escapeforlike($TRANSACTIONID)).
":%'";
582 $resqltransaction = $db->query($sqltransaction);
583 if (!$resqltransaction || $db->num_rows($resqltransaction) > 0) {
584 dol_syslog(
"The transaction ".$TRANSACTIONID.
" is already used by a recorded payment (or the check failed), so it is not recorded again", LOG_WARNING, 0,
'_payment');
585 $ispaymentok =
false;
586 $ErrorCode =
"ALREADYRECORDED";
587 $ErrorShortMsg =
"Payment already recorded";
588 $ErrorLongMsg =
"The transaction ".$TRANSACTIONID.
" of the payment service was already recorded for a payment. It is not recorded again.";
596$postactionmessages = array();
599 if (empty($user->rights->societe)) {
600 $user->rights->societe =
new stdClass();
602 if (empty($user->rights->facture)) {
603 $user->rights->facture =
new stdClass();
604 $user->rights->facture->invoice_advance =
new stdClass();
606 if (empty($user->rights->adherent)) {
607 $user->rights->adherent =
new stdClass();
608 $user->rights->adherent->cotisation =
new stdClass();
610 $user->rights->societe->creer = 1;
611 $user->rights->facture->creer = 1;
612 $user->rights->facture->invoice_advance->validate = 1;
613 $user->rights->adherent->cotisation->creer = 1;
615 if (array_key_exists(
'MEM', $tmptag) && $tmptag[
'MEM'] > 0) {
622 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
623 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent_type.class.php';
624 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
628 $result1 =
$object->fetch((
int) $tmptag[
'MEM']);
629 $result2 = $adht->fetch(
$object->typeid);
631 $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
632 $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit :
'y';
634 dol_syslog(
"We have to process member with id=".$tmptag[
'MEM'].
" result1=".$result1.
" result2=".$result2, LOG_DEBUG, 0,
'_payment');
636 if ($result1 > 0 && $result2 > 0) {
637 if ($paymentmethod ==
'paybox') {
640 if ($paymentmethod ==
'paypal') {
643 if ($paymentmethod ==
'stripe') {
646 if (empty($paymentTypeId)) {
647 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
649 if (empty($paymentType)) {
654 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
657 if (empty($paymentTypeId) || $paymentTypeId < 0) {
662 dol_syslog(
"FinalPaymentAmt=".$FinalPaymentAmt.
" paymentTypeId=".$paymentTypeId.
" currencyCodeType=".$currencyCodeType, LOG_DEBUG, 0,
'_payment');
665 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
667 $amountbytype = $adht->amountByType(1);
668 $minimumamountbytype = $adht->minimumamountbytype(1);
669 $minimumamount = empty($minimumamountbytype[$typeid]) ? 0 : $minimumamountbytype[$typeid];
671 if (empty($adht->caneditamount)) {
672 if (
$object->status == $object::STATUS_DRAFT) {
675 $amountexpected = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid];
681 $amountexpected = max(0, (
float) $amountexpected, (
float)
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"));
682 if (!empty($adht->caneditamountamount)) {
683 $amountexpected = max($amountexpected, $adht->minimumamount);
685 if ($amountexpected && $amountexpected != $FinalPaymentAmt) {
687 $errmsg =
'Value of FinalPayment ('.$FinalPaymentAmt.
') propagated by payment page differs from the expected value for membership ('.$amountexpected.
'). May be a hack to try to pay a different amount ?';
688 $postactionmessages[] = $errmsg;
689 $ispostactionok = -1;
690 dol_syslog(
"Failed to validate member (bad amount check): ".$errmsg, LOG_ERR, 0,
'_payment');
697 if ($FinalPaymentAmt <
getDolGlobalInt(
'MEMBER_MIN_AMOUNT') || $FinalPaymentAmt < $minimumamount) {
699 $errmsg =
'Value of FinalPayment ('.$FinalPaymentAmt.
') is lower than the minimum allowed (' . max(
getDolGlobalString(
'MEMBER_MIN_AMOUNT'), $minimumamount).
'). May be a hack to try to pay a different amount ?';
700 $postactionmessages[] = $errmsg;
701 $ispostactionok = -1;
702 dol_syslog(
"Failed to validate member (amount propagated from payment page is lower than allowed minimum): ".$errmsg, LOG_ERR, 0,
'_payment');
707 if ($currencyCodeType && $currencyCodeType !=
$conf->currency) {
709 $errmsg =
'Value of currencyCodeType ('.$currencyCodeType.
') differs from value expected for membership ('.
$conf->currency.
'). May be a hack to try to pay a different amount ?';
710 $postactionmessages[] = $errmsg;
711 $ispostactionok = -1;
712 dol_syslog(
"Failed to validate member (bad currency check): ".$errmsg, LOG_ERR, 0,
'_payment');
717 $result = (
$object->status == $object::STATUS_EXCLUDED) ? -1 :
$object->validate($user);
721 $postactionmessages[] = $errmsg;
722 $postactionmessages = array_merge($postactionmessages,
$object->errors);
723 $ispostactionok = -1;
724 dol_syslog(
"Failed to validate member: ".$errmsg, LOG_ERR, 0,
'_payment');
727 if (empty(
$object->datevalid)) {
728 dol_syslog(
"Member date of validation is empty. We define it", LOG_WARNING, 0,
'_payment');
730 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent SET";
731 $sql .=
" datevalid = '".$db->idate($now).
"'";
732 $sql .=
" WHERE rowid = ".((int)
$object->id);
733 $result = $db->query($sql);
737 $errmsg = $db->error();
738 $postactionmessages[] = $errmsg;
740 $ispostactionok = -1;
741 dol_syslog(
"Failed to set date of validation: ".$errmsg, LOG_ERR, 0,
'_payment');
747 $datesubscription =
$object->datevalid;
764 if ($datesubscription && $defaultdelay && $defaultdelayunit) {
767 while ($datesubend < $now) {
769 $datesubscription =
dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit);
776 $outputlangs->setDefaultLang(!empty(
$object->default_lang) ? (
string)
$object->default_lang : (empty(
$object->thirdparty->default_lang) ? (string)
$mysoc->default_lang : (string)
$object->thirdparty->default_lang));
778 $amount = $FinalPaymentAmt;
779 $formatteddate =
dol_print_date($paymentdate,
'dayhour',
'auto', $outputlangs);
780 $label = $langs->trans(
"OnlineSubscriptionPaymentLine", $formatteddate, $paymentmethod, $ipaddress, $TRANSACTIONID);
784 if ($paymentmethod ==
'paybox') {
787 if ($paymentmethod ==
'paypal') {
790 if ($paymentmethod ==
'stripe') {
795 'paymentmethod' => $paymentmethod,
797 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
799 if (isset($hookmanager->resArray[
'bankaccountid'])) {
800 dol_syslog(
'accountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
801 $accountid = $hookmanager->resArray[
'bankaccountid'];
806 $errmsg =
'Setup of bank account to use for payment is not correctly done for payment method '.$paymentmethod;
807 $postactionmessages[] = $errmsg;
808 $ispostactionok = -1;
809 dol_syslog(
"Failed to get the bank account to record payment: ".$errmsg, LOG_ERR, 0,
'_payment');
812 $operation =
dol_getIdFromCode($db, $paymentTypeId,
'c_paiement',
'id',
'code', 1);
815 $emetteur_banque =
'';
819 $option =
'bankviainvoice';
821 $option =
'bankdirect';
823 $option =
'invoiceonly';
825 if (empty($option)) {
836 dol_syslog(
"Call ->subscription to create subscription", LOG_DEBUG, 0,
'_payment');
838 $crowid =
$object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $membertypeid);
842 $postactionmessages[] = $errmsg;
843 $ispostactionok = -1;
845 $postactionmessages[] =
'Subscription created (id='.$crowid.
')';
850 $autocreatethirdparty = 0;
853 dol_syslog(
"Call ->subscriptionComplementaryActions option=".$option, LOG_DEBUG, 0,
'_payment');
855 $autocreatethirdparty = 1;
857 $result =
$object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque, $autocreatethirdparty, $TRANSACTIONID, $service);
862 $postactionmessages[] =
$object->error;
863 $postactionmessages = array_merge($postactionmessages,
$object->errors);
864 $ispostactionok = -1;
866 if ($option ==
'bankviainvoice') {
867 $postactionmessages[] =
'Invoice, payment and bank record created';
868 dol_syslog(
"Invoice, payment and bank record created", LOG_DEBUG, 0,
'_payment');
870 if ($option ==
'bankdirect') {
871 $postactionmessages[] =
'Bank record created';
872 dol_syslog(
"Bank record created", LOG_DEBUG, 0,
'_payment');
874 if ($option ==
'invoiceonly') {
875 $postactionmessages[] =
'Invoice recorded';
876 dol_syslog(
"Invoice recorded", LOG_DEBUG, 0,
'_payment');
886 if ($paymentmethod ==
'stripe' && $autocreatethirdparty && $option ==
'bankviainvoice') {
889 dol_syslog(
"Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0,
'_payment');
891 $service =
'StripeTest';
894 $service =
'StripeLive';
899 $thirdparty =
new Societe($db);
900 $thirdparty->fetch($thirdparty_id);
902 include_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
903 $stripe =
new Stripe($db);
906 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
908 if (!$customer && $TRANSACTIONID) {
909 dol_syslog(
"No stripe profile found, so we add it for TRANSACTIONID = ".$TRANSACTIONID, LOG_DEBUG, 0,
'_payment');
912 global $stripearrayofkeysbyenv;
913 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
915 if (preg_match(
'/^pi_/', $TRANSACTIONID)) {
917 $chpi = \Stripe\PaymentIntent::retrieve($TRANSACTIONID);
920 $chpi = \Stripe\Charge::retrieve($TRANSACTIONID);
924 $stripecu = $chpi->customer;
926 if (empty($stripecu)) {
928 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
931 if (preg_match(
'/^pi_/', $TRANSACTIONID) && $customer) {
932 \Stripe\PaymentIntent::update($chpi->id, array(
'customer' => $customer->id));
935 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
936 $sql .=
" VALUES (".((int) $thirdparty_id).
", '', '".$db->escape($stripecu).
"', 'stripe', '".$db->escape($stripearrayofkeysbyenv[$servicestatus][
'publishable_key']).
"', ".((int) $servicestatus).
", ".((int)
$conf->entity).
", '".$db->idate(
dol_now()).
"', 0)";
937 $resql = $db->query($sql);
940 $errmsg =
'Failed to insert customer stripe id in database : '.$db->lasterror();
942 $postactionmessages[] = $errmsg;
943 $ispostactionok = -1;
948 $errmsg =
'Failed to retrieve paymentintent or charge from id';
950 $postactionmessages[] = $errmsg;
951 $ispostactionok = -1;
955 $errmsg =
'Failed to get or save customer stripe id in database : '.$e->getMessage();
957 $postactionmessages[] = $errmsg;
958 $ispostactionok = -1;
975 $nuser =
new User($db);
980 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"user WHERE fk_member = ".((int)
$object->id);
981 $resqlcount = $db->query($sql);
983 $objcount = $db->fetch_object($resqlcount);
985 $found = $objcount->nb;
990 $result = $nuser->create_from_member($tmpuser,
$object->login);
991 $newpassword = $nuser->setPassword($user,
'');
994 $outputlangs->load(
"errors");
995 $postactionmessages[] =
'Error in create external user : '.$nuser->error;
997 $infouserlogin = $outputlangs->trans(
"Login").
': '.$nuser->login.
' '.
"\n".$outputlangs->trans(
"Password").
': '.$newpassword;
998 $postactionmessages[] = $langs->trans(
"NewUserCreated", $nuser->login);
1001 $outputlangs->load(
"errors");
1002 $postactionmessages[] =
'No user created because a user linked to member already exists';
1008 dol_syslog(
"Send email to customer to ".
$object->email.
" if we have to (sendalsoemail = ".$sendalsoemail.
")", LOG_DEBUG, 0,
'_payment');
1011 if (
$object->email && $sendalsoemail) {
1016 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1019 $outputlangs->loadLangs(array(
"main",
"members"));
1021 $arraydefaultmessage =
null;
1024 if (!empty($labeltouse)) {
1025 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'member', $user, $outputlangs, 0, 1, $labeltouse);
1028 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1029 $subject = $arraydefaultmessage->topic;
1030 $msg = $arraydefaultmessage->content;
1033 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $object);
1035 if ($infouserlogin) {
1036 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] = $infouserlogin;
1045 $listofpaths = array();
1046 $listofnames = array();
1047 $listofmimes = array();
1048 if (is_object(
$object->invoice)) {
1049 $invoicediroutput =
$conf->facture->dir_output;
1051 $file = $fileparams[
'fullname'];
1053 $listofpaths = array($file);
1054 $listofnames = array(basename($file));
1058 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/payment/paymentok.php'.
"\r\n";
1060 $result =
$object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames,
"",
"", 0, -1,
"", $moreinheader);
1064 $postactionmessages[] = $errmsg;
1065 $ispostactionok = -1;
1068 $postactionmessages[] =
'Email sent to member (with invoice document attached)';
1070 $postactionmessages[] =
'Email sent to member (without any attached document)';
1078 $postactionmessages[] =
'Failed to get a valid value for "amount paid" or "payment type" to record the payment of subscription for member '.$tmptag[
'MEM'].
'. May be payment was already recorded.';
1079 $ispostactionok = -1;
1082 $postactionmessages[] =
'Member '.$tmptag[
'MEM'].
' for subscription paid was not found';
1083 $ispostactionok = -1;
1085 } elseif (array_key_exists(
'INV', $tmptag) && $tmptag[
'INV'] > 0) {
1087 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1090 $result =
$object->fetch((
int) $tmptag[
'INV']);
1092 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1095 if ($paymentmethod ===
'paybox') {
1098 if ($paymentmethod ===
'paypal') {
1101 if ($paymentmethod ===
'stripe') {
1104 if (empty($paymentTypeId)) {
1105 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1107 if (empty($paymentType)) {
1108 $paymentType =
'CB';
1112 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1115 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1120 dol_syslog(
"FinalPaymentAmt = ".$FinalPaymentAmt.
" paymentTypeId = ".$paymentTypeId, LOG_DEBUG, 0,
'_payment');
1123 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1127 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1129 $paiement->datepaye = $now;
1130 if ($currencyCodeType ==
$conf->currency) {
1131 $paiement->amounts = array(
$object->id => $FinalPaymentAmt);
1133 $paiement->multicurrency_amounts = array(
$object->id => $FinalPaymentAmt);
1135 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.
$conf->currency.
')';
1136 $ispostactionok = -1;
1139 $paiement->paiementid = $paymentTypeId;
1140 $paiement->num_payment =
'';
1141 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1144 if ($LONGTRANSACTIONID) {
1145 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1147 $paiement->ext_payment_id = $TRANSACTIONID;
1149 $paiement->ext_payment_site = $service;
1153 $result =
$object->validate($user);
1155 $postactionmessages[] =
$object->error;
1156 $ispostactionok = -1;
1159 $postactionmessages[] =
'Invoice validated';
1160 $ispostactionok = 1;
1165 $paiement_id = $paiement->create($user, 1);
1166 if ($paiement_id < 0) {
1167 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1168 $ispostactionok = -1;
1171 $postactionmessages[] =
'Payment created';
1172 $ispostactionok = 1;
1178 if ($paymentmethod ==
'paybox') {
1180 } elseif ($paymentmethod ==
'paypal') {
1182 } elseif ($paymentmethod ==
'stripe') {
1188 'paymentmethod' => $paymentmethod,
1190 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1191 if ($reshook >= 0) {
1192 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1193 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1194 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1197 if ($bankaccountid > 0) {
1198 $label =
'(CustomerInvoicePayment)';
1200 $label =
'(CustomerInvoicePaymentBack)';
1202 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1204 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1205 $ispostactionok = -1;
1208 $postactionmessages[] =
'Bank transaction of payment created';
1209 $ispostactionok = 1;
1212 $postactionmessages[] =
'Setup of bank account to use in module '.$paymentmethod.
' was not set. Your payment was really executed but we failed to record it. Please contact us.';
1213 $ispostactionok = -1;
1224 $postactionmessages[] =
'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.
') or "payment type id" ('.$paymentTypeId.
') to record the payment of invoice '.$tmptag[
'INV'].
'. May be payment was already recorded.';
1225 $ispostactionok = -1;
1228 $postactionmessages[] =
'Invoice paid '.$tmptag[
'INV'].
' was not found';
1229 $ispostactionok = -1;
1231 } elseif (array_key_exists(
'ORD', $tmptag) && $tmptag[
'ORD'] > 0) {
1232 include_once DOL_DOCUMENT_ROOT .
'/commande/class/commande.class.php';
1234 $result =
$object->fetch((
int) $tmptag[
'ORD']);
1236 dol_syslog(
"We have loaded the order id=".
$object->id.
" to use to create the invoice", LOG_DEBUG, 0,
'_payment');
1238 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1241 if ($paymentmethod ==
'paybox') {
1244 if ($paymentmethod ==
'paypal') {
1247 if ($paymentmethod ==
'stripe') {
1250 if (empty($paymentTypeId)) {
1251 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1253 if (empty($paymentType)) {
1254 $paymentType =
'CB';
1258 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1261 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1266 dol_syslog(
"The payment type id to use is paymentTypeId=".$paymentTypeId.
" and FinalPaymentAmt=".$FinalPaymentAmt, LOG_DEBUG, 0,
'_payment');
1270 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1273 include_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1275 $result = $invoice->createFromOrder($object, $user);
1277 if ($FinalPaymentAmt !=
$object->total_ttc) {
1285 $object->classifyBilled($user);
1287 $invoice->validate($user);
1290 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
1292 $paiement->datepaye = $now;
1293 if ($currencyCodeType ==
$conf->currency) {
1294 $paiement->amounts = array($invoice->id => $FinalPaymentAmt);
1296 $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt);
1298 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.
$conf->currency.
')';
1299 $ispostactionok = -1;
1302 $paiement->paiementid = $paymentTypeId;
1303 $paiement->num_payment =
'';
1304 $paiement->note_public =
'Online payment ' .
dol_print_date($now,
'standard') .
' from ' . $ipaddress;
1307 if ($LONGTRANSACTIONID) {
1308 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1310 $paiement->ext_payment_id = $TRANSACTIONID;
1312 $paiement->ext_payment_site = $service;
1315 $paiement_id = $paiement->create($user, 1);
1316 if ($paiement_id < 0) {
1317 $postactionmessages[] = $paiement->error .
' ' . implode(
"<br>\n", $paiement->errors);
1318 $ispostactionok = -1;
1321 $postactionmessages[] =
'Payment created';
1322 $ispostactionok = 1;
1328 if ($paymentmethod ==
'paybox') {
1330 } elseif ($paymentmethod ==
'paypal') {
1332 } elseif ($paymentmethod ==
'stripe') {
1338 'paymentmethod' => $paymentmethod,
1340 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1341 if ($reshook >= 0) {
1342 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1343 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1344 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1347 if ($bankaccountid > 0) {
1348 $label =
'(CustomerInvoicePayment)';
1350 $label =
'(CustomerInvoicePaymentBack)';
1352 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1354 $postactionmessages[] = $paiement->error .
' ' . implode(
"<br>\n", $paiement->errors);
1355 $ispostactionok = -1;
1358 $postactionmessages[] =
'Bank transaction of payment created';
1359 $ispostactionok = 1;
1362 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
1363 $ispostactionok = -1;
1368 $postactionmessages[] =
'Failed to create invoice form order ' . $tmptag[
'ORD'] .
'.';
1369 $ispostactionok = -1;
1379 $postactionmessages[] =
'Failed to get a valid value for "amount paid" (' . $FinalPaymentAmt .
') or "payment type id" (' . $paymentTypeId .
') to record the payment of order ' . $tmptag[
'ORD'] .
'. May be payment was already recorded.';
1380 $ispostactionok = -1;
1383 $postactionmessages[] =
'Invoice module is not enable';
1384 $ispostactionok = -1;
1387 $postactionmessages[] =
'Order paid ' . $tmptag[
'ORD'] .
' was not found';
1388 $ispostactionok = -1;
1390 } elseif (array_key_exists(
'DON', $tmptag) && $tmptag[
'DON'] > 0) {
1391 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
1392 $don =
new Don($db);
1393 $result = $don->fetch((
int) $tmptag[
'DON']);
1396 if ($paymentmethod ==
'paybox') {
1399 if ($paymentmethod ==
'paypal') {
1402 if ($paymentmethod ==
'stripe') {
1405 if (empty($paymentTypeId)) {
1406 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1408 if (empty($paymentType)) {
1409 $paymentType =
'CB';
1413 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1416 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1422 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1426 include_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
1429 $totalpaid = $FinalPaymentAmt;
1431 if ($currencyCodeType ==
$conf->currency) {
1432 $paiement->amounts = array(
$object->id => $totalpaid);
1435 $postactionmessages[] =
'Payment donation can\'t be paid with different currency than '.$conf->currency;
1436 $ispostactionok = -1;
1440 $paiement->fk_donation = $don->id;
1441 $paiement->datep = $now;
1442 $paiement->paymenttype = $paymentTypeId;
1443 $paiement->num_payment =
'';
1444 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1447 if ($LONGTRANSACTIONID) {
1448 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1450 $paiement->ext_payment_id = $TRANSACTIONID;
1452 $paiement->ext_payment_site = $service;
1455 $paiement_id = $paiement->create($user, 1);
1456 if ($paiement_id < 0) {
1457 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1458 $ispostactionok = -1;
1461 $postactionmessages[] =
'Payment created';
1462 $ispostactionok = 1;
1464 if ($totalpaid >= $don->getRemainToPay()) {
1465 $don->valid_promesse($don->id, $user->id);
1466 $don->setPaid($don->id);
1473 if ($paymentmethod ==
'paybox') {
1475 } elseif ($paymentmethod ==
'paypal') {
1477 } elseif ($paymentmethod ==
'stripe') {
1483 'paymentmethod' => $paymentmethod,
1485 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1486 if ($reshook >= 0) {
1487 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1488 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1489 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1492 if ($bankaccountid > 0) {
1493 $label =
'(DonationPayment)';
1494 $result = $paiement->addPaymentToBank($user,
'payment_donation', $label, $bankaccountid,
'',
'');
1496 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1497 $ispostactionok = -1;
1500 $postactionmessages[] =
'Bank transaction of payment created';
1501 $ispostactionok = 1;
1504 $postactionmessages[] =
'Setup of bank account to use in module '.$paymentmethod.
' was not set. Your payment was really executed but we failed to record it. Please contact us.';
1505 $ispostactionok = -1;
1516 $postactionmessages[] =
'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.
') or "payment type id" ('.$paymentTypeId.
') to record the payment of donation '.$tmptag[
'DON'].
'. May be payment was already recorded.';
1517 $ispostactionok = -1;
1520 $postactionmessages[] =
'Donation paid '.$tmptag[
'DON'].
' was not found';
1521 $ispostactionok = -1;
1526 } elseif (array_key_exists(
'ATT', $tmptag) && $tmptag[
'ATT'] > 0) {
1528 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
1529 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
1530 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1532 $result =
$object->fetch((
int) $ref);
1535 if ($paymentmethod ==
'paybox') {
1538 if ($paymentmethod ==
'paypal') {
1541 if ($paymentmethod ==
'stripe') {
1544 if (empty($paymentTypeId)) {
1545 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1547 if (empty($paymentType)) {
1548 $paymentType =
'CB';
1552 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1555 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1561 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1562 $resultvalidate =
$object->validate($user);
1563 if ($resultvalidate < 0) {
1564 $postactionmessages[] =
'Cannot validate invoice';
1565 $ispostactionok = -1;
1571 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1573 $paiement->datepaye = $now;
1574 if ($currencyCodeType ==
$conf->currency) {
1575 $paiement->amounts = array(
$object->id => $FinalPaymentAmt);
1577 $paiement->multicurrency_amounts = array(
$object->id => $FinalPaymentAmt);
1579 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.
$conf->currency.
')';
1580 $ispostactionok = -1;
1583 $paiement->paiementid = $paymentTypeId;
1584 $paiement->num_payment =
'';
1585 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress.
' for event registration';
1588 if ($LONGTRANSACTIONID) {
1589 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1591 $paiement->ext_payment_id = $TRANSACTIONID;
1593 $paiement->ext_payment_site = $service;
1596 $paiement_id = $paiement->create($user, 1);
1597 if ($paiement_id < 0) {
1598 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1599 $ispostactionok = -1;
1602 $postactionmessages[] =
'Payment created';
1603 $ispostactionok = 1;
1609 if ($paymentmethod ==
'paybox') {
1611 } elseif ($paymentmethod ==
'paypal') {
1613 } elseif ($paymentmethod ==
'stripe') {
1619 'paymentmethod' => $paymentmethod,
1621 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1622 if ($reshook >= 0) {
1623 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1624 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1625 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1628 if ($bankaccountid > 0) {
1629 $label =
'(CustomerInvoicePayment)';
1631 $label =
'(CustomerInvoicePaymentBack)';
1633 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1635 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1636 $ispostactionok = -1;
1639 $postactionmessages[] =
'Bank transaction of payment created';
1640 $ispostactionok = 1;
1643 $postactionmessages[] =
'Setup of bank account to use in module '.$paymentmethod.
' was not set. Your payment was really executed but we failed to record it. Please contact us.';
1644 $ispostactionok = -1;
1653 $resultattendee = $attendeetovalidate->fetch((
int) $tmptag[
'ATT']);
1654 if ($resultattendee < 0) {
1656 setEventMessages(
null, $attendeetovalidate->errors,
"errors");
1658 $attendeetovalidate->validate($user);
1660 $attendeetovalidate->amount = $FinalPaymentAmt;
1661 $attendeetovalidate->date_subscription =
dol_now();
1662 $attendeetovalidate->update($user);
1669 setEventMessages(
null, $postactionmessages,
'warnings');
1676 $thirdparty =
new Societe($db);
1677 $resultthirdparty = $thirdparty->fetch($attendeetovalidate->fk_soc);
1678 if ($resultthirdparty < 0) {
1679 setEventMessages($thirdparty->error, $thirdparty->errors,
"errors");
1681 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1682 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1686 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? (
string)
$mysoc->default_lang : (string) $thirdparty->default_lang);
1688 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1690 $arraydefaultmessage =
null;
1692 $idoftemplatetouse =
getDolGlobalInt(
'EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT');
1694 if (!empty($idoftemplatetouse)) {
1695 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1698 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1699 $subject = $arraydefaultmessage->topic;
1700 $msg = $arraydefaultmessage->content;
1702 $subject =
'['.$appli.
'] '.
$object->ref.
' - '.$outputlangs->trans(
"NewRegistration");
1703 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfRegistrationWasReceived");
1706 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $thirdparty);
1712 $sendto = $attendeetovalidate->email;
1714 if ($thirdparty->email) {
1715 $cc = $thirdparty->email ??
'';
1717 if ($attendeetovalidate->email_company && $attendeetovalidate->email_company != $thirdparty->email) {
1718 $cc = ($cc ?
', ' :
'').$attendeetovalidate->email_company;
1723 $urlback = $_SERVER[
"REQUEST_URI"];
1729 $listofpaths = array();
1730 $listofnames = array();
1731 $listofmimes = array();
1732 if (is_object($object)) {
1733 $invoicediroutput =
$conf->facture->dir_output;
1735 $file = $fileparams[
'fullname'];
1737 $listofpaths = array($file);
1738 $listofnames = array(basename($file));
1742 $trackid =
'inv'.$object->id;
1744 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, $listofpaths, $listofmimes, $listofnames, $cc,
'', 0, ($ishtml ? 1 : 0),
'',
'', $trackid,
'',
'standard');
1746 $result = $mailfile->sendfile();
1748 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1750 dol_syslog(
"Failed to send EMail to ".$sendto.
' - '.$mailfile->error, LOG_ERR, 0,
'_payment');
1756 $postactionmessages[] =
'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.
') or "payment type id" ('.$paymentTypeId.
') to record the payment of invoice '.$tmptag[
'ATT'].
'. May be payment was already recorded.';
1757 $ispostactionok = -1;
1760 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1761 $ispostactionok = -1;
1763 } elseif (array_key_exists(
'BOO', $tmptag) && $tmptag[
'BOO'] > 0) {
1765 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
1766 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
1767 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1769 $result =
$object->fetch((
int) $ref);
1771 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1774 if ($paymentmethod ==
'paybox') {
1777 if ($paymentmethod ==
'paypal') {
1780 if ($paymentmethod ==
'stripe') {
1783 if (empty($paymentTypeId)) {
1784 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1786 if (empty($paymentType)) {
1787 $paymentType =
'CB';
1791 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1794 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1800 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1801 $resultvalidate =
$object->validate($user);
1802 if ($resultvalidate < 0) {
1803 $postactionmessages[] =
'Cannot validate invoice';
1804 $ispostactionok = -1;
1810 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1812 $paiement->datepaye = $now;
1813 if ($currencyCodeType ==
$conf->currency) {
1814 $paiement->amounts = array(
$object->id => $FinalPaymentAmt);
1816 $paiement->multicurrency_amounts = array(
$object->id => $FinalPaymentAmt);
1818 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.
$conf->currency.
')';
1819 $ispostactionok = -1;
1822 $paiement->paiementid = $paymentTypeId;
1823 $paiement->num_payment =
'';
1824 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1827 if ($LONGTRANSACTIONID) {
1828 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1830 $paiement->ext_payment_id = $TRANSACTIONID;
1832 $paiement->ext_payment_site = $service;
1835 $paiement_id = $paiement->create($user, 1);
1836 if ($paiement_id < 0) {
1837 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1838 $ispostactionok = -1;
1841 $postactionmessages[] =
'Payment created';
1842 $ispostactionok = 1;
1848 if ($paymentmethod ==
'paybox') {
1850 } elseif ($paymentmethod ==
'paypal') {
1852 } elseif ($paymentmethod ==
'stripe') {
1858 'paymentmethod' => $paymentmethod,
1860 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1861 if ($reshook >= 0) {
1862 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1863 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1864 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1867 if ($bankaccountid > 0) {
1868 $label =
'(CustomerInvoicePayment)';
1870 $label =
'(CustomerInvoicePaymentBack)';
1872 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1874 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1875 $ispostactionok = -1;
1878 $postactionmessages[] =
'Bank transaction of payment created';
1879 $ispostactionok = 1;
1882 $postactionmessages[] =
'Setup of bank account to use in module '.$paymentmethod.
' was not set. Your payment was really executed but we failed to record it. Please contact us.';
1883 $ispostactionok = -1;
1890 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
1891 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
1893 $resultbooth = $booth->fetch((
int) $tmptag[
'BOO']);
1894 if ($resultbooth < 0) {
1896 setEventMessages(
null, $booth->errors,
"errors");
1898 $booth->status = ConferenceOrBooth::STATUS_SUGGESTED;
1899 $resultboothupdate = $booth->update($user);
1900 if ($resultboothupdate < 0) {
1903 $resultinvoice = $invoice->fetch((
int) $ref);
1904 if ($resultinvoice < 0) {
1905 $postactionmessages[] =
'Could not find the associated invoice.';
1906 $ispostactionok = -1;
1909 $thirdparty =
new Societe($db);
1910 $resultthirdparty = $thirdparty->fetch($invoice->socid);
1911 if ($resultthirdparty < 0) {
1913 setEventMessages(
null, $thirdparty->errors,
"errors");
1918 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1919 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1923 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ?
$mysoc->default_lang : $thirdparty->default_lang);
1925 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1927 $arraydefaultmessage =
null;
1929 $idoftemplatetouse =
getDolGlobalInt(
'EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_BOOTH');
1931 if (!empty($idoftemplatetouse)) {
1932 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1935 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1936 $subject = $arraydefaultmessage->topic;
1937 $msg = $arraydefaultmessage->content;
1939 $subject =
'['.$appli.
'] '.$booth->ref.
' - '.$outputlangs->trans(
"NewRegistration").
']';
1940 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfBoothWasReceived");
1943 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $thirdparty);
1949 $sendto = $thirdparty->email;
1951 $urlback = $_SERVER[
"REQUEST_URI"];
1954 $trackid =
'inv'.$invoice->id;
1956 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(),
'',
'', 0, $ishtml ? 1 : 0,
'',
'', $trackid,
'',
'standard');
1958 $result = $mailfile->sendfile();
1960 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1962 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1977 $postactionmessages[] =
'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.
') or "payment type id" ('.$paymentTypeId.
') to record the payment of invoice '.$tmptag[
'ATT'].
'. May be payment was already recorded.';
1978 $ispostactionok = -1;
1981 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1982 $ispostactionok = -1;
1984 } elseif (array_key_exists(
'CON', $tmptag) && $tmptag[
'CON'] > 0) {
1985 include_once DOL_DOCUMENT_ROOT .
'/contrat/class/contrat.class.php';
1987 $result =
$object->fetch((
int) $tmptag[
'CON']);
1989 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1992 if ($paymentmethod ==
'paybox') {
1995 if ($paymentmethod ==
'paypal') {
1998 if ($paymentmethod ==
'stripe') {
2001 if (empty($paymentTypeId)) {
2002 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
2004 if (empty($paymentType)) {
2005 $paymentType =
'CB';
2009 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
2012 if (empty($paymentTypeId) || $paymentTypeId < 0) {
2017 $currencyCodeType = $_SESSION[
'currencyCodeType'];
2018 $contract_lines = (array_key_exists(
'COL', $tmptag) && $tmptag[
'COL'] > 0) ? $tmptag[
'COL'] : null;
2022 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
2025 include_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
2027 $result = $invoice->createFromContract($object, $user, array((
int) $contract_lines));
2030 $invoice->validate($user);
2032 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
2034 $paiement->datepaye = $now;
2035 if ($currencyCodeType ==
$conf->currency) {
2036 $paiement->amounts = array($invoice->id => $FinalPaymentAmt);
2038 $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt);
2040 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.
$conf->currency.
')';
2041 $ispostactionok = -1;
2044 $paiement->paiementid = $paymentTypeId;
2045 $paiement->num_payment =
'';
2046 $paiement->note_public =
'Online payment ' .
dol_print_date($now,
'standard') .
' from ' . $ipaddress;
2049 if ($LONGTRANSACTIONID) {
2050 $paiement->ext_payment_id = $LONGTRANSACTIONID;
2052 $paiement->ext_payment_id = $TRANSACTIONID;
2054 $paiement->ext_payment_site = $service;
2057 $paiement_id = $paiement->create($user, 1);
2058 if ($paiement_id < 0) {
2059 $postactionmessages[] = $paiement->error .
' ' . implode(
"<br>\n", $paiement->errors);
2060 $ispostactionok = -1;
2063 $postactionmessages[] =
'Payment created';
2064 $ispostactionok = 1;
2070 if ($paymentmethod ==
'paybox') {
2072 } elseif ($paymentmethod ==
'paypal') {
2074 } elseif ($paymentmethod ==
'stripe') {
2080 'paymentmethod' => $paymentmethod,
2082 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
2083 if ($reshook >= 0) {
2084 if (isset($hookmanager->resArray[
'bankaccountid'])) {
2085 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
2086 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
2089 if ($bankaccountid > 0) {
2090 $label =
'(CustomerInvoicePayment)';
2092 $label =
'(CustomerInvoicePaymentBack)';
2094 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
2096 $postactionmessages[] = $paiement->error .
' ' . implode(
"<br>\n", $paiement->errors);
2097 $ispostactionok = -1;
2100 $postactionmessages[] =
'Bank transaction of payment created';
2101 $ispostactionok = 1;
2104 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
2105 $ispostactionok = -1;
2110 $msg =
'Failed to create invoice form contract ' . $tmptag[
'CON'];
2111 if (!empty($tmptag[
'COL'])) {
2112 $msg .=
' and col '. $tmptag[
'COL'] .
'.';
2114 $postactionmessages[] = $msg;
2115 $ispostactionok = -1;
2125 $postactionmessages[] =
'Failed to get a valid value for "amount paid" (' . $FinalPaymentAmt .
') or "payment type id" (' . $paymentTypeId .
') to record the payment of contract ' . $tmptag[
'CON'] .
'. Maybe payment was already recorded.';
2126 $ispostactionok = -1;
2129 $postactionmessages[] =
'Invoice module is not enable';
2130 $ispostactionok = -1;
2133 $msg =
'Contract paid ' . $tmptag[
'CON'] .
' was not found';
2134 if (!empty($tmptag[
'COL'])) {
2135 $msg .=
' for col '.$tmptag[
'COL'] .
'.';
2137 $postactionmessages[] = $msg;
2138 $ispostactionok = -1;
2145dol_syslog(
"ispaymentok=".$ispaymentok.
" ispostactionok=".$ispostactionok.
" doactionsthenredirect=".$doactionsthenredirect, LOG_DEBUG, 0,
'_payment');
2149 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
2150 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
2152 $currencyCodeType = empty($_SESSION[
'currencyCodeType']) ?
'' : $_SESSION[
'currencyCodeType'];
2153 $FinalPaymentAmt = empty($_SESSION[
"FinalPaymentAmt"]) ?
'' : $_SESSION[
"FinalPaymentAmt"];
2154 $paymentType = empty($_SESSION[
'PaymentType']) ?
'' : $_SESSION[
'PaymentType'];
2156 if (is_object($object) && method_exists($object,
'call_trigger')) {
2157 '@phan-var-force CommonObject $object';
2159 $result =
$object->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
2164 } elseif (get_class($object) ==
'stdClass') {
2166 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
2168 $result = $paiement->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
2177if (empty($doactionsthenredirect)) {
2179 print $langs->trans(
"YourPaymentHasBeenRecorded").
"<br>\n";
2180 if ($TRANSACTIONID) {
2181 print $langs->trans(
"ThisIsTransactionId").
" : ".$TRANSACTIONID.
"<br><br>\n";
2185 print img_picto(
'',
'tick',
'class="green fa-2x"');
2188 if ($ispostactionok > 0) {
2190 $key =
'ONLINE_PAYMENT_MESSAGE_OK';
2197 print
'<div class="warning marginleftonly marginrightonly">';
2198 print $langs->trans(
"PaymentRecordedButPostPocessingKo").
'<br>';
2200 if ($ErrorLongMsg) {
2201 $s .= $langs->trans(
'DetailedErrorMessage').
": ".$ErrorLongMsg.
"<br>\n";
2203 if ($ErrorShortMsg) {
2204 $s .= $langs->trans(
'ShortErrorMessage').
": ".$ErrorShortMsg.
"<br>\n";
2207 $s .= $langs->trans(
'ErrorCode').
": ".$ErrorCode.
"<br>\n";
2209 if ($ErrorSeverityCode) {
2210 $s .= $langs->trans(
'ErrorSeverityCode').
": ".$ErrorSeverityCode.
"<br>\n";
2212 if (!empty($postactionmessages) && is_array($postactionmessages)) {
2213 foreach ($postactionmessages as $postactionmessage) {
2220 print
'<div class="small">';
2228 print
"Please, send a screenshot of this page to ".$mysoc->email.
"<br>\n";
2232 print $langs->trans(
'DoExpressCheckoutPaymentAPICallFailed').
"<br>\n";
2233 if ($ErrorLongMsg) {
2234 print $langs->trans(
'DetailedErrorMessage').
": ".$ErrorLongMsg.
"<br>\n";
2236 if ($ErrorShortMsg) {
2237 print $langs->trans(
'ShortErrorMessage').
": ".$ErrorShortMsg.
"<br>\n";
2240 print $langs->trans(
'ErrorCode').
": ".$ErrorCode.
"<br>\n";
2242 if ($ErrorSeverityCode) {
2243 print $langs->trans(
'ErrorSeverityCode').
": ".$ErrorSeverityCode.
"<br>\n";
2248 print
"Please, send a screenshot of this page to ".$mysoc->email.
"<br>\n";
2260 dol_syslog(
"Send email to admins if we have to (sendemail = ".$sendemail.
")", LOG_DEBUG, 0,
'_payment');
2265 $myCompanyDefaultLang = (string)
$mysoc->default_lang;
2266 if (empty($myCompanyDefaultLang) || $myCompanyDefaultLang ===
'auto') {
2273 $companylangs->setDefaultLang($myCompanyDefaultLang);
2274 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'stripe'));
2276 $sendto = $sendemail;
2279 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2280 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2285 $urlback = $_SERVER[
"REQUEST_URI"];
2286 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived");
2288 if (array_key_exists(
'MEM', $tmptag)) {
2289 $url = $urlwithroot.
"/adherents/subscription.php?rowid=".((int) $tmptag[
'MEM']);
2290 $content .=
'<strong>'.$companylangs->transnoentitiesnoconv(
"PaymentSubscription").
"</strong><br><br>\n";
2291 $content .= $companylangs->transnoentitiesnoconv(
"MemberId").
': <strong>'.$tmptag[
'MEM'].
"</strong><br>\n";
2292 $content .= $companylangs->transnoentitiesnoconv(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
2293 } elseif (array_key_exists(
'INV', $tmptag)) {
2294 $url = $urlwithroot.
"/compta/facture/card.php?id=".((int) $tmptag[
'INV']);
2295 $content .=
'<strong>'.$companylangs->transnoentitiesnoconv(
"Payment").
"</strong><br><br>\n";
2296 $content .= $companylangs->transnoentitiesnoconv(
"InvoiceId").
': <strong>'.$tmptag[
'INV'].
"</strong><br>\n";
2298 $content .= $companylangs->transnoentitiesnoconv(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
2300 $content .= $companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived").
"<br>\n";
2302 $content .= $companylangs->transnoentitiesnoconv(
"PostActionAfterPayment").
' : ';
2303 if ($ispostactionok > 0) {
2305 $content .=
'<span style="color: green">'.$companylangs->transnoentitiesnoconv(
"OK").
'</span>';
2306 } elseif ($ispostactionok == 0) {
2307 $content .= $companylangs->transnoentitiesnoconv(
"None");
2309 $topic .=
' ('.$companylangs->trans(
"WarningPostActionErrorAfterPayment").
')';
2310 $content .=
'<span class="star">'.$companylangs->transnoentitiesnoconv(
"Error").
'</span>';
2312 $content .=
'<br>'.
"\n";
2313 foreach ($postactionmessages as $postactionmessage) {
2314 $content .=
' * '.$postactionmessage.
'<br>'.
"\n";
2316 if ($ispostactionok < 0) {
2317 $content .= $langs->transnoentitiesnoconv(
"ARollbackWasPerformedOnPostActions");
2319 $content .=
'<br>'.
"\n";
2321 $content .=
"<br>\n";
2322 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
2323 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
2324 $content .= $companylangs->transnoentitiesnoconv(
"ThisIsTransactionId").
': <strong>'.$TRANSACTIONID.
"</strong><br>\n";
2325 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
2326 $content .=
"<br>\n";
2327 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
2329 if (!empty($ErrorCode)) {
2330 $content .=
"ErrorCode = ".$ErrorCode.
"<br>\n";
2332 if (!empty($ErrorShortMsg)) {
2333 $content .=
"ErrorShortMsg = ".$ErrorShortMsg.
"<br>\n";
2335 if (!empty($ErrorLongMsg)) {
2336 $content .=
"ErrorLongMsg = ".$ErrorLongMsg.
"<br>\n";
2338 if (!empty($ErrorSeverityCode)) {
2339 $content .=
"ErrorSeverityCode = ".$ErrorSeverityCode.
"<br>\n";
2342 dol_syslog(
"Content of email: ".$content, LOG_DEBUG, 0,
'_payment');
2347 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2348 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml ? 1 : 0,
'',
'', $trackid,
'',
'standard');
2350 $result = $mailfile->sendfile();
2352 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
2355 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
2363 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
2364 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
2366 $paymentType = $_SESSION[
'PaymentType'];
2367 $currencyCodeType = $_SESSION[
'currencyCodeType'];
2368 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
2370 if (is_object($object) && method_exists($object,
'call_trigger')) {
2372 $result =
$object->call_trigger(
'PAYMENTONLINE_PAYMENT_KO', $user);
2382 $companylangs->setDefaultLang(
$mysoc->default_lang);
2383 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'stripe'));
2385 $sendto = $sendemail;
2388 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2389 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2392 $urlback = $_SERVER[
"REQUEST_URI"];
2393 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"ValidationOfPaymentFailed");
2395 $content .=
'<span style="color: orange">'.$companylangs->transnoentitiesnoconv(
"PaymentSystemConfirmPaymentPageWasCalledButFailed").
"</span>\n";
2397 $content .=
"<br><br>\n";
2398 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
2399 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
2400 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
2401 $content .=
"<br>\n";
2402 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
2408 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2409 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml ? 1 : 0,
'',
'', $trackid,
'',
'standard');
2411 $result = $mailfile->sendfile();
2413 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
2415 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
2422if ($ispaymentok && $onlinepaymentsessionid) {
2423 onlinePaymentSessionConsume($onlinepaymentsessionservice, $onlinepaymentsessionid);
2427unset($_SESSION[
"FinalPaymentAmt"]);
2428unset($_SESSION[
"TRANSACTIONID"]);
2432if (empty($doactionsthenredirect)) {
2435 print
"<!-- Info for payment: FinalPaymentAmt=".dol_escape_htmltag($FinalPaymentAmt).
" paymentTypeId=".
dol_escape_htmltag((
string) $paymentTypeId).
" currencyCodeType=".
dol_escape_htmltag($currencyCodeType).
" -->\n";
2440if (empty($doactionsthenredirect)) {
2451if (!empty($doactionsthenredirect)) {
2455 $_SESSION[
'paymentoksessioncode'] = $randomseckey;
2458 if (!defined(
'USEDOLIBARRSERVER') && !empty($ws_virtuelhost)) {
2459 $ext_urlok = $ws_virtuelhost .
'/paymentok.php?paymentoksessioncode='.urlencode($randomseckey).
'&fulltag='.$FULLTAG;
2461 $ext_urlok = DOL_URL_ROOT.
'/public/website/index.php?paymentoksessioncode='.urlencode($randomseckey).
'&website='.urlencode($ws).
'&pageref=paymentok&fulltag='.$FULLTAG;
2464 dol_syslog(
"Now do a redirect using a Location: ".$ext_urlok, LOG_DEBUG, 0,
'_payment');
2465 header(
"Location: ".$ext_urlok);
2470 $_SESSION[
'paymentkosessioncode'] = $randomseckey;
2473 if (!defined(
'USEDOLIBARRSERVER') && !empty($ws_virtuelhost)) {
2474 $ext_urlko = $ws_virtuelhost .
'/paymentko.php?paymentkosessioncode='.urlencode($randomseckey).
'&fulltag='.$FULLTAG;
2476 $ext_urlko = DOL_URL_ROOT.
'/public/website/index.php?paymentkosessioncode='.urlencode($randomseckey).
'&website='.urlencode($ws).
'&pageref=paymentko&fulltag='.$FULLTAG;
2479 dol_syslog(
"Now do a redirect using a Location:".$ext_urlko, LOG_DEBUG, 0,
'_payment');
2480 header(
"Location: ".$ext_urlko);
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
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 send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage customers orders.
Class for ConferenceOrBoothAttendee.
Class for ConferenceOrBooth.
Class to manage donations.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage payments of customer invoices.
Class to manage payments of donations.
Class to manage third parties objects (customers, suppliers, prospects...)
Stripe class @TODO No reason to extend CommonObject.
Class to manage translations.
Class to manage Dolibarr users.
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML public pages.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png) $', '^\.'), $nohook=0, $mode=0, $limit=0)
Return file(s) into a directory (by default most recent)
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.
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_textishtml($msg, $option=0)
Return if a text is a html content.
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_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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).
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
Validate payment.
getDetails($token)
Prepares the parameters for the GetExpressCheckoutDetails API Call.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.