dolibarr  13.0.2
paymentok.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
28 if (!defined('NOLOGIN')) define("NOLOGIN", 1); // This means this output page does not require to be logged.
29 if (!defined('NOCSRFCHECK')) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
30 if (!defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
31 if (!defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1');
32 
33 // For MultiCompany module.
34 // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
35 // TODO This should be useless. Because entity must be retrieve from object ref and not from url.
36 $entity = (!empty($_GET['e']) ? (int) $_GET['e'] : (!empty($_POST['e']) ? (int) $_POST['e'] : 1));
37 if (is_numeric($entity)) define("DOLENTITY", $entity);
38 
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';
42 
43 if (!empty($conf->paypal->enabled))
44 {
45  require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
46  require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
47 }
48 
49 $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "paybox", "paypal"));
50 
51 // Clean parameters
52 if (!empty($conf->paypal->enabled))
53 {
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;
62  $PAYPAL_API_OK = "";
63  if ($urlok) $PAYPAL_API_OK = $urlok;
64  $PAYPAL_API_KO = "";
65  if ($urlko) $PAYPAL_API_KO = $urlko;
66 
67  $PAYPALTOKEN = GETPOST('TOKEN');
68  if (empty($PAYPALTOKEN)) $PAYPALTOKEN = GETPOST('token');
69  $PAYPALPAYERID = GETPOST('PAYERID');
70  if (empty($PAYPALPAYERID)) $PAYPALPAYERID = GETPOST('PayerID');
71 }
72 
73 $FULLTAG = GETPOST('FULLTAG');
74 if (empty($FULLTAG)) $FULLTAG = GETPOST('fulltag');
75 $source = GETPOST('s', 'alpha') ?GETPOST('s', 'alpha') : GETPOST('source', 'alpha');
76 $ref = GETPOST('ref');
77 
78 $suffix = GETPOST("suffix", 'aZ09');
79 
80 
81 // Detect $paymentmethod
82 $paymentmethod = '';
83 $reg = array();
84 if (preg_match('/PM=([^\.]+)/', $FULLTAG, $reg))
85 {
86  $paymentmethod = $reg[1];
87 }
88 if (empty($paymentmethod))
89 {
90  dol_print_error(null, 'The back url does not contains a parameter fulltag that should help us to find the payment method used');
91  exit;
92 }
93 
94 dol_syslog("***** paymentok.php is called paymentmethod=".$paymentmethod." FULLTAG=".$FULLTAG." REQUEST_URI=".$_SERVER["REQUEST_URI"], LOG_DEBUG, 0, '_payment');
95 
96 
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';
101 
102 // Security check
103 if (empty($validpaymentmethod)) accessforbidden('', 0, 0, 1);
104 
105 
106 $ispaymentok = false;
107 // If payment is ok
108 $PAYMENTSTATUS = $TRANSACTIONID = $TAXAMT = $NOTE = '';
109 // If payment is ko
110 $ErrorCode = $ErrorShortMsg = $ErrorLongMsg = $ErrorSeverityCode = '';
111 
112 
113 $object = new stdClass(); // For triggers
114 
115 $error = 0;
116 
117 
118 /*
119  * Actions
120  */
121 
122 
123 
124 /*
125  * View
126  */
127 
128 $now = dol_now();
129 
130 dol_syslog("Callback url when a payment was done. query_string=".(dol_escape_htmltag($_SERVER["QUERY_STRING"]) ?dol_escape_htmltag($_SERVER["QUERY_STRING"]) : '')." script_uri=".(dol_escape_htmltag($_SERVER["SCRIPT_URI"]) ?dol_escape_htmltag($_SERVER["SCRIPT_URI"]) : ''), LOG_DEBUG, 0, '_payment');
131 
132 $tracepost = "";
133 foreach ($_POST as $k => $v) $tracepost .= "{$k} - {$v}\n";
134 dol_syslog("POST=".$tracepost, LOG_DEBUG, 0, '_payment');
135 
136 $head = '';
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";
138 
139 $conf->dol_hide_topmenu = 1;
140 $conf->dol_hide_leftmenu = 1;
141 
142 $replacemainarea = (empty($conf->dol_hide_leftmenu) ? '<div>' : '').'<div>';
143 llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody', $replacemainarea);
144 
145 
146 // Show message
147 print '<span id="dolpaymentspan"></span>'."\n";
148 print '<div id="dolpaymentdiv" class="center">'."\n";
149 
150 
151 // Show logo (search order: logo defined by PAYMENT_LOGO_suffix, then PAYMENT_LOGO, then small company logo, large company logo, theme logo, common logo)
152 // Define logo and logosmall
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;
158 //print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
159 // Define urllogo
160 $urllogo = '';
161 $urllogofull = '';
162 if (!empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall))
163 {
164  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;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))
167 {
168  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$logo);
169  $urllogofull = $dolibarr_main_url_root.'/viewimage.php?modulepart=mycompany&entity='.$conf->entity.'&file='.urlencode('logos/'.$logo);
170 }
171 
172 // Output html code for logo
173 if ($urllogo)
174 {
175  print '<div class="backgreypublicpayment">';
176  print '<div class="logopublicpayment">';
177  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
178  print '>';
179  print '</div>';
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>';
182  }
183  print '</div>';
184 }
185 
186 
187 print '<br><br><br>';
188 
189 
190 if (!empty($conf->paypal->enabled))
191 {
192  if ($paymentmethod == 'paypal') // We call this page only if payment is ok on payment system
193  {
194  if ($PAYPALTOKEN)
195  {
196  // Get on url call
197  $onlinetoken = $PAYPALTOKEN;
198  $fulltag = $FULLTAG;
199  $payerID = $PAYPALPAYERID;
200  // Set by newpayment.php
201  $paymentType = $_SESSION['PaymentType'];
202  $currencyCodeType = $_SESSION['currencyCodeType'];
203  $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
204  // From env
205  $ipaddress = $_SESSION['ipaddress'];
206 
207  dol_syslog("Call paymentok with token=".$onlinetoken." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag, LOG_DEBUG, 0, '_payment');
208 
209  // Validate record
210  if (!empty($paymentType))
211  {
212  dol_syslog("We call GetExpressCheckoutDetails", LOG_DEBUG, 0, '_payment');
213  $resArray = getDetails($onlinetoken);
214  //var_dump($resarray);
215 
216  $ack = strtoupper($resArray["ACK"]);
217  if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
218  {
219  // Nothing to do
220  dol_syslog("Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0, '_payment');
221  } else {
222  dol_syslog("Call to GetExpressCheckoutDetails return error: ".json_encode($resArray), LOG_WARNING, '_payment');
223  }
224 
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);
227  //var_dump($resarray);
228 
229  $ack = strtoupper($resArray2["ACK"]);
230  if ($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING")
231  {
232  dol_syslog("Call to GetExpressCheckoutDetails return ".$ack, LOG_DEBUG, 0, '_payment');
233 
234  $object->source = $source;
235  $object->ref = $ref;
236  $object->payerID = $payerID;
237  $object->fulltag = $fulltag;
238  $object->resArray = $resArray2;
239 
240  // resArray was built from a string like that
241  // TOKEN=EC%2d1NJ057703V9359028&TIMESTAMP=2010%2d11%2d01T11%3a40%3a13Z&CORRELATIONID=1efa8c6a36bd8&ACK=Success&VERSION=56&BUILD=1553277&TRANSACTIONID=9B994597K9921420R&TRANSACTIONTYPE=expresscheckout&PAYMENTTYPE=instant&ORDERTIME=2010%2d11%2d01T11%3a40%3a12Z&AMT=155%2e57&FEEAMT=5%2e54&TAXAMT=0%2e00&CURRENCYCODE=EUR&PAYMENTSTATUS=Completed&PENDINGREASON=None&REASONCODE=None
242  $PAYMENTSTATUS = urldecode($resArray2["PAYMENTSTATUS"]); // Should contains 'Completed'
243  $TRANSACTIONID = urldecode($resArray2["TRANSACTIONID"]);
244  $TAXAMT = urldecode($resArray2["TAXAMT"]);
245  $NOTE = urldecode($resArray2["NOTE"]);
246 
247  $ispaymentok = true;
248  } else {
249  dol_syslog("Call to DoExpressCheckoutPayment return error: ".json_encode($resArray2), LOG_WARNING, 0, '_payment');
250 
251  //Display a user friendly Error on the page using any of the following error information returned by PayPal
252  $ErrorCode = urldecode($resArray2["L_ERRORCODE0"]);
253  $ErrorShortMsg = urldecode($resArray2["L_SHORTMESSAGE0"]);
254  $ErrorLongMsg = urldecode($resArray2["L_LONGMESSAGE0"]);
255  $ErrorSeverityCode = urldecode($resArray2["L_SEVERITYCODE0"]);
256  }
257  } else {
258  dol_print_error('', 'Session expired');
259  }
260  } else {
261  dol_print_error('', '$PAYPALTOKEN not defined');
262  }
263  }
264 }
265 
266 if (!empty($conf->paybox->enabled))
267 {
268  if ($paymentmethod == 'paybox') $ispaymentok = true; // We call this page only if payment is ok on payment system
269 }
270 
271 if (!empty($conf->stripe->enabled))
272 {
273  if ($paymentmethod == 'stripe') $ispaymentok = true; // We call this page only if payment is ok on payment system
274 }
275 
276 
277 // If data not provided from back url, search them into the session env
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"];
282 
283 $fulltag = $FULLTAG;
284 $tmptag = dolExplodeIntoArray($fulltag, '.', '=');
285 
286 
287 dol_syslog("ispaymentok=".$ispaymentok." tmptag=".var_export($tmptag, true), LOG_DEBUG, 0, '_payment');
288 
289 
290 // Make complementary actions
291 $ispostactionok = 0;
292 $postactionmessages = array();
293 if ($ispaymentok)
294 {
295  // Set permission for the anonymous user
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;
302 
303  if (array_key_exists('MEM', $tmptag) && $tmptag['MEM'] > 0)
304  {
305  // Validate member
306  // Create subscription
307  // Create complementary actions (this include creation of thirdparty)
308  // Send confirmation email
309 
310  $defaultdelay = 1;
311  $defaultdelayunit = 'y';
312 
313  // Record subscription
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';
317  $adht = new AdherentType($db);
318  $object = new Adherent($db);
319 
320  $result1 = $object->fetch($tmptag['MEM']);
321  $result2 = $adht->fetch($object->typeid);
322 
323  dol_syslog("We have to process member with id=".$tmptag['MEM']." result1=".$result1." result2=".$result2, LOG_DEBUG, 0, '_payment');
324 
325  if ($result1 > 0 && $result2 > 0)
326  {
327  $paymentTypeId = 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))
332  {
333  $paymentType = $_SESSION["paymentType"];
334  if (empty($paymentType)) $paymentType = 'CB';
335  $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
336  }
337 
338  $currencyCodeType = $_SESSION['currencyCodeType'];
339 
340  dol_syslog("FinalPaymentAmt=".$FinalPaymentAmt." paymentTypeId=".$paymentTypeId, LOG_DEBUG, 0, '_payment');
341 
342  // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
343  if (!empty($FinalPaymentAmt) && $paymentTypeId > 0)
344  {
345  $result = $object->validate($user);
346  if ($result < 0 || empty($object->datevalid))
347  {
348  $error++;
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');
354  }
355 
356  // Subscription informations
357  $datesubscription = $object->datevalid;
358  if ($object->datefin > 0)
359  {
360  $datesubscription = dol_time_plus_duree($object->datefin, 1, 'd');
361  }
362 
363  $datesubend = null;
364  if ($datesubscription && $defaultdelay && $defaultdelayunit) $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd');
365 
366  $paymentdate = $now;
367  $amount = $FinalPaymentAmt;
368  $label = 'Online subscription '.dol_print_date($now, 'standard').' using '.$paymentmethod.' from '.$ipaddress.' - Transaction ID = '.$TRANSACTIONID;
369 
370  // Payment informations
371  $accountid = 0;
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;
375  if ($accountid < 0)
376  {
377  $error++;
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');
382  }
383 
384  $operation = $paymentType; // Payment mode code
385  $num_chq = '';
386  $emetteur_nom = '';
387  $emetteur_banque = '';
388  // Define default choice for complementary actions
389  $option = '';
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';
394  $sendalsoemail = 1;
395 
396  // Record the subscription then complementary actions
397  $db->begin();
398 
399  // Create subscription
400  if (!$error)
401  {
402  dol_syslog("Call ->subscription to create subscription", LOG_DEBUG, 0, '_payment');
403 
404  $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
405  if ($crowid <= 0)
406  {
407  $error++;
408  $errmsg = $object->error;
409  $postactionmessages[] = $errmsg;
410  $ispostactionok = -1;
411  } else {
412  $postactionmessages[] = 'Subscription created (id='.$crowid.')';
413  $ispostactionok = 1;
414  }
415  }
416 
417  if (!$error)
418  {
419  dol_syslog("Call ->subscriptionComplementaryActions option=".$option, LOG_DEBUG, 0, '_payment');
420 
421  $autocreatethirdparty = 1; // will create thirdparty if member not yet linked to a thirdparty
422 
423  $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque, $autocreatethirdparty);
424  if ($result < 0)
425  {
426  dol_syslog("Error ".$object->error." ".join(',', $object->errors), LOG_DEBUG, 0, '_payment');
427 
428  $error++;
429  $postactionmessages[] = $object->error;
430  $postactionmessages = array_merge($postactionmessages, $object->errors);
431  $ispostactionok = -1;
432  } else {
433  if ($option == 'bankviainvoice')
434  {
435  $postactionmessages[] = 'Invoice, payment and bank record created';
436  dol_syslog("Invoice, payment and bank record created", LOG_DEBUG, 0, '_payment');
437  }
438  if ($option == 'bankdirect')
439  {
440  $postactionmessages[] = 'Bank record created';
441  dol_syslog("Bank record created", LOG_DEBUG, 0, '_payment');
442  }
443  if ($option == 'invoiceonly')
444  {
445  $postactionmessages[] = 'Invoice recorded';
446  dol_syslog("Invoice recorded", LOG_DEBUG, 0, '_payment');
447  }
448  $ispostactionok = 1;
449 
450  // If an invoice was created, it is into $object->invoice
451  }
452  }
453 
454  if (!$error)
455  {
456  if ($paymentmethod == 'stripe' && $autocreatethirdparty && $option == 'bankviainvoice')
457  {
458  $thirdparty_id = $object->fk_soc;
459 
460  dol_syslog("Search existing Stripe customer profile for thirdparty_id=".$thirdparty_id, LOG_DEBUG, 0, '_payment');
461 
462  $service = 'StripeTest';
463  $servicestatus = 0;
464  if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha'))
465  {
466  $service = 'StripeLive';
467  $servicestatus = 1;
468  }
469  $stripeacc = null; // No Oauth/connect use for public pages
470 
471  $thirdparty = new Societe($db);
472  $thirdparty->fetch($thirdparty_id);
473 
474  include_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; // This also set $stripearrayofkeysbyenv
475  $stripe = new Stripe($db);
476  //$stripeacc = $stripe->getStripeAccount($service); Already defined previously
477 
478  $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
479 
480  if (!$customer && $TRANSACTIONID) // Not linked to a stripe customer, we make the link
481  {
482  dol_syslog("No stripe profile found, so we add it for TRANSACTIONID = ".$TRANSACTIONID, LOG_DEBUG, 0, '_payment');
483 
484  try {
485  global $stripearrayofkeysbyenv;
486  \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']);
487 
488  if (preg_match('/^pi_/', $TRANSACTIONID)) {
489  // This may throw an error if not found.
490  $chpi = \Stripe\PaymentIntent::retrieve($TRANSACTIONID); // payment_intent (pi_...)
491  } else {
492  // This throw an error if not found
493  $chpi = \Stripe\Charge::retrieve($TRANSACTIONID); // old method, contains the charge id (ch_...)
494  }
495 
496  if ($chpi) {
497  $stripecu = $chpi->customer; // value 'cus_....'. WARNING: This property may be empty if first payment was recorded before the stripe customer was created.
498 
499  if (empty($stripecu)) {
500  // This include the INSERT
501  $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
502 
503  // Link this customer to the payment intent
504  if (preg_match('/^pi_/', $TRANSACTIONID) && $customer) {
505  \Stripe\PaymentIntent::update($chpi->id, array('customer' => $customer->id));
506  }
507  } else {
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);
511  if (!$resql) { // should not happen
512  $error++;
513  $errmsg = 'Failed to insert customer stripe id in database : '.$db->lasterror();
514  dol_syslog($errmsg, LOG_ERR, 0, '_payment');
515  $postactionmessages[] = $errmsg;
516  $ispostactionok = -1;
517  }
518  }
519  } else { // should not happen
520  $error++;
521  $errmsg = 'Failed to retreive paymentintent or charge from id';
522  dol_syslog($errmsg, LOG_ERR, 0, '_payment');
523  $postactionmessages[] = $errmsg;
524  $ispostactionok = -1;
525  }
526  } catch (Exception $e) { // should not happen
527  $error++;
528  $errmsg = 'Failed to get or save customer stripe id in database : '.$e->getMessage();
529  dol_syslog($errmsg, LOG_ERR, 0, '_payment');
530  $postactionmessages[] = $errmsg;
531  $ispostactionok = -1;
532  }
533  }
534  }
535  }
536 
537  if (!$error) {
538  $db->commit();
539  } else {
540  $db->rollback();
541  }
542 
543  // Send email to member
544  if (!$error)
545  {
546  dol_syslog("Send email to customer to ".$object->email." if we have to (sendalsoemail = ".$sendalsoemail.")", LOG_DEBUG, 0, '_payment');
547 
548  // Send confirmation Email
549  if ($object->email && $sendalsoemail)
550  {
551  $subject = '';
552  $msg = '';
553 
554  // Send subscription email
555  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
556  $formmail = new FormMail($db);
557  // Set output language
558  $outputlangs = new Translate('', $conf);
559  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
560  // Load traductions files required by page
561  $outputlangs->loadLangs(array("main", "members"));
562  // Get email content from template
563  $arraydefaultmessage = null;
564  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
565 
566  if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
567 
568  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
569  {
570  $subject = $arraydefaultmessage->topic;
571  $msg = $arraydefaultmessage->content;
572  }
573 
574  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
575  complete_substitutions_array($substitutionarray, $outputlangs, $object);
576  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
577  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
578 
579  // Attach a file ?
580  $file = '';
581  $listofpaths = array();
582  $listofnames = array();
583  $listofmimes = array();
584  if (is_object($object->invoice))
585  {
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'];
589 
590  $listofpaths = array($file);
591  $listofnames = array(basename($file));
592  $listofmimes = array(dol_mimetype($file));
593  }
594 
595  $moreinheader = 'X-Dolibarr-Info: send_an_email by public/payment/paymentok.php'."\r\n";
596 
597  $result = $object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, "", $moreinheader);
598 
599  if ($result < 0)
600  {
601  $errmsg = $object->error;
602  $postactionmessages[] = $errmsg;
603  $ispostactionok = -1;
604  } else {
605  if ($file) $postactionmessages[] = 'Email sent to member (with invoice document attached)';
606  else $postactionmessages[] = 'Email sent to member (without any attached document)';
607 
608  // TODO Add actioncomm event
609  }
610  }
611  }
612  } else {
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;
615  }
616  } else {
617  $postactionmessages[] = 'Member '.$tmptag['MEM'].' for subscription paid was not found';
618  $ispostactionok = -1;
619  }
620  } elseif (array_key_exists('INV', $tmptag) && $tmptag['INV'] > 0)
621  {
622  // Record payment
623  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
624  $object = new Facture($db);
625  $result = $object->fetch($tmptag['INV']);
626  if ($result)
627  {
628  $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
629 
630  $paymentTypeId = 0;
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))
635  {
636  $paymentType = $_SESSION["paymentType"];
637  if (empty($paymentType)) $paymentType = 'CB';
638  $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
639  }
640 
641  $currencyCodeType = $_SESSION['currencyCodeType'];
642 
643  // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time)
644  if (!empty($FinalPaymentAmt) && $paymentTypeId > 0)
645  {
646  $db->begin();
647 
648  // Creation of payment line
649  include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
650  $paiement = new Paiement($db);
651  $paiement->datepaye = $now;
652  if ($currencyCodeType == $conf->currency)
653  {
654  $paiement->amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id
655  } else {
656  $paiement->multicurrency_amounts = array($object->id => $FinalPaymentAmt); // Array with all payments dispatching
657 
658  $postactionmessages[] = 'Payment was done in a different currency that currency expected of company';
659  $ispostactionok = -1;
660  $error++; // Not yet supported
661  }
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;
667 
668  if (!$error)
669  {
670  $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents
671  if ($paiement_id < 0)
672  {
673  $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
674  $ispostactionok = -1;
675  $error++;
676  } else {
677  $postactionmessages[] = 'Payment created';
678  $ispostactionok = 1;
679  }
680  }
681 
682  if (!$error && !empty($conf->banque->enabled))
683  {
684  $bankaccountid = 0;
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;
688 
689  if ($bankaccountid > 0)
690  {
691  $label = '(CustomerInvoicePayment)';
692  if ($object->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note
693  $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', '');
694  if ($result < 0)
695  {
696  $postactionmessages[] = $paiement->error.' '.join("<br>\n", $paiement->errors);
697  $ispostactionok = -1;
698  $error++;
699  } else {
700  $postactionmessages[] = 'Bank transaction of payment created';
701  $ispostactionok = 1;
702  }
703  } else {
704  $postactionmessages[] = 'Setup of bank account to use in module '.$paymentmethod.' was not set. No way to record the payment.';
705  $ispostactionok = -1;
706  $error++;
707  }
708  }
709 
710  if (!$error)
711  {
712  $db->commit();
713  } else {
714  $db->rollback();
715  }
716  } else {
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;
719  }
720  } else {
721  $postactionmessages[] = 'Invoice paid '.$tmptag['INV'].' was not found';
722  $ispostactionok = -1;
723  }
724  } else {
725  // Nothing done
726  }
727 }
728 
729 if ($ispaymentok)
730 {
731  // Get on url call
732  $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
733  $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
734  // Set by newpayment.php
735  $paymentType = $_SESSION['PaymentType'];
736  $currencyCodeType = $_SESSION['currencyCodeType'];
737  $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
738 
739  if (is_object($object) && method_exists($object, 'call_trigger')) {
740  // Call trigger
741  $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_OK', $user);
742  if ($result < 0) $error++;
743  // End call triggers
744  }
745 
746  print $langs->trans("YourPaymentHasBeenRecorded")."<br>\n";
747  if ($TRANSACTIONID) print $langs->trans("ThisIsTransactionId", $TRANSACTIONID)."<br><br>\n";
748 
749  $key = 'ONLINE_PAYMENT_MESSAGE_OK';
750  if (!empty($conf->global->$key)) print $conf->global->$key;
751 
752  $sendemail = '';
753  if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) $sendemail = $conf->global->ONLINE_PAYMENT_SENDEMAIL;
754 
755  $tmptag = dolExplodeIntoArray($fulltag, '.', '=');
756 
757  dol_syslog("Send email to admins if we have to (sendemail = ".$sendemail.")", LOG_DEBUG, 0, '_payment');
758 
759  // Send an email to admins
760  if ($sendemail)
761  {
762  $companylangs = new Translate('', $conf);
763  $companylangs->setDefaultLang($mysoc->default_lang);
764  $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
765 
766  $sendto = $sendemail;
767  $from = $conf->global->MAILING_EMAIL_FROM;
768  // Define $urlwithroot
769  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
770  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
771  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
772 
773  // Define link to login card
774  $appli = constant('DOL_APPLICATION_TITLE');
775  if (!empty($conf->global->MAIN_APPLICATION_TITLE))
776  {
777  $appli = $conf->global->MAIN_APPLICATION_TITLE;
778  if (preg_match('/\d\.\d/', $appli))
779  {
780  if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
781  } else $appli .= " ".DOL_VERSION;
782  } else $appli .= " ".DOL_VERSION;
783 
784  $urlback = $_SERVER["REQUEST_URI"];
785  $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("NewOnlinePaymentReceived");
786  $content = "";
787  if (array_key_exists('MEM', $tmptag))
788  {
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))
794  {
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";
798  //$content.=$companylangs->trans("ThirdPartyId").': '.$tmptag['CUS']."<br>\n";
799  $content .= $companylangs->trans("Link").': <a href="'.$url.'">'.$url.'</a>'."<br>\n";
800  } else {
801  $content .= $companylangs->transnoentitiesnoconv("NewOnlinePaymentReceived")."<br>\n";
802  }
803  $content .= $companylangs->transnoentities("PostActionAfterPayment").' : ';
804  if ($ispostactionok > 0)
805  {
806  //$topic.=' ('.$companylangs->transnoentitiesnoconv("Status").' '.$companylangs->transnoentitiesnoconv("OK").')';
807  $content .= '<font color="green">'.$companylangs->transnoentitiesnoconv("OK").'</font>';
808  } elseif ($ispostactionok == 0)
809  {
810  $content .= $companylangs->transnoentitiesnoconv("None");
811  } else {
812  $topic .= ($ispostactionok ? '' : ' ('.$companylangs->trans("WarningPostActionErrorAfterPayment").')');
813  $content .= '<font color="red">'.$companylangs->transnoentitiesnoconv("Error").'</font>';
814  }
815  $content .= '<br>'."\n";
816  foreach ($postactionmessages as $postactionmessage)
817  {
818  $content .= ' * '.$postactionmessage.'<br>'."\n";
819  }
820  if ($ispostactionok < 0)
821  {
822  $content .= $langs->transnoentities("ARollbackWasPerformedOnPostActions");
823  }
824  $content .= '<br>'."\n";
825 
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";
833 
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";
838 
839  $ishtml = dol_textishtml($content); // May contain urls
840 
841  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
842  $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
843 
844  $result = $mailfile->sendfile();
845  if ($result)
846  {
847  dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
848  //dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0);
849  } else {
850  dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
851  //dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0);
852  }
853  }
854 } else {
855  // Get on url call
856  $onlinetoken = empty($PAYPALTOKEN) ? $_SESSION['onlinetoken'] : $PAYPALTOKEN;
857  $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID;
858  // Set by newpayment.php
859  $paymentType = $_SESSION['PaymentType'];
860  $currencyCodeType = $_SESSION['currencyCodeType'];
861  $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"];
862 
863  if (is_object($object) && method_exists($object, 'call_trigger')) {
864  // Call trigger
865  $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_KO', $user);
866  if ($result < 0) $error++;
867  // End call triggers
868  }
869 
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";
875 
876  if ($mysoc->email) print "\nPlease, send a screenshot of this page to ".$mysoc->email."<br>\n";
877 
878  $sendemail = '';
879  if (!empty($conf->global->PAYMENTONLINE_SENDEMAIL)) $sendemail = $conf->global->PAYMENTONLINE_SENDEMAIL;
880  // TODO Remove local option to keep only the generic one ?
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;
884 
885  // Send warning of error to administrator
886  if ($sendemail)
887  {
888  $companylangs = new Translate('', $conf);
889  $companylangs->setDefaultLang($mysoc->default_lang);
890  $companylangs->loadLangs(array('main', 'members', 'bills', 'paypal', 'paybox'));
891 
892  $sendto = $sendemail;
893  $from = $conf->global->MAILING_EMAIL_FROM;
894  // Define $urlwithroot
895  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
896  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
897  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
898 
899  // Define link to login card
900  $appli = constant('DOL_APPLICATION_TITLE');
901  if (!empty($conf->global->MAIN_APPLICATION_TITLE))
902  {
903  $appli = $conf->global->MAIN_APPLICATION_TITLE;
904  if (preg_match('/\d\.\d/', $appli))
905  {
906  if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
907  } else $appli .= " ".DOL_VERSION;
908  } else $appli .= " ".DOL_VERSION;
909 
910  $urlback = $_SERVER["REQUEST_URI"];
911  $topic = '['.$appli.'] '.$companylangs->transnoentitiesnoconv("ValidationOfPaymentFailed");
912  $content = "";
913  $content .= '<font color="orange">'.$companylangs->transnoentitiesnoconv("PaymentSystemConfirmPaymentPageWasCalledButFailed")."</font>\n";
914 
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";
921 
922 
923  $ishtml = dol_textishtml($content); // May contain urls
924 
925  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
926  $mailfile = new CMailFile($topic, $sendto, $from, $content, array(), array(), array(), '', '', 0, $ishtml);
927 
928  $result = $mailfile->sendfile();
929  if ($result)
930  {
931  dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
932  } else {
933  dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
934  }
935  }
936 }
937 
938 
939 print "\n</div>\n";
940 
941 
942 htmlPrintOnlinePaymentFooter($mysoc, $langs, 0, $suffix);
943 
944 
945 // Clean session variables to avoid duplicate actions if post is resent
946 unset($_SESSION["FinalPaymentAmt"]);
947 unset($_SESSION["TRANSACTIONID"]);
948 
949 
950 llxFooter('', 'public');
951 
952 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Classe permettant la generation du formulaire html d&#39;envoi de mail unitaire Usage: $formail = new For...
dol_now($mode= 'auto')
Return date for now.
confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag)
Validate payment.
Definition: paypal.lib.php:362
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...
Stripe class.
const TYPE_CREDIT_NOTE
Credit note invoice.
llxHeader()
Empty header.
Definition: wrapper.php:45
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-&gt;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.
Definition: index.php:89
dol_most_recent_file($dir, $regexfilter= '', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=false, $mode= '')
Return file(s) into a directory (by default most recent)
Definition: files.lib.php:2212
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.
Definition: index.php:1232
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=&gt;newva...
Class to manage invoices.
getDetails($token)
Prepares the parameters for the GetExpressCheckoutDetails API Call.
Definition: paypal.lib.php:312
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:114
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 &quot;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.