1268 public function LibStatut($paye, $status, $mode = 0, $alreadypaid = -1, $type = -1, $moreparams = array())
1271 global $langs, $hookmanager;
1272 $langs->load(
'bills');
1275 $type = $this->type;
1279 if (is_int($moreparams)) {
1280 $moreparams = array(
'nbofopendirectdebitorcredittransfer' => (
int) $moreparams);
1283 $nbofopendirectdebitorcredittransfer = 0;
1284 foreach ($moreparams as $moreparamkey => $moreparamvalue) {
1285 if ($moreparamkey ==
'nbofopendirectdebitorcredittransfer') {
1286 $nbofopendirectdebitorcredittransfer = $moreparamvalue;
1290 $statusType =
'status0';
1294 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusDraft');
1295 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusDraft');
1296 } elseif (($status == 3 || $status == 2) && $alreadypaid <= 0) {
1298 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusCanceled');
1299 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusCanceled');
1301 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedUnpaid');
1302 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedUnpaid');
1304 $statusType =
'status5';
1305 } elseif (($status == 3 || $status == 2) && $alreadypaid > 0) {
1306 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusClosedPaidPartially');
1307 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusClosedPaidPartially');
1308 $statusType =
'status9';
1309 } elseif ($alreadypaid == 0 && $nbofopendirectdebitorcredittransfer == 0) {
1310 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
1311 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusNotPaid');
1312 $statusType =
'status1';
1314 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusStarted');
1315 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusStarted');
1316 $statusType =
'status3';
1319 $statusType =
'status6';
1320 if ($type == self::TYPE_CREDIT_NOTE) {
1321 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaidBackOrConverted');
1322 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaidBackOrConverted');
1323 } elseif ($type == self::TYPE_DEPOSIT) {
1324 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusConverted');
1325 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusConverted');
1327 $labelStatus = $langs->transnoentitiesnoconv(
'BillStatusPaid');
1328 $labelStatusShort = $langs->transnoentitiesnoconv(
'Bill'.$prefix.
'StatusPaid');
1332 $paramsBadge = array(
'badgeParams' => array(
'attr' => array(
1333 'data-status-element' => $this->element,
1334 'data-already-paid' => $alreadypaid > 0 ? 1 : 0,
1335 'data-status' => (int) $status
1338 $parameters = array(
1339 'status' => $status,
1342 'alreadypaid' => $alreadypaid,
1344 'paramsBadge' => & $paramsBadge
1347 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
1350 return $hookmanager->resPrint;
1353 if (!empty($moreparams[
'close_code'])) {
1354 $titlestringtoshow =
'';
1356 if ($moreparams[
'close_code'] == self::CLOSECODE_DISCOUNTVAT) {
1357 $titlestringtoshow = $langs->trans(
"HelpEscompte");
1358 } elseif ($moreparams[
'close_code'] == self::CLOSECODE_BADDEBT) {
1359 $titlestringtoshow = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBadCustomer");
1360 } elseif ($moreparams[
'close_code'] == self::CLOSECODE_BANKCHARGE) {
1361 $titlestringtoshow = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonBankCharge");
1362 } elseif ($moreparams[
'close_code'] == self::CLOSECODE_WITHHOLDINGTAX) {
1363 $titlestringtoshow = $langs->trans(
"ConfirmClassifyPaidPartiallyReasonWithholdingTax");
1364 } elseif ($moreparams[
'close_code'] == self::CLOSECODE_OTHER) {
1365 $titlestringtoshow = $langs->trans(
"Other");
1369 $paramsBadge[
'badgeParams' ][
'attr'][
'title'] = $titlestringtoshow;
1372 if (isset($moreparams[
'dispute_status']) && $moreparams[
'dispute_status']) {
1373 $labelStatus .=
' - ';
1374 if ($moreparams[
'dispute_status'] == 8) {
1375 $labelStatus .= $langs->trans(
"DisputeLost");
1376 } elseif ($moreparams[
'dispute_status'] == 9) {
1377 $labelStatus .= $langs->trans(
"DisputeWon");
1379 $labelStatus .= $langs->trans(
"DisputeOpen");
1380 $statusType =
'status8';
1384 $statusbadge = dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $paramsBadge);
1386 return $statusbadge;
1503 public function demande_prelevement(
User $fuser,
float $amount = 0,
string $type =
'direct-debit',
string $sourcetype =
'facture',
int $checkduplicateamongall = 0,
int $ribId = 0)
1510 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
1512 if ($this->
status > self::STATUS_DRAFT && $this->paye == 0) {
1513 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1515 $bac->fetch($ribId,
'', $this->socid);
1522 $total_already_requested = 0;
1524 $sql =
"SELECT COALESCE(SUM(amount), 0) as total_requested";
1525 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
1526 if ($type ==
'bank-transfer') {
1527 $sql .=
" WHERE fk_facture_fourn = ".((int) $this->
id);
1529 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
1531 $sql .=
" AND type = 'ban'";
1532 $sql .=
" AND traite = 0";
1533 dol_syslog(get_class($this).
"::demande_prelevement - get pending requests not yet in receipt", LOG_DEBUG);
1534 $resql = $this->db->query($sql);
1536 $obj = $this->db->fetch_object($resql);
1537 $total_already_requested += $obj ? (float) $obj->total_requested : 0;
1539 $this->error = $this->db->error();
1540 dol_syslog(get_class($this).
'::demandeprelevement Error -2a');
1544 $sql =
"SELECT COALESCE(SUM(pl.amount), 0) as total_requested";
1545 $sql .=
" FROM ".$this->db->prefix().
"prelevement_lignes as pl";
1546 $sql .=
" INNER JOIN ".$this->db->prefix().
"prelevement as p ON p.fk_prelevement_lignes = pl.rowid";
1547 if ($type ==
'bank-transfer') {
1548 $sql .=
" WHERE p.fk_facture_fourn = ".((int) $this->
id);
1550 $sql .=
" WHERE p.fk_facture = ".((int) $this->
id);
1552 $sql .=
" AND (pl.statut IS NULL OR pl.statut = 0)";
1553 dol_syslog(get_class($this).
"::demande_prelevement - get requests in non-credited receipts", LOG_DEBUG);
1554 $resql = $this->db->query($sql);
1556 $obj = $this->db->fetch_object($resql);
1557 $total_already_requested += $obj ? (float) $obj->total_requested : 0;
1562 $resteapayer = (float)
price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1564 $remaining_for_request = (float)
price2num($resteapayer - $total_already_requested,
'MT');
1566 if (empty($amount)) {
1567 $amount = $remaining_for_request;
1570 $can_create_request = ($remaining_for_request > 0 && $amount <= $remaining_for_request);
1572 $this->error = $this->db->error();
1573 dol_syslog(get_class($this).
'::demandeprelevement Error -2b');
1578 $sql =
"SELECT count(rowid) as nb";
1579 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
1580 if ($type ==
'bank-transfer') {
1581 $sql .=
" WHERE fk_facture_fourn = ".((int) $this->
id);
1583 $sql .=
" WHERE fk_facture = ".((int) $this->
id);
1585 $sql .=
" AND type = 'ban'";
1586 if (empty($checkduplicateamongall)) {
1587 $sql .=
" AND traite = 0";
1590 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
1592 $resql = $this->db->query($sql);
1594 $obj = $this->db->fetch_object($resql);
1595 $can_create_request = ($obj && $obj->nb == 0);
1597 if (empty($amount)) {
1606 $amount =
price2num($this->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits,
'MT');
1608 $remaining_for_request = $amount;
1610 $this->error = $this->db->error();
1611 dol_syslog(get_class($this).
'::demandeprelevement Error -2');
1616 if ($can_create_request) {
1618 if (is_numeric($amount) && $amount != 0) {
1619 $sql =
'INSERT INTO '.$this->db->prefix().
'prelevement_demande(';
1620 if ($type ==
'bank-transfer') {
1621 $sql .=
'fk_facture_fourn, ';
1623 $sql .=
'fk_facture, ';
1625 $sql .=
' amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib, sourcetype, type, entity';
1626 if (empty($bac->id)) {
1629 $sql .=
', fk_societe_rib)';
1631 $sql .=
" VALUES (".((int) $this->
id);
1632 $sql .=
", ".((float)
price2num($amount));
1633 $sql .=
", '".$this->db->idate($now).
"'";
1634 $sql .=
", ".((int) $fuser->id);
1635 $sql .=
", '".$this->db->escape($bac->code_banque).
"'";
1636 $sql .=
", '".$this->db->escape($bac->code_guichet).
"'";
1637 $sql .=
", '".$this->db->escape($bac->number).
"'";
1638 $sql .=
", '".$this->db->escape($bac->cle_rib).
"'";
1639 $sql .=
", '".$this->db->escape($sourcetype).
"'";
1641 $sql .=
", ".((int)
$conf->entity);
1642 if (!empty($bac->id)) {
1643 $sql .=
", '".$this->db->escape((
string) $bac->id).
"'";
1646 dol_syslog(get_class($this).
"::demande_prelevement", LOG_DEBUG);
1647 $resql = $this->db->query($sql);
1649 $this->error = $this->db->lasterror();
1650 dol_syslog(get_class($this).
'::demandeprelevement Erreur');
1654 $this->error =
'WithdrawRequestErrorNilAmount';
1655 dol_syslog(get_class($this).
'::demandeprelevement WithdrawRequestErrorNilAmount');
1660 $payment_mode_id =
dol_getIdFromCode($this->db, ($type ==
'bank-transfer' ?
'VIR' :
'PRE'),
'c_paiement',
'code',
'id', 1);
1661 if ($payment_mode_id > 0) {
1672 if ($remaining_for_request <= 0) {
1673 $this->error =
"AmountRequestedAlreadyReachesTotal";
1675 $this->error =
"AmountExceedsRemainingToRequest";
1678 $this->error =
"A request already exists";
1683 $this->error =
"Status of invoice does not allow this";
1684 dol_syslog(get_class($this).
"::demandeprelevement ".$this->error.
" $this->status, $this->paye, $this->mode_reglement_id");
1719 public function makeStripeSepaRequest($fuser, $did, $type =
'direct-debit', $sourcetype =
'facture', $service =
'', $forcestripe =
'')
1721 global
$conf, $user, $langs;
1723 if ($type !=
'bank-transfer' && $type !=
'credit-transfer' && !
getDolGlobalString(
'STRIPE_SEPA_DIRECT_DEBIT')) {
1730 if (empty($service)) {
1731 $service =
'StripeTest';
1733 $service =
'StripeLive';
1739 dol_syslog(get_class($this).
"::makeStripeSepaRequest start did=".$did.
" type=".$type.
" service=".$service.
" sourcetype=".$sourcetype.
" forcestripe=".$forcestripe, LOG_DEBUG);
1741 if ($this->
status > self::STATUS_DRAFT && $this->paye == 0) {
1743 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1745 $result = $bac->fetch(0,
'', $this->socid, 1,
'ban');
1746 if ($result <= 0 || empty($bac->id)) {
1747 $this->error = $langs->trans(
"ThirdpartyHasNoDefaultBankAccount");
1748 $this->errors[] = $this->error;
1749 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error);
1754 $sql =
"SELECT rowid, date_demande, amount, fk_facture, fk_facture_fourn, fk_salary, fk_prelevement_bons";
1755 $sql .=
" FROM ".$this->db->prefix().
"prelevement_demande";
1756 $sql .=
" WHERE rowid = ".((int) $did);
1757 if ($type !=
'bank-transfer' && $type !=
'credit-transfer') {
1758 $sql .=
" AND fk_facture = ".((int) $this->
id);
1760 if ($type !=
'direct-debit') {
1761 if ($sourcetype ==
'salary') {
1762 $sql .=
" AND fk_salary = ".((int) $this->
id);
1764 $sql .=
" AND fk_facture_fourn = ".((int) $this->
id);
1767 $sql .=
" AND traite = 0";
1769 dol_syslog(get_class($this).
"::makeStripeSepaRequest load requests to process", LOG_DEBUG);
1770 $resql = $this->db->query($sql);
1772 $obj = $this->db->fetch_object($resql);
1774 dol_print_error($this->db,
'CantFindRequestWithId');
1779 $amount = $obj->amount;
1781 if (is_numeric($amount) && $amount != 0) {
1782 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companypaymentmode.class.php';
1784 $companypaymentmode->fetch($bac->id);
1785 $sepaSequenceType = strtoupper((
string) $companypaymentmode->frstrecur);
1786 if (!in_array($sepaSequenceType, array(
'FRST',
'RCUR',
'OOFF',
'FNAL'),
true)) {
1787 $sepaSequenceType =
'FRST';
1790 $this->stripechargedone = 0;
1791 $this->stripechargeerror = 0;
1795 $currency =
$conf->currency;
1797 $errorforinvoice = 0;
1801 dol_syslog(
"makeStripeSepaRequest Process payment request amount=".$amount.
" thirdparty_id=" . $this->thirdparty->id .
", thirdparty_name=" . $this->thirdparty->name .
" ban id=" . $bac->id, LOG_DEBUG);
1806 $amounttopay = $amount;
1810 $arrayzerounitcurrency = [
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF'];
1811 $amountstripe = $amounttopay;
1812 if (!in_array($currency, $arrayzerounitcurrency)) {
1813 $amountstripe *= 100;
1816 $fk_bank_account =
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS');
1817 if (!($fk_bank_account > 0)) {
1820 dol_syslog(
"makeStripeSepaRequest Error no bank account defined for Stripe payments", LOG_ERR);
1821 $this->error =
"Error bank account for Stripe payments not defined into Stripe module";
1822 $this->errors[] = $this->error;
1828 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
1831 if (empty($obj->fk_prelevement_bons)) {
1833 $nbinvoices = $bon->create(
'0',
'0',
'real', $sepaSequenceType, 0, 0, $type, $did, $fk_bank_account);
1834 if ($nbinvoices <= 0) {
1837 dol_syslog(
"makeStripeSepaRequest Error on BonPrelevement creation", LOG_ERR);
1838 $this->error =
"Error on BonPrelevement creation";
1839 $this->errors[] = $this->error;
1859 dol_syslog(
"makeStripeSepaRequest Error Line already part of a bank payment order", LOG_ERR);
1860 $this->error =
"The line is already included into a bank payment order. Delete the bank payment order first.";
1861 $this->errors[] = $this->error;
1865 $paymentintent =
null;
1867 if ($amountstripe > 0) {
1869 global $savstripearrayofkeysbyenv;
1870 global $stripearrayofkeysbyenv;
1872 if ($service ==
'StripeLive') {
1877 dol_syslog(
"makeStripeSepaRequest We will try to pay with companypaymentmodeid=" . $companypaymentmode->id .
" stripe_card_ref=" . $companypaymentmode->stripe_card_ref .
" mode=" . $companypaymentmode->status, LOG_DEBUG);
1879 $thirdparty =
new Societe($this->db);
1880 $resultthirdparty = $thirdparty->fetch($this->socid);
1882 include_once DOL_DOCUMENT_ROOT .
'/stripe/class/stripe.class.php';
1884 $stripe =
new Stripe($this->db);
1886 if (empty($savstripearrayofkeysbyenv)) {
1887 $savstripearrayofkeysbyenv = $stripearrayofkeysbyenv;
1889 dol_syslog(
"makeStripeSepaRequest Current Stripe environment is " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
1890 dol_syslog(
"makeStripeSepaRequest Current Saved Stripe environment is ".$savstripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
1892 $foundalternativestripeaccount =
'';
1893 $stripearrayofkeys = array();
1896 if (! empty($forcestripe)) {
1897 dol_syslog(
"makeStripeSepaRequest A dedicated stripe account was forced, so we switch to it.");
1899 $tmparray = explode(
'@', $forcestripe);
1900 if (! empty($tmparray[1])) {
1901 $tmparray2 = explode(
':', $tmparray[1]);
1902 if (! empty($tmparray2[1])) {
1903 $stripearrayofkeysbyenv[$servicestatus][
"publishable_key"] = $tmparray2[0];
1904 $stripearrayofkeysbyenv[$servicestatus][
"secret_key"] = $tmparray2[1];
1906 $stripearrayofkeys = $stripearrayofkeysbyenv[$servicestatus];
1907 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1909 $foundalternativestripeaccount = $tmparray[0];
1911 dol_syslog(
"makeStripeSepaRequest We use now customer=".$foundalternativestripeaccount.
" publishable_key=".$stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1915 if (! $foundalternativestripeaccount) {
1916 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1918 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1919 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1920 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);
1923 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1925 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1926 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1927 dol_syslog(
"makeStripeSepaRequest No dedicated Stripe Account requested, so we use global one, so ".$stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1930 $stripeacc = $stripe->getStripeAccount($service, $this->socid);
1932 if ($foundalternativestripeaccount) {
1933 if (empty($stripeacc)) {
1934 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'));
1936 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'), array(
"stripe_account" => $stripeacc));
1939 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
1940 if (empty($customer) && ! empty($stripe->error)) {
1941 $this->error = $stripe->error;
1942 $this->errors[] = $this->error;
1953 $postactionmessages = [];
1955 if ($resultthirdparty > 0 && !empty($customer)) {
1958 if ($companypaymentmode->type ==
'ban') {
1962 $stripecard = $stripe->sepaStripe($customer, $companypaymentmode, $stripeacc, $servicestatus, 0);
1965 $this->error =
'The payment mode type is not "ban"';
1969 $FULLTAG =
'DID='.$did.
'-INV=' . $this->
id .
'-CUS=' . $thirdparty->id;
1970 $description =
'Stripe payment from makeStripeSepaRequest: ' . $FULLTAG .
' did='.$did.
' ref=' . $this->ref;
1972 $stripefailurecode =
'';
1973 $stripefailuremessage =
'';
1974 $stripefailuredeclinecode =
'';
1977 dol_syslog(
"* Create payment on SEPA " . $stripecard->id .
", amounttopay=" . $amounttopay .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1980 $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $this, $customer->id, $stripeacc, $servicestatus, 0,
'automatic',
true, $stripecard->id, 1, 1, $did);
1984 if ($paymentintent->status ===
'succeeded' || $paymentintent->status ===
'processing') {
1985 $charge->status =
'ok';
1986 $charge->id = $paymentintent->id;
1987 $charge->customer = $customer->id;
1988 } elseif ($paymentintent->status ===
'requires_action') {
1992 $charge->status =
'failed';
1993 $charge->customer = $customer->id;
1994 $charge->failure_code = $stripe->code;
1995 $charge->failure_message = $stripe->error;
1996 $charge->failure_declinecode = $stripe->declinecode;
1997 $stripefailurecode = $stripe->code;
1998 $stripefailuremessage =
'Action required. Contact the support at ';
1999 $stripefailuredeclinecode = $stripe->declinecode;
2003 $charge->status =
'failed';
2004 $charge->customer = $customer->id;
2005 $charge->failure_code = $stripe->code;
2006 $charge->failure_message = $stripe->error;
2007 $charge->failure_declinecode = $stripe->declinecode;
2008 $stripefailurecode = $stripe->code;
2009 $stripefailuremessage = $stripe->error;
2010 $stripefailuredeclinecode = $stripe->declinecode;
2018 if (empty($charge) || $charge->status ==
'failed') {
2019 dol_syslog(
'Failed to charge payment mode ' . $stripecard->id .
' stripefailurecode=' . $stripefailurecode .
' stripefailuremessage=' . $stripefailuremessage .
' stripefailuredeclinecode=' . $stripefailuredeclinecode, LOG_WARNING);
2022 $this->stripechargeerror++;
2026 $errmsg = $langs->trans(
"FailedToChargeSEPA");
2027 if (!empty($charge)) {
2028 if ($stripefailuredeclinecode ==
'authentication_required') {
2029 $errauthenticationmessage = $langs->trans(
"ErrSCAAuthentication");
2030 $errmsg = $errauthenticationmessage;
2031 } elseif (in_array($stripefailuredeclinecode, [
'insufficient_funds',
'generic_decline'])) {
2032 $errmsg .=
': ' . $charge->failure_code;
2033 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' ' . $charge->failure_message;
2034 if (empty($stripefailurecode)) {
2035 $stripefailurecode = $charge->failure_code;
2037 if (empty($stripefailuremessage)) {
2038 $stripefailuremessage = $charge->failure_message;
2041 $errmsg .=
': failure_code=' . $charge->failure_code;
2042 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' failure_message=' . $charge->failure_message;
2043 if (empty($stripefailurecode)) {
2044 $stripefailurecode = $charge->failure_code;
2046 if (empty($stripefailuremessage)) {
2047 $stripefailuremessage = $charge->failure_message;
2051 $errmsg .=
': ' . $stripefailurecode .
' - ' . $stripefailuremessage;
2052 $errmsg .= ($stripefailuredeclinecode ?
' - ' . $stripefailuredeclinecode :
'');
2055 $description =
'Stripe payment ERROR from makeStripeSepaRequest: ' . $FULLTAG;
2056 $postactionmessages[] = $errmsg .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
2058 $this->error = $errmsg;
2059 $this->errors[] = $this->error;
2061 dol_syslog(
'Successfuly request '.$type.
' '.$stripecard->id);
2063 $postactionmessages[] =
'Success to request '.$type.
' (' . $charge->id .
' with ' . $stripearrayofkeys[
'publishable_key'] .
')';
2067 $this->stripechargedone++;
2070 $description =
'Stripe payment request OK (' . $charge->id .
') from makeStripeSepaRequest: ' . $FULLTAG;
2076 if (empty($charge) || $charge->status ==
'failed') {
2077 $actioncode =
'PAYMENT_STRIPE_KO';
2078 $extraparams = $stripefailurecode;
2079 $extraparams .= (($extraparams && $stripefailuremessage) ?
' - ' :
'') . $stripefailuremessage;
2080 $extraparams .= (($extraparams && $stripefailuredeclinecode) ?
' - ' :
'') . $stripefailuredeclinecode;
2082 $actioncode =
'PAYMENT_STRIPE_OK';
2083 $extraparams = array();
2088 dol_syslog(
"No ban payment method found for this stripe customer " . $customer->id, LOG_WARNING);
2090 $this->error =
'Failed to get direct debit payment method for stripe customer = ' . $customer->id;
2091 $this->errors[] = $this->error;
2093 $description =
'Failed to find or use the payment mode - no ban defined for the thirdparty account';
2094 $stripefailurecode =
'BADPAYMENTMODE';
2095 $stripefailuremessage =
'Failed to find or use the payment mode - no ban defined for the thirdparty account';
2096 $postactionmessages[] = $description .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
2100 $actioncode =
'PAYMENT_STRIPE_KO';
2101 $extraparams = array();
2106 $stripefailurecode =
'';
2107 $stripefailuremessage =
'';
2112 $extraparams = array();
2115 if ($resultthirdparty <= 0) {
2116 dol_syslog(
'SellYourSaasUtils Failed to load customer for thirdparty_id = ' . $thirdparty->id, LOG_WARNING);
2117 $this->error =
'Failed to load Stripe account for thirdparty_id = ' . $thirdparty->id;
2118 $this->errors[] = $this->error;
2120 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);
2121 $this->error =
'Failed to get Stripe account id for thirdparty_id = ' . $thirdparty->id .
" in mode " . $servicestatus .
" in Stripe env " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
2122 $this->errors[] = $this->error;
2127 $description =
'Failed to find or use your payment mode (no payment mode for this customer id)';
2128 $stripefailurecode =
'BADPAYMENTMODE';
2129 $stripefailuremessage =
'Failed to find or use your payment mode (no payment mode for this customer id)';
2130 $postactionmessages = [];
2134 $actioncode =
'PAYMENT_STRIPE_KO';
2135 $extraparams = array();
2139 dol_syslog(
"* Record event for credit transfer or direct debit request result - " . $description);
2140 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2145 $actioncomm->type_code =
'AC_OTH_AUTO';
2146 $actioncomm->code =
'AC_' . $actioncode;
2147 $actioncomm->label = $description;
2148 $actioncomm->note_private = implode(
",\n", $postactionmessages);
2149 $actioncomm->fk_project = $this->fk_project;
2150 $actioncomm->datep = $now;
2151 $actioncomm->datef = $now;
2152 $actioncomm->percentage = -1;
2153 $actioncomm->socid = $thirdparty->id;
2154 $actioncomm->contactid = 0;
2155 $actioncomm->authorid = $user->id;
2156 $actioncomm->userownerid = $user->id;
2166 $actioncomm->fk_element = $this->id;
2167 $actioncomm->elementid = $this->id;
2168 $actioncomm->elementtype = $this->element;
2169 $actioncomm->extraparams = $extraparams;
2171 $actioncomm->create($user);
2175 $this->postactionmessages = $postactionmessages;
2179 dol_syslog(
'Error ' . $e->getMessage(), LOG_ERR);
2180 $this->error =
'Error ' . $e->getMessage();
2181 $this->errors[] = $this->error;
2186 dol_syslog(
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->
ref .
". Why is the invoice not classified 'Paid' ?", LOG_WARNING);
2187 $this->error =
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->ref .
". Why is the invoice not classified 'Paid' ?";
2188 $this->errors[] = $this->error;
2193 if (!$error && !$errorforinvoice) {
2194 $result = $bon->set_infotrans($user, $now, 3);
2198 dol_syslog(
"Error on BonPrelevement creation", LOG_ERR);
2199 $this->error =
"Error on BonPrelevement creation";
2200 $this->errors[] = $this->error;
2204 if (!$error && !$errorforinvoice && $paymentintent !==
null) {
2206 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET";
2207 $sql .=
" ext_payment_id = '".$this->db->escape($paymentintent->id).
"',";
2208 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"'";
2209 $sql .=
" WHERE rowid = ".((int) $did);
2211 dol_syslog(get_class($this).
"::makeStripeSepaRequest update to save stripe paymentintent ids", LOG_DEBUG);
2212 $resql = $this->db->query($sql);
2214 $this->error = $this->db->lasterror();
2215 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur');
2220 if (!$error && !$errorforinvoice) {
2221 $this->db->commit();
2223 $this->db->rollback();
2226 $this->error =
'WithdrawRequestErrorNilAmount';
2227 dol_syslog(get_class($this).
'::makeStripeSepaRequest WithdrawRequestErrorNilAmount');
2245 $this->error = $this->db->error();
2246 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur -2');
2250 $this->error =
"Status of invoice does not allow this";
2251 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error.
" ".$this->status.
" ,".$this->paye.
", ".$this->mode_reglement_id, LOG_WARNING);
2428 $tmplang->setDefaultLang(
'en_US');
2429 $tmplang->load(
"main");
2431 $pricewithtaxstring =
price2num($this->total_ttc, 2, 1);
2432 $pricetaxstring =
price2num($this->total_tva, 2, 1);
2434 $complementaryinfo =
'';
2448 $complementaryinfo =
'//S1/10/'.str_replace(
'/',
'', $this->
ref).
'/11/'.$datestring;
2449 if ($this->ref_client) {
2450 $complementaryinfo .=
'/20/'.$this->ref_client;
2452 if ($this->thirdparty->tva_intra) {
2453 $complementaryinfo .=
'/30/'.$this->thirdparty->tva_intra;
2456 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
2457 $bankaccount =
new Account($this->db);
2465 if ($this->fk_account > 0) {
2467 $bankaccount->fetch($this->fk_account);
2468 $s .= $bankaccount->iban.
"\n";
2472 if ($bankaccount->id > 0 &&
getDolGlobalString(
'PDF_SWISS_QRCODE_USE_OWNER_OF_ACCOUNT_AS_CREDITOR')) {
2476 $s .=
dol_trunc($bankaccount->owner_name, 70,
'right',
'UTF-8', 1).
"\n";
2477 $addresslinearray = explode(
"\n", (
string) $bankaccount->owner_address);
2478 $s .=
dol_trunc(empty($addresslinearray[0]) ?
'' : $addresslinearray[0], 70,
'right',
'UTF-8', 1).
"\n";
2479 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2486 $addresslinearray = explode(
"\n", (
string)
$mysoc->address);
2487 $s .=
dol_trunc(empty($addresslinearray[0]) ?
'' : $addresslinearray[0], 70,
'right',
'UTF-8', 1).
"\n";
2488 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2502 $s .=
price($pricewithtaxstring, 0,
'none', 0, 0, 2).
"\n";
2503 $s .= ($this->multicurrency_code ? $this->multicurrency_code :
$conf->currency).
"\n";
2506 $s .=
dol_trunc((
string) $this->thirdparty->name, 70,
'right',
'UTF-8', 1).
"\n";
2507 $addresslinearray = explode(
"\n", (
string) $this->thirdparty->address);
2508 $s .=
dol_trunc(empty($addresslinearray[0]) ?
'' : $addresslinearray[0], 70,
'right',
'UTF-8', 1).
"\n";
2509 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2510 $s .=
dol_trunc($this->thirdparty->zip, 16,
'right',
'UTF-8', 1).
"\n";
2511 $s .=
dol_trunc($this->thirdparty->town, 35,
'right',
'UTF-8', 1).
"\n";
2512 $s .=
dol_trunc($this->thirdparty->country_code, 2,
'right',
'UTF-8', 1).
"\n";
2517 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_creditorref.lib.php';
2519 $paymentref = empty($this->payment_reference) ?
'' : (string) $this->payment_reference;
2533 if ($complementaryinfo) {
2534 $s .= $complementaryinfo.
"\n";