21if (!defined(
'NOLOGIN')) {
24if (!defined(
'NOCSRFCHECK')) {
25 define(
"NOCSRFCHECK", 1);
27if (!defined(
'NOIPCHECK')) {
28 define(
'NOIPCHECK',
'1');
30if (!defined(
'NOBROWSERNOTIF')) {
31 define(
'NOBROWSERNOTIF',
'1');
35$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
36if (is_numeric($entity)) {
37 define(
"DOLENTITY", $entity);
41if (!defined(
'USESUFFIXINLOG')) {
42 define(
'USESUFFIXINLOG',
'_stripeipn');
46require
'../../main.inc.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/class/ccountry.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
53require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
54require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
55require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/includes/stripe/stripe-php/init.php';
58require_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
62if (GETPOSTISSET(
'connect')) {
63 if (GETPOSTISSET(
'test')) {
65 $service =
'StripeTest';
69 $service =
'StripeLive';
73 if (GETPOSTISSET(
'test')) {
75 $service =
'StripeTest';
79 $service =
'StripeLive';
84if (!isModEnabled(
'stripe')) {
88if (empty($endpoint_secret)) {
94 $user =
new User($db);
111$payload = @file_get_contents(
"php://input");
112$sig_header = empty($_SERVER[
"HTTP_STRIPE_SIGNATURE"]) ?
'' : $_SERVER[
"HTTP_STRIPE_SIGNATURE"];
116 $fh = fopen(DOL_DATA_ROOT.
'/dolibarr_stripeipn_payload.log',
'w+');
118 fwrite($fh,
dol_print_date(
dol_now(
'gmt'),
'standard').
' IPN Called. service='.$service.
' HTTP_STRIPE_SIGNATURE='.$sig_header.
"\n");
119 fwrite($fh, $payload);
121 dolChmod(DOL_DATA_ROOT.
'/dolibarr_stripeipn_payload.log');
128 $event = \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret);
129}
catch (UnexpectedValueException $e) {
133 httponly_accessforbidden(
'Invalid signature. May be a hook for an event created by another Stripe env ? Check setup of your keys whsec_...', 400);
143if (isModEnabled(
'multicompany') && !empty($conf->stripeconnect->enabled) && is_object($mc)) {
144 $sql =
"SELECT entity";
145 $sql .=
" FROM ".MAIN_DB_PREFIX.
"oauth_token";
146 $sql .=
" WHERE service = '".$db->escape($service).
"' and tokenstring LIKE '%".$db->escape($db->escapeforlike($event->account)).
"%'";
148 dol_syslog(get_class($db).
"::fetch", LOG_DEBUG);
149 $result = $db->query($sql);
151 if ($db->num_rows($result)) {
152 $obj = $db->fetch_object($result);
160 $ret = $mc->switchEntity($key);
174dol_syslog(
"***** Stripe IPN was called with event->type=".$event->type.
" service=".$service);
177if ($event->type ==
'payout.created') {
181 $result =
dolibarr_set_const($db, $service.
"_NEXTPAYOUT", date(
'Y-m-d H:i:s', $event->data->object->arrival_date),
'chaine', 0,
'', $conf->entity);
184 $subject = $societeName.
' - [NOTIFICATION] Stripe payout scheduled';
185 if (!empty($user->email)) {
196 $message =
"A bank transfer of ".price2num($event->data->object->amount / 100).
" ".$event->data->object->currency.
" should arrive in your account the ".
dol_print_date($event->data->object->arrival_date,
'dayhour');
212 $ret = $mailfile->sendfile();
217 http_response_code(500);
220} elseif ($event->type ==
'payout.paid') {
223 $result =
dolibarr_set_const($db, $service.
"_NEXTPAYOUT", 0,
'chaine', 0,
'', $conf->entity);
225 $langs->load(
"errors");
228 $label = $event->data->object->description;
229 $amount = $event->data->object->amount / 100;
230 $amount_to = $event->data->object->amount / 100;
231 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
233 $accountfrom =
new Account($db);
234 $accountfrom->fetch(
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'));
237 $accountto->fetch(
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS'));
239 if (($accountto->id != $accountfrom->id) && empty($error)) {
240 $bank_line_id_from = 0;
241 $bank_line_id_to = 0;
249 $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1 * (
float)
price2num($amount),
'',
'', $user);
251 if (!($bank_line_id_from > 0)) {
255 $bank_line_id_to = $accountto->addline($dateo, $typeto, $label,
price2num($amount),
'',
'', $user);
257 if (!($bank_line_id_to > 0)) {
262 $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
264 if (!($result > 0)) {
268 $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
270 if (!($result > 0)) {
275 $subject = $societeName.
' - [NOTIFICATION] Stripe payout done';
276 if (!empty($user->email)) {
287 $message =
"A bank transfer of ".price2num($event->data->object->amount / 100).
" ".$event->data->object->currency.
" has been done to your account the ".
dol_print_date($event->data->object->arrival_date,
'dayhour');
303 $ret = $mailfile->sendfile();
308 http_response_code(500);
311} elseif ($event->type ==
'customer.source.created') {
313} elseif ($event->type ==
'customer.source.updated') {
315} elseif ($event->type ==
'customer.source.delete') {
317} elseif ($event->type ==
'customer.deleted') {
320 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_account WHERE key_account = '".$db->escape($event->data->object->id).
"' and site='stripe'";
323} elseif ($event->type ==
'payment_intent.succeeded') {
327 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
328 global $stripearrayofkeysbyenv;
330 $object = $event->data->object;
332 $ipaddress =
$object->metadata->ipaddress;
334 $currencyCodeType = strtoupper(
$object->currency);
335 $paymentmethodstripeid =
$object->payment_method;
336 $customer_id =
$object->customer;
338 $paymentTypeCode =
"";
339 $paymentTypeCodeInDolibarr =
"";
341 $payment_amountInDolibarr = 0;
343 dol_syslog(
"Try to find a payment in database for the payment_intent id = ".$TRANSACTIONID);
345 $sql =
"SELECT pi.rowid, pi.fk_facture, pi.fk_prelevement_bons, pi.amount, pi.type, pi.traite";
346 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pi";
347 $sql .=
" WHERE pi.ext_payment_id = '".$db->escape($TRANSACTIONID).
"'";
348 $sql .=
" AND pi.ext_payment_site = '".$db->escape($service).
"'";
350 $result = $db->query($sql);
352 $obj = $db->fetch_object($result);
354 if ($obj->type ==
'ban') {
355 if ($obj->traite == 1) {
359 $invoice_id = $obj->fk_facture;
360 $directdebitorcreditransfer_id = $obj->fk_prelevement_bons;
361 $payment_amountInDolibarr = $obj->amount;
362 $paymentTypeCodeInDolibarr = $obj->type;
364 dol_syslog(
"Found a request in database to pay with direct debit generated (pdid = ".$pdid.
" directdebitorcreditransfer_id=".$directdebitorcreditransfer_id.
")");
366 dol_syslog(
"Found a request in database not yet generated (pdid = ".$pdid.
" directdebitorcreditransfer_id=".$directdebitorcreditransfer_id.
"). Was the order deleted after being sent ?", LOG_WARNING);
369 if ($obj->type ==
'card' || empty($obj->type)) {
370 if ($obj->traite == 0) {
373 $invoice_id = $obj->fk_facture;
374 $payment_amountInDolibarr = $obj->amount;
375 $paymentTypeCodeInDolibarr = empty($obj->type) ?
'card' : $obj->type;
377 dol_syslog(
"Found a request in database to pay with card (pdid = ".$pdid.
"). We should fix status traite to 1");
379 dol_syslog(
"Found a request in database to pay with card (pdid = ".$pdid.
") already set to traite=1. Nothing to fix.");
383 dol_syslog(
"Payment intent ".$TRANSACTIONID.
" not found into database, so ignored.");
384 http_response_code(200);
385 print
"Payment intent ".$TRANSACTIONID.
" not found into database, so ignored.";
389 http_response_code(500);
390 print $db->lasterror();
394 if ($paymentTypeCodeInDolibarr) {
397 $stripeacc = $stripearrayofkeysbyenv[$servicestatus][
'secret_key'];
399 dol_syslog(
"Get the Stripe payment object for the payment method id = ".json_encode($paymentmethodstripeid));
401 $s = new \Stripe\StripeClient($stripeacc);
403 $paymentmethodstripe = $s->paymentMethods->retrieve($paymentmethodstripeid);
404 $paymentTypeCode = $paymentmethodstripe->type;
405 if ($paymentTypeCode ==
"ban" || $paymentTypeCode ==
"sepa_debit") {
406 $paymentTypeCode =
"PRE";
407 } elseif ($paymentTypeCode ==
"card") {
408 $paymentTypeCode =
"CB";
411 $payment_amount = $payment_amountInDolibarr;
414 $postactionmessages = array();
416 if ($paymentTypeCode ==
"CB" && ($paymentTypeCodeInDolibarr ==
'card' || empty($paymentTypeCodeInDolibarr))) {
422 } elseif ($paymentTypeCode ==
"PRE" && $paymentTypeCodeInDolibarr ==
'ban') {
427 $paiement->datepaye = $now;
428 $paiement->date = $now;
429 if ($currencyCodeType == $conf->currency) {
430 $paiement->amounts = [$invoice_id => $payment_amount];
432 $paiement->multicurrency_amounts = [$invoice_id => $payment_amount];
434 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.$conf->currency.
')';
435 $ispostactionok = -1;
441 $paiement->paiementcode = $paymentTypeCode;
442 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
443 $sql .=
" WHERE code = '".$db->escape($paymentTypeCode).
"'";
444 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
445 $resql = $db->query($sql);
447 $obj = $db->fetch_object($resql);
448 $paiement->paiementid = $obj->id;
453 $paiement->num_payment =
'';
454 $paiement->note_public =
'';
455 $paiement->note_private =
'StripeSepa payment received by IPN webhook - ' .
dol_print_date($now,
'standard') .
' (TZ server) using servicestatus=' . $servicestatus . ($ipaddress ?
' from ip ' . $ipaddress :
'') .
' - Transaction ID = ' . $TRANSACTIONID;
456 $paiement->ext_payment_id = $TRANSACTIONID.
':'.$customer_id.
'@'.$stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
457 $paiement->ext_payment_site = $service;
460 $sql =
"SELECT p.rowid FROM ".MAIN_DB_PREFIX.
"paiement as p";
461 $sql .=
" WHERE p.ext_payment_id = '".$db->escape($paiement->ext_payment_id).
"'";
462 $sql .=
" AND p.ext_payment_site = '".$db->escape($paiement->ext_payment_site).
"'";
463 $result = $db->query($sql);
465 if ($db->num_rows($result)) {
467 dol_syslog(
'* Payment for ext_payment_id '.$paiement->ext_payment_id.
' already done. We do not recreate the payment');
473 if (!$error && !$ispaymentdone) {
474 dol_syslog(
'* Record payment type PRE for invoice id ' . $invoice_id .
'. It includes closing of invoice and regenerating document.');
477 $paiement_id = $paiement->create($user, 1);
478 if ($paiement_id < 0) {
479 $postactionmessages[] = $paiement->error . ($paiement->error ?
' ' :
'') . implode(
"<br>\n", $paiement->errors);
480 $ispostactionok = -1;
483 dol_syslog(
"Failed to create the payment for invoice id " . $invoice_id);
485 $postactionmessages[] =
'Payment created';
487 dol_syslog(
"The payment has been created for invoice id " . $invoice_id);
491 if (!$error && isModEnabled(
'bank')) {
494 $sql =
"SELECT p.rowid, p.fk_bank FROM ".MAIN_DB_PREFIX.
"paiement as p";
495 $sql .=
" WHERE p.ext_payment_id = '".$db->escape($paiement->ext_payment_id).
"'";
496 $sql .=
" AND p.ext_payment_site = '".$db->escape($paiement->ext_payment_site).
"'";
497 $sql .=
" AND p.fk_bank <> 0";
498 $result = $db->query($sql);
500 if ($db->num_rows($result)) {
502 $obj = $db->fetch_object($result);
503 dol_syslog(
'* Payment already linked to bank record '.$obj->fk_bank.
' . We do not recreate the link');
506 if (!$ispaymentdone) {
510 $paymentmethod =
'stripe';
513 if ($bankaccountid > 0) {
514 $label =
'(CustomerInvoicePayment)';
515 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid, $customer_id,
'');
517 $postactionmessages[] = $paiement->error . ($paiement->error ?
' ' :
'') . implode(
"<br>\n", $paiement->errors);
518 $ispostactionok = -1;
521 $postactionmessages[] =
'Bank transaction of payment created (by ipn.php file)';
524 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
525 $ispostactionok = -1;
531 if (!$error && isModEnabled(
'prelevement')) {
534 $sql =
"SELECT dp.fk_prelevement_bons as idbon";
535 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as dp";
536 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"prelevement_bons as pb";
537 $sql .=
" ON pb.rowid = dp.fk_prelevement_bons";
538 $sql .=
" WHERE dp.fk_facture = ".((int) $invoice_id);
539 $sql .=
" AND dp.sourcetype = 'facture'";
540 $sql .=
" AND dp.ext_payment_id = '".$db->escape($TRANSACTIONID).
"'";
541 $sql .=
" AND dp.traite = 1";
542 $sql .=
" AND statut = ".((int) $bon::STATUS_TRANSFERED);
543 $result = $db->query($sql);
545 if ($db->num_rows($result)) {
546 $obj = $db->fetch_object($result);
547 $idbon = $obj->idbon;
548 dol_syslog(
'* Prelevement must be set to credited');
550 dol_syslog(
'* Prelevement not found or already credited');
553 $postactionmessages[] = $db->lasterror();
554 $ispostactionok = -1;
558 if (!$error && !empty($idbon)) {
559 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons";
560 $sql .=
" SET fk_user_credit = ".((int) $user->id);
561 $sql .=
", statut = ".((int) $bon::STATUS_CREDITED);
562 $sql .=
", date_credit = '".$db->idate($now).
"'";
563 $sql .=
", credite = 1";
564 $sql .=
" WHERE rowid = ".((int) $idbon);
565 $sql .=
" AND statut = ".((int) $bon::STATUS_TRANSFERED);
567 $result = $db->query($sql);
569 $postactionmessages[] = $db->lasterror();
570 $ispostactionok = -1;
575 if (!$error && !empty($idbon)) {
576 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes";
577 $sql .=
" SET statut = 2";
578 $sql .=
" WHERE fk_prelevement_bons = ".((int) $idbon);
579 $result = $db->query($sql);
581 $postactionmessages[] = $db->lasterror();
582 $ispostactionok = -1;
590 http_response_code(200);
594 http_response_code(500);
598 dol_syslog(
"The payment mode of this payment is ".$paymentTypeCode.
" in Stripe and ".$paymentTypeCodeInDolibarr.
" in Dolibarr. This case is not managed by the IPN");
601 dol_syslog(
"Nothing to do in database because we don't know paymentTypeIdInDolibarr");
603} elseif ($event->type ==
'payment_intent.payment_failed') {
605 dol_syslog(
"A try to make a payment has failed");
607 $object = $event->data->object;
608 $ipaddress =
$object->metadata->ipaddress;
609 $currencyCodeType = strtoupper(
$object->currency);
610 $paymentmethodstripeid =
$object->payment_method;
611 $customer_id =
$object->customer;
613 $chargesdataarray = array();
619 $objpaymentmodetype =
'';
620 if (!empty(
$object->charges)) {
621 $chargesdataarray =
$object->charges->data;
622 foreach ($chargesdataarray as $chargesdata) {
623 $objpayid = $chargesdata->id;
624 $objpaydesc = $chargesdata->description;
626 if ($chargesdata->metadata->dol_type ==
'facture') {
627 $objinvoiceid = $chargesdata->metadata->dol_id;
629 $objerrcode = $chargesdata->outcome->reason;
630 $objerrmessage = $chargesdata->outcome->seller_message;
632 $objpaymentmodetype = $chargesdata->payment_method_details->type;
636 if (!empty(
$object->last_payment_error)) {
638 $objpayid =
$object->latest_charge;
639 $objpaydesc =
$object->description;
641 if (
$object->metadata->dol_type ==
'facture') {
642 $objinvoiceid =
$object->metadata->dol_id;
644 $objerrcode = empty(
$object->last_payment_error->code) ?
$object->last_payment_error->decline_code :
$object->last_payment_error->code;
645 $objerrmessage =
$object->last_payment_error->message;
647 $objpaymentmodetype =
$object->last_payment_error->payment_method->type;
650 dol_syslog(
"objpayid=".$objpayid.
" objpaymentmodetype=".$objpaymentmodetype.
" objerrcode=".$objerrcode);
653 if ($objpaymentmodetype ==
'sepa_debit') {
656 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
659 if ($objinvoiceid > 0) {
660 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
662 $invoice->fetch($objinvoiceid);
664 $actioncomm->userownerid = 0;
665 $actioncomm->percentage = -1;
667 $actioncomm->type_code =
'AC_OTH_AUTO';
668 $actioncomm->code =
'AC_IPN';
670 $actioncomm->datep = $now;
671 $actioncomm->datef = $now;
673 $actioncomm->socid = $invoice->socid;
674 $actioncomm->fk_project = $invoice->fk_project;
675 $actioncomm->fk_element = $invoice->id;
676 $actioncomm->elementtype =
'invoice';
680 $actioncomm->note_private =
'Error returned on payment id '.$objpayid.
' after SEPA payment request '.$objpaydesc.
'<br>Error code is: '.$objerrcode.
'<br>Error message is: '.$objerrmessage;
681 $actioncomm->label =
'Payment error (SEPA Stripe)';
683 $result = $actioncomm->create($user);
693 http_response_code(500);
697} elseif ($event->type ==
'checkout.session.completed') {
699} elseif ($event->type ==
'payment_method.attached') {
701 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
702 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societeaccount.class.php';
707 $idthirdparty = $societeaccount->getThirdPartyID($db->escape($event->data->object->customer),
'stripe', $servicestatus);
708 if ($idthirdparty > 0) {
711 $companypaymentmode->stripe_card_ref = $db->escape($event->data->object->id);
712 $companypaymentmode->fk_soc = $idthirdparty;
713 $companypaymentmode->bank =
null;
714 $companypaymentmode->label =
'';
715 $companypaymentmode->number = $db->escape($event->data->object->id);
716 $companypaymentmode->last_four = $db->escape($event->data->object->card->last4);
717 $companypaymentmode->card_type = $db->escape($event->data->object->card->branding);
718 $companypaymentmode->proprio = $db->escape($event->data->object->billing_details->name);
719 $companypaymentmode->exp_date_month = $db->escape($event->data->object->card->exp_month);
720 $companypaymentmode->exp_date_year = $db->escape($event->data->object->card->exp_year);
721 $companypaymentmode->cvn =
null;
722 $companypaymentmode->datec = $db->escape($event->data->object->created);
723 $companypaymentmode->default_rib = 0;
724 $companypaymentmode->type = $db->escape($event->data->object->type);
725 $companypaymentmode->country_code = $db->escape($event->data->object->card->country);
726 $companypaymentmode->status = $servicestatus;
732 $result = $companypaymentmode->create($user);
740 http_response_code(500);
745} elseif ($event->type ==
'payment_method.updated') {
747 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
749 $companypaymentmode->fetch(0,
'', 0,
'',
" AND stripe_card_ref = '".$db->escape($event->data->object->id).
"'");
750 if ($companypaymentmode->id > 0) {
752 $companypaymentmode->bank =
null;
753 $companypaymentmode->label =
'';
754 $companypaymentmode->number = $db->escape($event->data->object->id);
755 $companypaymentmode->last_four = $db->escape($event->data->object->card->last4);
756 $companypaymentmode->proprio = $db->escape($event->data->object->billing_details->name);
757 $companypaymentmode->exp_date_month = $db->escape($event->data->object->card->exp_month);
758 $companypaymentmode->exp_date_year = $db->escape($event->data->object->card->exp_year);
759 $companypaymentmode->cvn =
null;
760 $companypaymentmode->datec = $db->escape($event->data->object->created);
761 $companypaymentmode->default_rib = 0;
762 $companypaymentmode->type = $db->escape($event->data->object->type);
763 $companypaymentmode->country_code = $db->escape($event->data->object->card->country);
764 $companypaymentmode->status = $servicestatus;
768 $result = $companypaymentmode->update($user);
779} elseif ($event->type ==
'payment_method.detached') {
782 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE number = '".$db->escape($event->data->object->id).
"' and status = ".((int) $servicestatus);
785} elseif ($event->type ==
'charge.succeeded') {
787} elseif ($event->type ==
'charge.failed') {
789} elseif (($event->type ==
'source.chargeable') && ($event->data->object->type ==
'three_d_secure') && ($event->data->object->three_d_secure->authenticated ==
true)) {
791} elseif ($event->type ==
'charge.dispute.closed') {
793 dol_syslog(
"object = ".var_export($event->data,
true));
794} elseif ($event->type ==
'charge.dispute.funds_withdrawn') {
796 dol_syslog(
"object = ".var_export($event->data,
true));
798 global $stripearrayofkeysbyenv;
801 $object = $event->data->object;
802 $TRANSACTIONID =
$object->payment_intent;
803 $ipaddress =
$object->metadata->ipaddress;
805 $currencyCodeType = strtoupper(
$object->currency);
806 $paymentmethodstripeid =
$object->payment_method;
807 $customer_id =
$object->customer;
809 $amountdisputestripe =
$object->amoutndispute;
810 $amountdispute = $amountdisputestripe;
813 $paymentTypeCode =
"";
814 $paymentTypeCodeInDolibarr =
"";
816 $payment_amountInDolibarr = 0;
818 dol_syslog(
"Try to find the payment in database for the payment_intent id = ".$TRANSACTIONID);
820 $sql =
"SELECT pi.rowid, pi.fk_facture, pi.fk_prelevement_bons, pi.amount, pi.type, pi.traite";
821 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pi";
822 $sql .=
" WHERE pi.ext_payment_id = '".$db->escape($TRANSACTIONID).
"'";
823 $sql .=
" AND pi.ext_payment_site = '".$db->escape($service).
"'";
825 $result = $db->query($sql);
827 $obj = $db->fetch_object($result);
829 if ($obj->type ==
'ban') {
832 $invoice_id = $obj->fk_facture;
833 $directdebitorcreditransfer_id = $obj->fk_prelevement_bons;
834 $payment_amountInDolibarr = $obj->amount;
835 $paymentTypeCodeInDolibarr = $obj->type;
837 dol_syslog(
"Found the payment intent for ban in database (pdid = ".$pdid.
" directdebitorcreditransfer_id=".$directdebitorcreditransfer_id.
")");
839 if ($obj->type ==
'card' || empty($obj->type)) {
842 $invoice_id = $obj->fk_facture;
843 $payment_amountInDolibarr = $obj->amount;
844 $paymentTypeCodeInDolibarr = empty($obj->type) ?
'card' : $obj->type;
846 dol_syslog(
"Found the payment intent for card in database (pdid = ".$pdid.
" directdebitorcreditransfer_id=".$directdebitorcreditransfer_id.
")");
849 dol_syslog(
"Payment intent ".$TRANSACTIONID.
" not found into database, so ignored.");
850 http_response_code(200);
851 print
"Payment intent ".$TRANSACTIONID.
" not found into database, so ignored.";
855 http_response_code(500);
856 print $db->lasterror();
861 $tmpinvoice =
new Facture($db);
862 $tmpinvoice->fetch($invoice_id);
863 $tmpinvoice->fetch_thirdparty();
865 dol_syslog(
"The payment disputed is ".$amountdispute.
" and the invoice is ".$payment_amountInDolibarr);
867 if ($amountdispute != $payment_amountInDolibarr) {
868 http_response_code(500);
869 print
"The payment disputed is ".$amountdispute.
" and the invoice is ".$payment_amountInDolibarr.
". Amount differs, we don't know what to do.";
873 $accountfrom =
new Account($db);
874 $accountfrom->fetch(
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'));
880 $amounts[$tmpinvoice->id] = -1 * $payment_amountInDolibarr;
882 $paiement->datepaye =
dol_now();
883 $paiement->amounts = $amounts;
888 $paiement->paiementid =
dol_getIdFromCode($db,
'PRE',
'c_paiement',
'code',
'id', 1);
889 $paiement->num_payment =
$object->id;
890 $paiement->note_public =
'Fund withdrawn by bank. Reason: '.$reason;
891 $paiement->note_private =
'';
892 $paiement->fk_account = $accountfrom->id;
896 $alreadytransferedinaccounting = $tmpinvoice->getVentilExportCompta();
898 if ($alreadytransferedinaccounting) {
901 $errormsg =
'Error: the invoice '.$tmpinvoice->id.
' is already transferred into accounting. Don\'t know what to do.';
909 $errormsg = $tmpinvoice->error.implode(
', ', $tmpinvoice->errors);
915 $paiement_id = $paiement->create($user, 0, $tmpinvoice->thirdparty);
916 if ($paiement_id < 0) {
917 $errormsg = $paiement->error.implode(
', ', $paiement->errors);
925 http_response_code(500);
929 http_response_code(500);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Class to manage bank accounts.
Class to manage agenda events (actions)
Class to manage withdrawal receipts.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class for CompanyPaymentMode.
Class to manage invoices.
const STATUS_VALIDATED
Validated (need to be paid)
const STATUS_CLOSED
Classified paid.
Class to manage payments of customer invoices.
Class for SocieteAccount.
Stripe class @TODO No reason to extends CommonObject.
Class to manage Dolibarr users.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.