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';
66if (GETPOSTISSET(
'connect')) {
67 if (GETPOSTISSET(
'test')) {
69 $service =
'StripeTest';
73 $service =
'StripeLive';
77 if (GETPOSTISSET(
'test')) {
79 $service =
'StripeTest';
83 $service =
'StripeLive';
88if (!isModEnabled(
'stripe')) {
92if (empty($endpoint_secret)) {
98 $user =
new User($db);
115$payload = @file_get_contents(
"php://input");
116$sig_header = empty($_SERVER[
"HTTP_STRIPE_SIGNATURE"]) ?
'' : $_SERVER[
"HTTP_STRIPE_SIGNATURE"];
120 $fh = fopen(DOL_DATA_ROOT.
'/dolibarr_stripeipn_payload.log',
'w+');
122 fwrite($fh,
dol_print_date(
dol_now(
'gmt'),
'standard').
' IPN Called. service='.$service.
' HTTP_STRIPE_SIGNATURE='.$sig_header.
"\n");
123 fwrite($fh, $payload);
125 dolChmod(DOL_DATA_ROOT.
'/dolibarr_stripeipn_payload.log');
132 $event = \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret);
133}
catch (UnexpectedValueException $e) {
137 httponly_accessforbidden(
'Invalid signature. May be a hook for an event created by another Stripe env ? Check setup of your keys whsec_...', 400);
147if (isModEnabled(
'multicompany') && !empty(
$conf->stripeconnect->enabled) && is_object($mc)) {
148 $sql =
"SELECT entity";
149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"oauth_token";
150 $sql .=
" WHERE service = '".$db->escape($service).
"' and tokenstring LIKE '%".$db->escape($db->escapeforlike($event->account)).
"%'";
152 dol_syslog(get_class($db).
"::fetch", LOG_DEBUG);
153 $result = $db->query($sql);
155 if ($db->num_rows($result)) {
156 $obj = $db->fetch_object($result);
164 $ret = $mc->switchEntity($key);
178dol_syslog(
"***** Stripe IPN was called with event->type=".$event->type.
" service=".$service);
181if ($event->type ==
'payout.created') {
185 $result =
dolibarr_set_const($db, $service.
"_NEXTPAYOUT", date(
'Y-m-d H:i:s', $event->data->object->arrival_date),
'chaine', 0,
'',
$conf->entity);
188 $subject = $societeName.
' - [NOTIFICATION] Stripe payout scheduled';
189 if (!empty($user->email)) {
200 $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');
216 $ret = $mailfile->sendfile();
221 http_response_code(500);
224} elseif ($event->type ==
'payout.paid') {
229 $langs->load(
"errors");
232 $label = $event->data->object->description;
233 $amount = $event->data->object->amount / 100;
234 $amount_to = $event->data->object->amount / 100;
235 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
237 $accountfrom =
new Account($db);
238 $accountfrom->fetch(
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'));
241 $accountto->fetch(
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS'));
243 if (($accountto->id != $accountfrom->id) && empty($error)) {
244 $bank_line_id_from = 0;
245 $bank_line_id_to = 0;
253 $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1 * (
float)
price2num($amount),
'',
'', $user);
255 if (!($bank_line_id_from > 0)) {
259 $bank_line_id_to = $accountto->addline($dateo, $typeto, $label,
price2num($amount),
'',
'', $user);
261 if (!($bank_line_id_to > 0)) {
266 $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
268 if (!($result > 0)) {
272 $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.
'/compta/bank/line.php?rowid=',
'(banktransfert)',
'banktransfert');
274 if (!($result > 0)) {
279 $subject = $societeName.
' - [NOTIFICATION] Stripe payout done';
280 if (!empty($user->email)) {
291 $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');
307 $ret = $mailfile->sendfile();
312 http_response_code(500);
315} elseif ($event->type ==
'customer.source.created') {
317} elseif ($event->type ==
'customer.source.updated') {
319} elseif ($event->type ==
'customer.source.delete') {
321} elseif ($event->type ==
'customer.deleted') {
324 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_account WHERE key_account = '".$db->escape($event->data->object->id).
"' and site='stripe'";
327} elseif ($event->type ==
'payment_intent.succeeded') {
331 include_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
332 global $stripearrayofkeysbyenv;
334 $object = $event->data->object;
336 $ipaddress =
$object->metadata->ipaddress;
338 $currencyCodeType = strtoupper(
$object->currency);
339 $paymentmethodstripeid =
$object->payment_method;
340 $customer_id =
$object->customer;
342 $paymentTypeCode =
"";
343 $paymentTypeCodeInDolibarr =
"";
345 $payment_amountInDolibarr = 0;
347 dol_syslog(
"Try to find a payment in database for the payment_intent id = ".$TRANSACTIONID);
349 $sql =
"SELECT pi.rowid, pi.fk_facture, pi.fk_prelevement_bons, pi.amount, pi.type, pi.traite";
350 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pi";
351 $sql .=
" WHERE pi.ext_payment_id = '".$db->escape($TRANSACTIONID).
"'";
352 $sql .=
" AND pi.ext_payment_site = '".$db->escape($service).
"'";
354 $result = $db->query($sql);
356 $obj = $db->fetch_object($result);
358 if ($obj->type ==
'ban') {
359 if ($obj->traite == 1) {
363 $invoice_id = $obj->fk_facture;
364 $directdebitorcreditransfer_id = $obj->fk_prelevement_bons;
365 $payment_amountInDolibarr = $obj->amount;
366 $paymentTypeCodeInDolibarr = $obj->type;
368 dol_syslog(
"Found a request in database to pay with direct debit generated (pdid = ".$pdid.
" directdebitorcreditransfer_id=".$directdebitorcreditransfer_id.
")");
370 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);
373 if ($obj->type ==
'card' || empty($obj->type)) {
374 if ($obj->traite == 0) {
377 $invoice_id = $obj->fk_facture;
378 $payment_amountInDolibarr = $obj->amount;
379 $paymentTypeCodeInDolibarr = empty($obj->type) ?
'card' : $obj->type;
381 dol_syslog(
"Found a request in database to pay with card (pdid = ".$pdid.
"). We should fix status traite to 1");
383 dol_syslog(
"Found a request in database to pay with card (pdid = ".$pdid.
") already set to traite=1. Nothing to fix.");
387 dol_syslog(
"Payment intent ".$TRANSACTIONID.
" not found into database, so ignored.");
388 http_response_code(200);
389 print
"Payment intent ".$TRANSACTIONID.
" not found into database, so ignored.";
393 http_response_code(500);
394 print $db->lasterror();
398 if ($paymentTypeCodeInDolibarr) {
401 $stripeacc = $stripearrayofkeysbyenv[$servicestatus][
'secret_key'];
403 dol_syslog(
"Get the Stripe payment object for the payment method id = ".json_encode($paymentmethodstripeid));
405 $s = new \Stripe\StripeClient($stripeacc);
407 $paymentmethodstripe = $s->paymentMethods->retrieve($paymentmethodstripeid);
408 $paymentTypeCode = $paymentmethodstripe->type;
409 if ($paymentTypeCode ==
"ban" || $paymentTypeCode ==
"sepa_debit") {
410 $paymentTypeCode =
"PRE";
411 } elseif ($paymentTypeCode ==
"card") {
412 $paymentTypeCode =
"CB";
415 $payment_amount = $payment_amountInDolibarr;
418 $postactionmessages = array();
420 if ($paymentTypeCode ==
"CB" && ($paymentTypeCodeInDolibarr ==
'card' || empty($paymentTypeCodeInDolibarr))) {
426 } elseif ($paymentTypeCode ==
"PRE" && $paymentTypeCodeInDolibarr ==
'ban') {
431 $paiement->datepaye = $now;
432 $paiement->date = $now;
433 if ($currencyCodeType ==
$conf->currency) {
434 $paiement->amounts = [$invoice_id => $payment_amount];
436 $paiement->multicurrency_amounts = [$invoice_id => $payment_amount];
438 $postactionmessages[] =
'Payment was done in a currency ('.$currencyCodeType.
') other than the expected currency of company ('.
$conf->currency.
')';
439 $ispostactionok = -1;
445 $paiement->paiementcode = $paymentTypeCode;
446 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement";
447 $sql .=
" WHERE code = '".$db->escape($paymentTypeCode).
"'";
448 $sql .=
" AND entity IN (".getEntity(
'c_paiement').
")";
449 $resql = $db->query($sql);
451 $obj = $db->fetch_object($resql);
452 $paiement->paiementid = $obj->id;
457 $paiement->num_payment =
'';
458 $paiement->note_public =
'';
459 $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;
460 $paiement->ext_payment_id = $TRANSACTIONID.
':'.$customer_id.
'@'.$stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
461 $paiement->ext_payment_site = $service;
464 $sql =
"SELECT p.rowid FROM ".MAIN_DB_PREFIX.
"paiement as p";
465 $sql .=
" WHERE p.ext_payment_id = '".$db->escape($paiement->ext_payment_id).
"'";
466 $sql .=
" AND p.ext_payment_site = '".$db->escape($paiement->ext_payment_site).
"'";
467 $result = $db->query($sql);
469 if ($db->num_rows($result)) {
471 dol_syslog(
'* Payment for ext_payment_id '.$paiement->ext_payment_id.
' already done. We do not recreate the payment');
477 if (!$error && !$ispaymentdone) {
478 dol_syslog(
'* Record payment type PRE for invoice id ' . $invoice_id .
'. It includes closing of invoice and regenerating document.');
481 $paiement_id = $paiement->create($user, 1);
482 if ($paiement_id < 0) {
483 $postactionmessages[] = $paiement->error . ($paiement->error ?
' ' :
'') . implode(
"<br>\n", $paiement->errors);
484 $ispostactionok = -1;
487 dol_syslog(
"Failed to create the payment for invoice id " . $invoice_id);
489 $postactionmessages[] =
'Payment created';
491 dol_syslog(
"The payment has been created for invoice id " . $invoice_id);
495 if (!$error && isModEnabled(
'bank')) {
498 $sql =
"SELECT p.rowid, p.fk_bank FROM ".MAIN_DB_PREFIX.
"paiement as p";
499 $sql .=
" WHERE p.ext_payment_id = '".$db->escape($paiement->ext_payment_id).
"'";
500 $sql .=
" AND p.ext_payment_site = '".$db->escape($paiement->ext_payment_site).
"'";
501 $sql .=
" AND p.fk_bank <> 0";
502 $result = $db->query($sql);
504 if ($db->num_rows($result)) {
506 $obj = $db->fetch_object($result);
507 dol_syslog(
'* Payment already linked to bank record '.$obj->fk_bank.
' . We do not recreate the link');
510 if (!$ispaymentdone) {
514 $paymentmethod =
'stripe';
517 if ($bankaccountid > 0) {
518 $label =
'(CustomerInvoicePayment)';
519 $result = $paiement->addPaymentToBank($user,
'payment', $label, $bankaccountid, $customer_id,
'');
521 $postactionmessages[] = $paiement->error . ($paiement->error ?
' ' :
'') . implode(
"<br>\n", $paiement->errors);
522 $ispostactionok = -1;
525 $postactionmessages[] =
'Bank transaction of payment created (by ipn.php file)';
528 $postactionmessages[] =
'Setup of bank account to use in module ' . $paymentmethod .
' was not set. No way to record the payment.';
529 $ispostactionok = -1;
535 if (!$error && isModEnabled(
'prelevement')) {
538 $sql =
"SELECT dp.fk_prelevement_bons as idbon";
539 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as dp";
540 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"prelevement_bons as pb";
541 $sql .=
" ON pb.rowid = dp.fk_prelevement_bons";
542 $sql .=
" WHERE dp.fk_facture = ".((int) $invoice_id);
543 $sql .=
" AND dp.sourcetype = 'facture'";
544 $sql .=
" AND dp.ext_payment_id = '".$db->escape($TRANSACTIONID).
"'";
545 $sql .=
" AND dp.traite = 1";
546 $sql .=
" AND statut = ".((int) $bon::STATUS_TRANSFERED);
547 $result = $db->query($sql);
549 if ($db->num_rows($result)) {
550 $obj = $db->fetch_object($result);
551 $idbon = $obj->idbon;
552 dol_syslog(
'* Prelevement must be set to credited');
554 dol_syslog(
'* Prelevement not found or already credited');
557 $postactionmessages[] = $db->lasterror();
558 $ispostactionok = -1;
562 if (!$error && !empty($idbon)) {
563 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons";
564 $sql .=
" SET fk_user_credit = ".((int) $user->id);
565 $sql .=
", statut = ".((int) $bon::STATUS_CREDITED);
566 $sql .=
", date_credit = '".$db->idate($now).
"'";
567 $sql .=
", credite = 1";
568 $sql .=
" WHERE rowid = ".((int) $idbon);
569 $sql .=
" AND statut = ".((int) $bon::STATUS_TRANSFERED);
571 $result = $db->query($sql);
573 $postactionmessages[] = $db->lasterror();
574 $ispostactionok = -1;
579 if (!$error && !empty($idbon)) {
580 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes";
581 $sql .=
" SET statut = 2";
582 $sql .=
" WHERE fk_prelevement_bons = ".((int) $idbon);
583 $result = $db->query($sql);
585 $postactionmessages[] = $db->lasterror();
586 $ispostactionok = -1;
594 http_response_code(200);
598 http_response_code(500);
602 dol_syslog(
"The payment mode of this payment is ".$paymentTypeCode.
" in Stripe and ".$paymentTypeCodeInDolibarr.
" in Dolibarr. This case is not managed by the IPN");
605 dol_syslog(
"Nothing to do in database because we don't know paymentTypeIdInDolibarr");
607} elseif ($event->type ==
'payment_intent.payment_failed') {
609 dol_syslog(
"A try to make a payment has failed");
611 $object = $event->data->object;
612 $ipaddress =
$object->metadata->ipaddress;
613 $currencyCodeType = strtoupper(
$object->currency);
614 $paymentmethodstripeid =
$object->payment_method;
615 $customer_id =
$object->customer;
617 $chargesdataarray = array();
623 $objpaymentmodetype =
'';
624 if (!empty(
$object->charges)) {
625 $chargesdataarray =
$object->charges->data;
626 foreach ($chargesdataarray as $chargesdata) {
627 $objpayid = $chargesdata->id;
628 $objpaydesc = $chargesdata->description;
630 if ($chargesdata->metadata->dol_type ==
'facture') {
631 $objinvoiceid = $chargesdata->metadata->dol_id;
633 $objerrcode = $chargesdata->outcome->reason;
634 $objerrmessage = $chargesdata->outcome->seller_message;
636 $objpaymentmodetype = $chargesdata->payment_method_details->type;
640 if (!empty(
$object->last_payment_error)) {
642 $objpayid =
$object->latest_charge;
643 $objpaydesc =
$object->description;
645 if (
$object->metadata->dol_type ==
'facture') {
646 $objinvoiceid =
$object->metadata->dol_id;
648 $objerrcode = empty(
$object->last_payment_error->code) ?
$object->last_payment_error->decline_code :
$object->last_payment_error->code;
649 $objerrmessage =
$object->last_payment_error->message;
651 $objpaymentmodetype =
$object->last_payment_error->payment_method->type;
654 dol_syslog(
"objpayid=".$objpayid.
" objpaymentmodetype=".$objpaymentmodetype.
" objerrcode=".$objerrcode);
657 if ($objpaymentmodetype ==
'sepa_debit') {
660 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
663 if ($objinvoiceid > 0) {
664 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
666 $invoice->fetch($objinvoiceid);
668 $actioncomm->userownerid = 0;
669 $actioncomm->percentage = -1;
671 $actioncomm->type_code =
'AC_OTH_AUTO';
672 $actioncomm->code =
'AC_IPN';
674 $actioncomm->datep = $now;
675 $actioncomm->datef = $now;
677 $actioncomm->socid = $invoice->socid;
678 $actioncomm->fk_project = $invoice->fk_project;
679 $actioncomm->fk_element = $invoice->id;
680 $actioncomm->elementtype =
'invoice';
684 $actioncomm->note_private =
'Error returned on payment id '.$objpayid.
' after SEPA payment request '.$objpaydesc.
'<br>Error code is: '.$objerrcode.
'<br>Error message is: '.$objerrmessage;
685 $actioncomm->label =
'Payment error (SEPA Stripe)';
687 $result = $actioncomm->create($user);
697 http_response_code(500);
701} elseif ($event->type ==
'checkout.session.completed') {
703} elseif ($event->type ==
'payment_method.attached') {
705 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
706 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societeaccount.class.php';
711 $idthirdparty = $societeaccount->getThirdPartyID($db->escape($event->data->object->customer),
'stripe', $servicestatus);
712 if ($idthirdparty > 0) {
715 $companypaymentmode->stripe_card_ref = $event->data->object->id;
716 $companypaymentmode->fk_soc = $idthirdparty;
717 $companypaymentmode->bank =
null;
718 $companypaymentmode->label =
'';
719 $companypaymentmode->number = $event->data->object->id;
720 $companypaymentmode->last_four = $event->data->object->card->last4;
721 $companypaymentmode->card_type = $event->data->object->card->branding;
723 $companypaymentmode->owner_name = $event->data->object->billing_details->name;
724 $companypaymentmode->proprio = $companypaymentmode->owner_name;
726 $companypaymentmode->exp_date_month = (int) $event->data->object->card->exp_month;
727 $companypaymentmode->exp_date_year = (int) $event->data->object->card->exp_year;
728 $companypaymentmode->cvn =
null;
729 $companypaymentmode->datec = $event->data->object->created;
730 $companypaymentmode->default_rib = 0;
731 $companypaymentmode->type = $event->data->object->type;
732 $companypaymentmode->country_code = $event->data->object->card->country;
733 $companypaymentmode->status = $servicestatus;
739 $result = $companypaymentmode->create($user);
747 http_response_code(500);
752} elseif ($event->type ==
'payment_method.updated') {
754 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
756 $companypaymentmode->fetch(0,
'', 0,
'',
" AND stripe_card_ref = '".$db->escape($event->data->object->id).
"'");
757 if ($companypaymentmode->id > 0) {
759 $companypaymentmode->bank =
null;
760 $companypaymentmode->label =
'';
761 $companypaymentmode->number = $db->escape($event->data->object->id);
762 $companypaymentmode->last_four = $db->escape($event->data->object->card->last4);
763 $companypaymentmode->proprio = $db->escape($event->data->object->billing_details->name);
764 $companypaymentmode->exp_date_month = (int) $event->data->object->card->exp_month;
765 $companypaymentmode->exp_date_year = (int) $event->data->object->card->exp_year;
766 $companypaymentmode->cvn =
null;
767 $companypaymentmode->datec = (int) $event->data->object->created;
768 $companypaymentmode->default_rib = 0;
769 $companypaymentmode->type = $db->escape($event->data->object->type);
770 $companypaymentmode->country_code = $db->escape($event->data->object->card->country);
771 $companypaymentmode->status = $servicestatus;
775 $result = $companypaymentmode->update($user);
786} elseif ($event->type ==
'payment_method.detached') {
789 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_rib WHERE number = '".$db->escape($event->data->object->id).
"' and status = ".((int) $servicestatus);
792} elseif ($event->type ==
'charge.succeeded') {
794} elseif ($event->type ==
'charge.failed') {
796} elseif (($event->type ==
'source.chargeable') && ($event->data->object->type ==
'three_d_secure') && ($event->data->object->three_d_secure->authenticated ==
true)) {
798} elseif ($event->type ==
'charge.dispute.closed') {
800 dol_syslog(
"object = ".var_export($event->data,
true));
801} elseif ($event->type ==
'charge.dispute.funds_withdrawn') {
803 dol_syslog(
"object = ".var_export($event->data,
true));
805 global $stripearrayofkeysbyenv;
808 $object = $event->data->object;
809 $TRANSACTIONID =
$object->payment_intent;
810 $ipaddress =
$object->metadata->ipaddress;
812 $currencyCodeType = strtoupper(
$object->currency);
813 $paymentmethodstripeid =
$object->payment_method;
814 $customer_id =
$object->customer;
816 $amountdisputestripe =
$object->amoutndispute;
817 $amountdispute = $amountdisputestripe;
820 $paymentTypeCode =
"";
821 $paymentTypeCodeInDolibarr =
"";
823 $payment_amountInDolibarr = 0;
825 dol_syslog(
"Try to find the payment in database for the payment_intent id = ".$TRANSACTIONID);
827 $sql =
"SELECT pi.rowid, pi.fk_facture, pi.fk_prelevement_bons, pi.amount, pi.type, pi.traite";
828 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_demande as pi";
829 $sql .=
" WHERE pi.ext_payment_id = '".$db->escape($TRANSACTIONID).
"'";
830 $sql .=
" AND pi.ext_payment_site = '".$db->escape($service).
"'";
832 $result = $db->query($sql);
834 $obj = $db->fetch_object($result);
836 if ($obj->type ==
'ban') {
839 $invoice_id = $obj->fk_facture;
840 $directdebitorcreditransfer_id = $obj->fk_prelevement_bons;
841 $payment_amountInDolibarr = $obj->amount;
842 $paymentTypeCodeInDolibarr = $obj->type;
844 dol_syslog(
"Found the payment intent for ban in database (pdid = ".$pdid.
" directdebitorcreditransfer_id=".$directdebitorcreditransfer_id.
")");
846 if ($obj->type ==
'card' || empty($obj->type)) {
849 $invoice_id = $obj->fk_facture;
850 $payment_amountInDolibarr = $obj->amount;
851 $paymentTypeCodeInDolibarr = empty($obj->type) ?
'card' : $obj->type;
853 dol_syslog(
"Found the payment intent for card in database (pdid = ".$pdid.
" directdebitorcreditransfer_id=".$directdebitorcreditransfer_id.
")");
856 dol_syslog(
"Payment intent ".$TRANSACTIONID.
" not found into database, so ignored.");
857 http_response_code(200);
858 print
"Payment intent ".$TRANSACTIONID.
" not found into database, so ignored.";
862 http_response_code(500);
863 print $db->lasterror();
868 $tmpinvoice =
new Facture($db);
869 $tmpinvoice->fetch($invoice_id);
870 $tmpinvoice->fetch_thirdparty();
872 dol_syslog(
"The payment disputed is ".$amountdispute.
" and the invoice is ".$payment_amountInDolibarr);
874 if ($amountdispute != $payment_amountInDolibarr) {
875 http_response_code(500);
876 print
"The payment disputed is ".$amountdispute.
" and the invoice is ".$payment_amountInDolibarr.
". Amount differs, we don't know what to do.";
880 $accountfrom =
new Account($db);
881 $accountfrom->fetch(
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS'));
887 $amounts[$tmpinvoice->id] = -1 * $payment_amountInDolibarr;
889 $paiement->datepaye =
dol_now();
890 $paiement->amounts = $amounts;
895 $paiement->paiementid =
dol_getIdFromCode($db,
'PRE',
'c_paiement',
'code',
'id', 1);
896 $paiement->num_payment =
$object->id;
897 $paiement->note_public =
'Fund withdrawn by bank. Reason: '.$reason;
898 $paiement->note_private =
'';
899 $paiement->fk_account = $accountfrom->id;
903 $alreadytransferedinaccounting = $tmpinvoice->getVentilExportCompta();
905 if ($alreadytransferedinaccounting) {
908 $errormsg =
'Error: the invoice '.$tmpinvoice->id.
' is already transferred into accounting. Don\'t know what to do.';
916 $errormsg = $tmpinvoice->error.implode(
', ', $tmpinvoice->errors);
922 $paiement_id = $paiement->create($user, 0, $tmpinvoice->thirdparty);
923 if ($paiement_id < 0) {
924 $errormsg = $paiement->error.implode(
', ', $paiement->errors);
932 http_response_code(500);
936 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.