28 if (!defined(
'NOLOGIN')) define(
"NOLOGIN", 1);
29 if (!defined(
'NOCSRFCHECK')) define(
"NOCSRFCHECK", 1);
30 if (!defined(
'NOIPCHECK')) define(
'NOIPCHECK',
'1');
31 if (!defined(
'NOBROWSERNOTIF')) define(
'NOBROWSERNOTIF',
'1');
36 $entity = (!empty($_GET[
'e']) ? (int) $_GET[
'e'] : (!empty($_POST[
'e']) ? (int) $_POST[
'e'] : 1));
37 if (is_numeric($entity)) define(
"DOLENTITY", $entity);
39 require
'../../main.inc.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
43 if (!empty($conf->paypal->enabled))
45 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypal.lib.php';
46 require_once DOL_DOCUMENT_ROOT.
'/paypal/lib/paypalfunctions.lib.php';
49 $langs->loadLangs(array(
"main",
"other",
"dict",
"bills",
"companies",
"paybox",
"paypal"));
52 if (!empty($conf->paypal->enabled))
54 $PAYPAL_API_USER =
"";
55 if (!empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER = $conf->global->PAYPAL_API_USER;
56 $PAYPAL_API_PASSWORD =
"";
57 if (!empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD = $conf->global->PAYPAL_API_PASSWORD;
58 $PAYPAL_API_SIGNATURE =
"";
59 if (!empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE = $conf->global->PAYPAL_API_SIGNATURE;
60 $PAYPAL_API_SANDBOX =
"";
61 if (!empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX = $conf->global->PAYPAL_API_SANDBOX;
63 if ($urlok) $PAYPAL_API_OK = $urlok;
65 if ($urlko) $PAYPAL_API_KO = $urlko;
67 $PAYPALTOKEN =
GETPOST(
'TOKEN');
68 if (empty($PAYPALTOKEN)) $PAYPALTOKEN =
GETPOST(
'token');
69 $PAYPALPAYERID =
GETPOST(
'PAYERID');
70 if (empty($PAYPALPAYERID)) $PAYPALPAYERID =
GETPOST(
'PayerID');
74 if (empty($FULLTAG)) $FULLTAG =
GETPOST(
'fulltag');
78 $suffix =
GETPOST(
"suffix",
'aZ09');
84 if (preg_match(
'/PM=([^\.]+)/', $FULLTAG, $reg))
86 $paymentmethod = $reg[1];
88 if (empty($paymentmethod))
90 dol_print_error(null,
'The back url does not contains a parameter fulltag that should help us to find the payment method used');
94 dol_syslog(
"***** paymentok.php is called paymentmethod=".$paymentmethod.
" FULLTAG=".$FULLTAG.
" REQUEST_URI=".
$_SERVER[
"REQUEST_URI"], LOG_DEBUG, 0,
'_payment');
97 $validpaymentmethod = array();
98 if (!empty($conf->paypal->enabled)) $validpaymentmethod[
'paypal'] =
'paypal';
99 if (!empty($conf->paybox->enabled)) $validpaymentmethod[
'paybox'] =
'paybox';
100 if (!empty($conf->stripe->enabled)) $validpaymentmethod[
'stripe'] =
'stripe';
106 $ispaymentok =
false;
108 $PAYMENTSTATUS = $TRANSACTIONID = $TAXAMT = $NOTE =
'';
110 $ErrorCode = $ErrorShortMsg = $ErrorLongMsg = $ErrorSeverityCode =
'';
113 $object =
new stdClass();
133 foreach ($_POST as $k => $v) $tracepost .=
"{$k} - {$v}\n";
134 dol_syslog(
"POST=".$tracepost, LOG_DEBUG, 0,
'_payment');
137 if (!empty($conf->global->ONLINE_PAYMENT_CSS_URL)) $head =
'<link rel="stylesheet" type="text/css" href="'.$conf->global->ONLINE_PAYMENT_CSS_URL.
'?lang='.$langs->defaultlang.
'">'.
"\n";
139 $conf->dol_hide_topmenu = 1;
140 $conf->dol_hide_leftmenu = 1;
142 $replacemainarea = (empty($conf->dol_hide_leftmenu) ?
'<div>' :
'').
'<div>';
143 llxHeader($head, $langs->trans(
"PaymentForm"),
'',
'', 0, 0,
'',
'',
'',
'onlinepaymentbody', $replacemainarea);
147 print '<span id="dolpaymentspan"></span>'.
"\n";
148 print '<div id="dolpaymentdiv" class="center">'.
"\n";
153 $logosmall = $mysoc->logo_small;
154 $logo = $mysoc->logo;
155 $paramlogo =
'ONLINE_PAYMENT_LOGO_'.$suffix;
156 if (!empty($conf->global->$paramlogo)) $logosmall = $conf->global->$paramlogo;
157 elseif (!empty($conf->global->ONLINE_PAYMENT_LOGO)) $logosmall = $conf->global->ONLINE_PAYMENT_LOGO;
162 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.
'/logos/thumbs/'.$logosmall))
164 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
165 $urllogofull = $dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/thumbs/'.$logosmall);
166 } elseif (!empty($logo) && is_readable($conf->mycompany->dir_output.
'/logos/'.$logo))
168 $urllogo = DOL_URL_ROOT.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
169 $urllogofull = $dolibarr_main_url_root.
'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.
'&file='.urlencode(
'logos/'.$logo);
175 print '<div class="backgreypublicpayment">';
176 print '<div class="logopublicpayment">';
177 print '<img id="dolpaymentlogo" src="'.$urllogo.
'"';
180 if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
181 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>';
187 print '<br><br><br>';
190 if (!empty($conf->paypal->enabled))
192 if ($paymentmethod ==
'paypal')
197 $onlinetoken = $PAYPALTOKEN;
199 $payerID = $PAYPALPAYERID;
201 $paymentType = $_SESSION[
'PaymentType'];
202 $currencyCodeType = $_SESSION[
'currencyCodeType'];
203 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
205 $ipaddress = $_SESSION[
'ipaddress'];
207 dol_syslog(
"Call paymentok with token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
210 if (!empty($paymentType))
212 dol_syslog(
"We call GetExpressCheckoutDetails", LOG_DEBUG, 0,
'_payment');
216 $ack = strtoupper($resArray[
"ACK"]);
217 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING")
220 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
222 dol_syslog(
"Call to GetExpressCheckoutDetails return error: ".json_encode($resArray), LOG_WARNING,
'_payment');
225 dol_syslog(
"We call DoExpressCheckoutPayment token=".$onlinetoken.
" paymentType=".$paymentType.
" currencyCodeType=".$currencyCodeType.
" payerID=".$payerID.
" ipaddress=".$ipaddress.
" FinalPaymentAmt=".$FinalPaymentAmt.
" fulltag=".$fulltag, LOG_DEBUG, 0,
'_payment');
226 $resArray2 =
confirmPayment($onlinetoken, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag);
229 $ack = strtoupper($resArray2[
"ACK"]);
230 if ($ack ==
"SUCCESS" || $ack ==
"SUCCESSWITHWARNING")
232 dol_syslog(
"Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0,
'_payment');
234 $object->source = $source;
236 $object->payerID = $payerID;
237 $object->fulltag = $fulltag;
238 $object->resArray = $resArray2;
242 $PAYMENTSTATUS = urldecode($resArray2[
"PAYMENTSTATUS"]);
243 $TRANSACTIONID = urldecode($resArray2[
"TRANSACTIONID"]);
244 $TAXAMT = urldecode($resArray2[
"TAXAMT"]);
245 $NOTE = urldecode($resArray2[
"NOTE"]);
249 dol_syslog(
"Call to DoExpressCheckoutPayment return error: ".json_encode($resArray2), LOG_WARNING, 0,
'_payment');
252 $ErrorCode = urldecode($resArray2[
"L_ERRORCODE0"]);
253 $ErrorShortMsg = urldecode($resArray2[
"L_SHORTMESSAGE0"]);
254 $ErrorLongMsg = urldecode($resArray2[
"L_LONGMESSAGE0"]);
255 $ErrorSeverityCode = urldecode($resArray2[
"L_SEVERITYCODE0"]);
266 if (!empty($conf->paybox->enabled))
268 if ($paymentmethod ==
'paybox') $ispaymentok =
true;
271 if (!empty($conf->stripe->enabled))
273 if ($paymentmethod ==
'stripe') $ispaymentok =
true;
278 if (empty($ipaddress)) $ipaddress = $_SESSION[
'ipaddress'];
279 if (empty($TRANSACTIONID)) $TRANSACTIONID = $_SESSION[
'TRANSACTIONID'];
280 if (empty($FinalPaymentAmt)) $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
281 if (empty($paymentType)) $paymentType = $_SESSION[
"paymentType"];
287 dol_syslog(
"ispaymentok=".$ispaymentok.
" tmptag=".var_export($tmptag,
true), LOG_DEBUG, 0,
'_payment');
292 $postactionmessages = array();
296 if (empty($user->rights->societe)) $user->rights->societe =
new stdClass();
297 if (empty($user->rights->facture)) $user->rights->facture =
new stdClass();
298 if (empty($user->rights->adherent)) { $user->rights->adherent =
new stdClass(); $user->rights->adherent->cotisation =
new stdClass(); }
299 $user->rights->societe->creer = 1;
300 $user->rights->facture->creer = 1;
301 $user->rights->adherent->cotisation->creer = 1;
303 if (array_key_exists(
'MEM', $tmptag) && $tmptag[
'MEM'] > 0)
311 $defaultdelayunit =
'y';
314 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
315 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent_type.class.php';
316 include_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
320 $result1 = $object->fetch($tmptag[
'MEM']);
321 $result2 = $adht->fetch($object->typeid);
323 dol_syslog(
"We have to process member with id=".$tmptag[
'MEM'].
" result1=".$result1.
" result2=".$result2, LOG_DEBUG, 0,
'_payment');
325 if ($result1 > 0 && $result2 > 0)
328 if ($paymentmethod ==
'paybox') $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
329 if ($paymentmethod ==
'paypal') $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
330 if ($paymentmethod ==
'stripe') $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
331 if (empty($paymentTypeId))
333 $paymentType = $_SESSION[
"paymentType"];
334 if (empty($paymentType)) $paymentType =
'CB';
335 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
338 $currencyCodeType = $_SESSION[
'currencyCodeType'];
340 dol_syslog(
"FinalPaymentAmt=".$FinalPaymentAmt.
" paymentTypeId=".$paymentTypeId, LOG_DEBUG, 0,
'_payment');
343 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0)
345 $result = $object->validate($user);
346 if ($result < 0 || empty($object->datevalid))
349 $errmsg = $object->error;
350 $postactionmessages[] = $errmsg;
351 $postactionmessages = array_merge($postactionmessages, $object->errors);
352 $ispostactionok = -1;
353 dol_syslog(
"Failed to validate member: ".$errmsg, LOG_ERR, 0,
'_payment');
357 $datesubscription = $object->datevalid;
358 if ($object->datefin > 0)
367 $amount = $FinalPaymentAmt;
368 $label =
'Online subscription '.dol_print_date($now,
'standard').
' using '.$paymentmethod.
' from '.$ipaddress.
' - Transaction ID = '.$TRANSACTIONID;
372 if ($paymentmethod ==
'paybox') $accountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
373 if ($paymentmethod ==
'paypal') $accountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
374 if ($paymentmethod ==
'stripe') $accountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
378 $errmsg =
'Setup of bank account to use for payment is not correctly done for payment method '.$paymentmethod;
379 $postactionmessages[] = $errmsg;
380 $ispostactionok = -1;
381 dol_syslog(
"Failed to get the bank account to record payment: ".$errmsg, LOG_ERR, 0,
'_payment');
384 $operation = $paymentType;
387 $emetteur_banque =
'';
390 if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'bankviainvoice' && !empty($conf->banque->enabled) && !empty($conf->societe->enabled) && !empty($conf->facture->enabled)) $option =
'bankviainvoice';
391 elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE ==
'bankdirect' && !empty($conf->banque->enabled)) $option = 'bankdirect';
392 elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && !empty($conf->banque->enabled) && !empty($conf->societe->enabled) && !empty($conf->facture->enabled)) $option = 'invoiceonly';
393 if (empty($option)) $option = 'none';
402 dol_syslog(
"Call ->subscription to create subscription", LOG_DEBUG, 0,
'_payment');
404 $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
408 $errmsg = $object->error;
409 $postactionmessages[] = $errmsg;
410 $ispostactionok = -1;
412 $postactionmessages[] =
'Subscription created (id='.$crowid.
')';
419 dol_syslog(
"Call ->subscriptionComplementaryActions option=".$option, LOG_DEBUG, 0,
'_payment');
421 $autocreatethirdparty = 1;
423 $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque, $autocreatethirdparty);
426 dol_syslog(
"Error ".$object->error.
" ".join(
',', $object->errors), LOG_DEBUG, 0,
'_payment');
429 $postactionmessages[] = $object->error;
430 $postactionmessages = array_merge($postactionmessages, $object->errors);
431 $ispostactionok = -1;
433 if ($option ==
'bankviainvoice')
435 $postactionmessages[] =
'Invoice, payment and bank record created';
436 dol_syslog(
"Invoice, payment and bank record created", LOG_DEBUG, 0,
'_payment');
438 if ($option ==
'bankdirect')
440 $postactionmessages[] =
'Bank record created';
441 dol_syslog(
"Bank record created", LOG_DEBUG, 0,
'_payment');
443 if ($option ==
'invoiceonly')
445 $postactionmessages[] =
'Invoice recorded';
446 dol_syslog(
"Invoice recorded", LOG_DEBUG, 0,
'_payment');
456 if ($paymentmethod ==
'stripe' && $autocreatethirdparty && $option ==
'bankviainvoice')
458 $thirdparty_id = $object->fk_soc;
460 dol_syslog(
"Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0,
'_payment');
462 $service =
'StripeTest';
464 if (!empty($conf->global->STRIPE_LIVE) && !
GETPOST(
'forcesandbox',
'alpha'))
466 $service =
'StripeLive';
471 $thirdparty =
new Societe($db);
472 $thirdparty->fetch($thirdparty_id);
474 include_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
475 $stripe =
new Stripe($db);
478 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
480 if (!$customer && $TRANSACTIONID)
482 dol_syslog(
"No stripe profile found, so we add it for TRANSACTIONID = ".$TRANSACTIONID, LOG_DEBUG, 0,
'_payment');
485 global $stripearrayofkeysbyenv;
486 \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus][
'secret_key']);
488 if (preg_match(
'/^pi_/', $TRANSACTIONID)) {
490 $chpi = \Stripe\PaymentIntent::retrieve($TRANSACTIONID);
493 $chpi = \Stripe\Charge::retrieve($TRANSACTIONID);
497 $stripecu = $chpi->customer;
499 if (empty($stripecu)) {
501 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
504 if (preg_match(
'/^pi_/', $TRANSACTIONID) && $customer) {
505 \Stripe\PaymentIntent::update($chpi->id, array(
'customer' => $customer->id));
508 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)";
509 $sql .=
" VALUES (".$object->fk_soc.
", '', '".$db->escape($stripecu).
"', 'stripe', '".$db->escape($stripearrayofkeysbyenv[$servicestatus][
'publishable_key']).
"', ".$servicestatus.
", ".$conf->entity.
", '".$db->idate(
dol_now()).
"', 0)";
510 $resql = $db->query($sql);
513 $errmsg =
'Failed to insert customer stripe id in database : '.$db->lasterror();
515 $postactionmessages[] = $errmsg;
516 $ispostactionok = -1;
521 $errmsg =
'Failed to retreive paymentintent or charge from id';
523 $postactionmessages[] = $errmsg;
524 $ispostactionok = -1;
528 $errmsg =
'Failed to get or save customer stripe id in database : '.$e->getMessage();
530 $postactionmessages[] = $errmsg;
531 $ispostactionok = -1;
546 dol_syslog(
"Send email to customer to ".$object->email.
" if we have to (sendalsoemail = ".$sendalsoemail.
")", LOG_DEBUG, 0,
'_payment');
549 if ($object->email && $sendalsoemail)
555 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
559 $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
561 $outputlangs->loadLangs(array(
"main",
"members"));
563 $arraydefaultmessage = null;
564 $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
566 if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($db,
'member', $user, $outputlangs, 0, 1, $labeltouse);
568 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
570 $subject = $arraydefaultmessage->topic;
571 $msg = $arraydefaultmessage->content;
581 $listofpaths = array();
582 $listofnames = array();
583 $listofmimes = array();
584 if (is_object($object->invoice))
586 $invoicediroutput = $conf->facture->dir_output;
587 $fileparams =
dol_most_recent_file($invoicediroutput.
'/'.$object->invoice->ref, preg_quote($object->invoice->ref,
'/').
'[^\-]+');
588 $file = $fileparams[
'fullname'];
590 $listofpaths = array($file);
591 $listofnames = array(basename($file));
595 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/payment/paymentok.php'.
"\r\n";
597 $result = $object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames,
"",
"", 0, -1,
"", $moreinheader);
601 $errmsg = $object->error;
602 $postactionmessages[] = $errmsg;
603 $ispostactionok = -1;
605 if ($file) $postactionmessages[] =
'Email sent to member (with invoice document attached)';
606 else $postactionmessages[] =
'Email sent to member (without any attached document)';
613 $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.';
614 $ispostactionok = -1;
617 $postactionmessages[] =
'Member '.$tmptag[
'MEM'].
' for subscription paid was not found';
618 $ispostactionok = -1;
620 } elseif (array_key_exists(
'INV', $tmptag) && $tmptag[
'INV'] > 0)
623 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
625 $result = $object->fetch($tmptag[
'INV']);
628 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
631 if ($paymentmethod ==
'paybox') $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS;
632 if ($paymentmethod ==
'paypal') $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS;
633 if ($paymentmethod ==
'stripe') $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS;
634 if (empty($paymentTypeId))
636 $paymentType = $_SESSION[
"paymentType"];
637 if (empty($paymentType)) $paymentType =
'CB';
638 $paymentTypeId =
dol_getIdFromCode($db, $paymentType,
'c_paiement',
'code',
'id', 1);
641 $currencyCodeType = $_SESSION[
'currencyCodeType'];
644 if (!empty($FinalPaymentAmt) && $paymentTypeId > 0)
649 include_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
651 $paiement->datepaye = $now;
652 if ($currencyCodeType == $conf->currency)
654 $paiement->amounts = array($object->id => $FinalPaymentAmt);
656 $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt);
658 $postactionmessages[] =
'Payment was done in a different currency that currency expected of company';
659 $ispostactionok = -1;
662 $paiement->paiementid = $paymentTypeId;
663 $paiement->num_payment =
'';
664 $paiement->note_public =
'Online payment '.dol_print_date($now,
'standard').
' from '.$ipaddress;
665 $paiement->ext_payment_id = $TRANSACTIONID;
666 $paiement->ext_payment_site = $service;
670 $paiement_id = $paiement->create($user, 1);
671 if ($paiement_id < 0)
673 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
674 $ispostactionok = -1;
677 $postactionmessages[] =
'Payment created';
682 if (!$error && !empty($conf->banque->enabled))
685 if ($paymentmethod ==
'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS;
686 elseif ($paymentmethod ==
'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS;
687 elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS;
689 if ($bankaccountid > 0)
691 $label =
'(CustomerInvoicePayment)';
693 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid,
'',
'');
696 $postactionmessages[] = $paiement->error.
' '.join(
"<br>\n", $paiement->errors);
697 $ispostactionok = -1;
700 $postactionmessages[] =
'Bank transaction of payment created';
704 $postactionmessages[] =
'Setup of bank account to use in module '.$paymentmethod.
' was not set. No way to record the payment.';
705 $ispostactionok = -1;
717 $postactionmessages[] =
'Failed to get a valid value for "amount paid" ('.$FinalPaymentAmt.
') or "payment type" ('.$paymentType.
') to record the payment of invoice '.$tmptag[
'INV'].
'. May be payment was already recorded.';
718 $ispostactionok = -1;
721 $postactionmessages[] =
'Invoice paid '.$tmptag[
'INV'].
' was not found';
722 $ispostactionok = -1;
732 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
733 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
735 $paymentType = $_SESSION[
'PaymentType'];
736 $currencyCodeType = $_SESSION[
'currencyCodeType'];
737 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
739 if (is_object($object) && method_exists($object,
'call_trigger')) {
741 $result = $object->call_trigger(
'PAYMENTONLINE_PAYMENT_OK', $user);
742 if ($result < 0) $error++;
746 print $langs->trans(
"YourPaymentHasBeenRecorded").
"<br>\n";
747 if ($TRANSACTIONID)
print $langs->trans(
"ThisIsTransactionId", $TRANSACTIONID).
"<br><br>\n";
749 $key =
'ONLINE_PAYMENT_MESSAGE_OK';
750 if (!empty($conf->global->$key))
print $conf->global->$key;
753 if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
757 dol_syslog(
"Send email to admins if we have to (sendemail = ".$sendemail.
")", LOG_DEBUG, 0,
'_payment');
762 $companylangs =
new Translate(
'', $conf);
763 $companylangs->setDefaultLang($mysoc->default_lang);
764 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox'));
766 $sendto = $sendemail;
767 $from = $conf->global->MAILING_EMAIL_FROM;
769 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
770 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
774 $appli = constant(
'DOL_APPLICATION_TITLE');
775 if (!empty($conf->global->MAIN_APPLICATION_TITLE))
777 $appli = $conf->global->MAIN_APPLICATION_TITLE;
778 if (preg_match(
'/\d\.\d/', $appli))
780 if (!preg_match(
'/'.preg_quote(DOL_VERSION).
'/', $appli)) $appli .=
" (".DOL_VERSION.
")";
781 }
else $appli .=
" ".DOL_VERSION;
782 }
else $appli .=
" ".DOL_VERSION;
785 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived");
787 if (array_key_exists(
'MEM', $tmptag))
789 $url = $urlwithroot.
"/adherents/subscription.php?rowid=".$tmptag[
'MEM'];
790 $content .=
'<strong>'.$companylangs->trans(
"PaymentSubscription").
"</strong><br><br>\n";
791 $content .= $companylangs->trans(
"MemberId").
': <strong>'.$tmptag[
'MEM'].
"</strong><br>\n";
792 $content .= $companylangs->trans(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
793 } elseif (array_key_exists(
'INV', $tmptag))
795 $url = $urlwithroot.
"/compta/facture/card.php?id=".$tmptag[
'INV'];
796 $content .=
'<strong>'.$companylangs->trans(
"Payment").
"</strong><br><br>\n";
797 $content .= $companylangs->trans(
"InvoiceId").
': <strong>'.$tmptag[
'INV'].
"</strong><br>\n";
799 $content .= $companylangs->trans(
"Link").
': <a href="'.$url.
'">'.$url.
'</a>'.
"<br>\n";
801 $content .= $companylangs->transnoentitiesnoconv(
"NewOnlinePaymentReceived").
"<br>\n";
803 $content .= $companylangs->transnoentities(
"PostActionAfterPayment").
' : ';
804 if ($ispostactionok > 0)
807 $content .=
'<font color="green">'.$companylangs->transnoentitiesnoconv(
"OK").
'</font>';
808 } elseif ($ispostactionok == 0)
810 $content .= $companylangs->transnoentitiesnoconv(
"None");
812 $topic .= ($ispostactionok ?
'' :
' ('.$companylangs->trans(
"WarningPostActionErrorAfterPayment").
')');
813 $content .=
'<font color="red">'.$companylangs->transnoentitiesnoconv(
"Error").
'</font>';
815 $content .=
'<br>'.
"\n";
816 foreach ($postactionmessages as $postactionmessage)
818 $content .=
' * '.$postactionmessage.
'<br>'.
"\n";
820 if ($ispostactionok < 0)
822 $content .= $langs->transnoentities(
"ARollbackWasPerformedOnPostActions");
824 $content .=
'<br>'.
"\n";
826 $content .=
"<br>\n";
827 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
828 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
829 $content .= $companylangs->transnoentitiesnoconv(
"ThisIsTransactionId").
': <strong>'.$TRANSACTIONID.
"</strong><br>\n";
830 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
831 $content .=
"<br>\n";
832 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
834 if (!empty($ErrorCode)) $content .=
"ErrorCode = ".$ErrorCode.
"<br>\n";
835 if (!empty($ErrorShortMsg)) $content .=
"ErrorShortMsg = ".$ErrorShortMsg.
"<br>\n";
836 if (!empty($ErrorLongMsg)) $content .=
"ErrorLongMsg = ".$ErrorLongMsg.
"<br>\n";
837 if (!empty($ErrorSeverityCode)) $content .=
"ErrorSeverityCode = ".$ErrorSeverityCode.
"<br>\n";
841 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
842 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml);
844 $result = $mailfile->sendfile();
847 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
850 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
856 $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION[
'onlinetoken'] : $PAYPALTOKEN;
857 $payerID = empty($PAYPALPAYERID) ? $_SESSION[
'payerID'] : $PAYPALPAYERID;
859 $paymentType = $_SESSION[
'PaymentType'];
860 $currencyCodeType = $_SESSION[
'currencyCodeType'];
861 $FinalPaymentAmt = $_SESSION[
"FinalPaymentAmt"];
863 if (is_object($object) && method_exists($object,
'call_trigger')) {
865 $result = $object->call_trigger(
'PAYMENTONLINE_PAYMENT_KO', $user);
866 if ($result < 0) $error++;
870 print $langs->trans(
'DoExpressCheckoutPaymentAPICallFailed').
"<br>\n";
871 print $langs->trans(
'DetailedErrorMessage').
": ".$ErrorLongMsg.
"<br>\n";
872 print $langs->trans(
'ShortErrorMessage').
": ".$ErrorShortMsg.
"<br>\n";
873 print $langs->trans(
'ErrorCode').
": ".$ErrorCode.
"<br>\n";
874 print $langs->trans(
'ErrorSeverityCode').
": ".$ErrorSeverityCode.
"<br>\n";
876 if ($mysoc->email)
print "\nPlease, send a screenshot of this page to ".$mysoc->email.
"<br>\n";
879 if (!empty($conf->global->PAYMENTONLINE_SENDEMAIL)) $sendemail = $conf->global->PAYMENTONLINE_SENDEMAIL;
881 if ($paymentmethod ==
'paypal' && !empty($conf->global->PAYPAL_PAYONLINE_SENDEMAIL)) $sendemail = $conf->global->PAYPAL_PAYONLINE_SENDEMAIL;
882 elseif ($paymentmethod ==
'paybox' && !empty($conf->global->PAYBOX_PAYONLINE_SENDEMAIL)) $sendemail = $conf->global->PAYBOX_PAYONLINE_SENDEMAIL;
883 elseif ($paymentmethod == 'stripe' && !empty($conf->global->STRIPE_PAYONLINE_SENDEMAIL)) $sendemail = $conf->global->STRIPE_PAYONLINE_SENDEMAIL;
888 $companylangs =
new Translate(
'', $conf);
889 $companylangs->setDefaultLang($mysoc->default_lang);
890 $companylangs->loadLangs(array(
'main',
'members',
'bills',
'paypal',
'paybox'));
892 $sendto = $sendemail;
893 $from = $conf->global->MAILING_EMAIL_FROM;
895 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
896 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
900 $appli = constant(
'DOL_APPLICATION_TITLE');
901 if (!empty($conf->global->MAIN_APPLICATION_TITLE))
903 $appli = $conf->global->MAIN_APPLICATION_TITLE;
904 if (preg_match(
'/\d\.\d/', $appli))
906 if (!preg_match(
'/'.preg_quote(DOL_VERSION).
'/', $appli)) $appli .=
" (".DOL_VERSION.
")";
907 }
else $appli .=
" ".DOL_VERSION;
908 }
else $appli .=
" ".DOL_VERSION;
911 $topic =
'['.$appli.
'] '.$companylangs->transnoentitiesnoconv(
"ValidationOfPaymentFailed");
913 $content .=
'<font color="orange">'.$companylangs->transnoentitiesnoconv(
"PaymentSystemConfirmPaymentPageWasCalledButFailed").
"</font>\n";
915 $content .=
"<br><br>\n";
916 $content .=
'<u>'.$companylangs->transnoentitiesnoconv(
"TechnicalInformation").
":</u><br>\n";
917 $content .= $companylangs->transnoentitiesnoconv(
"OnlinePaymentSystem").
': <strong>'.$paymentmethod.
"</strong><br>\n";
918 $content .= $companylangs->transnoentitiesnoconv(
"ReturnURLAfterPayment").
': '.$urlback.
"<br>\n";
919 $content .=
"<br>\n";
920 $content .=
"tag=".$fulltag.
"<br>\ntoken=".$onlinetoken.
"<br>\npaymentType=".$paymentType.
"<br>\ncurrencycodeType=".$currencyCodeType.
"<br>\npayerId=".$payerID.
"<br>\nipaddress=".$ipaddress.
"<br>\nFinalPaymentAmt=".$FinalPaymentAmt.
"<br>\n";
925 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
926 $mailfile =
new CMailFile($topic, $sendto, $from, $content, array(), array(), array(),
'',
'', 0, $ishtml);
928 $result = $mailfile->sendfile();
931 dol_syslog(
"EMail sent to ".$sendto, LOG_DEBUG, 0,
'_payment');
933 dol_syslog(
"Failed to send EMail to ".$sendto, LOG_ERR, 0,
'_payment');
942 htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
946 unset($_SESSION[
"FinalPaymentAmt"]);
947 unset($_SESSION[
"TRANSACTIONID"]);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
Validate payment.
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...
const TYPE_CREDIT_NOTE
Credit note invoice.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_mimetype($file, $default= 'application/octet-stream', $mode=0)
Return mime type of a file.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage payments of customer invoices.
Class to manage members of a foundation.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage translations.
Class to manage members type.
print $_SERVER["PHP_SELF"]
Edit parameters.
dolExplodeIntoArray($string, $delimiter= ';', $kv= '=')
Split a string with 2 keys into key array.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
print
Draft customers invoices.
dol_most_recent_file($dir, $regexfilter= '', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=false, $mode= '')
Return file(s) into a directory (by default most recent)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Class to manage invoices.
getDetails($token)
Prepares the parameters for the GetExpressCheckoutDetails API Call.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
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...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_textishtml($msg, $option=0)
Return if a text is a html content.