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);
53 require
'../../main.inc.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
55 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
56 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
59 if (!empty($conf->paypal->enabled)) {
60 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypal.lib.php';
61 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypalfunctions.lib.php';
64 $langs->loadLangs(array(
"main",
"other",
"dict",
"bills",
"companies",
"paybox",
"paypal"));
67 if (!empty($conf->paypal->enabled)) {
68 $PAYPAL_API_USER =
"";
69 if (!empty($conf->global->PAYPAL_API_USER)) {
70 $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
72 $PAYPAL_API_PASSWORD =
"";
73 if (!empty($conf->global->PAYPAL_API_PASSWORD)) {
74 $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
76 $PAYPAL_API_SIGNATURE =
"";
77 if (!empty($conf->global->PAYPAL_API_SIGNATURE)) {
78 $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
80 $PAYPAL_API_SANDBOX =
"";
81 if (!empty($conf->global->PAYPAL_API_SANDBOX)) {
82 $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
86 $PAYPAL_API_OK = $urlok;
90 $PAYPAL_API_KO = $urlko;
93 $PAYPALTOKEN =
GETPOST(
'TOKEN');
94 if (empty($PAYPALTOKEN)) {
95 $PAYPALTOKEN =
GETPOST(
'token');
97 $PAYPALPAYERID =
GETPOST(
'PAYERID');
98 if (empty($PAYPALPAYERID)) {
99 $PAYPALPAYERID =
GETPOST(
'PayerID');
104 if (empty($FULLTAG)) {
110 $suffix =
GETPOST(
"suffix",
'aZ09');
111 $membertypeid =
GETPOST(
"membertypeid",
'int');
117 if (preg_match(
'/PM=([^\.]+)/', $FULLTAG, $reg)) {
118 $paymentmethod = $reg[1];
120 if (empty($paymentmethod)) {
121 dol_print_error(
null,
'The back url does not contains a parameter fulltag that should help us to find the payment method used');
125 dol_syslog(
"***** paymentok.php is called paymentmethod=".$paymentmethod.
" FULLTAG=".$FULLTAG.
" REQUEST_URI=".$_SERVER[
"REQUEST_URI"], LOG_DEBUG, 0,
'_payment');
128 $validpaymentmethod = array();
129 if (!empty($conf->paypal->enabled)) {
130 $validpaymentmethod[
'paypal'] =
'paypal';
132 if (!empty($conf->paybox->enabled)) {
133 $validpaymentmethod[
'paybox'] =
'paybox';
135 if (!empty($conf->stripe->enabled)) {
136 $validpaymentmethod[
'stripe'] =
'stripe';
140 if (empty($validpaymentmethod)) {
145 $ispaymentok =
false;
147 $PAYMENTSTATUS = $TRANSACTIONID = $TAXAMT = $NOTE =
'';
149 $ErrorCode = $ErrorShortMsg = $ErrorLongMsg = $ErrorSeverityCode =
'';
152 $object =
new stdClass();
172 foreach ($_POST as $k => $v) {
173 $tracepost .=
"{$k} - {$v}\n";
175 dol_syslog(
"POST=".$tracepost, LOG_DEBUG, 0,
'_payment');
178 if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
179 $head =
'<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.
'?lang='.$langs->defaultlang.
'">'.
"\n";
182 $conf->dol_hide_topmenu = 1;
183 $conf->dol_hide_leftmenu = 1;
185 $replacemainarea = (empty($conf->dol_hide_leftmenu) ?
'<div>' :
'').
'<div>';
186 llxHeader($head, $langs->trans(
"PaymentForm"),
'',
'', 0, 0,
'',
'',
'',
'onlinepaymentbody', $replacemainarea);
190 print
'<span id="dolpaymentspan"></span>'.
"\n";
191 print
'<div id="dolpaymentdiv" class="center">'.
"\n";
196 $logosmall = $mysoc->logo_small;
197 $logo = $mysoc->logo;
198 $paramlogo =
'ONLINE_PAYMENT_LOGO_'.$suffix;
199 if (!empty($conf->global->$paramlogo)) {
200 $logosmall = $conf->global->$paramlogo;
201 } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
202 $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
208 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$logosmall)) {
209 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
210 $urllogofull = $dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
211 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$logo)) {
212 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
213 $urllogofull = $dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
218 print
'<div class="backgreypublicpayment">';
219 print
'<div class="logopublicpayment">';
220 print
'<img id="dolpaymentlogo" src="'.$urllogo.
'"';
223 if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
224 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>';
228 if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
229 print
'<div class="backimagepublicpayment">';
230 print
'<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.
'">';
235 print
'<br><br><br>';
238 if (!empty($conf->paypal->enabled)) {
239 if ($paymentmethod ==
'paypal') {
242 $onlinetoken = $PAYPALTOKEN;
244 $payerID = $PAYPALPAYERID;
246 $currencyCodeType = $_SESSION[
'currencyCodeType'];
247 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
248 $paymentType = $_SESSION[
'PaymentType'];
250 $ipaddress = $_SESSION[
'ipaddress'];
252 dol_syslog(
"Call paymentok with token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
255 if (!empty($paymentType)) {
256 dol_syslog(
"We call GetExpressCheckoutDetails", LOG_DEBUG, 0,
'_payment');
260 $ack = strtoupper($resArray[
"ACK"]);
261 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
263 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
265 dol_syslog(
"Call to GetExpressCheckoutDetails return error: ".json_encode($resArray), LOG_WARNING,
'_payment');
268 dol_syslog(
"We call DoExpressCheckoutPayment token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
269 $resArray2 =
confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag);
272 $ack = strtoupper($resArray2[
"ACK"]);
273 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
274 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
276 $object->source = $source;
278 $object->payerID = $payerID;
279 $object->fulltag = $fulltag;
280 $object->resArray = $resArray2;
284 $PAYMENTSTATUS = urldecode($resArray2[
"PAYMENTSTATUS"]);
285 $TRANSACTIONID = urldecode($resArray2[
"TRANSACTIONID"]);
286 $TAXAMT = urldecode($resArray2[
"TAXAMT"]);
287 $NOTE = urldecode($resArray2[
"NOTE"]);
291 dol_syslog(
"Call to DoExpressCheckoutPayment return error: ".json_encode($resArray2), LOG_WARNING, 0,
'_payment');
294 $ErrorCode = urldecode($resArray2[
"L_ERRORCODE0"]);
295 $ErrorShortMsg = urldecode($resArray2[
"L_SHORTMESSAGE0"]);
296 $ErrorLongMsg = urldecode($resArray2[
"L_LONGMESSAGE0"]);
297 $ErrorSeverityCode = urldecode($resArray2[
"L_SEVERITYCODE0"]);
300 $ErrorCode =
"SESSIONEXPIRED";
301 $ErrorLongMsg =
"Session expired. Can't retreive PaymentType. Payment has not been validated.";
302 $ErrorShortMsg =
"Session expired";
304 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
308 $ErrorCode =
"PAYPALTOKENNOTDEFINED";
309 $ErrorLongMsg =
"The parameter PAYPALTOKEN was not defined. Payment has not been validated.";
310 $ErrorShortMsg =
"Parameter PAYPALTOKEN not defined";
312 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
318 if (!empty($conf->paybox->enabled)) {
319 if ($paymentmethod ==
'paybox') {
325 if (!empty($conf->stripe->enabled)) {
326 if ($paymentmethod ==
'stripe') {
334 if (empty($ipaddress)) {
335 $ipaddress = $_SESSION[
'ipaddress'];
337 if (empty($TRANSACTIONID)) {
338 $TRANSACTIONID = $_SESSION[
'TRANSACTIONID'];
339 if (empty($TRANSACTIONID) &&
GETPOST(
'payment_intent',
'alphanohtml')) {
341 $TRANSACTIONID =
GETPOST(
'payment_intent',
'alphanohtml');
344 if (empty($FinalPaymentAmt)) {
345 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
347 if (empty($currencyCodeType)) {
348 $currencyCodeType = $_SESSION[
'currencyCodeType'];
351 if (empty($paymentType)) {
352 $paymentType = $_SESSION[
"paymentType"];
359 dol_syslog(
"ispaymentok=".$ispaymentok.
" tmptag=".var_export($tmptag,
true), LOG_DEBUG, 0,
'_payment');
364 $postactionmessages = array();
367 if (empty($user->rights->societe)) {
368 $user->rights->societe =
new stdClass();
370 if (empty($user->rights->facture)) {
371 $user->rights->facture =
new stdClass();
372 $user->rights->facture->invoice_advance =
new stdClass();
374 if (empty($user->rights->adherent)) {
375 $user->rights->adherent =
new stdClass();
376 $user->rights->adherent->cotisation =
new stdClass();
378 $user->rights->societe->creer = 1;
379 $user->rights->facture->creer = 1;
380 $user->rights->facture->invoice_advance->validate = 1;
381 $user->rights->adherent->cotisation->creer = 1;
383 if (array_key_exists(
'MEM', $tmptag) && $tmptag[
'MEM'] > 0) {
390 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
391 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent_type.class.php';
392 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
396 $result1 = $object->fetch((
int) $tmptag[
'MEM']);
397 $result2 = $adht->fetch($object->typeid);
399 $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
400 $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit :
'y';
402 dol_syslog(
"We have to process member with id=".$tmptag[
'MEM'].
" result1=".$result1.
" result2=".$result2, LOG_DEBUG, 0,
'_payment');
404 if ($result1 > 0 && $result2 > 0) {
406 if ($paymentmethod ==
'paybox') {
407 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
409 if ($paymentmethod ==
'paypal') {
410 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
412 if ($paymentmethod ==
'stripe') {
413 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
415 if (empty($paymentTypeId)) {
416 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
418 if (empty($paymentType)) {
423 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
426 if (empty($paymentTypeId) || $paymentTypeId < 0) {
431 dol_syslog(
"FinalPaymentAmt=".$FinalPaymentAmt.
" paymentTypeId=".$paymentTypeId.
" currencyCodeType=".$currencyCodeType, LOG_DEBUG, 0,
'_payment');
434 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
436 if (empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT)) {
437 if ($object->status == $object::STATUS_DRAFT) {
438 $typeid = $object->typeid;
442 $amountbytype = $adht->amountByType(1);
443 $amountexpected = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid];
445 if (empty($amountexpected) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
446 $amountexpected = $conf->global->MEMBER_NEWFORM_AMOUNT;
449 if ($amountexpected && $amountexpected != $FinalPaymentAmt) {
451 $errmsg =
'Value of FinalPayment ('.$FinalPaymentAmt.
') differs from value expected for membership ('.$amountexpected.
'). May be a hack to try to pay a different amount ?';
452 $postactionmessages[] = $errmsg;
453 $ispostactionok = -1;
454 dol_syslog(
"Failed to validate member (bad amount check): ".$errmsg, LOG_ERR, 0,
'_payment');
460 if (!empty($conf->global->MEMBER_MIN_AMOUNT)) {
461 if ($FinalPaymentAmt < $conf->global->MEMBER_MIN_AMOUNT) {
463 $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 ?';
464 $postactionmessages[] = $errmsg;
465 $ispostactionok = -1;
466 dol_syslog(
"Failed to validate member (amount lower than minimum): ".$errmsg, LOG_ERR, 0,
'_payment');
471 if ($currencyCodeType && $currencyCodeType != $conf->currency) {
473 $errmsg =
'Value of currencyCodeType ('.$currencyCodeType.
') differs from value expected for membership ('.$conf->currency.
'). May be a hack to try to pay a different amount ?';
474 $postactionmessages[] = $errmsg;
475 $ispostactionok = -1;
476 dol_syslog(
"Failed to validate member (bad currency check): ".$errmsg, LOG_ERR, 0,
'_payment');
481 $result = ($object->status == $object::STATUS_EXCLUDED) ? -1 : $object->validate($user);
482 if ($result < 0 || empty($object->datevalid)) {
484 $errmsg = $object->error;
485 $postactionmessages[] = $errmsg;
486 $postactionmessages = array_merge($postactionmessages, $object->errors);
487 $ispostactionok = -1;
488 dol_syslog(
"Failed to validate member: ".$errmsg, LOG_ERR, 0,
'_payment');
493 $datesubscription = $object->datevalid;
494 if ($object->datefin > 0) {
499 if ($datesubscription && $defaultdelay && $defaultdelayunit) {
502 while ($datesubend < $now) {
504 $datesubscription =
dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit);
510 $amount = $FinalPaymentAmt;
511 $label =
'Online subscription '.dol_print_date($now,
'standard').
' using '.$paymentmethod.
' from '.$ipaddress.
' - Transaction ID = '.$TRANSACTIONID;
515 if ($paymentmethod ==
'paybox') {
516 $accountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
518 if ($paymentmethod ==
'paypal') {
519 $accountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
521 if ($paymentmethod ==
'stripe') {
522 $accountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
524 if ($accountid < 0) {
526 $errmsg =
'Setup of bank account to use for payment is not correctly done for payment method '.$paymentmethod;
527 $postactionmessages[] = $errmsg;
528 $ispostactionok = -1;
529 dol_syslog(
"Failed to get the bank account to record payment: ".$errmsg, LOG_ERR, 0,
'_payment');
532 $operation =
dol_getIdFromCode($db, $paymentTypeId,
'c_paiement',
'id',
'code', 1);
535 $emetteur_banque =
'';
538 if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'bankviainvoice' && !empty($conf->banque->enabled) && !empty($conf->societe->enabled) &&
isModEnabled(
'facture')) {
539 $option =
'bankviainvoice';
540 } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'bankdirect' && !empty($conf->banque->enabled)) {
541 $option =
'bankdirect';
542 } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'invoiceonly' && !empty($conf->banque->enabled) && !empty($conf->societe->enabled) &&
isModEnabled(
'facture')) {
543 $option =
'invoiceonly';
545 if (empty($option)) {
555 dol_syslog(
"Call ->subscription to create subscription", LOG_DEBUG, 0,
'_payment');
557 $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $membertypeid);
560 $errmsg = $object->error;
561 $postactionmessages[] = $errmsg;
562 $ispostactionok = -1;
564 $postactionmessages[] =
'Subscription created (id='.$crowid.
')';
570 dol_syslog(
"Call ->subscriptionComplementaryActions option=".$option, LOG_DEBUG, 0,
'_payment');
572 $autocreatethirdparty = 1;
574 $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque, $autocreatethirdparty, $TRANSACTIONID, $service);
576 dol_syslog(
"Error ".$object->error.
" ".join(
',', $object->errors), LOG_DEBUG, 0,
'_payment');
579 $postactionmessages[] = $object->error;
580 $postactionmessages = array_merge($postactionmessages, $object->errors);
581 $ispostactionok = -1;
583 if ($option ==
'bankviainvoice') {
584 $postactionmessages[] =
'Invoice, payment and bank record created';
585 dol_syslog(
"Invoice, payment and bank record created", LOG_DEBUG, 0,
'_payment');
587 if ($option ==
'bankdirect') {
588 $postactionmessages[] =
'Bank record created';
589 dol_syslog(
"Bank record created", LOG_DEBUG, 0,
'_payment');
591 if ($option ==
'invoiceonly') {
592 $postactionmessages[] =
'Invoice recorded';
593 dol_syslog(
"Invoice recorded", LOG_DEBUG, 0,
'_payment');
602 if ($paymentmethod ==
'stripe' && $autocreatethirdparty && $option ==
'bankviainvoice') {
603 $thirdparty_id = $object->fk_soc;
605 dol_syslog(
"Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0,
'_payment');
607 $service =
'StripeTest';
609 if (!empty($conf->global->STRIPE_LIVE) && !
GETPOST(
'forcesandbox',
'alpha')) {
610 $service =
'StripeLive';
615 $thirdparty =
new Societe($db);
616 $thirdparty->fetch($thirdparty_id);
618 include_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
619 $stripe =
new Stripe($db);
622 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
624 if (!$customer && $TRANSACTIONID) {
625 dol_syslog(
"No stripe profile found, so we add it for TRANSACTIONID = ".$TRANSACTIONID, LOG_DEBUG, 0,
'_payment');
628 global $stripearrayofkeysbyenv;
629 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
631 if (preg_match(
'/^pi_/', $TRANSACTIONID)) {
633 $chpi = \Stripe\PaymentIntent::retrieve($TRANSACTIONID);
636 $chpi = \Stripe\Charge::retrieve($TRANSACTIONID);
640 $stripecu = $chpi->customer;
642 if (empty($stripecu)) {
644 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
647 if (preg_match(
'/^pi_/', $TRANSACTIONID) && $customer) {
648 \Stripe\PaymentIntent::update($chpi->id, array(
'customer' => $customer->id));
651 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
652 $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)";
653 $resql = $db->query($sql);
656 $errmsg =
'Failed to insert customer stripe id in database : '.$db->lasterror();
658 $postactionmessages[] = $errmsg;
659 $ispostactionok = -1;
664 $errmsg =
'Failed to retreive paymentintent or charge from id';
666 $postactionmessages[] = $errmsg;
667 $ispostactionok = -1;
671 $errmsg =
'Failed to get or save customer stripe id in database : '.$e->getMessage();
673 $postactionmessages[] = $errmsg;
674 $ispostactionok = -1;
688 dol_syslog(
"Send email to customer to ".$object->email.
" if we have to (sendalsoemail = ".$sendalsoemail.
")", LOG_DEBUG, 0,
'_payment');
691 if ($object->email && $sendalsoemail) {
696 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
700 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
702 $outputlangs->loadLangs(array(
"main",
"members"));
704 $arraydefaultmessage =
null;
705 $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
707 if (!empty($labeltouse)) {
708 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'member', $user, $outputlangs, 0, 1, $labeltouse);
711 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
712 $subject = $arraydefaultmessage->topic;
713 $msg = $arraydefaultmessage->content;
719 if (!empty($conf->global->ADHERENT_CREATE_EXTERNAL_USER_LOGIN)) {
721 $nuser =
new User($db);
724 $result = $nuser->create_from_member($tmpuser, $object->login);
725 $newpassword = $nuser->setPassword($user,
'');
728 $outputlangs->load(
"errors");
729 $postactionmessages[] =
'Error in create external user : '.$nuser->error;
731 $infouserlogin = $outputlangs->trans(
"Login").
': '.$nuser->login.
' '.
"\n".$outputlangs->trans(
"Password").
': '.$newpassword;
732 $postactionmessages[] = $langs->trans(
"NewUserCreated", $nuser->login);
734 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] = $infouserlogin;
743 $listofpaths = array();
744 $listofnames = array();
745 $listofmimes = array();
746 if (is_object($object->invoice)) {
747 $invoicediroutput = $conf->facture->dir_output;
748 $fileparams =
dol_most_recent_file($invoicediroutput.
'/'.$object->invoice->ref, preg_quote($object->invoice->ref,
'/').
'[^\-]+');
749 $file = $fileparams[
'fullname'];
751 $listofpaths = array($file);
752 $listofnames = array(basename($file));
756 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/payment/paymentok.php'.
"\r\n";
758 $result = $object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames,
"",
"", 0, -1,
"", $moreinheader);
761 $errmsg = $object->error;
762 $postactionmessages[] = $errmsg;
763 $ispostactionok = -1;
766 $postactionmessages[] =
'Email sent to member (with invoice document attached)';
768 $postactionmessages[] =
'Email sent to member (without any attached document)';
776 $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.';
777 $ispostactionok = -1;
780 $postactionmessages[] =
'Member '.$tmptag[
'MEM'].
' for subscription paid was not found';
781 $ispostactionok = -1;
783 } elseif (array_key_exists(
'INV', $tmptag) && $tmptag[
'INV'] > 0) {
785 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
787 $result = $object->fetch((
int) $tmptag[
'INV']);
789 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
792 if ($paymentmethod ==
'paybox') {
793 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
795 if ($paymentmethod ==
'paypal') {
796 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
798 if ($paymentmethod ==
'stripe') {
799 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
801 if (empty($paymentTypeId)) {
802 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
804 if (empty($paymentType)) {
809 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
812 if (empty($paymentTypeId) || $paymentTypeId < 0) {
817 dol_syslog(
"FinalPaymentAmt = ".$FinalPaymentAmt.
" paymentTypeId = ".$paymentTypeId, LOG_DEBUG, 0,
'_payment');
820 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
824 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
826 $paiement->datepaye = $now;
827 if ($currencyCodeType == $conf->currency) {
828 $paiement->amounts = array($object->id => $FinalPaymentAmt);
830 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
832 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
833 $ispostactionok = -1;
836 $paiement->paiementid = $paymentTypeId;
837 $paiement->num_payment =
'';
838 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
839 $paiement->ext_payment_id = $TRANSACTIONID;
840 $paiement->ext_payment_site = $service;
843 $paiement_id = $paiement->create($user, 1);
844 if ($paiement_id < 0) {
845 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
846 $ispostactionok = -1;
849 $postactionmessages[] =
'Payment created';
854 if (!$error && !empty($conf->banque->enabled)) {
856 if ($paymentmethod ==
'paybox') {
857 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
858 } elseif ($paymentmethod ==
'paypal') {
859 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
860 } elseif ($paymentmethod ==
'stripe') {
861 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
864 if ($bankaccountid > 0) {
865 $label =
'(CustomerInvoicePayment)';
867 $label =
'(CustomerInvoicePaymentBack)';
869 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
871 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
872 $ispostactionok = -1;
875 $postactionmessages[] =
'Bank transaction of payment created';
879 $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.';
880 $ispostactionok = -1;
891 $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.';
892 $ispostactionok = -1;
895 $postactionmessages[] =
'Invoice paid '.$tmptag[
'INV'].
' was not found';
896 $ispostactionok = -1;
898 } elseif (array_key_exists(
'ORD', $tmptag) && $tmptag[
'ORD'] > 0) {
899 include_once DOL_DOCUMENT_ROOT .
'/commande/class/commande.class.php';
901 $result = $object->fetch((
int) $tmptag[
'ORD']);
903 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
906 if ($paymentmethod ==
'paybox') {
907 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
909 if ($paymentmethod ==
'paypal') {
910 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
912 if ($paymentmethod ==
'stripe') {
913 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
915 if (empty($paymentTypeId)) {
916 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
918 if (empty($paymentType)) {
923 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
926 if (empty($paymentTypeId) || $paymentTypeId < 0) {
933 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0 ) {
934 include_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
936 $result = $invoice->createFromOrder($object, $user);
938 $object->classifyBilled($user);
939 $invoice->validate($user);
941 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
943 $paiement->datepaye = $now;
944 if ($currencyCodeType == $conf->currency) {
945 $paiement->amounts = array($invoice->id => $FinalPaymentAmt);
947 $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt);
949 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
950 $ispostactionok = -1;
953 $paiement->paiementid = $paymentTypeId;
954 $paiement->num_payment =
'';
955 $paiement->note_public =
'Online payment ' .
dol_print_date($now,
'standard') .
' from ' . $ipaddress;
956 $paiement->ext_payment_id = $TRANSACTIONID;
957 $paiement->ext_payment_site =
'';
960 $paiement_id = $paiement->create($user, 1);
961 if ($paiement_id < 0) {
962 $postactionmessages[] = $paiement->error .
' ' . join(
"<br>\n", $paiement->errors);
963 $ispostactionok = -1;
966 $postactionmessages[] =
'Payment created';
971 if (!$error && !empty($conf->banque->enabled)) {
973 if ($paymentmethod ==
'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
974 elseif ($paymentmethod ==
'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
975 elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
977 if ($bankaccountid > 0) {
978 $label =
'(CustomerInvoicePayment)';
980 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
982 $postactionmessages[] = $paiement->error .
' ' . join(
"<br>\n", $paiement->errors);
983 $ispostactionok = -1;
986 $postactionmessages[] =
'Bank transaction of payment created';
990 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
991 $ispostactionok = -1;
1002 $postactionmessages[] =
'Failed to create invoice form order ' . $tmptag[
'ORD'] .
'.';
1003 $ispostactionok = -1;
1006 $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.';
1007 $ispostactionok = -1;
1010 $postactionmessages[] =
'Invoice module is not enable';
1011 $ispostactionok = -1;
1014 $postactionmessages[] =
'Order paid ' . $tmptag[
'ORD'] .
' was not found';
1015 $ispostactionok = -1;
1017 } elseif (array_key_exists(
'DON', $tmptag) && $tmptag[
'DON'] > 0) {
1018 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
1019 $don =
new Don($db);
1020 $result = $don->fetch((
int) $tmptag[
'DON']);
1023 if ($paymentmethod ==
'paybox') {
1024 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1026 if ($paymentmethod ==
'paypal') {
1027 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1029 if ($paymentmethod ==
'stripe') {
1030 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1032 if (empty($paymentTypeId)) {
1033 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1035 if (empty($paymentType)) {
1036 $paymentType =
'CB';
1040 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1043 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1049 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1053 include_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
1056 $totalpaid = $FinalPaymentAmt;
1058 if ($currencyCodeType == $conf->currency) {
1059 $paiement->amounts = array($object->id => $totalpaid);
1062 $postactionmessages[] =
'Payment donation can\'t be payed with diffent currency than '.$conf->currency;
1063 $ispostactionok = -1;
1067 $paiement->fk_donation = $don->id;
1068 $paiement->datep = $now;
1069 $paiement->paymenttype = $paymentTypeId;
1070 $paiement->num_payment =
'';
1071 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1072 $paiement->ext_payment_id = $TRANSACTIONID;
1073 $paiement->ext_payment_site = $service;
1076 $paiement_id = $paiement->create($user, 1);
1077 if ($paiement_id < 0) {
1078 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1079 $ispostactionok = -1;
1082 $postactionmessages[] =
'Payment created';
1083 $ispostactionok = 1;
1085 if ($totalpaid >= $don->getRemainToPay()) {
1086 $don->setPaid($don->id);
1091 if (!$error && !empty($conf->banque->enabled)) {
1093 if ($paymentmethod ==
'paybox') {
1094 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1095 } elseif ($paymentmethod ==
'paypal') {
1096 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1097 } elseif ($paymentmethod ==
'stripe') {
1098 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1101 if ($bankaccountid > 0) {
1102 $result = $paiement->addPaymentToBank($user,
'payment_donation',
'(DonationPayment)', $bankaccountid,
'',
'');
1104 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1105 $ispostactionok = -1;
1108 $postactionmessages[] =
'Bank transaction of payment created';
1109 $ispostactionok = 1;
1112 $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.';
1113 $ispostactionok = -1;
1124 $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.';
1125 $ispostactionok = -1;
1128 $postactionmessages[] =
'Donation paid '.$tmptag[
'DON'].
' was not found';
1129 $ispostactionok = -1;
1134 } elseif (array_key_exists(
'ATT', $tmptag) && $tmptag[
'ATT'] > 0) {
1136 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1138 $result = $object->fetch($ref);
1141 if ($paymentmethod ==
'paybox') {
1142 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1144 if ($paymentmethod ==
'paypal') {
1145 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1147 if ($paymentmethod ==
'stripe') {
1148 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1150 if (empty($paymentTypeId)) {
1151 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1153 if (empty($paymentType)) {
1154 $paymentType =
'CB';
1158 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1161 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1167 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1168 $resultvalidate = $object->validate($user);
1169 if ($resultvalidate < 0) {
1170 $postactionmessages[] =
'Cannot validate invoice';
1171 $ispostactionok = -1;
1177 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1179 $paiement->datepaye = $now;
1180 if ($currencyCodeType == $conf->currency) {
1181 $paiement->amounts = array($object->id => $FinalPaymentAmt);
1183 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
1185 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
1186 $ispostactionok = -1;
1189 $paiement->paiementid = $paymentTypeId;
1190 $paiement->num_payment =
'';
1191 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress.
' for event registration';
1192 $paiement->ext_payment_id = $TRANSACTIONID;
1193 $paiement->ext_payment_site = $service;
1196 $paiement_id = $paiement->create($user, 1);
1197 if ($paiement_id < 0) {
1198 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1199 $ispostactionok = -1;
1202 $postactionmessages[] =
'Payment created';
1203 $ispostactionok = 1;
1207 if (!$error && !empty($conf->banque->enabled)) {
1209 if ($paymentmethod ==
'paybox') {
1210 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1211 } elseif ($paymentmethod ==
'paypal') {
1212 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1213 } elseif ($paymentmethod ==
'stripe') {
1214 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1217 if ($bankaccountid > 0) {
1218 $label =
'(CustomerInvoicePayment)';
1220 $label =
'(CustomerInvoicePaymentBack)';
1222 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1224 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1225 $ispostactionok = -1;
1228 $postactionmessages[] =
'Bank transaction of payment created';
1229 $ispostactionok = 1;
1232 $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.';
1233 $ispostactionok = -1;
1241 $resultattendee = $attendeetovalidate->fetch((
int) $tmptag[
'ATT']);
1242 if ($resultattendee < 0) {
1246 $attendeetovalidate->validate($user);
1248 $attendeetovalidate->amount = $FinalPaymentAmt;
1249 $attendeetovalidate->date_subscription =
dol_now();
1250 $attendeetovalidate->update($user);
1264 $thirdparty =
new Societe($db);
1265 $resultthirdparty = $thirdparty->fetch($attendeetovalidate->fk_soc);
1266 if ($resultthirdparty < 0) {
1269 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1270 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1273 $outputlangs =
new Translate(
'', $conf);
1274 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
1276 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1278 $arraydefaultmessage =
null;
1280 $idoftemplatetouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT;
1282 if (!empty($idoftemplatetouse)) {
1283 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1286 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1287 $subject = $arraydefaultmessage->topic;
1288 $msg = $arraydefaultmessage->content;
1290 $subject =
'['.$appli.
'] '.$object->ref.
' - '.$outputlangs->trans(
"NewRegistration").
']';
1291 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfRegistrationWasReceived");
1301 $sendto = $attendeetovalidate->email;
1302 $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM :
getDolGlobalString(
"MAIN_MAIL_EMAIL_FROM");
1303 $urlback = $_SERVER[
"REQUEST_URI"];
1309 $listofpaths = array();
1310 $listofnames = array();
1311 $listofmimes = array();
1312 if (is_object($object)) {
1313 $invoicediroutput = $conf->facture->dir_output;
1314 $fileparams =
dol_most_recent_file($invoicediroutput.
'/'.$object->ref, preg_quote($object->ref,
'/').
'[^\-]+');
1315 $file = $fileparams[
'fullname'];
1317 $listofpaths = array($file);
1318 $listofnames = array(basename($file));
1322 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, $listofpaths, $listofmimes, $listofnames,
'',
'', 0, $ishtml);
1324 $result = $mailfile->sendfile();
1326 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1328 dol_syslog(
"Failed to send EMail to ".$sendto.
' - '.$mailfile->error, LOG_ERR, 0,
'_payment');
1334 $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.';
1335 $ispostactionok = -1;
1338 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1339 $ispostactionok = -1;
1341 } elseif (array_key_exists(
'BOO', $tmptag) && $tmptag[
'BOO'] > 0) {
1343 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1345 $result = $object->fetch($ref);
1347 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1350 if ($paymentmethod ==
'paybox') {
1351 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1353 if ($paymentmethod ==
'paypal') {
1354 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1356 if ($paymentmethod ==
'stripe') {
1357 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1359 if (empty($paymentTypeId)) {
1360 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1362 if (empty($paymentType)) {
1363 $paymentType =
'CB';
1367 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1370 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1376 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1377 $resultvalidate = $object->validate($user);
1378 if ($resultvalidate < 0) {
1379 $postactionmessages[] =
'Cannot validate invoice';
1380 $ispostactionok = -1;
1386 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1388 $paiement->datepaye = $now;
1389 if ($currencyCodeType == $conf->currency) {
1390 $paiement->amounts = array($object->id => $FinalPaymentAmt);
1392 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
1394 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
1395 $ispostactionok = -1;
1398 $paiement->paiementid = $paymentTypeId;
1399 $paiement->num_payment =
'';
1400 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1401 $paiement->ext_payment_id = $TRANSACTIONID;
1402 $paiement->ext_payment_site = $service;
1405 $paiement_id = $paiement->create($user, 1);
1406 if ($paiement_id < 0) {
1407 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1408 $ispostactionok = -1;
1411 $postactionmessages[] =
'Payment created';
1412 $ispostactionok = 1;
1416 if (!$error && !empty($conf->banque->enabled)) {
1418 if ($paymentmethod ==
'paybox') {
1419 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1420 } elseif ($paymentmethod ==
'paypal') {
1421 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1422 } elseif ($paymentmethod ==
'stripe') {
1423 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1426 if ($bankaccountid > 0) {
1427 $label =
'(CustomerInvoicePayment)';
1429 $label =
'(CustomerInvoicePaymentBack)';
1431 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1433 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1434 $ispostactionok = -1;
1437 $postactionmessages[] =
'Bank transaction of payment created';
1438 $ispostactionok = 1;
1441 $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.';
1442 $ispostactionok = -1;
1450 $resultbooth = $booth->fetch((
int) $tmptag[
'BOO']);
1451 if ($resultbooth < 0) {
1455 $booth->status = CONFERENCEORBOOTH::STATUS_SUGGESTED;
1456 $resultboothupdate = $booth->update($user);
1457 if ($resultboothupdate<0) {
1460 $resultinvoice = $invoice->fetch($ref);
1461 if ($resultinvoice<0) {
1462 $postactionmessages[] =
'Could not find the associated invoice.';
1463 $ispostactionok = -1;
1466 $thirdparty =
new Societe($db);
1467 $resultthirdparty = $thirdparty->fetch($invoice->socid);
1468 if ($resultthirdparty<0) {
1473 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1474 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1477 $outputlangs =
new Translate(
'', $conf);
1478 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
1480 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1482 $arraydefaultmessage =
null;
1484 $idoftemplatetouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_BOOTH;
1486 if (!empty($idoftemplatetouse)) {
1487 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1490 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1491 $subject = $arraydefaultmessage->topic;
1492 $msg = $arraydefaultmessage->content;
1494 $subject =
'['.$appli.
'] '.$booth->ref.
' - '.$outputlangs->trans(
"NewRegistration").
']';
1495 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfBoothWasReceived");
1504 $sendto = $thirdparty->email;
1505 $from = $conf->global->MAILING_EMAIL_FROM;
1506 $urlback = $_SERVER[
"REQUEST_URI"];
1510 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(),
'',
'', 0, $ishtml);
1512 $result = $mailfile->sendfile();
1514 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1516 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1531 $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.';
1532 $ispostactionok = -1;
1535 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1536 $ispostactionok = -1;
1545 $appli = $mysoc->name;
1550 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
1551 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
1553 $currencyCodeType = $_SESSION[
'currencyCodeType'];
1554 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1555 $paymentType = $_SESSION[
'PaymentType'];
1557 if (is_object($object) && method_exists($object,
'call_trigger')) {
1559 $result = $object->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
1564 } elseif (get_class($object) ==
'stdClass') {
1566 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1568 $result = $paiement->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
1569 if ($result < 0) $error++;
1572 print $langs->trans(
"YourPaymentHasBeenRecorded").
"<br>\n";
1573 if ($TRANSACTIONID) {
1574 print $langs->trans(
"ThisIsTransactionId", $TRANSACTIONID).
"<br><br>\n";
1577 $key =
'ONLINE_PAYMENT_MESSAGE_OK';
1578 if (!empty($conf->global->$key)) {
1580 print $conf->global->$key;
1584 if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
1585 $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
1590 dol_syslog(
"Send email to admins if we have to (sendemail = ".$sendemail.
")", LOG_DEBUG, 0,
'_payment');
1594 $companylangs =
new Translate(
'', $conf);
1595 $companylangs->setDefaultLang($mysoc->default_lang);
1596 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox'));
1598 $sendto = $sendemail;
1599 $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM :
getDolGlobalString(
"MAIN_MAIL_EMAIL_FROM");
1601 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1602 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1607 $urlback = $_SERVER[
"REQUEST_URI"];
1608 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived");
1610 if (array_key_exists(
'MEM', $tmptag)) {
1611 $url = $urlwithroot.
"/adherents/subscription.php?rowid=".((int) $tmptag[
'MEM']);
1612 $content .=
'<strong>'.$companylangs->trans(
"PaymentSubscription").
"</strong><br><br>\n";
1613 $content .= $companylangs->trans(
"MemberId").
': <strong>'.$tmptag[
'MEM'].
"</strong><br>\n";
1614 $content .= $companylangs->trans(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
1615 } elseif (array_key_exists(
'INV', $tmptag)) {
1616 $url = $urlwithroot.
"/compta/facture/card.php?id=".((int) $tmptag[
'INV']);
1617 $content .=
'<strong>'.$companylangs->trans(
"Payment").
"</strong><br><br>\n";
1618 $content .= $companylangs->trans(
"InvoiceId").
': <strong>'.$tmptag[
'INV'].
"</strong><br>\n";
1620 $content .= $companylangs->trans(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
1622 $content .= $companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived").
"<br>\n";
1624 $content .= $companylangs->transnoentities(
"PostActionAfterPayment").
' : ';
1625 if ($ispostactionok > 0) {
1627 $content .=
'<span style="color: green">'.$companylangs->transnoentitiesnoconv(
"OK").
'</span>';
1628 } elseif ($ispostactionok == 0) {
1629 $content .= $companylangs->transnoentitiesnoconv(
"None");
1631 $topic .= ($ispostactionok ?
'' :
' ('.$companylangs->trans(
"WarningPostActionErrorAfterPayment").
')');
1632 $content .=
'<span style="color: red">'.$companylangs->transnoentitiesnoconv(
"Error").
'</span>';
1634 $content .=
'<br>'.
"\n";
1635 foreach ($postactionmessages as $postactionmessage) {
1636 $content .=
' * '.$postactionmessage.
'<br>'.
"\n";
1638 if ($ispostactionok < 0) {
1639 $content .= $langs->transnoentities(
"ARollbackWasPerformedOnPostActions");
1641 $content .=
'<br>'.
"\n";
1643 $content .=
"<br>\n";
1644 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
1645 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
1646 $content .= $companylangs->transnoentitiesnoconv(
"ThisIsTransactionId").
': <strong>'.$TRANSACTIONID.
"</strong><br>\n";
1647 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
1648 $content .=
"<br>\n";
1649 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
1651 if (!empty($ErrorCode)) {
1652 $content .=
"ErrorCode = ".$ErrorCode.
"<br>\n";
1654 if (!empty($ErrorShortMsg)) {
1655 $content .=
"ErrorShortMsg = ".$ErrorShortMsg.
"<br>\n";
1657 if (!empty($ErrorLongMsg)) {
1658 $content .=
"ErrorLongMsg = ".$ErrorLongMsg.
"<br>\n";
1660 if (!empty($ErrorSeverityCode)) {
1661 $content .=
"ErrorSeverityCode = ".$ErrorSeverityCode.
"<br>\n";
1667 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1668 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml);
1670 $result = $mailfile->sendfile();
1672 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1675 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1681 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
1682 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
1684 $paymentType = $_SESSION[
'PaymentType'];
1685 $currencyCodeType = $_SESSION[
'currencyCodeType'];
1686 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1688 if (is_object($object) && method_exists($object,
'call_trigger')) {
1690 $result = $object->call_trigger(
'PAYMENTONLINE_PAYMENT_KO', $user);
1697 print $langs->trans(
'DoExpressCheckoutPaymentAPICallFailed').
"<br>\n";
1698 print $langs->trans(
'DetailedErrorMessage').
": ".$ErrorLongMsg.
"<br>\n";
1699 print $langs->trans(
'ShortErrorMessage').
": ".$ErrorShortMsg.
"<br>\n";
1700 print $langs->trans(
'ErrorCode').
": ".$ErrorCode.
"<br>\n";
1701 print $langs->trans(
'ErrorSeverityCode').
": ".$ErrorSeverityCode.
"<br>\n";
1703 if ($mysoc->email) {
1704 print
"\nPlease, send a screenshot of this page to ".$mysoc->email.
"<br>\n";
1708 if (!empty($conf->global->PAYMENTONLINE_SENDEMAIL)) {
1709 $sendemail = $conf->global->PAYMENTONLINE_SENDEMAIL;
1712 if ($paymentmethod ==
'paypal' && !empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) {
1713 $sendemail = $conf->global->PAYPAL_PAYONLINE_SENDEMAIL;
1714 } elseif ($paymentmethod ==
'paybox' && !empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) {
1715 $sendemail = $conf->global->PAYBOX_PAYONLINE_SENDEMAIL;
1716 } elseif ($paymentmethod ==
'stripe' && !empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) {
1717 $sendemail = $conf->global->STRIPE_PAYONLINE_SENDEMAIL;
1722 $companylangs =
new Translate(
'', $conf);
1723 $companylangs->setDefaultLang($mysoc->default_lang);
1724 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox'));
1726 $sendto = $sendemail;
1727 $from = !empty($conf->global->MAILING_EMAIL_FROM) ? $conf->global->MAILING_EMAIL_FROM :
getDolGlobalString(
"MAIN_MAIL_EMAIL_FROM");
1729 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1730 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1733 $urlback = $_SERVER[
"REQUEST_URI"];
1734 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"ValidationOfPaymentFailed");
1736 $content .=
'<span style="color: orange">'.$companylangs->transnoentitiesnoconv(
"PaymentSystemConfirmPaymentPageWasCalledButFailed").
"</span>\n";
1738 $content .=
"<br><br>\n";
1739 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
1740 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
1741 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
1742 $content .=
"<br>\n";
1743 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
1748 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1749 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml);
1751 $result = $mailfile->sendfile();
1753 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1755 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1763 print
"<!-- Info for payment: FinalPaymentAmt=".dol_escape_htmltag($FinalPaymentAmt).
" paymentTypeId=".
dol_escape_htmltag($paymentTypeId).
" currencyCodeType=".
dol_escape_htmltag($currencyCodeType).
" -->\n";
1766 htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
1770 unset($_SESSION[
"FinalPaymentAmt"]);
1771 unset($_SESSION[
"TRANSACTIONID"]);