1221 public function LibStatut($paye, $status, $mode = 0, $alreadypaid = -1, $type = -1, $moreparams = array())
1224 global $langs, $hookmanager;
1225 $langs->load(
'bills');
1228 $type = $this->type;
1232 if (is_int($moreparams)) {
1233 $moreparams = array(
'nbofopendirectdebitorcredittransfer' => (
int) $moreparams);
1236 $nbofopendirectdebitorcredittransfer = 0;
1237 foreach ($moreparams as $moreparamkey => $moreparamvalue) {
1238 if ($moreparamkey ==
'nbofopendirectdebitorcredittransfer') {
1239 $nbofopendirectdebitorcredittransfer = $moreparamvalue;
1243 $statusType =
'status0';
1247 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusDraft');
1248 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusDraft');
1249 } elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) {
1251 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusCanceled');
1252 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusCanceled');
1254 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedUnpaid');
1255 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedUnpaid');
1257 $statusType =
'status5';
1258 } elseif (($status == 3 || $status == 2) && $alreadypaid > 0) {
1259 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedPaidPartially');
1260 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedPaidPartially');
1261 $statusType =
'status9';
1262 } elseif ($alreadypaid == 0 && $nbofopendirectdebitorcredittransfer == 0) {
1263 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
1264 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusNotPaid');
1265 $statusType =
'status1';
1267 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusStarted');
1268 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusStarted');
1269 $statusType =
'status3';
1272 $statusType =
'status6';
1273 if ($type == self::TYPE_CREDIT_NOTE) {
1274 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaidBackOrConverted');
1275 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaidBackOrConverted');
1276 } elseif ($type == self::TYPE_DEPOSIT) {
1277 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusConverted');
1278 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusConverted');
1280 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaid');
1281 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaid');
1285 $paramsBadge = array(
'badgeParams' => array(
'attr' => array(
1286 'data-status-element' => $this->element,
1287 'data-already-paid' => $alreadypaid > 0 ? 1 : 0,
1288 'data-status' => (int) $status
1291 $parameters = array(
1292 'status' => $status,
1295 'alreadypaid' => $alreadypaid,
1297 'paramsBadge' => & $paramsBadge
1300 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
1303 return $hookmanager->resPrint;
1306 if (!empty($moreparams[
'close_code'])) {
1307 $titlestringtoshow =
'';
1309 if ($moreparams[
'close_code'] == self::CLOSECODE_DISCOUNTVAT) {
1310 $titlestringtoshow = $langs->trans(
"HelpEscompte");
1311 } elseif ($moreparams[
'close_code'] == self::CLOSECODE_BADDEBT) {
1312 $titlestringtoshow = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomer");
1313 } elseif ($moreparams[
'close_code'] == self::CLOSECODE_BANKCHARGE) {
1314 $titlestringtoshow = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankCharge");
1315 } elseif ($moreparams[
'close_code'] == self::CLOSECODE_WITHHOLDINGTAX) {
1316 $titlestringtoshow = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax");
1317 } elseif ($moreparams[
'close_code'] == self::CLOSECODE_OTHER) {
1318 $titlestringtoshow = $langs->trans(
"Other");
1322 $paramsBadge[
'badgeParams' ][
'attr'][
'title'] = $titlestringtoshow;
1325 if (isset($moreparams[
'dispute_status']) && $moreparams[
'dispute_status']) {
1326 $labelStatus .=
' - ';
1327 if ($moreparams[
'dispute_status'] == 8) {
1328 $labelStatus .= $langs->trans(
"DisputeLost");
1329 } elseif ($moreparams[
'dispute_status'] == 9) {
1330 $labelStatus .= $langs->trans(
"DisputeWon");
1332 $labelStatus .= $langs->trans(
"DisputeOpen");
1333 $statusType =
'status8';
1337 $statusbadge =
dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $paramsBadge);
1339 return $statusbadge;
1456 public function demande_prelevement(
User $fuser,
float $amount = 0,
string $type =
'direct-debit',
string $sourcetype =
'facture',
int $checkduplicateamongall = 0,
int $ribId = 0)
1463 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
1465 if ($this->
status > self::STATUS_DRAFT && $this->paye == 0) {
1466 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1468 $bac->fetch($ribId,
'', $this->socid);
1475 $total_already_requested = 0;
1477 $sql =
"SELECT COALESCE(SUM(amount), 0) as total_requested";
1478 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
1479 if ($type ==
'bank-transfer') {
1480 $sql .=
" WHERE fk_facture_fourn = ".((int) $this->
id);
1482 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
1484 $sql .=
" AND type = 'ban'";
1485 $sql .=
" AND traite = 0";
1486 dol_syslog(get_class($this).
"::demande_prelevement - get pending requests not yet in receipt", LOG_DEBUG);
1487 $resql = $this->db->query($sql);
1489 $obj = $this->db->fetch_object($resql);
1490 $total_already_requested += $obj ? (float) $obj->total_requested : 0;
1492 $this->error = $this->db->error();
1493 dol_syslog(get_class($this).
'::demandeprelevement Error -2a');
1497 $sql =
"SELECT COALESCE(SUM(pl.amount), 0) as total_requested";
1498 $sql .=
" FROM ".$this->db->prefix().
"prelevement_lignes as pl";
1499 $sql .=
" INNER JOIN ".$this->db->prefix().
"prelevement as p ON p.fk_prelevement_lignes = pl.rowid";
1500 if ($type ==
'bank-transfer') {
1501 $sql .=
" WHERE p.fk_facture_fourn = ".((int) $this->
id);
1503 $sql .=
" WHERE p.fk_facture = ".((int) $this->
id);
1505 $sql .=
" AND (pl.statut IS NULL OR pl.statut = 0)";
1506 dol_syslog(get_class($this).
"::demande_prelevement - get requests in non-credited receipts", LOG_DEBUG);
1507 $resql = $this->db->query($sql);
1509 $obj = $this->db->fetch_object($resql);
1510 $total_already_requested += $obj ? (float) $obj->total_requested : 0;
1515 $resteapayer = (float)
price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1517 $remaining_for_request = (float)
price2num($resteapayer - $total_already_requested,
'MT');
1519 if (empty($amount)) {
1520 $amount = $remaining_for_request;
1523 $can_create_request = ($remaining_for_request > 0 && $amount <= $remaining_for_request);
1525 $this->error = $this->db->error();
1526 dol_syslog(get_class($this).
'::demandeprelevement Error -2b');
1531 $sql =
"SELECT count(rowid) as nb";
1532 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
1533 if ($type ==
'bank-transfer') {
1534 $sql .=
" WHERE fk_facture_fourn = ".((int) $this->
id);
1536 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
1538 $sql .=
" AND type = 'ban'";
1539 if (empty($checkduplicateamongall)) {
1540 $sql .=
" AND traite = 0";
1543 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
1545 $resql = $this->db->query($sql);
1547 $obj = $this->db->fetch_object($resql);
1548 $can_create_request = ($obj && $obj->nb == 0);
1550 if (empty($amount)) {
1559 $amount =
price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1561 $remaining_for_request = $amount;
1563 $this->error = $this->db->error();
1564 dol_syslog(get_class($this).
'::demandeprelevement Error -2');
1569 if ($can_create_request) {
1571 if (is_numeric($amount) && $amount != 0) {
1572 $sql =
'INSERT INTO '.$this->db->prefix().
'prelevement_demande(';
1573 if ($type ==
'bank-transfer') {
1574 $sql .=
'fk_facture_fourn, ';
1576 $sql .=
'fk_facture, ';
1578 $sql .=
' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity';
1579 if (empty($bac->id)) {
1582 $sql .=
', fk_societe_rib)';
1584 $sql .=
" VALUES (".((int) $this->
id);
1585 $sql .=
", ".((float)
price2num($amount));
1586 $sql .=
", '".$this->db->idate($now).
"'";
1587 $sql .=
", ".((int) $fuser->id);
1588 $sql .=
", '".$this->db->escape($bac->code_banque).
"'";
1589 $sql .=
", '".$this->db->escape($bac->code_guichet).
"'";
1590 $sql .=
", '".$this->db->escape($bac->number).
"'";
1591 $sql .=
", '".$this->db->escape($bac->cle_rib).
"'";
1592 $sql .=
", '".$this->db->escape($sourcetype).
"'";
1594 $sql .=
", ".((int)
$conf->entity);
1595 if (!empty($bac->id)) {
1596 $sql .=
", '".$this->db->escape((
string) $bac->id).
"'";
1599 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
1600 $resql = $this->db->query($sql);
1602 $this->error = $this->db->lasterror();
1603 dol_syslog(get_class($this).
'::demandeprelevement Erreur');
1607 $this->error =
'WithdrawRequestErrorNilAmount';
1608 dol_syslog(get_class($this).
'::demandeprelevement WithdrawRequestErrorNilAmount');
1613 $payment_mode_id =
dol_getIdFromCode($this->db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
1614 if ($payment_mode_id > 0) {
1625 if ($remaining_for_request <= 0) {
1626 $this->error =
"AmountRequestedAlreadyReachesTotal";
1628 $this->error =
"AmountExceedsRemainingToRequest";
1631 $this->error =
"A request already exists";
1636 $this->error =
"Status of invoice does not allow this";
1637 dol_syslog(get_class($this).
"::demandeprelevement ".$this->error.
" $this->status, $this->paye, $this->mode_reglement_id");
1672 public function makeStripeSepaRequest($fuser, $did, $type =
'direct-debit', $sourcetype =
'facture', $service =
'', $forcestripe =
'')
1674 global
$conf, $user, $langs;
1676 if ($type !=
'bank-transfer' && $type !=
'credit-transfer' && !
getDolGlobalString(
'STRIPE_SEPA_DIRECT_DEBIT')) {
1683 if (empty($service)) {
1684 $service =
'StripeTest';
1686 $service =
'StripeLive';
1692 dol_syslog(get_class($this).
"::makeStripeSepaRequest start did=".$did.
" type=".$type.
" service=".$service.
" sourcetype=".$sourcetype.
" forcestripe=".$forcestripe, LOG_DEBUG);
1694 if ($this->
status > self::STATUS_DRAFT && $this->paye == 0) {
1696 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1698 $result = $bac->fetch(0,
'', $this->socid, 1,
'ban');
1699 if ($result <= 0 || empty($bac->id)) {
1700 $this->error = $langs->trans(
"ThirdpartyHasNoDefaultBankAccount");
1701 $this->errors[] = $this->error;
1702 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error);
1707 $sql =
"SELECT rowid, date_demande, amount, fk_facture, fk_facture_fourn, fk_salary, fk_prelevement_bons";
1708 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
1709 $sql .=
" WHERE rowid = ".((int) $did);
1710 if ($type !=
'bank-transfer' && $type !=
'credit-transfer') {
1711 $sql .=
" AND fk_facture = ".((int) $this->
id);
1713 if ($type !=
'direct-debit') {
1714 if ($sourcetype ==
'salary') {
1715 $sql .=
" AND fk_salary = ".((int) $this->
id);
1717 $sql .=
" AND fk_facture_fourn = ".((int) $this->
id);
1720 $sql .=
" AND traite = 0";
1722 dol_syslog(get_class($this).
"::makeStripeSepaRequest load requests to process", LOG_DEBUG);
1723 $resql = $this->db->query($sql);
1725 $obj = $this->db->fetch_object($resql);
1732 $amount = $obj->amount;
1734 if (is_numeric($amount) && $amount != 0) {
1735 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
1737 $companypaymentmode->fetch($bac->id);
1738 $sepaSequenceType = strtoupper((
string) $companypaymentmode->frstrecur);
1739 if (!in_array($sepaSequenceType, array(
'FRST',
'RCUR',
'OOFF',
'FNAL'),
true)) {
1740 $sepaSequenceType =
'FRST';
1743 $this->stripechargedone = 0;
1744 $this->stripechargeerror = 0;
1748 $currency =
$conf->currency;
1750 $errorforinvoice = 0;
1754 dol_syslog(
"makeStripeSepaRequest Process payment request amount=".$amount.
" thirdparty_id=" . $this->thirdparty->id .
", thirdparty_name=" . $this->thirdparty->name .
" ban id=" . $bac->id, LOG_DEBUG);
1759 $amounttopay = $amount;
1763 $arrayzerounitcurrency = [
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF'];
1764 $amountstripe = $amounttopay;
1765 if (!in_array($currency, $arrayzerounitcurrency)) {
1766 $amountstripe *= 100;
1769 $fk_bank_account =
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS');
1770 if (!($fk_bank_account > 0)) {
1773 dol_syslog(
"makeStripeSepaRequest Error no bank account defined for Stripe payments", LOG_ERR);
1774 $this->error =
"Error bank account for Stripe payments not defined into Stripe module";
1775 $this->errors[] = $this->error;
1781 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
1784 if (empty($obj->fk_prelevement_bons)) {
1786 $nbinvoices = $bon->create(
'0',
'0',
'real', $sepaSequenceType, 0, 0, $type, $did, $fk_bank_account);
1787 if ($nbinvoices <= 0) {
1790 dol_syslog(
"makeStripeSepaRequest Error on BonPrelevement creation", LOG_ERR);
1791 $this->error =
"Error on BonPrelevement creation";
1792 $this->errors[] = $this->error;
1812 dol_syslog(
"makeStripeSepaRequest Error Line already part of a bank payment order", LOG_ERR);
1813 $this->error =
"The line is already included into a bank payment order. Delete the bank payment order first.";
1814 $this->errors[] = $this->error;
1818 $paymentintent =
null;
1820 if ($amountstripe > 0) {
1822 global $savstripearrayofkeysbyenv;
1823 global $stripearrayofkeysbyenv;
1825 if ($service ==
'StripeLive') {
1830 dol_syslog(
"makeStripeSepaRequest We will try to pay with companypaymentmodeid=" . $companypaymentmode->id .
" stripe_card_ref=" . $companypaymentmode->stripe_card_ref .
" mode=" . $companypaymentmode->status, LOG_DEBUG);
1832 $thirdparty =
new Societe($this->db);
1833 $resultthirdparty = $thirdparty->fetch($this->socid);
1835 include_once DOL_DOCUMENT_ROOT .
'/stripe/class/stripe.class.php';
1837 $stripe =
new Stripe($this->db);
1839 if (empty($savstripearrayofkeysbyenv)) {
1840 $savstripearrayofkeysbyenv = $stripearrayofkeysbyenv;
1842 dol_syslog(
"makeStripeSepaRequest Current Stripe environment is " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
1843 dol_syslog(
"makeStripeSepaRequest Current Saved Stripe environment is ".$savstripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
1845 $foundalternativestripeaccount =
'';
1848 if (! empty($forcestripe)) {
1849 dol_syslog(
"makeStripeSepaRequest A dedicated stripe account was forced, so we switch to it.");
1851 $tmparray = explode(
'@', $forcestripe);
1852 if (! empty($tmparray[1])) {
1853 $tmparray2 = explode(
':', $tmparray[1]);
1854 if (! empty($tmparray2[1])) {
1855 $stripearrayofkeysbyenv[$servicestatus][
"publishable_key"] = $tmparray2[0];
1856 $stripearrayofkeysbyenv[$servicestatus][
"secret_key"] = $tmparray2[1];
1858 $stripearrayofkeys = $stripearrayofkeysbyenv[$servicestatus];
1859 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1861 $foundalternativestripeaccount = $tmparray[0];
1863 dol_syslog(
"makeStripeSepaRequest We use now customer=".$foundalternativestripeaccount.
" publishable_key=".$stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1867 if (! $foundalternativestripeaccount) {
1868 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1870 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1871 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1872 dol_syslog(
"makeStripeSepaRequest We found a bad value for Stripe Account for thirdparty id=".$thirdparty->id.
", so we ignore it and keep using the global one, so ".$stripearrayofkeys[
'publishable_key'], LOG_WARNING);
1875 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1877 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1878 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1879 dol_syslog(
"makeStripeSepaRequest No dedicated Stripe Account requested, so we use global one, so ".$stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1882 $stripeacc = $stripe->getStripeAccount($service, $this->socid);
1884 if ($foundalternativestripeaccount) {
1885 if (empty($stripeacc)) {
1886 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'));
1888 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'), array(
"stripe_account" => $stripeacc));
1891 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
1892 if (empty($customer) && ! empty($stripe->error)) {
1893 $this->error = $stripe->error;
1894 $this->errors[] = $this->error;
1905 $postactionmessages = [];
1907 if ($resultthirdparty > 0 && !empty($customer)) {
1910 if ($companypaymentmode->type ==
'ban') {
1914 $stripecard = $stripe->sepaStripe($customer, $companypaymentmode, $stripeacc, $servicestatus, 0);
1917 $this->error =
'The payment mode type is not "ban"';
1921 $FULLTAG =
'DID='.$did.
'-INV=' . $this->
id .
'-CUS=' . $thirdparty->id;
1922 $description =
'Stripe payment from makeStripeSepaRequest: ' . $FULLTAG .
' did='.$did.
' ref=' . $this->ref;
1924 $stripefailurecode =
'';
1925 $stripefailuremessage =
'';
1926 $stripefailuredeclinecode =
'';
1929 dol_syslog(
"* Create payment on SEPA " . $stripecard->id .
", amounttopay=" . $amounttopay .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1932 $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $this, $customer->id, $stripeacc, $servicestatus, 0,
'automatic',
true, $stripecard->id, 1, 1, $did);
1936 if ($paymentintent->status ===
'succeeded' || $paymentintent->status ===
'processing') {
1937 $charge->status =
'ok';
1938 $charge->id = $paymentintent->id;
1939 $charge->customer = $customer->id;
1940 } elseif ($paymentintent->status ===
'requires_action') {
1944 $charge->status =
'failed';
1945 $charge->customer = $customer->id;
1946 $charge->failure_code = $stripe->code;
1947 $charge->failure_message = $stripe->error;
1948 $charge->failure_declinecode = $stripe->declinecode;
1949 $stripefailurecode = $stripe->code;
1950 $stripefailuremessage =
'Action required. Contact the support at ';
1951 $stripefailuredeclinecode = $stripe->declinecode;
1955 $charge->status =
'failed';
1956 $charge->customer = $customer->id;
1957 $charge->failure_code = $stripe->code;
1958 $charge->failure_message = $stripe->error;
1959 $charge->failure_declinecode = $stripe->declinecode;
1960 $stripefailurecode = $stripe->code;
1961 $stripefailuremessage = $stripe->error;
1962 $stripefailuredeclinecode = $stripe->declinecode;
1970 if (empty($charge) || $charge->status ==
'failed') {
1971 dol_syslog(
'Failed to charge payment mode ' . $stripecard->id .
' stripefailurecode=' . $stripefailurecode .
' stripefailuremessage=' . $stripefailuremessage .
' stripefailuredeclinecode=' . $stripefailuredeclinecode, LOG_WARNING);
1974 $this->stripechargeerror++;
1978 $errmsg = $langs->trans(
"FailedToChargeSEPA");
1979 if (!empty($charge)) {
1980 if ($stripefailuredeclinecode ==
'authentication_required') {
1981 $errauthenticationmessage = $langs->trans(
"ErrSCAAuthentication");
1982 $errmsg = $errauthenticationmessage;
1983 } elseif (in_array($stripefailuredeclinecode, [
'insufficient_funds',
'generic_decline'])) {
1984 $errmsg .=
': ' . $charge->failure_code;
1985 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' ' . $charge->failure_message;
1986 if (empty($stripefailurecode)) {
1987 $stripefailurecode = $charge->failure_code;
1989 if (empty($stripefailuremessage)) {
1990 $stripefailuremessage = $charge->failure_message;
1993 $errmsg .=
': failure_code=' . $charge->failure_code;
1994 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' failure_message=' . $charge->failure_message;
1995 if (empty($stripefailurecode)) {
1996 $stripefailurecode = $charge->failure_code;
1998 if (empty($stripefailuremessage)) {
1999 $stripefailuremessage = $charge->failure_message;
2003 $errmsg .=
': ' . $stripefailurecode .
' - ' . $stripefailuremessage;
2004 $errmsg .= ($stripefailuredeclinecode ?
' - ' . $stripefailuredeclinecode :
'');
2007 $description =
'Stripe payment ERROR from makeStripeSepaRequest: ' . $FULLTAG;
2008 $postactionmessages[] = $errmsg .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
2010 $this->error = $errmsg;
2011 $this->errors[] = $this->error;
2013 dol_syslog(
'Successfuly request '.$type.
' '.$stripecard->id);
2015 $postactionmessages[] =
'Success to request '.$type.
' (' . $charge->id .
' with ' . $stripearrayofkeys[
'publishable_key'] .
')';
2019 $this->stripechargedone++;
2022 $description =
'Stripe payment request OK (' . $charge->id .
') from makeStripeSepaRequest: ' . $FULLTAG;
2028 if (empty($charge) || $charge->status ==
'failed') {
2029 $actioncode =
'PAYMENT_STRIPE_KO';
2030 $extraparams = $stripefailurecode;
2031 $extraparams .= (($extraparams && $stripefailuremessage) ?
' - ' :
'') . $stripefailuremessage;
2032 $extraparams .= (($extraparams && $stripefailuredeclinecode) ?
' - ' :
'') . $stripefailuredeclinecode;
2034 $actioncode =
'PAYMENT_STRIPE_OK';
2035 $extraparams = array();
2040 dol_syslog(
"No ban payment method found for this stripe customer " . $customer->id, LOG_WARNING);
2042 $this->error =
'Failed to get direct debit payment method for stripe customer = ' . $customer->id;
2043 $this->errors[] = $this->error;
2045 $description =
'Failed to find or use the payment mode - no ban defined for the thirdparty account';
2046 $stripefailurecode =
'BADPAYMENTMODE';
2047 $stripefailuremessage =
'Failed to find or use the payment mode - no ban defined for the thirdparty account';
2048 $postactionmessages[] = $description .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
2052 $actioncode =
'PAYMENT_STRIPE_KO';
2053 $extraparams = array();
2058 $stripefailurecode =
'';
2059 $stripefailuremessage =
'';
2064 $extraparams = array();
2067 if ($resultthirdparty <= 0) {
2068 dol_syslog(
'SellYourSaasUtils Failed to load customer for thirdparty_id = ' . $thirdparty->id, LOG_WARNING);
2069 $this->error =
'Failed to load Stripe account for thirdparty_id = ' . $thirdparty->id;
2070 $this->errors[] = $this->error;
2072 dol_syslog(
'SellYourSaasUtils Failed to get Stripe customer id for thirdparty_id = ' . $thirdparty->id .
" in mode " . $servicestatus .
" in Stripe env " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'], LOG_WARNING);
2073 $this->error =
'Failed to get Stripe account id for thirdparty_id = ' . $thirdparty->id .
" in mode " . $servicestatus .
" in Stripe env " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
2074 $this->errors[] = $this->error;
2079 $description =
'Failed to find or use your payment mode (no payment mode for this customer id)';
2080 $stripefailurecode =
'BADPAYMENTMODE';
2081 $stripefailuremessage =
'Failed to find or use your payment mode (no payment mode for this customer id)';
2082 $postactionmessages = [];
2086 $actioncode =
'PAYMENT_STRIPE_KO';
2087 $extraparams = array();
2091 dol_syslog(
"* Record event for credit transfer or direct debit request result - " . $description);
2092 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2097 $actioncomm->type_code =
'AC_OTH_AUTO';
2098 $actioncomm->code =
'AC_' . $actioncode;
2099 $actioncomm->label = $description;
2100 $actioncomm->note_private = implode(
",\n", $postactionmessages);
2101 $actioncomm->fk_project = $this->fk_project;
2102 $actioncomm->datep = $now;
2103 $actioncomm->datef = $now;
2104 $actioncomm->percentage = -1;
2105 $actioncomm->socid = $thirdparty->id;
2106 $actioncomm->contactid = 0;
2107 $actioncomm->authorid = $user->id;
2108 $actioncomm->userownerid = $user->id;
2118 $actioncomm->fk_element = $this->id;
2119 $actioncomm->elementid = $this->id;
2120 $actioncomm->elementtype = $this->element;
2121 $actioncomm->extraparams = $extraparams;
2123 $actioncomm->create($user);
2127 $this->postactionmessages = $postactionmessages;
2131 dol_syslog(
'Error ' . $e->getMessage(), LOG_ERR);
2132 $this->error =
'Error ' . $e->getMessage();
2133 $this->errors[] = $this->error;
2138 dol_syslog(
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->
ref .
". Why is the invoice not classified 'Paid' ?", LOG_WARNING);
2139 $this->error =
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->ref .
". Why is the invoice not classified 'Paid' ?";
2140 $this->errors[] = $this->error;
2145 if (!$error && !$errorforinvoice) {
2146 $result = $bon->set_infotrans($user, $now, 3);
2150 dol_syslog(
"Error on BonPrelevement creation", LOG_ERR);
2151 $this->error =
"Error on BonPrelevement creation";
2152 $this->errors[] = $this->error;
2156 if (!$error && !$errorforinvoice && $paymentintent !==
null) {
2158 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET";
2159 $sql .=
" ext_payment_id = '".$this->db->escape($paymentintent->id).
"',";
2160 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"'";
2161 $sql .=
" WHERE rowid = ".((int) $did);
2163 dol_syslog(get_class($this).
"::makeStripeSepaRequest update to save stripe paymentintent ids", LOG_DEBUG);
2164 $resql = $this->db->query($sql);
2166 $this->error = $this->db->lasterror();
2167 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur');
2172 if (!$error && !$errorforinvoice) {
2173 $this->db->commit();
2175 $this->db->rollback();
2178 $this->error =
'WithdrawRequestErrorNilAmount';
2179 dol_syslog(get_class($this).
'::makeStripeSepaRequest WithdrawRequestErrorNilAmount');
2197 $this->error = $this->db->error();
2198 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur -2');
2202 $this->error =
"Status of invoice does not allow this";
2203 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error.
" ".$this->status.
" ,".$this->paye.
", ".$this->mode_reglement_id, LOG_WARNING);
2367 $tmplang->setDefaultLang(
'en_US');
2368 $tmplang->load(
"main");
2370 $pricewithtaxstring =
price2num($this->total_ttc, 2, 1);
2371 $pricetaxstring =
price2num($this->total_tva, 2, 1);
2373 $complementaryinfo =
'';
2387 $complementaryinfo =
'//S1/10/'.str_replace(
'/',
'', $this->
ref).
'/11/'.$datestring;
2388 if ($this->ref_client) {
2389 $complementaryinfo .=
'/20/'.$this->ref_client;
2391 if ($this->thirdparty->tva_intra) {
2392 $complementaryinfo .=
'/30/'.$this->thirdparty->tva_intra;
2395 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
2396 $bankaccount =
new Account($this->db);
2404 if ($this->fk_account > 0) {
2406 $bankaccount->fetch($this->fk_account);
2407 $s .= $bankaccount->iban.
"\n";
2411 if ($bankaccount->id > 0 &&
getDolGlobalString(
'PDF_SWISS_QRCODE_USE_OWNER_OF_ACCOUNT_AS_CREDITOR')) {
2415 $s .=
dol_trunc($bankaccount->owner_name, 70,
'right',
'UTF-8', 1).
"\n";
2416 $addresslinearray = explode(
"\n", $bankaccount->owner_address);
2417 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2418 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
2425 $addresslinearray = explode(
"\n",
$mysoc->address);
2426 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2427 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
2441 $s .=
price($pricewithtaxstring, 0,
'none', 0, 0, 2).
"\n";
2442 $s .= ($this->multicurrency_code ? $this->multicurrency_code :
$conf->currency).
"\n";
2445 $s .=
dol_trunc((
string) $this->thirdparty->name, 70,
'right',
'UTF-8', 1).
"\n";
2446 $addresslinearray = explode(
"\n", $this->thirdparty->address);
2447 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2448 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
2449 $s .=
dol_trunc($this->thirdparty->zip, 16,
'right',
'UTF-8', 1).
"\n";
2450 $s .=
dol_trunc($this->thirdparty->town, 35,
'right',
'UTF-8', 1).
"\n";
2451 $s .=
dol_trunc($this->thirdparty->country_code, 2,
'right',
'UTF-8', 1).
"\n";
2456 if ($complementaryinfo) {
2457 $s .= $complementaryinfo.
"\n";
2463 if ($complementaryinfo) {
2464 $s .= $complementaryinfo.
"\n";