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;
1451 public function demande_prelevement(
User $fuser,
float $amount = 0,
string $type =
'direct-debit',
string $sourcetype =
'facture',
int $checkduplicateamongall = 0,
int $ribId = 0)
1458 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
1460 if ($this->
status > self::STATUS_DRAFT && $this->paye == 0) {
1461 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1463 $bac->fetch($ribId,
'', $this->socid);
1470 $total_already_requested = 0;
1472 $sql =
"SELECT COALESCE(SUM(amount), 0) as total_requested";
1473 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
1474 if ($type ==
'bank-transfer') {
1475 $sql .=
" WHERE fk_facture_fourn = ".((int) $this->
id);
1477 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
1479 $sql .=
" AND type = 'ban'";
1480 $sql .=
" AND traite = 0";
1481 dol_syslog(get_class($this).
"::demande_prelevement - get pending requests not yet in receipt", LOG_DEBUG);
1482 $resql = $this->db->query($sql);
1484 $obj = $this->db->fetch_object($resql);
1485 $total_already_requested += $obj ? (float) $obj->total_requested : 0;
1487 $this->error = $this->db->error();
1488 dol_syslog(get_class($this).
'::demandeprelevement Error -2a');
1492 $sql =
"SELECT COALESCE(SUM(pl.amount), 0) as total_requested";
1493 $sql .=
" FROM ".$this->db->prefix().
"prelevement_lignes as pl";
1494 $sql .=
" INNER JOIN ".$this->db->prefix().
"prelevement as p ON p.fk_prelevement_lignes = pl.rowid";
1495 if ($type ==
'bank-transfer') {
1496 $sql .=
" WHERE p.fk_facture_fourn = ".((int) $this->
id);
1498 $sql .=
" WHERE p.fk_facture = ".((int) $this->
id);
1500 $sql .=
" AND (pl.statut IS NULL OR pl.statut = 0)";
1501 dol_syslog(get_class($this).
"::demande_prelevement - get requests in non-credited receipts", LOG_DEBUG);
1502 $resql = $this->db->query($sql);
1504 $obj = $this->db->fetch_object($resql);
1505 $total_already_requested += $obj ? (float) $obj->total_requested : 0;
1510 $resteapayer = (float)
price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1512 $remaining_for_request = (float)
price2num($resteapayer - $total_already_requested,
'MT');
1514 if (empty($amount)) {
1515 $amount = $remaining_for_request;
1518 $can_create_request = ($remaining_for_request > 0 && $amount <= $remaining_for_request);
1520 $this->error = $this->db->error();
1521 dol_syslog(get_class($this).
'::demandeprelevement Error -2b');
1526 $sql =
"SELECT count(rowid) as nb";
1527 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
1528 if ($type ==
'bank-transfer') {
1529 $sql .=
" WHERE fk_facture_fourn = ".((int) $this->
id);
1531 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
1533 $sql .=
" AND type = 'ban'";
1534 if (empty($checkduplicateamongall)) {
1535 $sql .=
" AND traite = 0";
1538 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
1540 $resql = $this->db->query($sql);
1542 $obj = $this->db->fetch_object($resql);
1543 $can_create_request = ($obj && $obj->nb == 0);
1545 if (empty($amount)) {
1554 $amount =
price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1556 $remaining_for_request = $amount;
1558 $this->error = $this->db->error();
1559 dol_syslog(get_class($this).
'::demandeprelevement Error -2');
1564 if ($can_create_request) {
1566 if (is_numeric($amount) && $amount != 0) {
1567 $sql =
'INSERT INTO '.$this->db->prefix().
'prelevement_demande(';
1568 if ($type ==
'bank-transfer') {
1569 $sql .=
'fk_facture_fourn, ';
1571 $sql .=
'fk_facture, ';
1573 $sql .=
' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity';
1574 if (empty($bac->id)) {
1577 $sql .=
', fk_societe_rib)';
1579 $sql .=
" VALUES (".((int) $this->
id);
1580 $sql .=
", ".((float)
price2num($amount));
1581 $sql .=
", '".$this->db->idate($now).
"'";
1582 $sql .=
", ".((int) $fuser->id);
1583 $sql .=
", '".$this->db->escape($bac->code_banque).
"'";
1584 $sql .=
", '".$this->db->escape($bac->code_guichet).
"'";
1585 $sql .=
", '".$this->db->escape($bac->number).
"'";
1586 $sql .=
", '".$this->db->escape($bac->cle_rib).
"'";
1587 $sql .=
", '".$this->db->escape($sourcetype).
"'";
1589 $sql .=
", ".((int)
$conf->entity);
1590 if (!empty($bac->id)) {
1591 $sql .=
", '".$this->db->escape((
string) $bac->id).
"'";
1594 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
1595 $resql = $this->db->query($sql);
1597 $this->error = $this->db->lasterror();
1598 dol_syslog(get_class($this).
'::demandeprelevement Erreur');
1602 $this->error =
'WithdrawRequestErrorNilAmount';
1603 dol_syslog(get_class($this).
'::demandeprelevement WithdrawRequestErrorNilAmount');
1608 $payment_mode_id =
dol_getIdFromCode($this->db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
1609 if ($payment_mode_id > 0) {
1620 if ($remaining_for_request <= 0) {
1621 $this->error =
"AmountRequestedAlreadyReachesTotal";
1623 $this->error =
"AmountExceedsRemainingToRequest";
1626 $this->error =
"A request already exists";
1631 $this->error =
"Status of invoice does not allow this";
1632 dol_syslog(get_class($this).
"::demandeprelevement ".$this->error.
" $this->status, $this->paye, $this->mode_reglement_id");
1667 public function makeStripeSepaRequest($fuser, $did, $type =
'direct-debit', $sourcetype =
'facture', $service =
'', $forcestripe =
'')
1669 global
$conf, $user, $langs;
1671 if ($type !=
'bank-transfer' && $type !=
'credit-transfer' && !
getDolGlobalString(
'STRIPE_SEPA_DIRECT_DEBIT')) {
1678 if (empty($service)) {
1679 $service =
'StripeTest';
1681 $service =
'StripeLive';
1687 dol_syslog(get_class($this).
"::makeStripeSepaRequest start did=".$did.
" type=".$type.
" service=".$service.
" sourcetype=".$sourcetype.
" forcestripe=".$forcestripe, LOG_DEBUG);
1689 if ($this->
status > self::STATUS_DRAFT && $this->paye == 0) {
1691 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1693 $result = $bac->fetch(0,
'', $this->socid, 1,
'ban');
1694 if ($result <= 0 || empty($bac->id)) {
1695 $this->error = $langs->trans(
"ThirdpartyHasNoDefaultBankAccount");
1696 $this->errors[] = $this->error;
1697 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error);
1702 $sql =
"SELECT rowid, date_demande, amount, fk_facture, fk_facture_fourn, fk_salary, fk_prelevement_bons";
1703 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
1704 $sql .=
" WHERE rowid = ".((int) $did);
1705 if ($type !=
'bank-transfer' && $type !=
'credit-transfer') {
1706 $sql .=
" AND fk_facture = ".((int) $this->
id);
1708 if ($type !=
'direct-debit') {
1709 if ($sourcetype ==
'salary') {
1710 $sql .=
" AND fk_salary = ".((int) $this->
id);
1712 $sql .=
" AND fk_facture_fourn = ".((int) $this->
id);
1715 $sql .=
" AND traite = 0";
1717 dol_syslog(get_class($this).
"::makeStripeSepaRequest load requests to process", LOG_DEBUG);
1718 $resql = $this->db->query($sql);
1720 $obj = $this->db->fetch_object($resql);
1727 $amount = $obj->amount;
1729 if (is_numeric($amount) && $amount != 0) {
1730 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
1732 $companypaymentmode->fetch($bac->id);
1734 $this->stripechargedone = 0;
1735 $this->stripechargeerror = 0;
1739 $currency =
$conf->currency;
1741 $errorforinvoice = 0;
1745 dol_syslog(
"makeStripeSepaRequest Process payment request amount=".$amount.
" thirdparty_id=" . $this->thirdparty->id .
", thirdparty_name=" . $this->thirdparty->name .
" ban id=" . $bac->id, LOG_DEBUG);
1750 $amounttopay = $amount;
1754 $arrayzerounitcurrency = [
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF'];
1755 $amountstripe = $amounttopay;
1756 if (!in_array($currency, $arrayzerounitcurrency)) {
1757 $amountstripe *= 100;
1760 $fk_bank_account =
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS');
1761 if (!($fk_bank_account > 0)) {
1764 dol_syslog(
"makeStripeSepaRequest Error no bank account defined for Stripe payments", LOG_ERR);
1765 $this->error =
"Error bank account for Stripe payments not defined into Stripe module";
1766 $this->errors[] = $this->error;
1772 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
1775 if (empty($obj->fk_prelevement_bons)) {
1777 $nbinvoices = $bon->create(
'0',
'0',
'real',
'ALL', 0, 0, $type, $did, $fk_bank_account);
1778 if ($nbinvoices <= 0) {
1781 dol_syslog(
"makeStripeSepaRequest Error on BonPrelevement creation", LOG_ERR);
1782 $this->error =
"Error on BonPrelevement creation";
1783 $this->errors[] = $this->error;
1803 dol_syslog(
"makeStripeSepaRequest Error Line already part of a bank payment order", LOG_ERR);
1804 $this->error =
"The line is already included into a bank payment order. Delete the bank payment order first.";
1805 $this->errors[] = $this->error;
1809 $paymentintent =
null;
1811 if ($amountstripe > 0) {
1813 global $savstripearrayofkeysbyenv;
1814 global $stripearrayofkeysbyenv;
1816 if ($service ==
'StripeLive') {
1821 dol_syslog(
"makeStripeSepaRequest We will try to pay with companypaymentmodeid=" . $companypaymentmode->id .
" stripe_card_ref=" . $companypaymentmode->stripe_card_ref .
" mode=" . $companypaymentmode->status, LOG_DEBUG);
1823 $thirdparty =
new Societe($this->db);
1824 $resultthirdparty = $thirdparty->fetch($this->socid);
1826 include_once DOL_DOCUMENT_ROOT .
'/stripe/class/stripe.class.php';
1828 $stripe =
new Stripe($this->db);
1830 if (empty($savstripearrayofkeysbyenv)) {
1831 $savstripearrayofkeysbyenv = $stripearrayofkeysbyenv;
1833 dol_syslog(
"makeStripeSepaRequest Current Stripe environment is " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
1834 dol_syslog(
"makeStripeSepaRequest Current Saved Stripe environment is ".$savstripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
1836 $foundalternativestripeaccount =
'';
1839 if (! empty($forcestripe)) {
1840 dol_syslog(
"makeStripeSepaRequest A dedicated stripe account was forced, so we switch to it.");
1842 $tmparray = explode(
'@', $forcestripe);
1843 if (! empty($tmparray[1])) {
1844 $tmparray2 = explode(
':', $tmparray[1]);
1845 if (! empty($tmparray2[1])) {
1846 $stripearrayofkeysbyenv[$servicestatus][
"publishable_key"] = $tmparray2[0];
1847 $stripearrayofkeysbyenv[$servicestatus][
"secret_key"] = $tmparray2[1];
1849 $stripearrayofkeys = $stripearrayofkeysbyenv[$servicestatus];
1850 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1852 $foundalternativestripeaccount = $tmparray[0];
1854 dol_syslog(
"makeStripeSepaRequest We use now customer=".$foundalternativestripeaccount.
" publishable_key=".$stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1858 if (! $foundalternativestripeaccount) {
1859 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1861 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1862 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1863 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);
1866 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1868 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1869 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1870 dol_syslog(
"makeStripeSepaRequest No dedicated Stripe Account requested, so we use global one, so ".$stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1873 $stripeacc = $stripe->getStripeAccount($service, $this->socid);
1875 if ($foundalternativestripeaccount) {
1876 if (empty($stripeacc)) {
1877 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'));
1879 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'), array(
"stripe_account" => $stripeacc));
1882 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
1883 if (empty($customer) && ! empty($stripe->error)) {
1884 $this->error = $stripe->error;
1885 $this->errors[] = $this->error;
1896 $postactionmessages = [];
1898 if ($resultthirdparty > 0 && !empty($customer)) {
1901 if ($companypaymentmode->type ==
'ban') {
1905 $stripecard = $stripe->sepaStripe($customer, $companypaymentmode, $stripeacc, $servicestatus, 0);
1908 $this->error =
'The payment mode type is not "ban"';
1912 $FULLTAG =
'DID='.$did.
'-INV=' . $this->
id .
'-CUS=' . $thirdparty->id;
1913 $description =
'Stripe payment from makeStripeSepaRequest: ' . $FULLTAG .
' did='.$did.
' ref=' . $this->ref;
1915 $stripefailurecode =
'';
1916 $stripefailuremessage =
'';
1917 $stripefailuredeclinecode =
'';
1920 dol_syslog(
"* Create payment on SEPA " . $stripecard->id .
", amounttopay=" . $amounttopay .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1923 $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $this, $customer->id, $stripeacc, $servicestatus, 0,
'automatic',
true, $stripecard->id, 1, 1, $did);
1927 if ($paymentintent->status ===
'succeeded' || $paymentintent->status ===
'processing') {
1928 $charge->status =
'ok';
1929 $charge->id = $paymentintent->id;
1930 $charge->customer = $customer->id;
1931 } elseif ($paymentintent->status ===
'requires_action') {
1935 $charge->status =
'failed';
1936 $charge->customer = $customer->id;
1937 $charge->failure_code = $stripe->code;
1938 $charge->failure_message = $stripe->error;
1939 $charge->failure_declinecode = $stripe->declinecode;
1940 $stripefailurecode = $stripe->code;
1941 $stripefailuremessage =
'Action required. Contact the support at ';
1942 $stripefailuredeclinecode = $stripe->declinecode;
1946 $charge->status =
'failed';
1947 $charge->customer = $customer->id;
1948 $charge->failure_code = $stripe->code;
1949 $charge->failure_message = $stripe->error;
1950 $charge->failure_declinecode = $stripe->declinecode;
1951 $stripefailurecode = $stripe->code;
1952 $stripefailuremessage = $stripe->error;
1953 $stripefailuredeclinecode = $stripe->declinecode;
1961 if (empty($charge) || $charge->status ==
'failed') {
1962 dol_syslog(
'Failed to charge payment mode ' . $stripecard->id .
' stripefailurecode=' . $stripefailurecode .
' stripefailuremessage=' . $stripefailuremessage .
' stripefailuredeclinecode=' . $stripefailuredeclinecode, LOG_WARNING);
1965 $this->stripechargeerror++;
1969 $errmsg = $langs->trans(
"FailedToChargeSEPA");
1970 if (!empty($charge)) {
1971 if ($stripefailuredeclinecode ==
'authentication_required') {
1972 $errauthenticationmessage = $langs->trans(
"ErrSCAAuthentication");
1973 $errmsg = $errauthenticationmessage;
1974 } elseif (in_array($stripefailuredeclinecode, [
'insufficient_funds',
'generic_decline'])) {
1975 $errmsg .=
': ' . $charge->failure_code;
1976 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' ' . $charge->failure_message;
1977 if (empty($stripefailurecode)) {
1978 $stripefailurecode = $charge->failure_code;
1980 if (empty($stripefailuremessage)) {
1981 $stripefailuremessage = $charge->failure_message;
1984 $errmsg .=
': failure_code=' . $charge->failure_code;
1985 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' failure_message=' . $charge->failure_message;
1986 if (empty($stripefailurecode)) {
1987 $stripefailurecode = $charge->failure_code;
1989 if (empty($stripefailuremessage)) {
1990 $stripefailuremessage = $charge->failure_message;
1994 $errmsg .=
': ' . $stripefailurecode .
' - ' . $stripefailuremessage;
1995 $errmsg .= ($stripefailuredeclinecode ?
' - ' . $stripefailuredeclinecode :
'');
1998 $description =
'Stripe payment ERROR from makeStripeSepaRequest: ' . $FULLTAG;
1999 $postactionmessages[] = $errmsg .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
2001 $this->error = $errmsg;
2002 $this->errors[] = $this->error;
2004 dol_syslog(
'Successfuly request '.$type.
' '.$stripecard->id);
2006 $postactionmessages[] =
'Success to request '.$type.
' (' . $charge->id .
' with ' . $stripearrayofkeys[
'publishable_key'] .
')';
2010 $this->stripechargedone++;
2013 $description =
'Stripe payment request OK (' . $charge->id .
') from makeStripeSepaRequest: ' . $FULLTAG;
2019 if (empty($charge) || $charge->status ==
'failed') {
2020 $actioncode =
'PAYMENT_STRIPE_KO';
2021 $extraparams = $stripefailurecode;
2022 $extraparams .= (($extraparams && $stripefailuremessage) ?
' - ' :
'') . $stripefailuremessage;
2023 $extraparams .= (($extraparams && $stripefailuredeclinecode) ?
' - ' :
'') . $stripefailuredeclinecode;
2025 $actioncode =
'PAYMENT_STRIPE_OK';
2026 $extraparams = array();
2031 dol_syslog(
"No ban payment method found for this stripe customer " . $customer->id, LOG_WARNING);
2033 $this->error =
'Failed to get direct debit payment method for stripe customer = ' . $customer->id;
2034 $this->errors[] = $this->error;
2036 $description =
'Failed to find or use the payment mode - no ban defined for the thirdparty account';
2037 $stripefailurecode =
'BADPAYMENTMODE';
2038 $stripefailuremessage =
'Failed to find or use the payment mode - no ban defined for the thirdparty account';
2039 $postactionmessages[] = $description .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
2043 $actioncode =
'PAYMENT_STRIPE_KO';
2044 $extraparams = array();
2049 $stripefailurecode =
'';
2050 $stripefailuremessage =
'';
2055 $extraparams = array();
2058 if ($resultthirdparty <= 0) {
2059 dol_syslog(
'SellYourSaasUtils Failed to load customer for thirdparty_id = ' . $thirdparty->id, LOG_WARNING);
2060 $this->error =
'Failed to load Stripe account for thirdparty_id = ' . $thirdparty->id;
2061 $this->errors[] = $this->error;
2063 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);
2064 $this->error =
'Failed to get Stripe account id for thirdparty_id = ' . $thirdparty->id .
" in mode " . $servicestatus .
" in Stripe env " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
2065 $this->errors[] = $this->error;
2070 $description =
'Failed to find or use your payment mode (no payment mode for this customer id)';
2071 $stripefailurecode =
'BADPAYMENTMODE';
2072 $stripefailuremessage =
'Failed to find or use your payment mode (no payment mode for this customer id)';
2073 $postactionmessages = [];
2077 $actioncode =
'PAYMENT_STRIPE_KO';
2078 $extraparams = array();
2082 dol_syslog(
"* Record event for credit transfer or direct debit request result - " . $description);
2083 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2088 $actioncomm->type_code =
'AC_OTH_AUTO';
2089 $actioncomm->code =
'AC_' . $actioncode;
2090 $actioncomm->label = $description;
2091 $actioncomm->note_private = implode(
",\n", $postactionmessages);
2092 $actioncomm->fk_project = $this->fk_project;
2093 $actioncomm->datep = $now;
2094 $actioncomm->datef = $now;
2095 $actioncomm->percentage = -1;
2096 $actioncomm->socid = $thirdparty->id;
2097 $actioncomm->contactid = 0;
2098 $actioncomm->authorid = $user->id;
2099 $actioncomm->userownerid = $user->id;
2109 $actioncomm->fk_element = $this->id;
2110 $actioncomm->elementid = $this->id;
2111 $actioncomm->elementtype = $this->element;
2112 $actioncomm->extraparams = $extraparams;
2114 $actioncomm->create($user);
2118 $this->postactionmessages = $postactionmessages;
2122 dol_syslog(
'Error ' . $e->getMessage(), LOG_ERR);
2123 $this->error =
'Error ' . $e->getMessage();
2124 $this->errors[] = $this->error;
2129 dol_syslog(
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->
ref .
". Why is the invoice not classified 'Paid' ?", LOG_WARNING);
2130 $this->error =
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->ref .
". Why is the invoice not classified 'Paid' ?";
2131 $this->errors[] = $this->error;
2136 if (!$error && !$errorforinvoice) {
2137 $result = $bon->set_infotrans($user, $now, 3);
2141 dol_syslog(
"Error on BonPrelevement creation", LOG_ERR);
2142 $this->error =
"Error on BonPrelevement creation";
2143 $this->errors[] = $this->error;
2147 if (!$error && !$errorforinvoice && $paymentintent !==
null) {
2149 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET";
2150 $sql .=
" ext_payment_id = '".$this->db->escape($paymentintent->id).
"',";
2151 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"'";
2152 $sql .=
" WHERE rowid = ".((int) $did);
2154 dol_syslog(get_class($this).
"::makeStripeSepaRequest update to save stripe paymentintent ids", LOG_DEBUG);
2155 $resql = $this->db->query($sql);
2157 $this->error = $this->db->lasterror();
2158 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur');
2163 if (!$error && !$errorforinvoice) {
2164 $this->db->commit();
2166 $this->db->rollback();
2169 $this->error =
'WithdrawRequestErrorNilAmount';
2170 dol_syslog(get_class($this).
'::makeStripeSepaRequest WithdrawRequestErrorNilAmount');
2188 $this->error = $this->db->error();
2189 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur -2');
2193 $this->error =
"Status of invoice does not allow this";
2194 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error.
" ".$this->status.
" ,".$this->paye.
", ".$this->mode_reglement_id, LOG_WARNING);
2358 $tmplang->setDefaultLang(
'en_US');
2359 $tmplang->load(
"main");
2361 $pricewithtaxstring =
price2num($this->total_ttc, 2, 1);
2362 $pricetaxstring =
price2num($this->total_tva, 2, 1);
2364 $complementaryinfo =
'';
2378 $complementaryinfo =
'//S1/10/'.str_replace(
'/',
'', $this->
ref).
'/11/'.$datestring;
2379 if ($this->ref_client) {
2380 $complementaryinfo .=
'/20/'.$this->ref_client;
2382 if ($this->thirdparty->tva_intra) {
2383 $complementaryinfo .=
'/30/'.$this->thirdparty->tva_intra;
2386 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
2387 $bankaccount =
new Account($this->db);
2395 if ($this->fk_account > 0) {
2397 $bankaccount->fetch($this->fk_account);
2398 $s .= $bankaccount->iban.
"\n";
2402 if ($bankaccount->id > 0 &&
getDolGlobalString(
'PDF_SWISS_QRCODE_USE_OWNER_OF_ACCOUNT_AS_CREDITOR')) {
2406 $s .=
dol_trunc($bankaccount->owner_name, 70,
'right',
'UTF-8', 1).
"\n";
2407 $addresslinearray = explode(
"\n", $bankaccount->owner_address);
2408 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2409 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
2416 $addresslinearray = explode(
"\n",
$mysoc->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";
2432 $s .=
price($pricewithtaxstring, 0,
'none', 0, 0, 2).
"\n";
2433 $s .= ($this->multicurrency_code ? $this->multicurrency_code :
$conf->currency).
"\n";
2436 $s .=
dol_trunc((
string) $this->thirdparty->name, 70,
'right',
'UTF-8', 1).
"\n";
2437 $addresslinearray = explode(
"\n", $this->thirdparty->address);
2438 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2439 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
2440 $s .=
dol_trunc($this->thirdparty->zip, 16,
'right',
'UTF-8', 1).
"\n";
2441 $s .=
dol_trunc($this->thirdparty->town, 35,
'right',
'UTF-8', 1).
"\n";
2442 $s .=
dol_trunc($this->thirdparty->country_code, 2,
'right',
'UTF-8', 1).
"\n";
2447 if ($complementaryinfo) {
2448 $s .= $complementaryinfo.
"\n";
2454 if ($complementaryinfo) {
2455 $s .= $complementaryinfo.
"\n";