34if (!defined(
'NOLOGIN')) {
37if (!defined(
'NOCSRFCHECK')) {
38 define(
"NOCSRFCHECK", 1);
40if (!defined(
'NOIPCHECK')) {
41 define(
'NOIPCHECK',
'1');
43if (!defined(
'NOBROWSERNOTIF')) {
44 define(
'NOBROWSERNOTIF',
'1');
47if (!defined(
'XFRAMEOPTIONS_ALLOWALL')) {
48 define(
'XFRAMEOPTIONS_ALLOWALL',
'1');
54$entity = (!empty($_GET[
'e']) ? (int) $_GET[
'e'] : (!empty($_POST[
'e']) ? (int) $_POST[
'e'] : 1));
55if (is_numeric($entity)) {
56 define(
"DOLENTITY", $entity);
60require
'../../main.inc.php';
71require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
72require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
73require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
75 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypal.lib.php';
76 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypalfunctions.lib.php';
82$hookmanager->initHooks(array(
'newpayment'));
84$langs->loadLangs(array(
"main",
"other",
"dict",
"bills",
"companies",
"paypal",
"stripe"));
88$PAYPAL_API_PASSWORD =
"";
89$PAYPAL_API_SIGNATURE =
"";
90$PAYPAL_API_SANDBOX =
"";
99 $PAYPALTOKEN =
GETPOST(
'TOKEN');
100 if (empty($PAYPALTOKEN)) {
101 $PAYPALTOKEN =
GETPOST(
'token');
103 $PAYPALPAYERID =
GETPOST(
'PAYERID');
104 if (empty($PAYPALPAYERID)) {
105 $PAYPALPAYERID =
GETPOST(
'PayerID');
110if (empty($FULLTAG)) {
116$suffix =
GETPOST(
"suffix",
'aZ09');
123if (preg_match(
'/PM=([^\.]+)/', $FULLTAG, $reg)) {
124 $paymentmethod = $reg[1];
126if (empty($paymentmethod)) {
127 dol_syslog(
"***** paymentok.php was called with a non valid parameter FULLTAG=".$FULLTAG, LOG_DEBUG, 0,
'_payment');
128 dol_print_error(
null,
'The callback url does not contain a parameter fulltag that should help us to find the payment method used');
132dol_syslog(
"***** paymentok.php is called paymentmethod=".$paymentmethod.
" FULLTAG=".$FULLTAG.
" REQUEST_URI=".$_SERVER[
"REQUEST_URI"], LOG_DEBUG, 0,
'_payment');
136$ws = preg_match(
'/WS=([^\.]+)/', $FULLTAG, $reg_ws) ? $reg_ws[1] : 0;
138 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');
141$validpaymentmethod = getValidOnlinePaymentMethods($paymentmethod);
144if (empty($validpaymentmethod)) {
150$paramcreditor =
'ONLINE_PAYMENT_CREDITOR';
151$paramcreditorlong =
'ONLINE_PAYMENT_CREDITOR_'.$suffix;
161$PAYMENTSTATUS = $TRANSACTIONID = $LONGTRANSACTIONID = $TAXAMT = $NOTE =
'';
163$ErrorCode = $ErrorShortMsg = $ErrorLongMsg = $ErrorSeverityCode =
'';
171$ws_virtuelhost =
null;
173$doactionsthenredirect = 0;
175 $doactionsthenredirect = 1;
176 include_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
178 $result = $website->fetch(0, $ws);
180 $ws_virtuelhost = $website->virtualhost;
181 $ws_id = $website->id;
198dol_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');
199dol_syslog(
"_SERVER[SERVER_NAME] = ".(empty($_SERVER[
"SERVER_NAME"]) ?
'' :
dol_escape_htmltag($_SERVER[
"SERVER_NAME"])), LOG_DEBUG, 0,
'_payment');
200dol_syslog(
"_SERVER[SERVER_ADDR] = ".(empty($_SERVER[
"SERVER_ADDR"]) ?
'' :
dol_escape_htmltag($_SERVER[
"SERVER_ADDR"])), LOG_DEBUG, 0,
'_payment');
203foreach ($_POST as $k => $v) {
204 if (is_scalar($k) && is_scalar($v)) {
205 $tracepost .=
"$k=$v\n";
208dol_syslog(
"POST: ".$tracepost, LOG_DEBUG, 0,
'_payment');
211foreach ($_SESSION as $k => $v) {
212 if (is_scalar($k) && is_scalar($v) && in_array($k, array(
'currencyCodeType',
'errormessage',
'FinalPaymentAmt',
'ipaddress',
'onlinetoken',
'payerID',
'paymentType',
'TRANSACTIONID',
'paymentoksessionkey',
'paymentkosessionkey'))) {
213 $tracesession .=
"$k=$v\n";
216dol_syslog(
"session_id=".session_id().
" SESSION: ".$tracesession, LOG_DEBUG, 0,
'_payment');
218dol_syslog(
"paymentoksessioncode=".
GETPOST(
'paymentoksessioncode').
" SESSION['paymentoksessioncode']=".$_SESSION[
'paymentoksessioncode'], LOG_DEBUG, 0,
'_payment');
222 $head =
'<link rel="stylesheet" type="text/css" href="' .
getDolGlobalString(
'ONLINE_PAYMENT_CSS_URL').
'?lang='.$langs->defaultlang.
'">'.
"\n";
225$conf->dol_hide_topmenu = 1;
226$conf->dol_hide_leftmenu = 1;
230if (empty($doactionsthenredirect)) {
231 $replacemainarea = (empty($conf->dol_hide_leftmenu) ?
'<div>' :
'').
'<div>';
232 llxHeader($head, $langs->trans(
"PaymentForm"),
'',
'', 0, 0,
'',
'',
'',
'onlinepaymentbody', $replacemainarea);
236 print
'<span id="dolpaymentspan"></span>'.
"\n";
237 print
'<div id="dolpaymentdiv" class="center">'.
"\n";
242 $logosmall =
$mysoc->logo_small;
244 $paramlogo =
'ONLINE_PAYMENT_LOGO_'.$suffix;
254 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$logosmall)) {
255 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
256 $urllogofull =
$dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
257 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$logo)) {
258 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
259 $urllogofull =
$dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
264 print
'<div class="backgreypublicpayment">';
265 print
'<div class="logopublicpayment">';
266 print
'<img id="dolpaymentlogo" src="'.$urllogo.
'"';
270 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>';
273 } elseif ($creditor) {
274 print
'<div class="backgreypublicpayment">';
275 print
'<div class="logopublicpayment">';
281 print
'<div class="backimagepublicpayment">';
282 print
'<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="' .
getDolGlobalString(
'MAIN_IMAGE_PUBLIC_PAYMENT').
'">';
287 print
'<br><br><br>';
292$service = $paymentmethod;
295if (
isModEnabled(
'paypal') && $paymentmethod ===
'paypal') {
296 if (!empty($PAYPALTOKEN)) {
299 $onlinetoken = $PAYPALTOKEN;
301 $payerID = !empty($PAYPALPAYERID) ? $PAYPALPAYERID :
'';
303 $ipaddress = $_SESSION[
'ipaddress'];
304 $currencyCodeType = $_SESSION[
'currencyCodeType'];
305 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
306 $paymentType = $_SESSION[
'PaymentType'];
308 dol_syslog(
"Call paymentok with token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
311 if (!empty($paymentType)) {
312 dol_syslog(
"We call GetExpressCheckoutDetails", LOG_DEBUG, 0,
'_payment');
316 $ack = strtoupper($resArray[
"ACK"]);
317 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
319 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
321 dol_syslog(
"Call to GetExpressCheckoutDetails return error: ".json_encode($resArray), LOG_WARNING, 0,
'_payment');
324 dol_syslog(
"We call DoExpressCheckoutPayment token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
325 $resArray2 =
confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag);
328 $ack = strtoupper($resArray2[
"ACK"]);
329 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
330 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
336 $object->resArray = $resArray2;
340 $PAYMENTSTATUS = urldecode($resArray2[
"PAYMENTSTATUS"]);
341 $TRANSACTIONID = urldecode($resArray2[
"TRANSACTIONID"]);
342 $TAXAMT = urldecode($resArray2[
"TAXAMT"]);
343 $NOTE = urldecode($resArray2[
"NOTE"]);
347 dol_syslog(
"Call to DoExpressCheckoutPayment return error: ".json_encode($resArray2), LOG_WARNING, 0,
'_payment');
350 $ErrorCode = urldecode($resArray2[
"L_ERRORCODE0"]);
351 $ErrorShortMsg = urldecode($resArray2[
"L_SHORTMESSAGE0"]);
352 $ErrorLongMsg = urldecode($resArray2[
"L_LONGMESSAGE0"]);
353 $ErrorSeverityCode = urldecode($resArray2[
"L_SEVERITYCODE0"]);
356 $ErrorCode =
"SESSIONEXPIRED";
357 $ErrorLongMsg =
"Session expired. Can't retrieve PaymentType. Payment has not been validated.";
358 $ErrorShortMsg =
"Session expired";
360 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
364 $ErrorCode =
"PAYPALTOKENNOTDEFINED";
365 $ErrorLongMsg =
"The parameter PAYPALTOKEN was not defined. Payment has not been validated.";
366 $ErrorShortMsg =
"Parameter PAYPALTOKEN not defined";
368 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
374if (
isModEnabled(
'paybox') && $paymentmethod ===
'paybox') {
380if (
isModEnabled(
'stripe') && $paymentmethod ===
'stripe') {
382 if (empty($TRANSACTIONID)) {
383 $TRANSACTIONID = empty($_SESSION[
'TRANSACTIONID']) ?
'' : $_SESSION[
'TRANSACTIONID'];
384 if (empty($TRANSACTIONID) &&
GETPOST(
'payment_intent',
'alphanohtml')) {
386 $TRANSACTIONID =
GETPOST(
'payment_intent',
'alphanohtml');
389 $FinalPaymentAmt = empty($_SESSION[
"FinalPaymentAmt"]) ?
'' : $_SESSION[
"FinalPaymentAmt"];
390 $currencyCodeType = empty($_SESSION[
'currencyCodeType']) ?
'' : $_SESSION[
'currencyCodeType'];
392 $service =
'StripeTest';
395 $service =
'StripeLive';
402 if (!
GETPOST(
'payment_intent',
'alphanohtml') &&
GETPOST(
'paymentoksessioncode') !== $_SESSION[
'paymentoksessioncode']) {
404 $errmsg =
'Attempted direct access to the paymentok page without a valid session.';
409 if (!$error && $TRANSACTIONID) {
412 include_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
413 $stripe =
new Stripe($db);
414 $stripeacc = $stripe->getStripeAccount($service);
417 global $stripearrayofkeysbyenv;
418 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
421 if (empty($stripeacc)) {
422 $paymentIntent = \Stripe\PaymentIntent::retrieve($TRANSACTIONID);
424 $paymentIntent = \Stripe\PaymentIntent::retrieve($TRANSACTIONID, array(
"stripe_account" => $stripeacc));
428 $expectedAmount = (int) round($FinalPaymentAmt * 100);
429 $expectedCurrency = strtolower($currencyCodeType);
431 if ((
int) $paymentIntent->amount !== $expectedAmount || strtolower($paymentIntent->currency) !== $expectedCurrency) {
433 $errmsg =
'Stripe payment information mismatch: expected amount ' . $expectedAmount .
' and currency ' . $expectedCurrency .
', got amount ' . $paymentIntent->amount .
' and currency ' . $paymentIntent->currency;
436 if ($paymentIntent->status !==
'succeeded') {
438 $errmsg =
'Stripe payment not succeeded. Status: ' . $paymentIntent->status;
445 if ($paymentIntent instanceof \
Stripe\PaymentIntent) {
446 $customerid = $paymentIntent->customer;
448 if (isset($stripearrayofkeysbyenv[$servicestatus][
'publishable_key'])) {
449 $pkey = $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
452 if ($customerid && $pkey) {
453 $LONGTRANSACTIONID = $TRANSACTIONID.
':'.$customerid.
'@'.$pkey;
457 $errormessage =
"Stripe API error: ".$e->getMessage();
458 dol_syslog($errormessage, LOG_ERR, 0,
'_payment');
462 $errormessage =
"CantRetrievePaymentIntent: ".$e->getMessage();
463 dol_syslog($errormessage, LOG_ERR, 0,
'_payment');
468 $errmsg =
'Stripe API error: ' . $e->getMessage();
473 $errmsg =
'Stripe payment verification failed: TRANSACTIONID is not set or session key does not match.';
481 $ispaymentok =
false;
486if (!in_array($paymentmethod, array(
'paypal',
'paybox',
'stripe'))) {
490 'paymentmethod' => $paymentmethod,
492 $reshook = $hookmanager->executeHooks(
'isPaymentOK', $parameters, $object, $action);
494 if (isset($hookmanager->resArray[
'ispaymentok'])) {
495 dol_syslog(
'ispaymentok overwrite by hook return with value='.$hookmanager->resArray[
'ispaymentok'], LOG_DEBUG, 0,
'_payment');
496 $ispaymentok = $hookmanager->resArray[
'ispaymentok'];
505if (empty($ipaddress)) {
506 $ipaddress = $_SESSION[
'ipaddress'];
508if (empty($FinalPaymentAmt)) {
509 $FinalPaymentAmt = empty($_SESSION[
"FinalPaymentAmt"]) ?
'' : $_SESSION[
"FinalPaymentAmt"];
511if (empty($currencyCodeType)) {
512 $currencyCodeType = empty($_SESSION[
'currencyCodeType']) ?
'' : $_SESSION[
'currencyCodeType'];
514if (empty($paymentType)) {
515 $paymentType = empty($_SESSION[
"paymentType"]) ?
'' : $_SESSION[
"paymentType"];
518if (empty($TRANSACTIONID)) {
519 $TRANSACTIONID = empty($_SESSION[
'TRANSACTIONID']) ?
'' : $_SESSION[
'TRANSACTIONID'];
520 if (empty($TRANSACTIONID) &&
GETPOST(
'payment_intent',
'alphanohtml')) {
522 $TRANSACTIONID =
GETPOST(
'payment_intent',
'alphanohtml');
530dol_syslog(
"ispaymentok=".$ispaymentok.
" tmptag=".var_export($tmptag,
true), LOG_DEBUG, 0,
'_payment');
537if ($ispaymentok && !empty($TRANSACTIONID)) {
538 $sqltransaction =
"SELECT p.rowid FROM ".MAIN_DB_PREFIX.
"paiement as p";
539 $sqltransaction .=
" WHERE p.ext_payment_id = '".$db->escape($TRANSACTIONID).
"' OR p.ext_payment_id LIKE '".$db->escape($db->escapeforlike($TRANSACTIONID)).
":%'";
540 $sqltransaction .=
" UNION";
541 $sqltransaction .=
" SELECT pd.rowid FROM ".MAIN_DB_PREFIX.
"payment_donation as pd";
542 $sqltransaction .=
" WHERE pd.ext_payment_id = '".$db->escape($TRANSACTIONID).
"' OR pd.ext_payment_id LIKE '".$db->escape($db->escapeforlike($TRANSACTIONID)).
":%'";
543 $resqltransaction = $db->query($sqltransaction);
544 if (!$resqltransaction || $db->num_rows($resqltransaction) > 0) {
545 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');
546 $ispaymentok =
false;
547 $ErrorCode =
"ALREADYRECORDED";
548 $ErrorShortMsg =
"Payment already recorded";
549 $ErrorLongMsg =
"The transaction ".$TRANSACTIONID.
" of the payment service was already recorded for a payment. It is not recorded again.";
557$postactionmessages = array();
560 if (empty($user->rights->societe)) {
561 $user->rights->societe =
new stdClass();
563 if (empty($user->rights->facture)) {
564 $user->rights->facture =
new stdClass();
565 $user->rights->facture->invoice_advance =
new stdClass();
567 if (empty($user->rights->adherent)) {
568 $user->rights->adherent =
new stdClass();
569 $user->rights->adherent->cotisation =
new stdClass();
571 $user->rights->societe->creer = 1;
572 $user->rights->facture->creer = 1;
573 $user->rights->facture->invoice_advance->validate = 1;
574 $user->rights->adherent->cotisation->creer = 1;
576 if (array_key_exists(
'MEM', $tmptag) && $tmptag[
'MEM'] > 0) {
583 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
584 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent_type.class.php';
585 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
589 $result1 =
$object->fetch((
int) $tmptag[
'MEM']);
590 $result2 = $adht->fetch(
$object->typeid);
592 $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
593 $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit :
'y';
595 dol_syslog(
"We have to process member with id=".$tmptag[
'MEM'].
" result1=".$result1.
" result2=".$result2, LOG_DEBUG, 0,
'_payment');
597 if ($result1 > 0 && $result2 > 0) {
598 if ($paymentmethod ==
'paybox') {
601 if ($paymentmethod ==
'paypal') {
604 if ($paymentmethod ==
'stripe') {
607 if (empty($paymentTypeId)) {
608 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
610 if (empty($paymentType)) {
615 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
618 if (empty($paymentTypeId) || $paymentTypeId < 0) {
623 dol_syslog(
"FinalPaymentAmt=".$FinalPaymentAmt.
" paymentTypeId=".$paymentTypeId.
" currencyCodeType=".$currencyCodeType, LOG_DEBUG, 0,
'_payment');
626 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
628 if (empty($adht->caneditamount)) {
629 if (
$object->status == $object::STATUS_DRAFT) {
631 $amountbytype = $adht->amountByType(1);
635 $amountexpected = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid];
645 $amountexpected = max(0, (
float) $amountexpected, (
float)
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"));
647 if ($amountexpected && $amountexpected != $FinalPaymentAmt) {
649 $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 ?';
650 $postactionmessages[] = $errmsg;
651 $ispostactionok = -1;
652 dol_syslog(
"Failed to validate member (bad amount check): ".$errmsg, LOG_ERR, 0,
'_payment');
661 $errmsg =
'Value of FinalPayment ('.$FinalPaymentAmt.
') is lower than the minimum allowed (' .
getDolGlobalString(
'MEMBER_MIN_AMOUNT').
'). May be a hack to try to pay a different amount ?';
662 $postactionmessages[] = $errmsg;
663 $ispostactionok = -1;
664 dol_syslog(
"Failed to validate member (amount propagated from payment page is lower than allowed minimum): ".$errmsg, LOG_ERR, 0,
'_payment');
669 if ($currencyCodeType && $currencyCodeType != $conf->currency) {
671 $errmsg =
'Value of currencyCodeType ('.$currencyCodeType.
') differs from value expected for membership ('.$conf->currency.
'). May be a hack to try to pay a different amount ?';
672 $postactionmessages[] = $errmsg;
673 $ispostactionok = -1;
674 dol_syslog(
"Failed to validate member (bad currency check): ".$errmsg, LOG_ERR, 0,
'_payment');
679 $result = (
$object->status == $object::STATUS_EXCLUDED) ? -1 :
$object->validate($user);
680 if ($result < 0 || empty(
$object->datevalid)) {
683 $postactionmessages[] = $errmsg;
684 $postactionmessages = array_merge($postactionmessages,
$object->errors);
685 $ispostactionok = -1;
686 dol_syslog(
"Failed to validate member: ".$errmsg, LOG_ERR, 0,
'_payment');
691 $datesubscription =
$object->datevalid;
708 if ($datesubscription && $defaultdelay && $defaultdelayunit) {
711 while ($datesubend < $now) {
713 $datesubscription =
dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit);
720 $outputlangs->setDefaultLang(!empty(
$object->default_lang) ? (
string)
$object->default_lang : (empty(
$object->thirdparty->default_lang) ? (string)
$mysoc->default_lang : (string)
$object->thirdparty->default_lang));
722 $amount = $FinalPaymentAmt;
723 $formatteddate =
dol_print_date($paymentdate,
'dayhour',
'auto', $outputlangs);
724 $label = $langs->trans(
"OnlineSubscriptionPaymentLine", $formatteddate, $paymentmethod, $ipaddress, $TRANSACTIONID);
728 if ($paymentmethod ==
'paybox') {
731 if ($paymentmethod ==
'paypal') {
734 if ($paymentmethod ==
'stripe') {
740 'paymentmethod' => $paymentmethod,
742 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
744 if (isset($hookmanager->resArray[
'bankaccountid'])) {
745 dol_syslog(
'accountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
746 $accountid = $hookmanager->resArray[
'bankaccountid'];
749 if ($accountid < 0) {
751 $errmsg =
'Setup of bank account to use for payment is not correctly done for payment method '.$paymentmethod;
752 $postactionmessages[] = $errmsg;
753 $ispostactionok = -1;
754 dol_syslog(
"Failed to get the bank account to record payment: ".$errmsg, LOG_ERR, 0,
'_payment');
757 $operation =
dol_getIdFromCode($db, $paymentTypeId,
'c_paiement',
'id',
'code', 1);
760 $emetteur_banque =
'';
764 $option =
'bankviainvoice';
766 $option =
'bankdirect';
768 $option =
'invoiceonly';
770 if (empty($option)) {
781 dol_syslog(
"Call ->subscription to create subscription", LOG_DEBUG, 0,
'_payment');
783 $crowid =
$object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $membertypeid);
787 $postactionmessages[] = $errmsg;
788 $ispostactionok = -1;
790 $postactionmessages[] =
'Subscription created (id='.$crowid.
')';
795 $autocreatethirdparty = 0;
798 dol_syslog(
"Call ->subscriptionComplementaryActions option=".$option, LOG_DEBUG, 0,
'_payment');
800 $autocreatethirdparty = 1;
802 $result =
$object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque, $autocreatethirdparty, $TRANSACTIONID, $service);
807 $postactionmessages[] =
$object->error;
808 $postactionmessages = array_merge($postactionmessages,
$object->errors);
809 $ispostactionok = -1;
811 if ($option ==
'bankviainvoice') {
812 $postactionmessages[] =
'Invoice, payment and bank record created';
813 dol_syslog(
"Invoice, payment and bank record created", LOG_DEBUG, 0,
'_payment');
815 if ($option ==
'bankdirect') {
816 $postactionmessages[] =
'Bank record created';
817 dol_syslog(
"Bank record created", LOG_DEBUG, 0,
'_payment');
819 if ($option ==
'invoiceonly') {
820 $postactionmessages[] =
'Invoice recorded';
821 dol_syslog(
"Invoice recorded", LOG_DEBUG, 0,
'_payment');
831 if ($paymentmethod ==
'stripe' && $autocreatethirdparty && $option ==
'bankviainvoice') {
834 dol_syslog(
"Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0,
'_payment');
836 $service =
'StripeTest';
839 $service =
'StripeLive';
844 $thirdparty =
new Societe($db);
845 $thirdparty->fetch($thirdparty_id);
847 include_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
848 $stripe =
new Stripe($db);
851 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
853 if (!$customer && $TRANSACTIONID) {
854 dol_syslog(
"No stripe profile found, so we add it for TRANSACTIONID = ".$TRANSACTIONID, LOG_DEBUG, 0,
'_payment');
857 global $stripearrayofkeysbyenv;
858 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
860 if (preg_match(
'/^pi_/', $TRANSACTIONID)) {
862 $chpi = \Stripe\PaymentIntent::retrieve($TRANSACTIONID);
865 $chpi = \Stripe\Charge::retrieve($TRANSACTIONID);
869 $stripecu = $chpi->customer;
871 if (empty($stripecu)) {
873 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
876 if (preg_match(
'/^pi_/', $TRANSACTIONID) && $customer) {
877 \Stripe\PaymentIntent::update($chpi->id, array(
'customer' => $customer->id));
880 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
881 $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)";
882 $resql = $db->query($sql);
885 $errmsg =
'Failed to insert customer stripe id in database : '.$db->lasterror();
887 $postactionmessages[] = $errmsg;
888 $ispostactionok = -1;
893 $errmsg =
'Failed to retrieve paymentintent or charge from id';
895 $postactionmessages[] = $errmsg;
896 $ispostactionok = -1;
900 $errmsg =
'Failed to get or save customer stripe id in database : '.$e->getMessage();
902 $postactionmessages[] = $errmsg;
903 $ispostactionok = -1;
920 $nuser =
new User($db);
925 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"user WHERE fk_member = ".((int)
$object->id);
926 $resqlcount = $db->query($sql);
928 $objcount = $db->fetch_object($resqlcount);
930 $found = $objcount->nb;
935 $result = $nuser->create_from_member($tmpuser,
$object->login);
936 $newpassword = $nuser->setPassword($user,
'');
939 $outputlangs->load(
"errors");
940 $postactionmessages[] =
'Error in create external user : '.$nuser->error;
942 $infouserlogin = $outputlangs->trans(
"Login").
': '.$nuser->login.
' '.
"\n".$outputlangs->trans(
"Password").
': '.$newpassword;
943 $postactionmessages[] = $langs->trans(
"NewUserCreated", $nuser->login);
946 $outputlangs->load(
"errors");
947 $postactionmessages[] =
'No user created because a user linked to member already exists';
953 dol_syslog(
"Send email to customer to ".
$object->email.
" if we have to (sendalsoemail = ".$sendalsoemail.
")", LOG_DEBUG, 0,
'_payment');
956 if (
$object->email && $sendalsoemail) {
961 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
964 $outputlangs->loadLangs(array(
"main",
"members"));
966 $arraydefaultmessage =
null;
969 if (!empty($labeltouse)) {
970 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'member', $user, $outputlangs, 0, 1, $labeltouse);
973 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
974 $subject = $arraydefaultmessage->topic;
975 $msg = $arraydefaultmessage->content;
978 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $object);
980 if ($infouserlogin) {
981 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] = $infouserlogin;
990 $listofpaths = array();
991 $listofnames = array();
992 $listofmimes = array();
993 if (is_object(
$object->invoice)) {
994 $invoicediroutput = $conf->facture->dir_output;
996 $file = $fileparams[
'fullname'];
998 $listofpaths = array($file);
999 $listofnames = array(basename($file));
1003 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/payment/paymentok.php'.
"\r\n";
1005 $result =
$object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames,
"",
"", 0, -1,
"", $moreinheader);
1009 $postactionmessages[] = $errmsg;
1010 $ispostactionok = -1;
1013 $postactionmessages[] =
'Email sent to member (with invoice document attached)';
1015 $postactionmessages[] =
'Email sent to member (without any attached document)';
1023 $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.';
1024 $ispostactionok = -1;
1027 $postactionmessages[] =
'Member '.$tmptag[
'MEM'].
' for subscription paid was not found';
1028 $ispostactionok = -1;
1030 } elseif (array_key_exists(
'INV', $tmptag) && $tmptag[
'INV'] > 0) {
1032 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1034 $result =
$object->fetch((
int) $tmptag[
'INV']);
1036 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1039 if ($paymentmethod ===
'paybox') {
1042 if ($paymentmethod ===
'paypal') {
1045 if ($paymentmethod ===
'stripe') {
1048 if (empty($paymentTypeId)) {
1049 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1051 if (empty($paymentType)) {
1052 $paymentType =
'CB';
1056 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1059 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1064 dol_syslog(
"FinalPaymentAmt = ".$FinalPaymentAmt.
" paymentTypeId = ".$paymentTypeId, LOG_DEBUG, 0,
'_payment');
1067 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1071 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1073 $paiement->datepaye = $now;
1074 if ($currencyCodeType == $conf->currency) {
1075 $paiement->amounts = array(
$object->id => $FinalPaymentAmt);
1077 $paiement->multicurrency_amounts = array(
$object->id => $FinalPaymentAmt);
1079 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.$conf->currency.
')';
1080 $ispostactionok = -1;
1083 $paiement->paiementid = $paymentTypeId;
1084 $paiement->num_payment =
'';
1085 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1088 if ($LONGTRANSACTIONID) {
1089 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1091 $paiement->ext_payment_id = $TRANSACTIONID;
1093 $paiement->ext_payment_site = $service;
1097 $result =
$object->validate($user);
1099 $postactionmessages[] =
$object->error;
1100 $ispostactionok = -1;
1103 $postactionmessages[] =
'Invoice validated';
1104 $ispostactionok = 1;
1109 $paiement_id = $paiement->create($user, 1);
1110 if ($paiement_id < 0) {
1111 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1112 $ispostactionok = -1;
1115 $postactionmessages[] =
'Payment created';
1116 $ispostactionok = 1;
1122 if ($paymentmethod ==
'paybox') {
1124 } elseif ($paymentmethod ==
'paypal') {
1126 } elseif ($paymentmethod ==
'stripe') {
1132 'paymentmethod' => $paymentmethod,
1134 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1135 if ($reshook >= 0) {
1136 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1137 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1138 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1141 if ($bankaccountid > 0) {
1142 $label =
'(CustomerInvoicePayment)';
1144 $label =
'(CustomerInvoicePaymentBack)';
1146 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1148 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1149 $ispostactionok = -1;
1152 $postactionmessages[] =
'Bank transaction of payment created';
1153 $ispostactionok = 1;
1156 $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.';
1157 $ispostactionok = -1;
1168 $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.';
1169 $ispostactionok = -1;
1172 $postactionmessages[] =
'Invoice paid '.$tmptag[
'INV'].
' was not found';
1173 $ispostactionok = -1;
1175 } elseif (array_key_exists(
'ORD', $tmptag) && $tmptag[
'ORD'] > 0) {
1176 include_once DOL_DOCUMENT_ROOT .
'/commande/class/commande.class.php';
1178 $result =
$object->fetch((
int) $tmptag[
'ORD']);
1180 dol_syslog(
"We have loaded the order id=".
$object->id.
" to use to create the invoice", LOG_DEBUG, 0,
'_payment');
1182 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1185 if ($paymentmethod ==
'paybox') {
1188 if ($paymentmethod ==
'paypal') {
1191 if ($paymentmethod ==
'stripe') {
1194 if (empty($paymentTypeId)) {
1195 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1197 if (empty($paymentType)) {
1198 $paymentType =
'CB';
1202 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1205 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1210 dol_syslog(
"The payment type id to use is paymentTypeId=".$paymentTypeId.
" and FinalPaymentAmt=".$FinalPaymentAmt, LOG_DEBUG, 0,
'_payment');
1214 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1217 include_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1219 $result = $invoice->createFromOrder($object, $user);
1221 if ($FinalPaymentAmt !=
$object->total_ttc) {
1229 $object->classifyBilled($user);
1231 $invoice->validate($user);
1234 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
1236 $paiement->datepaye = $now;
1237 if ($currencyCodeType == $conf->currency) {
1238 $paiement->amounts = array($invoice->id => $FinalPaymentAmt);
1240 $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt);
1242 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.$conf->currency.
')';
1243 $ispostactionok = -1;
1246 $paiement->paiementid = $paymentTypeId;
1247 $paiement->num_payment =
'';
1248 $paiement->note_public =
'Online payment ' .
dol_print_date($now,
'standard') .
' from ' . $ipaddress;
1251 if ($LONGTRANSACTIONID) {
1252 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1254 $paiement->ext_payment_id = $TRANSACTIONID;
1256 $paiement->ext_payment_site = $service;
1259 $paiement_id = $paiement->create($user, 1);
1260 if ($paiement_id < 0) {
1261 $postactionmessages[] = $paiement->error .
' ' . implode(
"<br>\n", $paiement->errors);
1262 $ispostactionok = -1;
1265 $postactionmessages[] =
'Payment created';
1266 $ispostactionok = 1;
1272 if ($paymentmethod ==
'paybox') {
1274 } elseif ($paymentmethod ==
'paypal') {
1276 } elseif ($paymentmethod ==
'stripe') {
1282 'paymentmethod' => $paymentmethod,
1284 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1285 if ($reshook >= 0) {
1286 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1287 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1288 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1291 if ($bankaccountid > 0) {
1292 $label =
'(CustomerInvoicePayment)';
1294 $label =
'(CustomerInvoicePaymentBack)';
1296 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1298 $postactionmessages[] = $paiement->error .
' ' . implode(
"<br>\n", $paiement->errors);
1299 $ispostactionok = -1;
1302 $postactionmessages[] =
'Bank transaction of payment created';
1303 $ispostactionok = 1;
1306 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
1307 $ispostactionok = -1;
1312 $postactionmessages[] =
'Failed to create invoice form order ' . $tmptag[
'ORD'] .
'.';
1313 $ispostactionok = -1;
1323 $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.';
1324 $ispostactionok = -1;
1327 $postactionmessages[] =
'Invoice module is not enable';
1328 $ispostactionok = -1;
1331 $postactionmessages[] =
'Order paid ' . $tmptag[
'ORD'] .
' was not found';
1332 $ispostactionok = -1;
1334 } elseif (array_key_exists(
'DON', $tmptag) && $tmptag[
'DON'] > 0) {
1335 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
1336 $don =
new Don($db);
1337 $result = $don->fetch((
int) $tmptag[
'DON']);
1340 if ($paymentmethod ==
'paybox') {
1343 if ($paymentmethod ==
'paypal') {
1344 $paymentTypeId =
getDolGlobalInt(
'global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS');
1346 if ($paymentmethod ==
'stripe') {
1349 if (empty($paymentTypeId)) {
1350 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1352 if (empty($paymentType)) {
1353 $paymentType =
'CB';
1357 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1360 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1366 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1370 include_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
1373 $totalpaid = $FinalPaymentAmt;
1375 if ($currencyCodeType == $conf->currency) {
1376 $paiement->amounts = array(
$object->id => $totalpaid);
1379 $postactionmessages[] =
'Payment donation can\'t be paid with different currency than '.$conf->currency;
1380 $ispostactionok = -1;
1384 $paiement->fk_donation = $don->id;
1385 $paiement->datep = $now;
1386 $paiement->paymenttype = $paymentTypeId;
1387 $paiement->num_payment =
'';
1388 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1391 if ($LONGTRANSACTIONID) {
1392 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1394 $paiement->ext_payment_id = $TRANSACTIONID;
1396 $paiement->ext_payment_site = $service;
1399 $paiement_id = $paiement->create($user, 1);
1400 if ($paiement_id < 0) {
1401 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1402 $ispostactionok = -1;
1405 $postactionmessages[] =
'Payment created';
1406 $ispostactionok = 1;
1408 if ($totalpaid >= $don->getRemainToPay()) {
1409 $don->valid_promesse($don->id, $user->id);
1410 $don->setPaid($don->id);
1417 if ($paymentmethod ==
'paybox') {
1419 } elseif ($paymentmethod ==
'paypal') {
1421 } elseif ($paymentmethod ==
'stripe') {
1427 'paymentmethod' => $paymentmethod,
1429 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1430 if ($reshook >= 0) {
1431 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1432 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1433 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1436 if ($bankaccountid > 0) {
1437 $label =
'(DonationPayment)';
1438 $result = $paiement->addPaymentToBank($user,
'payment_donation', $label, $bankaccountid,
'',
'');
1440 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1441 $ispostactionok = -1;
1444 $postactionmessages[] =
'Bank transaction of payment created';
1445 $ispostactionok = 1;
1448 $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.';
1449 $ispostactionok = -1;
1460 $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.';
1461 $ispostactionok = -1;
1464 $postactionmessages[] =
'Donation paid '.$tmptag[
'DON'].
' was not found';
1465 $ispostactionok = -1;
1470 } elseif (array_key_exists(
'ATT', $tmptag) && $tmptag[
'ATT'] > 0) {
1472 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
1473 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
1474 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1476 $result =
$object->fetch((
int) $ref);
1479 if ($paymentmethod ==
'paybox') {
1482 if ($paymentmethod ==
'paypal') {
1485 if ($paymentmethod ==
'stripe') {
1488 if (empty($paymentTypeId)) {
1489 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1491 if (empty($paymentType)) {
1492 $paymentType =
'CB';
1496 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1499 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1505 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1506 $resultvalidate =
$object->validate($user);
1507 if ($resultvalidate < 0) {
1508 $postactionmessages[] =
'Cannot validate invoice';
1509 $ispostactionok = -1;
1515 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1517 $paiement->datepaye = $now;
1518 if ($currencyCodeType == $conf->currency) {
1519 $paiement->amounts = array(
$object->id => $FinalPaymentAmt);
1521 $paiement->multicurrency_amounts = array(
$object->id => $FinalPaymentAmt);
1523 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.$conf->currency.
')';
1524 $ispostactionok = -1;
1527 $paiement->paiementid = $paymentTypeId;
1528 $paiement->num_payment =
'';
1529 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress.
' for event registration';
1532 if ($LONGTRANSACTIONID) {
1533 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1535 $paiement->ext_payment_id = $TRANSACTIONID;
1537 $paiement->ext_payment_site = $service;
1540 $paiement_id = $paiement->create($user, 1);
1541 if ($paiement_id < 0) {
1542 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1543 $ispostactionok = -1;
1546 $postactionmessages[] =
'Payment created';
1547 $ispostactionok = 1;
1553 if ($paymentmethod ==
'paybox') {
1555 } elseif ($paymentmethod ==
'paypal') {
1557 } elseif ($paymentmethod ==
'stripe') {
1563 'paymentmethod' => $paymentmethod,
1565 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1566 if ($reshook >= 0) {
1567 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1568 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1569 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1572 if ($bankaccountid > 0) {
1573 $label =
'(CustomerInvoicePayment)';
1575 $label =
'(CustomerInvoicePaymentBack)';
1577 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1579 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1580 $ispostactionok = -1;
1583 $postactionmessages[] =
'Bank transaction of payment created';
1584 $ispostactionok = 1;
1587 $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.';
1588 $ispostactionok = -1;
1597 $resultattendee = $attendeetovalidate->fetch((
int) $tmptag[
'ATT']);
1598 if ($resultattendee < 0) {
1602 $attendeetovalidate->validate($user);
1604 $attendeetovalidate->amount = $FinalPaymentAmt;
1605 $attendeetovalidate->date_subscription =
dol_now();
1606 $attendeetovalidate->update($user);
1620 $thirdparty =
new Societe($db);
1621 $resultthirdparty = $thirdparty->fetch($attendeetovalidate->fk_soc);
1622 if ($resultthirdparty < 0) {
1625 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1626 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1629 $outputlangs =
new Translate(
'', $conf);
1630 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? (
string)
$mysoc->default_lang : (string) $thirdparty->default_lang);
1632 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1634 $arraydefaultmessage =
null;
1636 $idoftemplatetouse =
getDolGlobalInt(
'EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT');
1638 if (!empty($idoftemplatetouse)) {
1639 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1642 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1643 $subject = $arraydefaultmessage->topic;
1644 $msg = $arraydefaultmessage->content;
1646 $subject =
'['.$appli.
'] '.
$object->ref.
' - '.$outputlangs->trans(
"NewRegistration");
1647 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfRegistrationWasReceived");
1650 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $thirdparty);
1656 $sendto = $attendeetovalidate->email;
1658 if ($thirdparty->email) {
1659 $cc = $thirdparty->email ??
'';
1661 if ($attendeetovalidate->email_company && $attendeetovalidate->email_company != $thirdparty->email) {
1662 $cc = ($cc ?
', ' :
'').$attendeetovalidate->email_company;
1667 $urlback = $_SERVER[
"REQUEST_URI"];
1673 $listofpaths = array();
1674 $listofnames = array();
1675 $listofmimes = array();
1676 if (is_object($object)) {
1677 $invoicediroutput = $conf->facture->dir_output;
1679 $file = $fileparams[
'fullname'];
1681 $listofpaths = array($file);
1682 $listofnames = array(basename($file));
1686 $trackid =
'inv'.$object->id;
1688 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, $listofpaths, $listofmimes, $listofnames, $cc,
'', 0, ($ishtml ? 1 : 0),
'',
'', $trackid,
'',
'standard');
1690 $result = $mailfile->sendfile();
1692 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1694 dol_syslog(
"Failed to send EMail to ".$sendto.
' - '.$mailfile->error, LOG_ERR, 0,
'_payment');
1700 $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.';
1701 $ispostactionok = -1;
1704 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1705 $ispostactionok = -1;
1707 } elseif (array_key_exists(
'BOO', $tmptag) && $tmptag[
'BOO'] > 0) {
1709 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
1710 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
1711 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1713 $result =
$object->fetch((
int) $ref);
1715 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1718 if ($paymentmethod ==
'paybox') {
1721 if ($paymentmethod ==
'paypal') {
1724 if ($paymentmethod ==
'stripe') {
1727 if (empty($paymentTypeId)) {
1728 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1730 if (empty($paymentType)) {
1731 $paymentType =
'CB';
1735 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1738 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1744 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1745 $resultvalidate =
$object->validate($user);
1746 if ($resultvalidate < 0) {
1747 $postactionmessages[] =
'Cannot validate invoice';
1748 $ispostactionok = -1;
1754 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1756 $paiement->datepaye = $now;
1757 if ($currencyCodeType == $conf->currency) {
1758 $paiement->amounts = array(
$object->id => $FinalPaymentAmt);
1760 $paiement->multicurrency_amounts = array(
$object->id => $FinalPaymentAmt);
1762 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.$conf->currency.
')';
1763 $ispostactionok = -1;
1766 $paiement->paiementid = $paymentTypeId;
1767 $paiement->num_payment =
'';
1768 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1771 if ($LONGTRANSACTIONID) {
1772 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1774 $paiement->ext_payment_id = $TRANSACTIONID;
1776 $paiement->ext_payment_site = $service;
1779 $paiement_id = $paiement->create($user, 1);
1780 if ($paiement_id < 0) {
1781 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1782 $ispostactionok = -1;
1785 $postactionmessages[] =
'Payment created';
1786 $ispostactionok = 1;
1792 if ($paymentmethod ==
'paybox') {
1794 } elseif ($paymentmethod ==
'paypal') {
1796 } elseif ($paymentmethod ==
'stripe') {
1802 'paymentmethod' => $paymentmethod,
1804 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
1805 if ($reshook >= 0) {
1806 if (isset($hookmanager->resArray[
'bankaccountid'])) {
1807 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
1808 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
1811 if ($bankaccountid > 0) {
1812 $label =
'(CustomerInvoicePayment)';
1814 $label =
'(CustomerInvoicePaymentBack)';
1816 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1818 $postactionmessages[] = $paiement->error.
' '.implode(
"<br>\n", $paiement->errors);
1819 $ispostactionok = -1;
1822 $postactionmessages[] =
'Bank transaction of payment created';
1823 $ispostactionok = 1;
1826 $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.';
1827 $ispostactionok = -1;
1834 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
1835 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
1837 $resultbooth = $booth->fetch((
int) $tmptag[
'BOO']);
1838 if ($resultbooth < 0) {
1842 $booth->status = ConferenceOrBooth::STATUS_SUGGESTED;
1843 $resultboothupdate = $booth->update($user);
1844 if ($resultboothupdate < 0) {
1847 $resultinvoice = $invoice->fetch((
int) $ref);
1848 if ($resultinvoice < 0) {
1849 $postactionmessages[] =
'Could not find the associated invoice.';
1850 $ispostactionok = -1;
1853 $thirdparty =
new Societe($db);
1854 $resultthirdparty = $thirdparty->fetch($invoice->socid);
1855 if ($resultthirdparty < 0) {
1862 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1863 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1866 $outputlangs =
new Translate(
'', $conf);
1867 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ?
$mysoc->default_lang : $thirdparty->default_lang);
1869 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1871 $arraydefaultmessage =
null;
1873 $idoftemplatetouse =
getDolGlobalInt(
'EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_BOOTH');
1875 if (!empty($idoftemplatetouse)) {
1876 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1879 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1880 $subject = $arraydefaultmessage->topic;
1881 $msg = $arraydefaultmessage->content;
1883 $subject =
'['.$appli.
'] '.$booth->ref.
' - '.$outputlangs->trans(
"NewRegistration").
']';
1884 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfBoothWasReceived");
1887 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $thirdparty);
1893 $sendto = $thirdparty->email;
1895 $urlback = $_SERVER[
"REQUEST_URI"];
1898 $trackid =
'inv'.$invoice->id;
1900 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(),
'',
'', 0, $ishtml ? 1 : 0,
'',
'', $trackid,
'',
'standard');
1902 $result = $mailfile->sendfile();
1904 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1906 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1921 $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.';
1922 $ispostactionok = -1;
1925 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1926 $ispostactionok = -1;
1928 } elseif (array_key_exists(
'CON', $tmptag) && $tmptag[
'CON'] > 0) {
1929 include_once DOL_DOCUMENT_ROOT .
'/contrat/class/contrat.class.php';
1931 $result =
$object->fetch((
int) $tmptag[
'CON']);
1933 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1936 if ($paymentmethod ==
'paybox') {
1939 if ($paymentmethod ==
'paypal') {
1942 if ($paymentmethod ==
'stripe') {
1945 if (empty($paymentTypeId)) {
1946 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1948 if (empty($paymentType)) {
1949 $paymentType =
'CB';
1953 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1956 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1961 $currencyCodeType = $_SESSION[
'currencyCodeType'];
1962 $contract_lines = (array_key_exists(
'COL', $tmptag) && $tmptag[
'COL'] > 0) ? $tmptag[
'COL'] : null;
1966 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1969 include_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
1971 $result = $invoice->createFromContract($object, $user, array((
int) $contract_lines));
1974 $invoice->validate($user);
1976 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
1978 $paiement->datepaye = $now;
1979 if ($currencyCodeType == $conf->currency) {
1980 $paiement->amounts = array($invoice->id => $FinalPaymentAmt);
1982 $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt);
1984 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.$conf->currency.
')';
1985 $ispostactionok = -1;
1988 $paiement->paiementid = $paymentTypeId;
1989 $paiement->num_payment =
'';
1990 $paiement->note_public =
'Online payment ' .
dol_print_date($now,
'standard') .
' from ' . $ipaddress;
1993 if ($LONGTRANSACTIONID) {
1994 $paiement->ext_payment_id = $LONGTRANSACTIONID;
1996 $paiement->ext_payment_id = $TRANSACTIONID;
1998 $paiement->ext_payment_site = $service;
2001 $paiement_id = $paiement->create($user, 1);
2002 if ($paiement_id < 0) {
2003 $postactionmessages[] = $paiement->error .
' ' . implode(
"<br>\n", $paiement->errors);
2004 $ispostactionok = -1;
2007 $postactionmessages[] =
'Payment created';
2008 $ispostactionok = 1;
2014 if ($paymentmethod ==
'paybox') {
2016 } elseif ($paymentmethod ==
'paypal') {
2018 } elseif ($paymentmethod ==
'stripe') {
2024 'paymentmethod' => $paymentmethod,
2026 $reshook = $hookmanager->executeHooks(
'getBankAccountPaymentMethod', $parameters, $object, $action);
2027 if ($reshook >= 0) {
2028 if (isset($hookmanager->resArray[
'bankaccountid'])) {
2029 dol_syslog(
'bankaccountid overwrite by hook return with value='.$hookmanager->resArray[
'bankaccountid'], LOG_DEBUG, 0,
'_payment');
2030 $bankaccountid = $hookmanager->resArray[
'bankaccountid'];
2033 if ($bankaccountid > 0) {
2034 $label =
'(CustomerInvoicePayment)';
2036 $label =
'(CustomerInvoicePaymentBack)';
2038 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
2040 $postactionmessages[] = $paiement->error .
' ' . implode(
"<br>\n", $paiement->errors);
2041 $ispostactionok = -1;
2044 $postactionmessages[] =
'Bank transaction of payment created';
2045 $ispostactionok = 1;
2048 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
2049 $ispostactionok = -1;
2054 $msg =
'Failed to create invoice form contract ' . $tmptag[
'CON'];
2055 if (!empty($tmptag[
'COL'])) {
2056 $msg .=
' and col '. $tmptag[
'COL'] .
'.';
2058 $postactionmessages[] = $msg;
2059 $ispostactionok = -1;
2069 $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.';
2070 $ispostactionok = -1;
2073 $postactionmessages[] =
'Invoice module is not enable';
2074 $ispostactionok = -1;
2077 $msg =
'Contract paid ' . $tmptag[
'CON'] .
' was not found';
2078 if (!empty($tmptag[
'COL'])) {
2079 $msg .=
' for col '.$tmptag[
'COL'] .
'.';
2081 $postactionmessages[] = $msg;
2082 $ispostactionok = -1;
2089dol_syslog(
"ispaymentok=".$ispaymentok.
" ispostactionok=".$ispostactionok.
" doactionsthenredirect=".$doactionsthenredirect, LOG_DEBUG, 0,
'_payment');
2093 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
2094 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
2096 $currencyCodeType = empty($_SESSION[
'currencyCodeType']) ?
'' : $_SESSION[
'currencyCodeType'];
2097 $FinalPaymentAmt = empty($_SESSION[
"FinalPaymentAmt"]) ?
'' : $_SESSION[
"FinalPaymentAmt"];
2098 $paymentType = empty($_SESSION[
'PaymentType']) ?
'' : $_SESSION[
'PaymentType'];
2100 if (is_object($object) && method_exists($object,
'call_trigger')) {
2101 '@phan-var-force CommonObject $object';
2103 $result =
$object->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
2108 } elseif (get_class($object) ==
'stdClass') {
2110 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
2112 $result = $paiement->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
2121if (empty($doactionsthenredirect)) {
2123 print $langs->trans(
"YourPaymentHasBeenRecorded").
"<br>\n";
2124 if ($TRANSACTIONID) {
2125 print $langs->trans(
"ThisIsTransactionId", $TRANSACTIONID).
"<br><br>\n";
2129 print
img_picto(
'',
'tick',
'class="green fa-2x"');
2133 $key =
'ONLINE_PAYMENT_MESSAGE_OK';
2139 print $langs->trans(
'DoExpressCheckoutPaymentAPICallFailed').
"<br>\n";
2140 if ($ErrorLongMsg) {
2141 print $langs->trans(
'DetailedErrorMessage').
": ".$ErrorLongMsg.
"<br>\n";
2143 if ($ErrorShortMsg) {
2144 print $langs->trans(
'ShortErrorMessage').
": ".$ErrorShortMsg.
"<br>\n";
2147 print $langs->trans(
'ErrorCode').
": ".$ErrorCode.
"<br>\n";
2149 if ($ErrorSeverityCode) {
2150 print $langs->trans(
'ErrorSeverityCode').
": ".$ErrorSeverityCode.
"<br>\n";
2154 print
"\nPlease, send a screenshot of this page to ".$mysoc->email.
"<br>\n";
2166 dol_syslog(
"Send email to admins if we have to (sendemail = ".$sendemail.
")", LOG_DEBUG, 0,
'_payment');
2171 $myCompanyDefaultLang = (string)
$mysoc->default_lang;
2172 if (empty($myCompanyDefaultLang) || $myCompanyDefaultLang ===
'auto') {
2178 $companylangs =
new Translate(
'', $conf);
2179 $companylangs->setDefaultLang($myCompanyDefaultLang);
2180 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox',
'stripe'));
2182 $sendto = $sendemail;
2185 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2186 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2191 $urlback = $_SERVER[
"REQUEST_URI"];
2192 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived");
2194 if (array_key_exists(
'MEM', $tmptag)) {
2195 $url = $urlwithroot.
"/adherents/subscription.php?rowid=".((int) $tmptag[
'MEM']);
2196 $content .=
'<strong>'.$companylangs->transnoentitiesnoconv(
"PaymentSubscription").
"</strong><br><br>\n";
2197 $content .= $companylangs->transnoentitiesnoconv(
"MemberId").
': <strong>'.$tmptag[
'MEM'].
"</strong><br>\n";
2198 $content .= $companylangs->transnoentitiesnoconv(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
2199 } elseif (array_key_exists(
'INV', $tmptag)) {
2200 $url = $urlwithroot.
"/compta/facture/card.php?id=".((int) $tmptag[
'INV']);
2201 $content .=
'<strong>'.$companylangs->transnoentitiesnoconv(
"Payment").
"</strong><br><br>\n";
2202 $content .= $companylangs->transnoentitiesnoconv(
"InvoiceId").
': <strong>'.$tmptag[
'INV'].
"</strong><br>\n";
2204 $content .= $companylangs->transnoentitiesnoconv(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
2206 $content .= $companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived").
"<br>\n";
2208 $content .= $companylangs->transnoentitiesnoconv(
"PostActionAfterPayment").
' : ';
2209 if ($ispostactionok > 0) {
2211 $content .=
'<span style="color: green">'.$companylangs->transnoentitiesnoconv(
"OK").
'</span>';
2212 } elseif ($ispostactionok == 0) {
2213 $content .= $companylangs->transnoentitiesnoconv(
"None");
2215 $topic .= ($ispostactionok ?
'' :
' ('.$companylangs->trans(
"WarningPostActionErrorAfterPayment").
')');
2216 $content .=
'<span class="star">'.$companylangs->transnoentitiesnoconv(
"Error").
'</span>';
2218 $content .=
'<br>'.
"\n";
2219 foreach ($postactionmessages as $postactionmessage) {
2220 $content .=
' * '.$postactionmessage.
'<br>'.
"\n";
2222 if ($ispostactionok < 0) {
2223 $content .= $langs->transnoentitiesnoconv(
"ARollbackWasPerformedOnPostActions");
2225 $content .=
'<br>'.
"\n";
2227 $content .=
"<br>\n";
2228 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
2229 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
2230 $content .= $companylangs->transnoentitiesnoconv(
"ThisIsTransactionId").
': <strong>'.$TRANSACTIONID.
"</strong><br>\n";
2231 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
2232 $content .=
"<br>\n";
2233 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
2235 if (!empty($ErrorCode)) {
2236 $content .=
"ErrorCode = ".$ErrorCode.
"<br>\n";
2238 if (!empty($ErrorShortMsg)) {
2239 $content .=
"ErrorShortMsg = ".$ErrorShortMsg.
"<br>\n";
2241 if (!empty($ErrorLongMsg)) {
2242 $content .=
"ErrorLongMsg = ".$ErrorLongMsg.
"<br>\n";
2244 if (!empty($ErrorSeverityCode)) {
2245 $content .=
"ErrorSeverityCode = ".$ErrorSeverityCode.
"<br>\n";
2248 dol_syslog(
"Content of email: ".$content, LOG_DEBUG, 0,
'_payment');
2253 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2254 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml ? 1 : 0,
'',
'', $trackid,
'',
'standard');
2256 $result = $mailfile->sendfile();
2258 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
2261 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
2269 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
2270 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
2272 $paymentType = $_SESSION[
'PaymentType'];
2273 $currencyCodeType = $_SESSION[
'currencyCodeType'];
2274 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
2276 if (is_object($object) && method_exists($object,
'call_trigger')) {
2278 $result =
$object->call_trigger(
'PAYMENTONLINE_PAYMENT_KO', $user);
2287 $companylangs =
new Translate(
'', $conf);
2288 $companylangs->setDefaultLang(
$mysoc->default_lang);
2289 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox',
'stripe'));
2291 $sendto = $sendemail;
2294 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2295 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2298 $urlback = $_SERVER[
"REQUEST_URI"];
2299 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"ValidationOfPaymentFailed");
2301 $content .=
'<span style="color: orange">'.$companylangs->transnoentitiesnoconv(
"PaymentSystemConfirmPaymentPageWasCalledButFailed").
"</span>\n";
2303 $content .=
"<br><br>\n";
2304 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
2305 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
2306 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
2307 $content .=
"<br>\n";
2308 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
2314 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2315 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml ? 1 : 0,
'',
'', $trackid,
'',
'standard');
2317 $result = $mailfile->sendfile();
2319 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
2321 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
2328unset($_SESSION[
"FinalPaymentAmt"]);
2329unset($_SESSION[
"TRANSACTIONID"]);
2333if (empty($doactionsthenredirect)) {
2336 print
"<!-- Info for payment: FinalPaymentAmt=".dol_escape_htmltag($FinalPaymentAmt).
" paymentTypeId=".
dol_escape_htmltag((
string) $paymentTypeId).
" currencyCodeType=".
dol_escape_htmltag($currencyCodeType).
" -->\n";
2341if (empty($doactionsthenredirect)) {
2352if (!empty($doactionsthenredirect)) {
2356 $_SESSION[
'paymentoksessioncode'] = $randomseckey;
2359 if (!defined(
'USEDOLIBARRSERVER') && !empty($ws_virtuelhost)) {
2360 $ext_urlok = $ws_virtuelhost .
'/paymentok.php?paymentoksessioncode='.urlencode($randomseckey).
'&fulltag='.$FULLTAG;
2362 $ext_urlok = DOL_URL_ROOT.
'/public/website/index.php?paymentoksessioncode='.urlencode($randomseckey).
'&website='.urlencode($ws).
'&pageref=paymentok&fulltag='.$FULLTAG;
2365 dol_syslog(
"Now do a redirect using a Location: ".$ext_urlok, LOG_DEBUG, 0,
'_payment');
2366 header(
"Location: ".$ext_urlok);
2371 $_SESSION[
'paymentkosessioncode'] = $randomseckey;
2374 if (!defined(
'USEDOLIBARRSERVER') && !empty($ws_virtuelhost)) {
2375 $ext_urlko = $ws_virtuelhost .
'/paymentko.php?paymentkosessioncode='.urlencode($randomseckey).
'&fulltag='.$FULLTAG;
2377 $ext_urlko = DOL_URL_ROOT.
'/public/website/index.php?paymentkosessioncode='.urlencode($randomseckey).
'&website='.urlencode($ws).
'&pageref=paymentko&fulltag='.$FULLTAG;
2380 dol_syslog(
"Now do a redirect using a Location:".$ext_urlko, LOG_DEBUG, 0,
'_payment');
2381 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.
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)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.