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';
58 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypal.lib.php';
59 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypalfunctions.lib.php';
62 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
64 $hookmanager->initHooks(array(
'newpayment'));
66 $langs->loadLangs(array(
"main",
"other",
"dict",
"bills",
"companies",
"paybox",
"paypal"));
70 $PAYPAL_API_USER =
"";
71 if (!empty($conf->global->PAYPAL_API_USER)) {
72 $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
74 $PAYPAL_API_PASSWORD =
"";
75 if (!empty($conf->global->PAYPAL_API_PASSWORD)) {
76 $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
78 $PAYPAL_API_SIGNATURE =
"";
79 if (!empty($conf->global->PAYPAL_API_SIGNATURE)) {
80 $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
82 $PAYPAL_API_SANDBOX =
"";
83 if (!empty($conf->global->PAYPAL_API_SANDBOX)) {
84 $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
88 $PAYPAL_API_OK = $urlok;
92 $PAYPAL_API_KO = $urlko;
95 $PAYPALTOKEN =
GETPOST(
'TOKEN');
96 if (empty($PAYPALTOKEN)) {
97 $PAYPALTOKEN =
GETPOST(
'token');
99 $PAYPALPAYERID =
GETPOST(
'PAYERID');
100 if (empty($PAYPALPAYERID)) {
101 $PAYPALPAYERID =
GETPOST(
'PayerID');
106 if (empty($FULLTAG)) {
112 $suffix =
GETPOST(
"suffix",
'aZ09');
113 $membertypeid =
GETPOST(
"membertypeid",
'int');
119 if (preg_match(
'/PM=([^\.]+)/', $FULLTAG, $reg)) {
120 $paymentmethod = $reg[1];
122 if (empty($paymentmethod)) {
123 dol_print_error(
null,
'The back url does not contains a parameter fulltag that should help us to find the payment method used');
127 dol_syslog(
"***** paymentok.php is called paymentmethod=".$paymentmethod.
" FULLTAG=".$FULLTAG.
" REQUEST_URI=".$_SERVER[
"REQUEST_URI"], LOG_DEBUG, 0,
'_payment');
130 $validpaymentmethod = array();
132 $validpaymentmethod[
'paypal'] =
'paypal';
135 $validpaymentmethod[
'paybox'] =
'paybox';
138 $validpaymentmethod[
'stripe'] =
'stripe';
142 if (empty($validpaymentmethod)) {
147 $ispaymentok =
false;
149 $PAYMENTSTATUS = $TRANSACTIONID = $TAXAMT = $NOTE =
'';
151 $ErrorCode = $ErrorShortMsg = $ErrorLongMsg = $ErrorSeverityCode =
'';
154 $object =
new stdClass();
171 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');
172 dol_syslog(
"_SERVER[SERVER_NAME] = ".(empty($_SERVER[
"SERVER_NAME"]) ?
'' :
dol_escape_htmltag($_SERVER[
"SERVER_NAME"])), LOG_DEBUG, 0,
'_payment');
173 dol_syslog(
"_SERVER[SERVER_ADDR] = ".(empty($_SERVER[
"SERVER_ADDR"]) ?
'' :
dol_escape_htmltag($_SERVER[
"SERVER_ADDR"])), LOG_DEBUG, 0,
'_payment');
176 foreach ($_POST as $k => $v) {
177 $tracepost .=
"{$k} - {$v}\n";
179 dol_syslog(
"POST=".$tracepost, LOG_DEBUG, 0,
'_payment');
181 foreach ($_SESSION as $k => $v) {
182 $tracesession .=
"{$k} - {$v}\n";
184 dol_syslog(
"SESSION=".$tracesession, LOG_DEBUG, 0,
'_payment');
187 if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) {
188 $head =
'<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.
'?lang='.$langs->defaultlang.
'">'.
"\n";
191 $conf->dol_hide_topmenu = 1;
192 $conf->dol_hide_leftmenu = 1;
194 $replacemainarea = (empty($conf->dol_hide_leftmenu) ?
'<div>' :
'').
'<div>';
195 llxHeader($head, $langs->trans(
"PaymentForm"),
'',
'', 0, 0,
'',
'',
'',
'onlinepaymentbody', $replacemainarea);
199 print
'<span id="dolpaymentspan"></span>'.
"\n";
200 print
'<div id="dolpaymentdiv" class="center">'.
"\n";
205 $logosmall = $mysoc->logo_small;
206 $logo = $mysoc->logo;
207 $paramlogo =
'ONLINE_PAYMENT_LOGO_'.$suffix;
208 if (!empty($conf->global->$paramlogo)) {
209 $logosmall = $conf->global->$paramlogo;
210 } elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) {
211 $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
217 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$logosmall)) {
218 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
219 $urllogofull = $dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
220 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$logo)) {
221 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
222 $urllogofull = $dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
227 print
'<div class="backgreypublicpayment">';
228 print
'<div class="logopublicpayment">';
229 print
'<img id="dolpaymentlogo" src="'.$urllogo.
'"';
232 if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
233 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>';
237 if (!empty($conf->global->MAIN_IMAGE_PUBLIC_PAYMENT)) {
238 print
'<div class="backimagepublicpayment">';
239 print
'<img id="idMAIN_IMAGE_PUBLIC_PAYMENT" src="'.$conf->global->MAIN_IMAGE_PUBLIC_PAYMENT.
'">';
244 print
'<br><br><br>';
248 if ($paymentmethod ==
'paypal') {
251 $onlinetoken = $PAYPALTOKEN;
253 $payerID = $PAYPALPAYERID;
255 $currencyCodeType = $_SESSION[
'currencyCodeType'];
256 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
257 $paymentType = $_SESSION[
'PaymentType'];
259 $ipaddress = $_SESSION[
'ipaddress'];
261 dol_syslog(
"Call paymentok with token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
264 if (!empty($paymentType)) {
265 dol_syslog(
"We call GetExpressCheckoutDetails", LOG_DEBUG, 0,
'_payment');
269 $ack = strtoupper($resArray[
"ACK"]);
270 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
272 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
274 dol_syslog(
"Call to GetExpressCheckoutDetails return error: ".json_encode($resArray), LOG_WARNING,
'_payment');
277 dol_syslog(
"We call DoExpressCheckoutPayment token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
278 $resArray2 =
confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag);
281 $ack = strtoupper($resArray2[
"ACK"]);
282 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING") {
283 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
285 $object->source = $source;
287 $object->payerID = $payerID;
288 $object->fulltag = $fulltag;
289 $object->resArray = $resArray2;
293 $PAYMENTSTATUS = urldecode($resArray2[
"PAYMENTSTATUS"]);
294 $TRANSACTIONID = urldecode($resArray2[
"TRANSACTIONID"]);
295 $TAXAMT = urldecode($resArray2[
"TAXAMT"]);
296 $NOTE = urldecode($resArray2[
"NOTE"]);
300 dol_syslog(
"Call to DoExpressCheckoutPayment return error: ".json_encode($resArray2), LOG_WARNING, 0,
'_payment');
303 $ErrorCode = urldecode($resArray2[
"L_ERRORCODE0"]);
304 $ErrorShortMsg = urldecode($resArray2[
"L_SHORTMESSAGE0"]);
305 $ErrorLongMsg = urldecode($resArray2[
"L_LONGMESSAGE0"]);
306 $ErrorSeverityCode = urldecode($resArray2[
"L_SEVERITYCODE0"]);
309 $ErrorCode =
"SESSIONEXPIRED";
310 $ErrorLongMsg =
"Session expired. Can't retreive PaymentType. Payment has not been validated.";
311 $ErrorShortMsg =
"Session expired";
313 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
317 $ErrorCode =
"PAYPALTOKENNOTDEFINED";
318 $ErrorLongMsg =
"The parameter PAYPALTOKEN was not defined. Payment has not been validated.";
319 $ErrorShortMsg =
"Parameter PAYPALTOKEN not defined";
321 dol_syslog($ErrorLongMsg, LOG_WARNING, 0,
'_payment');
328 if ($paymentmethod ==
'paybox') {
335 if ($paymentmethod ==
'stripe') {
344 'paymentmethod' => $paymentmethod,
346 $reshook = $hookmanager->executeHooks(
'isPaymentOK', $parameters, $object, $action);
348 $ispaymentok = $hookmanager->resArray[
'ispaymentok'];
353 if (empty($ipaddress)) {
354 $ipaddress = $_SESSION[
'ipaddress'];
356 if (empty($TRANSACTIONID)) {
357 $TRANSACTIONID = $_SESSION[
'TRANSACTIONID'];
358 if (empty($TRANSACTIONID) &&
GETPOST(
'payment_intent',
'alphanohtml')) {
360 $TRANSACTIONID =
GETPOST(
'payment_intent',
'alphanohtml');
363 if (empty($FinalPaymentAmt)) {
364 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
366 if (empty($currencyCodeType)) {
367 $currencyCodeType = $_SESSION[
'currencyCodeType'];
370 if (empty($paymentType)) {
371 $paymentType = $_SESSION[
"paymentType"];
378 dol_syslog(
"ispaymentok=".$ispaymentok.
" tmptag=".var_export($tmptag,
true), LOG_DEBUG, 0,
'_payment');
383 $postactionmessages = array();
386 if (empty($user->rights->societe)) {
387 $user->rights->societe =
new stdClass();
389 if (empty($user->rights->facture)) {
390 $user->rights->facture =
new stdClass();
391 $user->rights->facture->invoice_advance =
new stdClass();
393 if (empty($user->rights->adherent)) {
394 $user->rights->adherent =
new stdClass();
395 $user->rights->adherent->cotisation =
new stdClass();
397 $user->rights->societe->creer = 1;
398 $user->rights->facture->creer = 1;
399 $user->rights->facture->invoice_advance->validate = 1;
400 $user->rights->adherent->cotisation->creer = 1;
402 if (array_key_exists(
'MEM', $tmptag) && $tmptag[
'MEM'] > 0) {
409 $defaultdelayunit =
'y';
412 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
413 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent_type.class.php';
414 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
418 $result1 = $object->fetch((
int) $tmptag[
'MEM']);
419 $result2 = $adht->fetch($object->typeid);
421 dol_syslog(
"We have to process member with id=".$tmptag[
'MEM'].
" result1=".$result1.
" result2=".$result2, LOG_DEBUG, 0,
'_payment');
423 if ($result1 > 0 && $result2 > 0) {
425 if ($paymentmethod ==
'paybox') {
426 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
428 if ($paymentmethod ==
'paypal') {
429 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
431 if ($paymentmethod ==
'stripe') {
432 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
434 if (empty($paymentTypeId)) {
435 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
437 if (empty($paymentType)) {
442 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
445 if (empty($paymentTypeId) || $paymentTypeId < 0) {
450 dol_syslog(
"FinalPaymentAmt=".$FinalPaymentAmt.
" paymentTypeId=".$paymentTypeId.
" currencyCodeType=".$currencyCodeType, LOG_DEBUG, 0,
'_payment');
453 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
455 if (empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT)) {
456 if ($object->status == $object::STATUS_DRAFT) {
457 $typeid = $object->typeid;
461 $amountbytype = $adht->amountByType(1);
462 $amountexpected = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid];
464 if (empty($amountexpected) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
465 $amountexpected = $conf->global->MEMBER_NEWFORM_AMOUNT;
468 if ($amountexpected && $amountexpected != $FinalPaymentAmt) {
470 $errmsg =
'Value of FinalPayment ('.$FinalPaymentAmt.
') differs from value expected for membership ('.$amountexpected.
'). May be a hack to try to pay a different amount ?';
471 $postactionmessages[] = $errmsg;
472 $ispostactionok = -1;
473 dol_syslog(
"Failed to validate member (bad amount check): ".$errmsg, LOG_ERR, 0,
'_payment');
479 if (!empty($conf->global->MEMBER_MIN_AMOUNT)) {
480 if ($FinalPaymentAmt < $conf->global->MEMBER_MIN_AMOUNT) {
482 $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 ?';
483 $postactionmessages[] = $errmsg;
484 $ispostactionok = -1;
485 dol_syslog(
"Failed to validate member (amount lower than minimum): ".$errmsg, LOG_ERR, 0,
'_payment');
490 if ($currencyCodeType && $currencyCodeType != $conf->currency) {
492 $errmsg =
'Value of currencyCodeType ('.$currencyCodeType.
') differs from value expected for membership ('.$conf->currency.
'). May be a hack to try to pay a different amount ?';
493 $postactionmessages[] = $errmsg;
494 $ispostactionok = -1;
495 dol_syslog(
"Failed to validate member (bad currency check): ".$errmsg, LOG_ERR, 0,
'_payment');
500 $result = ($object->status == $object::STATUS_EXCLUDED) ? -1 : $object->validate($user);
501 if ($result < 0 || empty($object->datevalid)) {
503 $errmsg = $object->error;
504 $postactionmessages[] = $errmsg;
505 $postactionmessages = array_merge($postactionmessages, $object->errors);
506 $ispostactionok = -1;
507 dol_syslog(
"Failed to validate member: ".$errmsg, LOG_ERR, 0,
'_payment');
512 $datesubscription = $object->datevalid;
513 if ($object->datefin > 0) {
518 if ($datesubscription && $defaultdelay && $defaultdelayunit) {
521 while ($datesubend < $now) {
523 $datesubscription =
dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit);
530 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
532 $amount = $FinalPaymentAmt;
533 $formatteddate =
dol_print_date($paymentdate,
'dayhour',
'auto', $outputlangs);
534 $label = $langs->trans(
"OnlineSubscriptionPaymentLine", $formatteddate, $paymentmethod, $ipaddress, $TRANSACTIONID);
538 if ($paymentmethod ==
'paybox') {
539 $accountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
541 if ($paymentmethod ==
'paypal') {
542 $accountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
544 if ($paymentmethod ==
'stripe') {
545 $accountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
547 if ($accountid < 0) {
549 $errmsg =
'Setup of bank account to use for payment is not correctly done for payment method '.$paymentmethod;
550 $postactionmessages[] = $errmsg;
551 $ispostactionok = -1;
552 dol_syslog(
"Failed to get the bank account to record payment: ".$errmsg, LOG_ERR, 0,
'_payment');
555 $operation =
dol_getIdFromCode($db, $paymentTypeId,
'c_paiement',
'id',
'code', 1);
558 $emetteur_banque =
'';
561 if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'bankviainvoice' &&
isModEnabled(
"banque") &&
isModEnabled(
"societe") &&
isModEnabled(
'facture')) {
562 $option =
'bankviainvoice';
563 } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'bankdirect' &&
isModEnabled(
"banque")) {
564 $option =
'bankdirect';
565 } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'invoiceonly' &&
isModEnabled(
"banque") &&
isModEnabled(
"societe") &&
isModEnabled(
'facture')) {
566 $option =
'invoiceonly';
568 if (empty($option)) {
578 dol_syslog(
"Call ->subscription to create subscription", LOG_DEBUG, 0,
'_payment');
580 $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend, $membertypeid);
583 $errmsg = $object->error;
584 $postactionmessages[] = $errmsg;
585 $ispostactionok = -1;
587 $postactionmessages[] =
'Subscription created (id='.$crowid.
')';
593 dol_syslog(
"Call ->subscriptionComplementaryActions option=".$option, LOG_DEBUG, 0,
'_payment');
595 $autocreatethirdparty = 1;
597 $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque, $autocreatethirdparty, $TRANSACTIONID, $service);
599 dol_syslog(
"Error ".$object->error.
" ".join(
',', $object->errors), LOG_DEBUG, 0,
'_payment');
602 $postactionmessages[] = $object->error;
603 $postactionmessages = array_merge($postactionmessages, $object->errors);
604 $ispostactionok = -1;
606 if ($option ==
'bankviainvoice') {
607 $postactionmessages[] =
'Invoice, payment and bank record created';
608 dol_syslog(
"Invoice, payment and bank record created", LOG_DEBUG, 0,
'_payment');
610 if ($option ==
'bankdirect') {
611 $postactionmessages[] =
'Bank record created';
612 dol_syslog(
"Bank record created", LOG_DEBUG, 0,
'_payment');
614 if ($option ==
'invoiceonly') {
615 $postactionmessages[] =
'Invoice recorded';
616 dol_syslog(
"Invoice recorded", LOG_DEBUG, 0,
'_payment');
625 if ($paymentmethod ==
'stripe' && $autocreatethirdparty && $option ==
'bankviainvoice') {
626 $thirdparty_id = $object->fk_soc;
628 dol_syslog(
"Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0,
'_payment');
630 $service =
'StripeTest';
632 if (!empty($conf->global->STRIPE_LIVE) && !
GETPOST(
'forcesandbox',
'alpha')) {
633 $service =
'StripeLive';
638 $thirdparty =
new Societe($db);
639 $thirdparty->fetch($thirdparty_id);
641 include_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
642 $stripe =
new Stripe($db);
645 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
647 if (!$customer && $TRANSACTIONID) {
648 dol_syslog(
"No stripe profile found, so we add it for TRANSACTIONID = ".$TRANSACTIONID, LOG_DEBUG, 0,
'_payment');
651 global $stripearrayofkeysbyenv;
652 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
654 if (preg_match(
'/^pi_/', $TRANSACTIONID)) {
656 $chpi = \Stripe\PaymentIntent::retrieve($TRANSACTIONID);
659 $chpi = \Stripe\Charge::retrieve($TRANSACTIONID);
663 $stripecu = $chpi->customer;
665 if (empty($stripecu)) {
667 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
670 if (preg_match(
'/^pi_/', $TRANSACTIONID) && $customer) {
671 \Stripe\PaymentIntent::update($chpi->id, array(
'customer' => $customer->id));
674 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
675 $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)";
676 $resql = $db->query($sql);
679 $errmsg =
'Failed to insert customer stripe id in database : '.$db->lasterror();
681 $postactionmessages[] = $errmsg;
682 $ispostactionok = -1;
687 $errmsg =
'Failed to retreive paymentintent or charge from id';
689 $postactionmessages[] = $errmsg;
690 $ispostactionok = -1;
694 $errmsg =
'Failed to get or save customer stripe id in database : '.$e->getMessage();
696 $postactionmessages[] = $errmsg;
697 $ispostactionok = -1;
711 dol_syslog(
"Send email to customer to ".$object->email.
" if we have to (sendalsoemail = ".$sendalsoemail.
")", LOG_DEBUG, 0,
'_payment');
714 if ($object->email && $sendalsoemail) {
719 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
722 $outputlangs->loadLangs(array(
"main",
"members"));
724 $arraydefaultmessage =
null;
725 $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
727 if (!empty($labeltouse)) {
728 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'member', $user, $outputlangs, 0, 1, $labeltouse);
731 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
732 $subject = $arraydefaultmessage->topic;
733 $msg = $arraydefaultmessage->content;
739 if (!empty($conf->global->ADHERENT_CREATE_EXTERNAL_USER_LOGIN)) {
741 $nuser =
new User($db);
744 $result = $nuser->create_from_member($tmpuser, $object->login);
745 $newpassword = $nuser->setPassword($user,
'');
748 $outputlangs->load(
"errors");
749 $postactionmessages[] =
'Error in create external user : '.$nuser->error;
751 $infouserlogin = $outputlangs->trans(
"Login").
': '.$nuser->login.
' '.
"\n".$outputlangs->trans(
"Password").
': '.$newpassword;
752 $postactionmessages[] = $langs->trans(
"NewUserCreated", $nuser->login);
754 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] = $infouserlogin;
763 $listofpaths = array();
764 $listofnames = array();
765 $listofmimes = array();
766 if (is_object($object->invoice)) {
767 $invoicediroutput = $conf->facture->dir_output;
768 $fileparams =
dol_most_recent_file($invoicediroutput.
'/'.$object->invoice->ref, preg_quote($object->invoice->ref,
'/').
'[^\-]+');
769 $file = $fileparams[
'fullname'];
771 $listofpaths = array($file);
772 $listofnames = array(basename($file));
776 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/payment/paymentok.php'.
"\r\n";
778 $result = $object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames,
"",
"", 0, -1,
"", $moreinheader);
781 $errmsg = $object->error;
782 $postactionmessages[] = $errmsg;
783 $ispostactionok = -1;
786 $postactionmessages[] =
'Email sent to member (with invoice document attached)';
788 $postactionmessages[] =
'Email sent to member (without any attached document)';
796 $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.';
797 $ispostactionok = -1;
800 $postactionmessages[] =
'Member '.$tmptag[
'MEM'].
' for subscription paid was not found';
801 $ispostactionok = -1;
803 } elseif (array_key_exists(
'INV', $tmptag) && $tmptag[
'INV'] > 0) {
805 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
807 $result = $object->fetch((
int) $tmptag[
'INV']);
809 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
812 if ($paymentmethod ==
'paybox') {
813 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
815 if ($paymentmethod ==
'paypal') {
816 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
818 if ($paymentmethod ==
'stripe') {
819 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
821 if (empty($paymentTypeId)) {
822 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
824 if (empty($paymentType)) {
829 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
832 if (empty($paymentTypeId) || $paymentTypeId < 0) {
837 dol_syslog(
"FinalPaymentAmt = ".$FinalPaymentAmt.
" paymentTypeId = ".$paymentTypeId, LOG_DEBUG, 0,
'_payment');
840 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
844 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
846 $paiement->datepaye = $now;
847 if ($currencyCodeType == $conf->currency) {
848 $paiement->amounts = array($object->id => $FinalPaymentAmt);
850 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
852 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
853 $ispostactionok = -1;
856 $paiement->paiementid = $paymentTypeId;
857 $paiement->num_payment =
'';
858 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
859 $paiement->ext_payment_id = $TRANSACTIONID;
860 $paiement->ext_payment_site = $service;
863 $paiement_id = $paiement->create($user, 1);
864 if ($paiement_id < 0) {
865 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
866 $ispostactionok = -1;
869 $postactionmessages[] =
'Payment created';
876 if ($paymentmethod ==
'paybox') {
877 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
878 } elseif ($paymentmethod ==
'paypal') {
879 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
880 } elseif ($paymentmethod ==
'stripe') {
881 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
884 if ($bankaccountid > 0) {
885 $label =
'(CustomerInvoicePayment)';
887 $label =
'(CustomerInvoicePaymentBack)';
889 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
891 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
892 $ispostactionok = -1;
895 $postactionmessages[] =
'Bank transaction of payment created';
899 $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.';
900 $ispostactionok = -1;
911 $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.';
912 $ispostactionok = -1;
915 $postactionmessages[] =
'Invoice paid '.$tmptag[
'INV'].
' was not found';
916 $ispostactionok = -1;
918 } elseif (array_key_exists(
'ORD', $tmptag) && $tmptag[
'ORD'] > 0) {
919 include_once DOL_DOCUMENT_ROOT .
'/commande/class/commande.class.php';
921 $result = $object->fetch((
int) $tmptag[
'ORD']);
923 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
926 if ($paymentmethod ==
'paybox') {
927 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
929 if ($paymentmethod ==
'paypal') {
930 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
932 if ($paymentmethod ==
'stripe') {
933 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
935 if (empty($paymentTypeId)) {
936 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
938 if (empty($paymentType)) {
943 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
946 if (empty($paymentTypeId) || $paymentTypeId < 0) {
953 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0 ) {
954 include_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
956 $result = $invoice->createFromOrder($object, $user);
958 $object->classifyBilled($user);
959 $invoice->validate($user);
961 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
963 $paiement->datepaye = $now;
964 if ($currencyCodeType == $conf->currency) {
965 $paiement->amounts = array($invoice->id => $FinalPaymentAmt);
967 $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt);
969 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
970 $ispostactionok = -1;
973 $paiement->paiementid = $paymentTypeId;
974 $paiement->num_payment =
'';
975 $paiement->note_public =
'Online payment ' .
dol_print_date($now,
'standard') .
' from ' . $ipaddress;
976 $paiement->ext_payment_id = $TRANSACTIONID;
977 $paiement->ext_payment_site =
'';
980 $paiement_id = $paiement->create($user, 1);
981 if ($paiement_id < 0) {
982 $postactionmessages[] = $paiement->error .
' ' . join(
"<br>\n", $paiement->errors);
983 $ispostactionok = -1;
986 $postactionmessages[] =
'Payment created';
993 if ($paymentmethod ==
'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
994 elseif ($paymentmethod ==
'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
995 elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
997 if ($bankaccountid > 0) {
998 $label =
'(CustomerInvoicePayment)';
1000 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1002 $postactionmessages[] = $paiement->error .
' ' . join(
"<br>\n", $paiement->errors);
1003 $ispostactionok = -1;
1006 $postactionmessages[] =
'Bank transaction of payment created';
1007 $ispostactionok = 1;
1010 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
1011 $ispostactionok = -1;
1022 $postactionmessages[] =
'Failed to create invoice form order ' . $tmptag[
'ORD'] .
'.';
1023 $ispostactionok = -1;
1026 $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.';
1027 $ispostactionok = -1;
1030 $postactionmessages[] =
'Invoice module is not enable';
1031 $ispostactionok = -1;
1034 $postactionmessages[] =
'Order paid ' . $tmptag[
'ORD'] .
' was not found';
1035 $ispostactionok = -1;
1037 } elseif (array_key_exists(
'DON', $tmptag) && $tmptag[
'DON'] > 0) {
1038 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
1039 $don =
new Don($db);
1040 $result = $don->fetch((
int) $tmptag[
'DON']);
1043 if ($paymentmethod ==
'paybox') {
1044 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1046 if ($paymentmethod ==
'paypal') {
1047 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1049 if ($paymentmethod ==
'stripe') {
1050 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1052 if (empty($paymentTypeId)) {
1053 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1055 if (empty($paymentType)) {
1056 $paymentType =
'CB';
1060 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1063 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1069 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1073 include_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
1076 $totalpaid = $FinalPaymentAmt;
1078 if ($currencyCodeType == $conf->currency) {
1079 $paiement->amounts = array($object->id => $totalpaid);
1082 $postactionmessages[] =
'Payment donation can\'t be payed with diffent currency than '.$conf->currency;
1083 $ispostactionok = -1;
1087 $paiement->fk_donation = $don->id;
1088 $paiement->datep = $now;
1089 $paiement->paymenttype = $paymentTypeId;
1090 $paiement->num_payment =
'';
1091 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1092 $paiement->ext_payment_id = $TRANSACTIONID;
1093 $paiement->ext_payment_site = $service;
1096 $paiement_id = $paiement->create($user, 1);
1097 if ($paiement_id < 0) {
1098 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1099 $ispostactionok = -1;
1102 $postactionmessages[] =
'Payment created';
1103 $ispostactionok = 1;
1105 if ($totalpaid >= $don->getRemainToPay()) {
1106 $don->setPaid($don->id);
1113 if ($paymentmethod ==
'paybox') {
1114 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1115 } elseif ($paymentmethod ==
'paypal') {
1116 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1117 } elseif ($paymentmethod ==
'stripe') {
1118 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1121 if ($bankaccountid > 0) {
1122 $result = $paiement->addPaymentToBank($user,
'payment_donation',
'(DonationPayment)', $bankaccountid,
'',
'');
1124 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1125 $ispostactionok = -1;
1128 $postactionmessages[] =
'Bank transaction of payment created';
1129 $ispostactionok = 1;
1132 $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.';
1133 $ispostactionok = -1;
1144 $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.';
1145 $ispostactionok = -1;
1148 $postactionmessages[] =
'Donation paid '.$tmptag[
'DON'].
' was not found';
1149 $ispostactionok = -1;
1154 } elseif (array_key_exists(
'ATT', $tmptag) && $tmptag[
'ATT'] > 0) {
1156 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
1157 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
1158 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1160 $result = $object->fetch($ref);
1163 if ($paymentmethod ==
'paybox') {
1164 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1166 if ($paymentmethod ==
'paypal') {
1167 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1169 if ($paymentmethod ==
'stripe') {
1170 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1172 if (empty($paymentTypeId)) {
1173 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1175 if (empty($paymentType)) {
1176 $paymentType =
'CB';
1180 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1183 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1189 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1190 $resultvalidate = $object->validate($user);
1191 if ($resultvalidate < 0) {
1192 $postactionmessages[] =
'Cannot validate invoice';
1193 $ispostactionok = -1;
1199 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1201 $paiement->datepaye = $now;
1202 if ($currencyCodeType == $conf->currency) {
1203 $paiement->amounts = array($object->id => $FinalPaymentAmt);
1205 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
1207 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
1208 $ispostactionok = -1;
1211 $paiement->paiementid = $paymentTypeId;
1212 $paiement->num_payment =
'';
1213 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress.
' for event registration';
1214 $paiement->ext_payment_id = $TRANSACTIONID;
1215 $paiement->ext_payment_site = $service;
1218 $paiement_id = $paiement->create($user, 1);
1219 if ($paiement_id < 0) {
1220 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1221 $ispostactionok = -1;
1224 $postactionmessages[] =
'Payment created';
1225 $ispostactionok = 1;
1231 if ($paymentmethod ==
'paybox') {
1232 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1233 } elseif ($paymentmethod ==
'paypal') {
1234 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1235 } elseif ($paymentmethod ==
'stripe') {
1236 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1239 if ($bankaccountid > 0) {
1240 $label =
'(CustomerInvoicePayment)';
1242 $label =
'(CustomerInvoicePaymentBack)';
1244 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1246 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1247 $ispostactionok = -1;
1250 $postactionmessages[] =
'Bank transaction of payment created';
1251 $ispostactionok = 1;
1254 $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.';
1255 $ispostactionok = -1;
1263 $resultattendee = $attendeetovalidate->fetch((
int) $tmptag[
'ATT']);
1264 if ($resultattendee < 0) {
1268 $attendeetovalidate->validate($user);
1270 $attendeetovalidate->amount = $FinalPaymentAmt;
1271 $attendeetovalidate->date_subscription =
dol_now();
1272 $attendeetovalidate->update($user);
1286 $thirdparty =
new Societe($db);
1287 $resultthirdparty = $thirdparty->fetch($attendeetovalidate->fk_soc);
1288 if ($resultthirdparty < 0) {
1289 setEventMessages($resultthirdparty->error, $resultthirdparty->errors,
"errors");
1291 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1292 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1295 $outputlangs =
new Translate(
'', $conf);
1296 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
1298 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1300 $arraydefaultmessage =
null;
1302 $idoftemplatetouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT;
1304 if (!empty($idoftemplatetouse)) {
1305 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1308 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1309 $subject = $arraydefaultmessage->topic;
1310 $msg = $arraydefaultmessage->content;
1312 $subject =
'['.$appli.
'] '.$object->ref.
' - '.$outputlangs->trans(
"NewRegistration").
']';
1313 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfRegistrationWasReceived");
1322 $sendto = $attendeetovalidate->email;
1324 if ($thirdparty->email) {
1325 $cc = $thirdparty->email;
1327 if ($attendeetovalidate->email_company && $attendeetovalidate->email_company != $thirdparty->email) {
1328 $cc = ($cc ?
', ' :
'').$attendeetovalidate->email_company;
1330 $from = $conf->global->MAILING_EMAIL_FROM;
1331 $urlback = $_SERVER[
"REQUEST_URI"];
1337 $listofpaths = array();
1338 $listofnames = array();
1339 $listofmimes = array();
1340 if (is_object($object)) {
1341 $invoicediroutput = $conf->facture->dir_output;
1342 $fileparams =
dol_most_recent_file($invoicediroutput.
'/'.$object->ref, preg_quote($object->ref,
'/').
'[^\-]+');
1343 $file = $fileparams[
'fullname'];
1345 $listofpaths = array($file);
1346 $listofnames = array(basename($file));
1350 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, $listofpaths, $listofmimes, $listofnames, $cc,
'', 0, $ishtml);
1352 $result = $mailfile->sendfile();
1354 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1356 dol_syslog(
"Failed to send EMail to ".$sendto.
' - '.$mailfile->error, LOG_ERR, 0,
'_payment');
1362 $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.';
1363 $ispostactionok = -1;
1366 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1367 $ispostactionok = -1;
1369 } elseif (array_key_exists(
'BOO', $tmptag) && $tmptag[
'BOO'] > 0) {
1371 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
1372 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
1373 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1375 $result = $object->fetch($ref);
1377 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1380 if ($paymentmethod ==
'paybox') {
1381 $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
1383 if ($paymentmethod ==
'paypal') {
1384 $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
1386 if ($paymentmethod ==
'stripe') {
1387 $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
1389 if (empty($paymentTypeId)) {
1390 dol_syslog(
"paymentType = ".$paymentType, LOG_DEBUG, 0,
'_payment');
1392 if (empty($paymentType)) {
1393 $paymentType =
'CB';
1397 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
1400 if (empty($paymentTypeId) || $paymentTypeId < 0) {
1406 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) {
1407 $resultvalidate = $object->validate($user);
1408 if ($resultvalidate < 0) {
1409 $postactionmessages[] =
'Cannot validate invoice';
1410 $ispostactionok = -1;
1416 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1418 $paiement->datepaye = $now;
1419 if ($currencyCodeType == $conf->currency) {
1420 $paiement->amounts = array($object->id => $FinalPaymentAmt);
1422 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
1424 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
1425 $ispostactionok = -1;
1428 $paiement->paiementid = $paymentTypeId;
1429 $paiement->num_payment =
'';
1430 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
1431 $paiement->ext_payment_id = $TRANSACTIONID;
1432 $paiement->ext_payment_site = $service;
1435 $paiement_id = $paiement->create($user, 1);
1436 if ($paiement_id < 0) {
1437 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1438 $ispostactionok = -1;
1441 $postactionmessages[] =
'Payment created';
1442 $ispostactionok = 1;
1448 if ($paymentmethod ==
'paybox') {
1449 $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
1450 } elseif ($paymentmethod ==
'paypal') {
1451 $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
1452 } elseif ($paymentmethod ==
'stripe') {
1453 $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
1456 if ($bankaccountid > 0) {
1457 $label =
'(CustomerInvoicePayment)';
1459 $label =
'(CustomerInvoicePaymentBack)';
1461 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
1463 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
1464 $ispostactionok = -1;
1467 $postactionmessages[] =
'Bank transaction of payment created';
1468 $ispostactionok = 1;
1471 $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.';
1472 $ispostactionok = -1;
1479 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorboothattendee.class.php';
1480 require_once DOL_DOCUMENT_ROOT.
'/eventorganization/class/conferenceorbooth.class.php';
1482 $resultbooth = $booth->fetch((
int) $tmptag[
'BOO']);
1483 if ($resultbooth < 0) {
1487 $booth->status = CONFERENCEORBOOTH::STATUS_SUGGESTED;
1488 $resultboothupdate = $booth->update($user);
1489 if ($resultboothupdate<0) {
1492 $resultinvoice = $invoice->fetch($ref);
1493 if ($resultinvoice<0) {
1494 $postactionmessages[] =
'Could not find the associated invoice.';
1495 $ispostactionok = -1;
1498 $thirdparty =
new Societe($db);
1499 $resultthirdparty = $thirdparty->fetch($invoice->socid);
1500 if ($resultthirdparty<0) {
1505 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1506 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1509 $outputlangs =
new Translate(
'', $conf);
1510 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
1512 $outputlangs->loadLangs(array(
"main",
"members",
"eventorganization"));
1514 $arraydefaultmessage =
null;
1516 $idoftemplatetouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_BOOTH;
1518 if (!empty($idoftemplatetouse)) {
1519 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'conferenceorbooth', $user, $outputlangs, $idoftemplatetouse, 1,
'');
1522 if (!empty($idoftemplatetouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1523 $subject = $arraydefaultmessage->topic;
1524 $msg = $arraydefaultmessage->content;
1526 $subject =
'['.$appli.
'] '.$booth->ref.
' - '.$outputlangs->trans(
"NewRegistration").
']';
1527 $msg = $outputlangs->trans(
"OrganizationEventPaymentOfBoothWasReceived");
1536 $sendto = $thirdparty->email;
1537 $from = $conf->global->MAILING_EMAIL_FROM;
1538 $urlback = $_SERVER[
"REQUEST_URI"];
1542 $mailfile =
new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(),
'',
'', 0, $ishtml);
1544 $result = $mailfile->sendfile();
1546 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1548 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1563 $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.';
1564 $ispostactionok = -1;
1567 $postactionmessages[] =
'Invoice paid '.$tmptag[
'ATT'].
' was not found';
1568 $ispostactionok = -1;
1577 $appli = $mysoc->name;
1582 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
1583 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
1585 $currencyCodeType = $_SESSION[
'currencyCodeType'];
1586 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1587 $paymentType = $_SESSION[
'PaymentType'];
1589 if (is_object($object) && method_exists($object,
'call_trigger')) {
1591 $result = $object->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
1596 } elseif (get_class($object) ==
'stdClass') {
1598 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1600 $result = $paiement->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
1601 if ($result < 0) $error++;
1604 print $langs->trans(
"YourPaymentHasBeenRecorded").
"<br>\n";
1605 if ($TRANSACTIONID) {
1606 print $langs->trans(
"ThisIsTransactionId", $TRANSACTIONID).
"<br><br>\n";
1609 $key =
'ONLINE_PAYMENT_MESSAGE_OK';
1610 if (!empty($conf->global->$key)) {
1612 print $conf->global->$key;
1616 if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
1617 $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
1622 dol_syslog(
"Send email to admins if we have to (sendemail = ".$sendemail.
")", LOG_DEBUG, 0,
'_payment');
1626 $companylangs =
new Translate(
'', $conf);
1627 $companylangs->setDefaultLang($mysoc->default_lang);
1628 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox'));
1630 $sendto = $sendemail;
1631 $from = $conf->global->MAILING_EMAIL_FROM;
1633 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1634 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1639 $urlback = $_SERVER[
"REQUEST_URI"];
1640 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived");
1642 if (array_key_exists(
'MEM', $tmptag)) {
1643 $url = $urlwithroot.
"/adherents/subscription.php?rowid=".((int) $tmptag[
'MEM']);
1644 $content .=
'<strong>'.$companylangs->trans(
"PaymentSubscription").
"</strong><br><br>\n";
1645 $content .= $companylangs->trans(
"MemberId").
': <strong>'.$tmptag[
'MEM'].
"</strong><br>\n";
1646 $content .= $companylangs->trans(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
1647 } elseif (array_key_exists(
'INV', $tmptag)) {
1648 $url = $urlwithroot.
"/compta/facture/card.php?id=".((int) $tmptag[
'INV']);
1649 $content .=
'<strong>'.$companylangs->trans(
"Payment").
"</strong><br><br>\n";
1650 $content .= $companylangs->trans(
"InvoiceId").
': <strong>'.$tmptag[
'INV'].
"</strong><br>\n";
1652 $content .= $companylangs->trans(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
1654 $content .= $companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived").
"<br>\n";
1656 $content .= $companylangs->transnoentities(
"PostActionAfterPayment").
' : ';
1657 if ($ispostactionok > 0) {
1659 $content .=
'<span style="color: green">'.$companylangs->transnoentitiesnoconv(
"OK").
'</span>';
1660 } elseif ($ispostactionok == 0) {
1661 $content .= $companylangs->transnoentitiesnoconv(
"None");
1663 $topic .= ($ispostactionok ?
'' :
' ('.$companylangs->trans(
"WarningPostActionErrorAfterPayment").
')');
1664 $content .=
'<span style="color: red">'.$companylangs->transnoentitiesnoconv(
"Error").
'</span>';
1666 $content .=
'<br>'.
"\n";
1667 foreach ($postactionmessages as $postactionmessage) {
1668 $content .=
' * '.$postactionmessage.
'<br>'.
"\n";
1670 if ($ispostactionok < 0) {
1671 $content .= $langs->transnoentities(
"ARollbackWasPerformedOnPostActions");
1673 $content .=
'<br>'.
"\n";
1675 $content .=
"<br>\n";
1676 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
1677 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
1678 $content .= $companylangs->transnoentitiesnoconv(
"ThisIsTransactionId").
': <strong>'.$TRANSACTIONID.
"</strong><br>\n";
1679 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
1680 $content .=
"<br>\n";
1681 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
1683 if (!empty($ErrorCode)) {
1684 $content .=
"ErrorCode = ".$ErrorCode.
"<br>\n";
1686 if (!empty($ErrorShortMsg)) {
1687 $content .=
"ErrorShortMsg = ".$ErrorShortMsg.
"<br>\n";
1689 if (!empty($ErrorLongMsg)) {
1690 $content .=
"ErrorLongMsg = ".$ErrorLongMsg.
"<br>\n";
1692 if (!empty($ErrorSeverityCode)) {
1693 $content .=
"ErrorSeverityCode = ".$ErrorSeverityCode.
"<br>\n";
1699 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1700 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml);
1702 $result = $mailfile->sendfile();
1704 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1707 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1713 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
1714 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
1716 $paymentType = $_SESSION[
'PaymentType'];
1717 $currencyCodeType = $_SESSION[
'currencyCodeType'];
1718 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
1720 if (is_object($object) && method_exists($object,
'call_trigger')) {
1722 $result = $object->call_trigger(
'PAYMENTONLINE_PAYMENT_KO', $user);
1729 print $langs->trans(
'DoExpressCheckoutPaymentAPICallFailed').
"<br>\n";
1730 print $langs->trans(
'DetailedErrorMessage').
": ".$ErrorLongMsg.
"<br>\n";
1731 print $langs->trans(
'ShortErrorMessage').
": ".$ErrorShortMsg.
"<br>\n";
1732 print $langs->trans(
'ErrorCode').
": ".$ErrorCode.
"<br>\n";
1733 print $langs->trans(
'ErrorSeverityCode').
": ".$ErrorSeverityCode.
"<br>\n";
1735 if ($mysoc->email) {
1736 print
"\nPlease, send a screenshot of this page to ".$mysoc->email.
"<br>\n";
1740 if (!empty($conf->global->PAYMENTONLINE_SENDEMAIL)) {
1741 $sendemail = $conf->global->PAYMENTONLINE_SENDEMAIL;
1744 if ($paymentmethod ==
'paypal' && !empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) {
1745 $sendemail = $conf->global->PAYPAL_PAYONLINE_SENDEMAIL;
1746 } elseif ($paymentmethod ==
'paybox' && !empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) {
1747 $sendemail = $conf->global->PAYBOX_PAYONLINE_SENDEMAIL;
1748 } elseif ($paymentmethod ==
'stripe' && !empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) {
1749 $sendemail = $conf->global->STRIPE_PAYONLINE_SENDEMAIL;
1754 $companylangs =
new Translate(
'', $conf);
1755 $companylangs->setDefaultLang($mysoc->default_lang);
1756 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox'));
1758 $sendto = $sendemail;
1759 $from = $conf->global->MAILING_EMAIL_FROM;
1761 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1762 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1765 $urlback = $_SERVER[
"REQUEST_URI"];
1766 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"ValidationOfPaymentFailed");
1768 $content .=
'<span style="color: orange">'.$companylangs->transnoentitiesnoconv(
"PaymentSystemConfirmPaymentPageWasCalledButFailed").
"</span>\n";
1770 $content .=
"<br><br>\n";
1771 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
1772 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
1773 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
1774 $content .=
"<br>\n";
1775 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
1780 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1781 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml);
1783 $result = $mailfile->sendfile();
1785 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
1787 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
1795 print
"<!-- Info for payment: FinalPaymentAmt=".dol_escape_htmltag($FinalPaymentAmt).
" paymentTypeId=".
dol_escape_htmltag($paymentTypeId).
" currencyCodeType=".
dol_escape_htmltag($currencyCodeType).
" -->\n";
1798 htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
1802 unset($_SESSION[
"FinalPaymentAmt"]);
1803 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.
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.