32 if (!defined(
'NOLOGIN')) {
35 if (!defined(
'NOCSRFCHECK')) {
36 define(
"NOCSRFCHECK", 1);
38 if (!defined(
'NOIPCHECK')) {
39 define(
'NOIPCHECK',
'1');
41 if (!defined(
'NOBROWSERNOTIF')) {
42 define(
'NOBROWSERNOTIF',
'1');
48 $entity = (!empty($_GET[
'e']) ? (int) $_GET[
'e'] : (!empty($_POST[
'e']) ? (int) $_POST[
'e'] : 1));
49 if (is_numeric($entity)) {
50 define(
"DOLENTITY", $entity);
54 require
'../../main.inc.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
56 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
57 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
61 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypal.lib.php';
62 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypalfunctions.lib.php';
65 $langs->loadLangs(array(
"main",
"other",
"dict",
"bills",
"companies",
"paybox",
"paypal"));
69 $PAYPAL_API_USER =
"";
70 if (!empty($conf->global->PAYPAL_API_USER)) {
71 $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
73 $PAYPAL_API_PASSWORD =
"";
74 if (!empty($conf->global->PAYPAL_API_PASSWORD)) {
75 $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
77 $PAYPAL_API_SIGNATURE =
"";
78 if (!empty($conf->global->PAYPAL_API_SIGNATURE)) {
79 $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
81 $PAYPAL_API_SANDBOX =
"";
82 if (!empty($conf->global->PAYPAL_API_SANDBOX)) {
83 $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
87 $PAYPAL_API_OK = $urlok;
91 $PAYPAL_API_KO = $urlko;
94 $PAYPALTOKEN =
GETPOST(
'TOKEN');
95 if (empty($PAYPALTOKEN)) {
96 $PAYPALTOKEN =
GETPOST(
'token');
98 $PAYPALPAYERID =
GETPOST(
'PAYERID');
99 if (empty($PAYPALPAYERID)) {
100 $PAYPALPAYERID =
GETPOST(
'PayerID');
105 if (empty($FULLTAG)) {
111 $suffix =
GETPOST(
"suffix",
'aZ09');
112 $membertypeid =
GETPOST(
"membertypeid",
'int');
118 if (preg_match(
'/PM=([^\.]+)/', $FULLTAG, $reg)) {
119 $paymentmethod = $reg[1];
121 if (empty($paymentmethod)) {
122 dol_print_error(
null,
'The back url does not contains a parameter fulltag that should help us to find the payment method used');
126 dol_syslog(
"***** paymentok.php is called paymentmethod=".$paymentmethod.
" FULLTAG=".$FULLTAG.
" REQUEST_URI=".$_SERVER[
"REQUEST_URI"], LOG_DEBUG, 0,
'_payment');
129 $validpaymentmethod = array();
131 $validpaymentmethod[
'paypal'] =
'paypal';
134 $validpaymentmethod[
'paybox'] =
'paybox';
137 $validpaymentmethod[
'stripe'] =
'stripe';
141 if (empty($validpaymentmethod)) {
146 $ispaymentok =
false;
148 $PAYMENTSTATUS = $TRANSACTIONID = $TAXAMT = $NOTE =
'';
150 $ErrorCode = $ErrorShortMsg = $ErrorLongMsg = $ErrorSeverityCode =
'';
153 $object =
new stdClass();
170 dol_syslog(
"Callback url when a payment was done. 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');
171 dol_syslog(
"_SERVER[SERVER_NAME] = ".(empty($_SERVER[
"SERVER_NAME"]) ?
'' :
dol_escape_htmltag($_SERVER[
"SERVER_NAME"])), LOG_DEBUG, 0,
'_payment');
172 dol_syslog(
"_SERVER[SERVER_ADDR] = ".(empty($_SERVER[
"SERVER_ADDR"]) ?
'' :
dol_escape_htmltag($_SERVER[
"SERVER_ADDR"])), LOG_DEBUG, 0,
'_payment');
175 foreach ($_POST as $k => $v) {
176 if (is_scalar($k) && is_scalar($v)) {
177 $tracepost .=
"{$k} - {$v}\n";
180 dol_syslog(
"POST=".$tracepost, LOG_DEBUG, 0,
'_payment');
182 foreach ($_SESSION as $k => $v) {
183 if (is_scalar($k) && is_scalar($v)) {
184 $tracesession .=
"{$k} - {$v}\n";
187 dol_syslog(
"SESSION=".$tracesession, LOG_DEBUG, 0,
'_payment');
190 if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
191 $head =
'<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.
'?lang='.$langs->defaultlang.
'">'.
"\n";
194 $conf->dol_hide_topmenu = 1;
195 $conf->dol_hide_leftmenu = 1;
197 $replacemainarea = (empty($conf->dol_hide_leftmenu) ?
'<div>' :
'').
'<div>';
198 llxHeader($head, $langs->trans(
"PaymentForm"),
'',
'', 0, 0,
'',
'',
'',
'onlinepaymentbody', $replacemainarea);
202 print
'<span id="dolpaymentspan"></span>'.
"\n";
203 print
'<div id="dolpaymentdiv" class="center">'.
"\n";
208 $logosmall = $mysoc->logo_small;
209 $logo = $mysoc->logo;
210 $paramlogo =
'ONLINE_PAYMENT_LOGO_'.$suffix;
211 if (!empty($conf->global->$paramlogo)) {
212 $logosmall = $conf->global->$paramlogo;
213 } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
214 $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
220 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$logosmall)) {
221 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
222 $urllogofull = $dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
223 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$logo)) {
224 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
225 $urllogofull = $dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
230 print
'<div class="backgreypublicpayment">';
231 print
'<div class="logopublicpayment">';
232 print
'<img id="dolpaymentlogo" src="'.$urllogo.
'"';
235 if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
236 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>';
240 if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
241 print
'<div class="backimagepublicpayment">';
242 print
'<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.
'">';
247 print
'<br><br><br>';
251 if ($paymentmethod ==
'paypal') {
254 $onlinetoken = $PAYPALTOKEN;
256 $payerID = $PAYPALPAYERID;
258 $currencyCodeType = $_SESSION[
'currencyCodeType'];
259 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
260 $paymentType = $_SESSION[
'PaymentType'];
262 $ipaddress = $_SESSION[
'ipaddress'];
264 dol_syslog(
"Call paymentok with token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
267 if (!empty($paymentType)) {
268 dol_syslog(
"We call GetExpressCheckoutDetails", LOG_DEBUG, 0,
'_payment');
272 $ack = strtoupper($resArray[
"ACK"]);
273 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
275 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
277 dol_syslog(
"Call to GetExpressCheckoutDetails return error: ".json_encode($resArray), LOG_WARNING,
'_payment');
280 dol_syslog(
"We call DoExpressCheckoutPayment token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
281 $resArray2 =
confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag);
284 $ack = strtoupper($resArray2[
"ACK"]);
285 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
286 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
288 $object->source = $source;
290 $object->payerID = $payerID;
291 $object->fulltag = $fulltag;
292 $object->resArray = $resArray2;
296 $PAYMENTSTATUS = urldecode($resArray2[
"PAYMENTSTATUS"]);
297 $TRANSACTIONID = urldecode($resArray2[
"TRANSACTIONID"]);
298 $TAXAMT = urldecode($resArray2[
"TAXAMT"]);
299 $NOTE = urldecode($resArray2[
"NOTE"]);
303 dol_syslog(
"Call to DoExpressCheckoutPayment return error: ".json_encode($resArray2), LOG_WARNING, 0,
'_payment');
306 $ErrorCode = urldecode($resArray2[
"L_ERRORCODE0"]);
307 $ErrorShortMsg = urldecode($resArray2[
"L_SHORTMESSAGE0"]);
308 $ErrorLongMsg = urldecode($resArray2[
"L_LONGMESSAGE0"]);
309 $ErrorSeverityCode = urldecode($resArray2[
"L_SEVERITYCODE0"]);
312 $ErrorCode =
"SESSIONEXPIRED";
313 $ErrorLongMsg =
"Session expired. Can't retreive PaymentType. Payment has not been validated.";
314 $ErrorShortMsg =
"Session expired";
316 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
320 $ErrorCode =
"PAYPALTOKENNOTDEFINED";
321 $ErrorLongMsg =
"The parameter PAYPALTOKEN was not defined. Payment has not been validated.";
322 $ErrorShortMsg =
"Parameter PAYPALTOKEN not defined";
324 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
331 if ($paymentmethod ==
'paybox') {
338 if ($paymentmethod ==
'stripe') {
346 if (empty($ipaddress)) {
347 $ipaddress = $_SESSION[
'ipaddress'];
349 if (empty($TRANSACTIONID)) {
350 $TRANSACTIONID = $_SESSION[
'TRANSACTIONID'];
351 if (empty($TRANSACTIONID) &&
GETPOST(
'payment_intent',
'alphanohtml')) {
353 $TRANSACTIONID =
GETPOST(
'payment_intent',
'alphanohtml');
356 if (empty($FinalPaymentAmt)) {
357 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
359 if (empty($currencyCodeType)) {
360 $currencyCodeType = $_SESSION[
'currencyCodeType'];
363 if (empty($paymentType)) {
364 $paymentType = $_SESSION[
"paymentType"];
371 dol_syslog(
"ispaymentok=".$ispaymentok.
" tmptag=".var_export($tmptag,
true), LOG_DEBUG, 0,
'_payment');
376 $postactionmessages = array();
379 if (empty($user->rights->societe)) {
380 $user->rights->societe =
new stdClass();
382 if (empty($user->rights->facture)) {
383 $user->rights->facture =
new stdClass();
384 $user->rights->facture->invoice_advance =
new stdClass();
386 if (empty($user->rights->adherent)) {
387 $user->rights->adherent =
new stdClass();
388 $user->rights->adherent->cotisation =
new stdClass();
390 $user->rights->societe->creer = 1;
391 $user->rights->facture->creer = 1;
392 $user->rights->facture->invoice_advance->validate = 1;
393 $user->rights->adherent->cotisation->creer = 1;
395 if (array_key_exists(
'MEM', $tmptag) && $tmptag[
'MEM'] > 0) {
402 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
403 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent_type.class.php';
404 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
408 $result1 = $object->fetch((
int) $tmptag[
'MEM']);
409 $result2 = $adht->fetch($object->typeid);
411 $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
412 $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit :
'y';
414 dol_syslog(
"We have to process member with id=".$tmptag[
'MEM'].
" result1=".$result1.
" result2=".$result2, LOG_DEBUG, 0,
'_payment');
416 if ($result1 > 0 && $result2 > 0) {
418 if ($paymentmethod ==
'paybox') {
419 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
421 if ($paymentmethod ==
'paypal') {
422 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
424 if ($paymentmethod ==
'stripe') {
425 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
427 if (empty($paymentTypeId)) {
428 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
430 if (empty($paymentType)) {
435 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
438 if (empty($paymentTypeId) || $paymentTypeId < 0) {
443 dol_syslog(
"FinalPaymentAmt=".$FinalPaymentAmt.
" paymentTypeId=".$paymentTypeId.
" currencyCodeType=".$currencyCodeType, LOG_DEBUG, 0,
'_payment');
446 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
448 if (empty($adht->caneditamount)) {
449 if ($object->status == $object::STATUS_DRAFT) {
450 $typeid = $object->typeid;
454 $amountbytype = $adht->amountByType(1);
455 $amountexpected = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid];
457 if (empty($amountexpected) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
458 $amountexpected = $conf->global->MEMBER_NEWFORM_AMOUNT;
461 if ($amountexpected && $amountexpected != $FinalPaymentAmt) {
463 $errmsg =
'Value of FinalPayment ('.$FinalPaymentAmt.
') differs from value expected for membership ('.$amountexpected.
'). May be a hack to try to pay a different amount ?';
464 $postactionmessages[] = $errmsg;
465 $ispostactionok = -1;
466 dol_syslog(
"Failed to validate member (bad amount check): ".$errmsg, LOG_ERR, 0,
'_payment');
472 if (!empty($conf->global->MEMBER_MIN_AMOUNT)) {
473 if ($FinalPaymentAmt < $conf->global->MEMBER_MIN_AMOUNT) {
475 $errmsg =
'Value of FinalPayment ('.$FinalPaymentAmt.
') is lower than the minimum allowed ('.$conf->global->MEMBER_MIN_AMOUNT.
'). May be a hack to try to pay a different amount ?';
476 $postactionmessages[] = $errmsg;
477 $ispostactionok = -1;
478 dol_syslog(
"Failed to validate member (amount lower than minimum): ".$errmsg, LOG_ERR, 0,
'_payment');
483 if ($currencyCodeType && $currencyCodeType != $conf->currency) {
485 $errmsg =
'Value of currencyCodeType ('.$currencyCodeType.
') differs from value expected for membership ('.$conf->currency.
'). May be a hack to try to pay a different amount ?';
486 $postactionmessages[] = $errmsg;
487 $ispostactionok = -1;
488 dol_syslog(
"Failed to validate member (bad currency check): ".$errmsg, LOG_ERR, 0,
'_payment');
493 $result = ($object->status == $object::STATUS_EXCLUDED) ? -1 : $object->validate($user);
494 if ($result < 0 || empty($object->datevalid)) {
496 $errmsg = $object->error;
497 $postactionmessages[] = $errmsg;
498 $postactionmessages = array_merge($postactionmessages, $object->errors);
499 $ispostactionok = -1;
500 dol_syslog(
"Failed to validate member: ".$errmsg, LOG_ERR, 0,
'_payment');
505 $datesubscription = $object->datevalid;
506 if ($object->datefin > 0) {
511 if ($datesubscription && $defaultdelay && $defaultdelayunit) {
514 while ($datesubend < $now) {
516 $datesubscription =
dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit);
523 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
525 $amount = $FinalPaymentAmt;
526 $formatteddate =
dol_print_date($paymentdate,
'dayhour',
'auto', $outputlangs);
527 $label = $langs->trans(
"OnlineSubscriptionPaymentLine", $formatteddate, $paymentmethod, $ipaddress, $TRANSACTIONID);
531 if ($paymentmethod ==
'paybox') {
532 $accountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
534 if ($paymentmethod ==
'paypal') {
535 $accountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
537 if ($paymentmethod ==
'stripe') {
538 $accountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
540 if ($accountid < 0) {
542 $errmsg =
'Setup of bank account to use for payment is not correctly done for payment method '.$paymentmethod;
543 $postactionmessages[] = $errmsg;
544 $ispostactionok = -1;
545 dol_syslog(
"Failed to get the bank account to record payment: ".$errmsg, LOG_ERR, 0,
'_payment');
548 $operation =
dol_getIdFromCode($db, $paymentTypeId,
'c_paiement',
'id',
'code', 1);
551 $emetteur_banque =
'';
554 if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'bankviainvoice' &&
isModEnabled(
"banque") &&
isModEnabled(
"societe") &&
isModEnabled(
'facture')) {
555 $option =
'bankviainvoice';
556 } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'bankdirect' &&
isModEnabled(
"banque")) {
557 $option =
'bankdirect';
558 } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'invoiceonly' &&
isModEnabled(
"banque") &&
isModEnabled(
"societe") &&
isModEnabled(
'facture')) {
559 $option =
'invoiceonly';
561 if (empty($option)) {
571 dol_syslog(
"Call ->subscription to create subscription", LOG_DEBUG, 0,
'_payment');
573 $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $membertypeid);
576 $errmsg = $object->error;
577 $postactionmessages[] = $errmsg;
578 $ispostactionok = -1;
580 $postactionmessages[] =
'Subscription created (id='.$crowid.
')';
586 dol_syslog(
"Call ->subscriptionComplementaryActions option=".$option, LOG_DEBUG, 0,
'_payment');
588 $autocreatethirdparty = 1;
590 $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque, $autocreatethirdparty, $TRANSACTIONID, $service);
592 dol_syslog(
"Error ".$object->error.
" ".join(
',', $object->errors), LOG_DEBUG, 0,
'_payment');
595 $postactionmessages[] = $object->error;
596 $postactionmessages = array_merge($postactionmessages, $object->errors);
597 $ispostactionok = -1;
599 if ($option ==
'bankviainvoice') {
600 $postactionmessages[] =
'Invoice, payment and bank record created';
601 dol_syslog(
"Invoice, payment and bank record created", LOG_DEBUG, 0,
'_payment');
603 if ($option ==
'bankdirect') {
604 $postactionmessages[] =
'Bank record created';
605 dol_syslog(
"Bank record created", LOG_DEBUG, 0,
'_payment');
607 if ($option ==
'invoiceonly') {
608 $postactionmessages[] =
'Invoice recorded';
609 dol_syslog(
"Invoice recorded", LOG_DEBUG, 0,
'_payment');
618 if ($paymentmethod ==
'stripe' && $autocreatethirdparty && $option ==
'bankviainvoice') {
619 $thirdparty_id = $object->fk_soc;
621 dol_syslog(
"Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0,
'_payment');
623 $service =
'StripeTest';
625 if (!empty($conf->global->STRIPE_LIVE) && !
GETPOST(
'forcesandbox',
'alpha')) {
626 $service =
'StripeLive';
631 $thirdparty =
new Societe($db);
632 $thirdparty->fetch($thirdparty_id);
634 include_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
635 $stripe =
new Stripe($db);
638 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
640 if (!$customer && $TRANSACTIONID) {
641 dol_syslog(
"No stripe profile found, so we add it for TRANSACTIONID = ".$TRANSACTIONID, LOG_DEBUG, 0,
'_payment');
644 global $stripearrayofkeysbyenv;
645 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
647 if (preg_match(
'/^pi_/', $TRANSACTIONID)) {
649 $chpi = \Stripe\PaymentIntent::retrieve($TRANSACTIONID);
652 $chpi = \Stripe\Charge::retrieve($TRANSACTIONID);
656 $stripecu = $chpi->customer;
658 if (empty($stripecu)) {
660 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
663 if (preg_match(
'/^pi_/', $TRANSACTIONID) && $customer) {
664 \Stripe\PaymentIntent::update($chpi->id, array(
'customer' => $customer->id));
667 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
668 $sql .=
" VALUES (".((int) $object->fk_soc).
", '', '".$db->escape($stripecu).
"', 'stripe', '".$db->escape($stripearrayofkeysbyenv[$servicestatus][
'publishable_key']).
"', ".((int) $servicestatus).
", ".((int) $conf->entity).
", '".$db->idate(
dol_now()).
"', 0)";
669 $resql = $db->query($sql);
672 $errmsg =
'Failed to insert customer stripe id in database : '.$db->lasterror();
674 $postactionmessages[] = $errmsg;
675 $ispostactionok = -1;
680 $errmsg =
'Failed to retreive paymentintent or charge from id';
682 $postactionmessages[] = $errmsg;
683 $ispostactionok = -1;
687 $errmsg =
'Failed to get or save customer stripe id in database : '.$e->getMessage();
689 $postactionmessages[] = $errmsg;
690 $ispostactionok = -1;
704 dol_syslog(
"Send email to customer to ".$object->email.
" if we have to (sendalsoemail = ".$sendalsoemail.
")", LOG_DEBUG, 0,
'_payment');
707 if ($object->email && $sendalsoemail) {
712 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
715 $outputlangs->loadLangs(array(
"main",
"members"));
717 $arraydefaultmessage =
null;
718 $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
720 if (!empty($labeltouse)) {
721 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'member', $user, $outputlangs, 0, 1, $labeltouse);
724 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
725 $subject = $arraydefaultmessage->topic;
726 $msg = $arraydefaultmessage->content;
732 if (!empty($conf->global->ADHERENT_CREATE_EXTERNAL_USER_LOGIN)) {
734 $nuser =
new User($db);
737 $result = $nuser->create_from_member($tmpuser, $object->login);
738 $newpassword = $nuser->setPassword($user,
'');
741 $outputlangs->load(
"errors");
742 $postactionmessages[] =
'Error in create external user : '.$nuser->error;
744 $infouserlogin = $outputlangs->trans(
"Login").
': '.$nuser->login.
' '.
"\n".$outputlangs->trans(
"Password").
': '.$newpassword;
745 $postactionmessages[] = $langs->trans(
"NewUserCreated", $nuser->login);
747 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] = $infouserlogin;
756 $listofpaths = array();
757 $listofnames = array();
758 $listofmimes = array();
759 if (is_object($object->invoice)) {
760 $invoicediroutput = $conf->facture->dir_output;
761 $fileparams =
dol_most_recent_file($invoicediroutput.
'/'.$object->invoice->ref, preg_quote($object->invoice->ref,
'/').
'[^\-]+');
762 $file = $fileparams[
'fullname'];
764 $listofpaths = array($file);
765 $listofnames = array(basename($file));
769 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/payment/paymentok.php'.
"\r\n";
771 $result = $object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames,
"",
"", 0, -1,
"", $moreinheader);
774 $errmsg = $object->error;
775 $postactionmessages[] = $errmsg;
776 $ispostactionok = -1;
779 $postactionmessages[] =
'Email sent to member (with invoice document attached)';
781 $postactionmessages[] =
'Email sent to member (without any attached document)';
789 $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.';
790 $ispostactionok = -1;
793 $postactionmessages[] =
'Member '.$tmptag[
'MEM'].
' for subscription paid was not found';
794 $ispostactionok = -1;
796 } elseif (array_key_exists(
'INV', $tmptag) && $tmptag[
'INV'] > 0) {
798 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
800 $result = $object->fetch((
int) $tmptag[
'INV']);
802 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
805 if ($paymentmethod ==
'paybox') {
806 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
808 if ($paymentmethod ==
'paypal') {
809 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
811 if ($paymentmethod ==
'stripe') {
812 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
814 if (empty($paymentTypeId)) {
815 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
817 if (empty($paymentType)) {
822 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
825 if (empty($paymentTypeId) || $paymentTypeId < 0) {
830 dol_syslog(
"FinalPaymentAmt = ".$FinalPaymentAmt.
" paymentTypeId = ".$paymentTypeId, LOG_DEBUG, 0,
'_payment');
833 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
837 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
839 $paiement->datepaye = $now;
840 if ($currencyCodeType == $conf->currency) {
841 $paiement->amounts = array($object->id => $FinalPaymentAmt);
843 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
845 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
846 $ispostactionok = -1;
849 $paiement->paiementid = $paymentTypeId;
850 $paiement->num_payment =
'';
851 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
852 $paiement->ext_payment_id = $TRANSACTIONID;
853 $paiement->ext_payment_site = $service;
856 $paiement_id = $paiement->create($user, 1);
857 if ($paiement_id < 0) {
858 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
859 $ispostactionok = -1;
862 $postactionmessages[] =
'Payment created';
869 if ($paymentmethod ==
'paybox') {
870 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
871 } elseif ($paymentmethod ==
'paypal') {
872 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
873 } elseif ($paymentmethod ==
'stripe') {
874 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
877 if ($bankaccountid > 0) {
878 $label =
'(CustomerInvoicePayment)';
880 $label =
'(CustomerInvoicePaymentBack)';
882 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
884 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
885 $ispostactionok = -1;
888 $postactionmessages[] =
'Bank transaction of payment created';
892 $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.';
893 $ispostactionok = -1;
904 $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.';
905 $ispostactionok = -1;
908 $postactionmessages[] =
'Invoice paid '.$tmptag[
'INV'].
' was not found';
909 $ispostactionok = -1;
911 } elseif (array_key_exists(
'ORD', $tmptag) && $tmptag[
'ORD'] > 0) {
912 include_once DOL_DOCUMENT_ROOT .
'/commande/class/commande.class.php';
914 $result = $object->fetch((
int) $tmptag[
'ORD']);
916 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
919 if ($paymentmethod ==
'paybox') {
920 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
922 if ($paymentmethod ==
'paypal') {
923 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
925 if ($paymentmethod ==
'stripe') {
926 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
928 if (empty($paymentTypeId)) {
929 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
931 if (empty($paymentType)) {
936 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
939 if (empty($paymentTypeId) || $paymentTypeId < 0) {
946 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0 ) {
947 include_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
949 $result = $invoice->createFromOrder($object, $user);
951 $object->classifyBilled($user);
952 $invoice->validate($user);
954 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
956 $paiement->datepaye = $now;
957 if ($currencyCodeType == $conf->currency) {
958 $paiement->amounts = array($invoice->id => $FinalPaymentAmt);
960 $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt);
962 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
963 $ispostactionok = -1;
966 $paiement->paiementid = $paymentTypeId;
967 $paiement->num_payment =
'';
968 $paiement->note_public =
'Online payment ' .
dol_print_date($now,
'standard') .
' from ' . $ipaddress;
969 $paiement->ext_payment_id = $TRANSACTIONID;
970 $paiement->ext_payment_site =
'';
973 $paiement_id = $paiement->create($user, 1);
974 if ($paiement_id < 0) {
975 $postactionmessages[] = $paiement->error .
' ' . join(
"<br>\n", $paiement->errors);
976 $ispostactionok = -1;
979 $postactionmessages[] =
'Payment created';
986 if ($paymentmethod ==
'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
987 elseif ($paymentmethod ==
'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
988 elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
990 if ($bankaccountid > 0) {
991 $label =
'(CustomerInvoicePayment)';
993 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
995 $postactionmessages[] = $paiement->error .
' ' . join(
"<br>\n", $paiement->errors);
996 $ispostactionok = -1;
999 $postactionmessages[] =
'Bank transaction of payment created';
1000 $ispostactionok = 1;
1003 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
1004 $ispostactionok = -1;
1015 $postactionmessages[] =
'Failed to create invoice form order ' . $tmptag[
'ORD'] .
'.';
1016 $ispostactionok = -1;
1019 $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.';
1020 $ispostactionok = -1;
1023 $postactionmessages[] =
'Invoice module is not enable';
1024 $ispostactionok = -1;
1027 $postactionmessages[] =
'Order paid ' . $tmptag[
'ORD'] .
' was not found';
1028 $ispostactionok = -1;
1030 } elseif (array_key_exists(
'DON', $tmptag) && $tmptag[
'DON'] > 0) {
1031 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
1032 $don =
new Don($db);
1033 $result = $don->fetch((
int) $tmptag[
'DON']);
1036 if ($paymentmethod ==
'paybox') {
1037 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1039 if ($paymentmethod ==
'paypal') {
1040 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1042 if ($paymentmethod ==
'stripe') {
1043 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1045 if (empty($paymentTypeId)) {
1046 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1048 if (empty($paymentType)) {
1049 $paymentType =
'CB';
1053 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1056 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1062 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1066 include_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
1069 $totalpaid = $FinalPaymentAmt;
1071 if ($currencyCodeType == $conf->currency) {
1072 $paiement->amounts = array($object->id => $totalpaid);
1075 $postactionmessages[] =
'Payment donation can\'t be payed with diffent currency than '.$conf->currency;
1076 $ispostactionok = -1;
1080 $paiement->fk_donation = $don->id;
1081 $paiement->datep = $now;
1082 $paiement->paymenttype = $paymentTypeId;
1083 $paiement->num_payment =
'';
1084 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1085 $paiement->ext_payment_id = $TRANSACTIONID;
1086 $paiement->ext_payment_site = $service;
1089 $paiement_id = $paiement->create($user, 1);
1090 if ($paiement_id < 0) {
1091 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1092 $ispostactionok = -1;
1095 $postactionmessages[] =
'Payment created';
1096 $ispostactionok = 1;
1098 if ($totalpaid >= $don->getRemainToPay()) {
1099 $don->setPaid($don->id);
1106 if ($paymentmethod ==
'paybox') {
1107 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1108 } elseif ($paymentmethod ==
'paypal') {
1109 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1110 } elseif ($paymentmethod ==
'stripe') {
1111 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1114 if ($bankaccountid > 0) {
1115 $result = $paiement->addPaymentToBank($user,
'payment_donation',
'(DonationPayment)', $bankaccountid,
'',
'');
1117 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1118 $ispostactionok = -1;
1121 $postactionmessages[] =
'Bank transaction of payment created';
1122 $ispostactionok = 1;
1125 $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.';
1126 $ispostactionok = -1;
1137 $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.';
1138 $ispostactionok = -1;
1141 $postactionmessages[] =
'Donation paid '.$tmptag[
'DON'].
' was not found';
1142 $ispostactionok = -1;
1147 } elseif (array_key_exists(
'ATT', $tmptag) && $tmptag[
'ATT'] > 0) {
1149 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1151 $result = $object->fetch($ref);
1154 if ($paymentmethod ==
'paybox') {
1155 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1157 if ($paymentmethod ==
'paypal') {
1158 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1160 if ($paymentmethod ==
'stripe') {
1161 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1163 if (empty($paymentTypeId)) {
1164 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1166 if (empty($paymentType)) {
1167 $paymentType =
'CB';
1171 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1174 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1180 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1181 $resultvalidate = $object->validate($user);
1182 if ($resultvalidate < 0) {
1183 $postactionmessages[] =
'Cannot validate invoice';
1184 $ispostactionok = -1;
1190 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1192 $paiement->datepaye = $now;
1193 if ($currencyCodeType == $conf->currency) {
1194 $paiement->amounts = array($object->id => $FinalPaymentAmt);
1196 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
1198 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
1199 $ispostactionok = -1;
1202 $paiement->paiementid = $paymentTypeId;
1203 $paiement->num_payment =
'';
1204 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress.
' for event registration';
1205 $paiement->ext_payment_id = $TRANSACTIONID;
1206 $paiement->ext_payment_site = $service;
1209 $paiement_id = $paiement->create($user, 1);
1210 if ($paiement_id < 0) {
1211 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1212 $ispostactionok = -1;
1215 $postactionmessages[] =
'Payment created';
1216 $ispostactionok = 1;
1222 if ($paymentmethod ==
'paybox') {
1223 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1224 } elseif ($paymentmethod ==
'paypal') {
1225 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1226 } elseif ($paymentmethod ==
'stripe') {
1227 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1230 if ($bankaccountid > 0) {
1231 $label =
'(CustomerInvoicePayment)';
1233 $label =
'(CustomerInvoicePaymentBack)';
1235 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1237 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1238 $ispostactionok = -1;
1241 $postactionmessages[] =
'Bank transaction of payment created';
1242 $ispostactionok = 1;
1245 $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.';
1246 $ispostactionok = -1;
1254 $resultattendee = $attendeetovalidate->fetch((
int) $tmptag[
'ATT']);
1255 if ($resultattendee < 0) {
1259 $attendeetovalidate->validate($user);
1261 $attendeetovalidate->amount = $FinalPaymentAmt;
1262 $attendeetovalidate->date_subscription =
dol_now();
1263 $attendeetovalidate->update($user);
1277 $thirdparty =
new Societe($db);
1278 $resultthirdparty = $thirdparty->fetch($attendeetovalidate->fk_soc);
1279 if ($resultthirdparty < 0) {
1280 setEventMessages($resultthirdparty->error, $resultthirdparty->errors,
"errors");
1282 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1283 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1286 $outputlangs =
new Translate(
'', $conf);
1287 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
1289 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1291 $arraydefaultmessage =
null;
1293 $idoftemplatetouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT;
1295 if (!empty($idoftemplatetouse)) {
1296 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1299 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1300 $subject = $arraydefaultmessage->topic;
1301 $msg = $arraydefaultmessage->content;
1303 $subject =
'['.$appli.
'] '.$object->ref.
' - '.$outputlangs->trans(
"NewRegistration").
']';
1304 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfRegistrationWasReceived");
1313 $sendto = $attendeetovalidate->email;
1315 if ($thirdparty->email) {
1316 $cc = $thirdparty->email;
1318 if ($attendeetovalidate->email_company && $attendeetovalidate->email_company != $thirdparty->email) {
1319 $cc = ($cc ?
', ' :
'').$attendeetovalidate->email_company;
1322 $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM :
getDolGlobalString(
"MAIN_MAIL_EMAIL_FROM");
1324 $urlback = $_SERVER[
"REQUEST_URI"];
1330 $listofpaths = array();
1331 $listofnames = array();
1332 $listofmimes = array();
1333 if (is_object($object)) {
1334 $invoicediroutput = $conf->facture->dir_output;
1335 $fileparams =
dol_most_recent_file($invoicediroutput.
'/'.$object->ref, preg_quote($object->ref,
'/').
'[^\-]+');
1336 $file = $fileparams[
'fullname'];
1338 $listofpaths = array($file);
1339 $listofnames = array(basename($file));
1343 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, $listofpaths, $listofmimes, $listofnames, $cc,
'', 0, $ishtml);
1345 $result = $mailfile->sendfile();
1347 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1349 dol_syslog(
"Failed to send EMail to ".$sendto.
' - '.$mailfile->error, LOG_ERR, 0,
'_payment');
1355 $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.';
1356 $ispostactionok = -1;
1359 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1360 $ispostactionok = -1;
1362 } elseif (array_key_exists(
'BOO', $tmptag) && $tmptag[
'BOO'] > 0) {
1364 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1366 $result = $object->fetch($ref);
1368 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1371 if ($paymentmethod ==
'paybox') {
1372 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1374 if ($paymentmethod ==
'paypal') {
1375 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1377 if ($paymentmethod ==
'stripe') {
1378 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1380 if (empty($paymentTypeId)) {
1381 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1383 if (empty($paymentType)) {
1384 $paymentType =
'CB';
1388 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1391 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1397 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1398 $resultvalidate = $object->validate($user);
1399 if ($resultvalidate < 0) {
1400 $postactionmessages[] =
'Cannot validate invoice';
1401 $ispostactionok = -1;
1407 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1409 $paiement->datepaye = $now;
1410 if ($currencyCodeType == $conf->currency) {
1411 $paiement->amounts = array($object->id => $FinalPaymentAmt);
1413 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
1415 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
1416 $ispostactionok = -1;
1419 $paiement->paiementid = $paymentTypeId;
1420 $paiement->num_payment =
'';
1421 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1422 $paiement->ext_payment_id = $TRANSACTIONID;
1423 $paiement->ext_payment_site = $service;
1426 $paiement_id = $paiement->create($user, 1);
1427 if ($paiement_id < 0) {
1428 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1429 $ispostactionok = -1;
1432 $postactionmessages[] =
'Payment created';
1433 $ispostactionok = 1;
1439 if ($paymentmethod ==
'paybox') {
1440 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1441 } elseif ($paymentmethod ==
'paypal') {
1442 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1443 } elseif ($paymentmethod ==
'stripe') {
1444 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1447 if ($bankaccountid > 0) {
1448 $label =
'(CustomerInvoicePayment)';
1450 $label =
'(CustomerInvoicePaymentBack)';
1452 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1454 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1455 $ispostactionok = -1;
1458 $postactionmessages[] =
'Bank transaction of payment created';
1459 $ispostactionok = 1;
1462 $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.';
1463 $ispostactionok = -1;
1471 $resultbooth = $booth->fetch((
int) $tmptag[
'BOO']);
1472 if ($resultbooth < 0) {
1476 $booth->status = CONFERENCEORBOOTH::STATUS_SUGGESTED;
1477 $resultboothupdate = $booth->update($user);
1478 if ($resultboothupdate<0) {
1481 $resultinvoice = $invoice->fetch($ref);
1482 if ($resultinvoice<0) {
1483 $postactionmessages[] =
'Could not find the associated invoice.';
1484 $ispostactionok = -1;
1487 $thirdparty =
new Societe($db);
1488 $resultthirdparty = $thirdparty->fetch($invoice->socid);
1489 if ($resultthirdparty<0) {
1494 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1495 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1498 $outputlangs =
new Translate(
'', $conf);
1499 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
1501 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1503 $arraydefaultmessage =
null;
1505 $idoftemplatetouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_BOOTH;
1507 if (!empty($idoftemplatetouse)) {
1508 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1511 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1512 $subject = $arraydefaultmessage->topic;
1513 $msg = $arraydefaultmessage->content;
1515 $subject =
'['.$appli.
'] '.$booth->ref.
' - '.$outputlangs->trans(
"NewRegistration").
']';
1516 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfBoothWasReceived");
1525 $sendto = $thirdparty->email;
1526 $from = $conf->global->MAILING_EMAIL_FROM;
1527 $urlback = $_SERVER[
"REQUEST_URI"];
1531 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(),
'',
'', 0, $ishtml);
1533 $result = $mailfile->sendfile();
1535 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1537 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1552 $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.';
1553 $ispostactionok = -1;
1556 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1557 $ispostactionok = -1;
1566 $appli = $mysoc->name;
1571 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
1572 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
1574 $currencyCodeType = $_SESSION[
'currencyCodeType'];
1575 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1576 $paymentType = $_SESSION[
'PaymentType'];
1578 if (is_object($object) && method_exists($object,
'call_trigger')) {
1580 $result = $object->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
1585 } elseif (get_class($object) ==
'stdClass') {
1587 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1589 $result = $paiement->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
1590 if ($result < 0) $error++;
1593 print $langs->trans(
"YourPaymentHasBeenRecorded").
"<br>\n";
1594 if ($TRANSACTIONID) {
1595 print $langs->trans(
"ThisIsTransactionId", $TRANSACTIONID).
"<br><br>\n";
1598 $key =
'ONLINE_PAYMENT_MESSAGE_OK';
1599 if (!empty($conf->global->$key)) {
1601 print $conf->global->$key;
1605 if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
1606 $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
1611 dol_syslog(
"Send email to admins if we have to (sendemail = ".$sendemail.
")", LOG_DEBUG, 0,
'_payment');
1615 $companylangs =
new Translate(
'', $conf);
1616 $companylangs->setDefaultLang($mysoc->default_lang);
1617 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox'));
1619 $sendto = $sendemail;
1620 $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM :
getDolGlobalString(
"MAIN_MAIL_EMAIL_FROM");
1622 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1623 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1628 $urlback = $_SERVER[
"REQUEST_URI"];
1629 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived");
1631 if (array_key_exists(
'MEM', $tmptag)) {
1632 $url = $urlwithroot.
"/adherents/subscription.php?rowid=".((int) $tmptag[
'MEM']);
1633 $content .=
'<strong>'.$companylangs->trans(
"PaymentSubscription").
"</strong><br><br>\n";
1634 $content .= $companylangs->trans(
"MemberId").
': <strong>'.$tmptag[
'MEM'].
"</strong><br>\n";
1635 $content .= $companylangs->trans(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
1636 } elseif (array_key_exists(
'INV', $tmptag)) {
1637 $url = $urlwithroot.
"/compta/facture/card.php?id=".((int) $tmptag[
'INV']);
1638 $content .=
'<strong>'.$companylangs->trans(
"Payment").
"</strong><br><br>\n";
1639 $content .= $companylangs->trans(
"InvoiceId").
': <strong>'.$tmptag[
'INV'].
"</strong><br>\n";
1641 $content .= $companylangs->trans(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
1643 $content .= $companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived").
"<br>\n";
1645 $content .= $companylangs->transnoentities(
"PostActionAfterPayment").
' : ';
1646 if ($ispostactionok > 0) {
1648 $content .=
'<span style="color: green">'.$companylangs->transnoentitiesnoconv(
"OK").
'</span>';
1649 } elseif ($ispostactionok == 0) {
1650 $content .= $companylangs->transnoentitiesnoconv(
"None");
1652 $topic .= ($ispostactionok ?
'' :
' ('.$companylangs->trans(
"WarningPostActionErrorAfterPayment").
')');
1653 $content .=
'<span style="color: red">'.$companylangs->transnoentitiesnoconv(
"Error").
'</span>';
1655 $content .=
'<br>'.
"\n";
1656 foreach ($postactionmessages as $postactionmessage) {
1657 $content .=
' * '.$postactionmessage.
'<br>'.
"\n";
1659 if ($ispostactionok < 0) {
1660 $content .= $langs->transnoentities(
"ARollbackWasPerformedOnPostActions");
1662 $content .=
'<br>'.
"\n";
1664 $content .=
"<br>\n";
1665 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
1666 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
1667 $content .= $companylangs->transnoentitiesnoconv(
"ThisIsTransactionId").
': <strong>'.$TRANSACTIONID.
"</strong><br>\n";
1668 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
1669 $content .=
"<br>\n";
1670 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
1672 if (!empty($ErrorCode)) {
1673 $content .=
"ErrorCode = ".$ErrorCode.
"<br>\n";
1675 if (!empty($ErrorShortMsg)) {
1676 $content .=
"ErrorShortMsg = ".$ErrorShortMsg.
"<br>\n";
1678 if (!empty($ErrorLongMsg)) {
1679 $content .=
"ErrorLongMsg = ".$ErrorLongMsg.
"<br>\n";
1681 if (!empty($ErrorSeverityCode)) {
1682 $content .=
"ErrorSeverityCode = ".$ErrorSeverityCode.
"<br>\n";
1688 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1689 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml);
1691 $result = $mailfile->sendfile();
1693 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1696 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1702 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
1703 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
1705 $paymentType = $_SESSION[
'PaymentType'];
1706 $currencyCodeType = $_SESSION[
'currencyCodeType'];
1707 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1709 if (is_object($object) && method_exists($object,
'call_trigger')) {
1711 $result = $object->call_trigger(
'PAYMENTONLINE_PAYMENT_KO', $user);
1718 print $langs->trans(
'DoExpressCheckoutPaymentAPICallFailed').
"<br>\n";
1719 print $langs->trans(
'DetailedErrorMessage').
": ".$ErrorLongMsg.
"<br>\n";
1720 print $langs->trans(
'ShortErrorMessage').
": ".$ErrorShortMsg.
"<br>\n";
1721 print $langs->trans(
'ErrorCode').
": ".$ErrorCode.
"<br>\n";
1722 print $langs->trans(
'ErrorSeverityCode').
": ".$ErrorSeverityCode.
"<br>\n";
1724 if ($mysoc->email) {
1725 print
"\nPlease, send a screenshot of this page to ".$mysoc->email.
"<br>\n";
1729 if (!empty($conf->global->PAYMENTONLINE_SENDEMAIL)) {
1730 $sendemail = $conf->global->PAYMENTONLINE_SENDEMAIL;
1733 if ($paymentmethod ==
'paypal' && !empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) {
1734 $sendemail = $conf->global->PAYPAL_PAYONLINE_SENDEMAIL;
1735 } elseif ($paymentmethod ==
'paybox' && !empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) {
1736 $sendemail = $conf->global->PAYBOX_PAYONLINE_SENDEMAIL;
1737 } elseif ($paymentmethod ==
'stripe' && !empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) {
1738 $sendemail = $conf->global->STRIPE_PAYONLINE_SENDEMAIL;
1743 $companylangs =
new Translate(
'', $conf);
1744 $companylangs->setDefaultLang($mysoc->default_lang);
1745 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox'));
1747 $sendto = $sendemail;
1748 $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM :
getDolGlobalString(
"MAIN_MAIL_EMAIL_FROM");
1750 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1751 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1754 $urlback = $_SERVER[
"REQUEST_URI"];
1755 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"ValidationOfPaymentFailed");
1757 $content .=
'<span style="color: orange">'.$companylangs->transnoentitiesnoconv(
"PaymentSystemConfirmPaymentPageWasCalledButFailed").
"</span>\n";
1759 $content .=
"<br><br>\n";
1760 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
1761 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
1762 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
1763 $content .=
"<br>\n";
1764 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
1769 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1770 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml);
1772 $result = $mailfile->sendfile();
1774 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1776 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1784 print
"<!-- Info for payment: FinalPaymentAmt=".dol_escape_htmltag($FinalPaymentAmt).
" paymentTypeId=".
dol_escape_htmltag($paymentTypeId).
" currencyCodeType=".
dol_escape_htmltag($currencyCodeType).
" -->\n";
1787 htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
1791 unset($_SESSION[
"FinalPaymentAmt"]);
1792 unset($_SESSION[
"TRANSACTIONID"]);
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
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 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...)
Class to manage translations.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=false, $mode='')
Return file(s) into a directory (by default most recent)
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
Validate payment.
getDetails($token)
Prepares the parameters for the GetExpressCheckoutDetails API Call.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.