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);
1722 dol_print_error($this->db,
'CantFindRequestWithId');
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);
1733 $sepaSequenceType = strtoupper((
string) $companypaymentmode->frstrecur);
1734 if (!in_array($sepaSequenceType, array(
'FRST',
'RCUR',
'OOFF',
'FNAL'),
true)) {
1735 $sepaSequenceType =
'FRST';
1738 $this->stripechargedone = 0;
1739 $this->stripechargeerror = 0;
1743 $currency =
$conf->currency;
1745 $errorforinvoice = 0;
1749 dol_syslog(
"makeStripeSepaRequest Process payment request amount=".$amount.
" thirdparty_id=" . $this->thirdparty->id .
", thirdparty_name=" . $this->thirdparty->name .
" ban id=" . $bac->id, LOG_DEBUG);
1754 $amounttopay = $amount;
1758 $arrayzerounitcurrency = [
'BIF',
'CLP',
'DJF',
'GNF',
'JPY',
'KMF',
'KRW',
'MGA',
'PYG',
'RWF',
'VND',
'VUV',
'XAF',
'XOF',
'XPF'];
1759 $amountstripe = $amounttopay;
1760 if (!in_array($currency, $arrayzerounitcurrency)) {
1761 $amountstripe *= 100;
1764 $fk_bank_account =
getDolGlobalInt(
'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS');
1765 if (!($fk_bank_account > 0)) {
1768 dol_syslog(
"makeStripeSepaRequest Error no bank account defined for Stripe payments", LOG_ERR);
1769 $this->error =
"Error bank account for Stripe payments not defined into Stripe module";
1770 $this->errors[] = $this->error;
1776 require_once DOL_DOCUMENT_ROOT.
'/compta/prelevement/class/bonprelevement.class.php';
1779 if (empty($obj->fk_prelevement_bons)) {
1781 $nbinvoices = $bon->create(
'0',
'0',
'real', $sepaSequenceType, 0, 0, $type, $did, $fk_bank_account);
1782 if ($nbinvoices <= 0) {
1785 dol_syslog(
"makeStripeSepaRequest Error on BonPrelevement creation", LOG_ERR);
1786 $this->error =
"Error on BonPrelevement creation";
1787 $this->errors[] = $this->error;
1807 dol_syslog(
"makeStripeSepaRequest Error Line already part of a bank payment order", LOG_ERR);
1808 $this->error =
"The line is already included into a bank payment order. Delete the bank payment order first.";
1809 $this->errors[] = $this->error;
1813 $paymentintent =
null;
1815 if ($amountstripe > 0) {
1817 global $savstripearrayofkeysbyenv;
1818 global $stripearrayofkeysbyenv;
1820 if ($service ==
'StripeLive') {
1825 dol_syslog(
"makeStripeSepaRequest We will try to pay with companypaymentmodeid=" . $companypaymentmode->id .
" stripe_card_ref=" . $companypaymentmode->stripe_card_ref .
" mode=" . $companypaymentmode->status, LOG_DEBUG);
1827 $thirdparty =
new Societe($this->db);
1828 $resultthirdparty = $thirdparty->fetch($this->socid);
1830 include_once DOL_DOCUMENT_ROOT .
'/stripe/class/stripe.class.php';
1832 $stripe =
new Stripe($this->db);
1834 if (empty($savstripearrayofkeysbyenv)) {
1835 $savstripearrayofkeysbyenv = $stripearrayofkeysbyenv;
1837 dol_syslog(
"makeStripeSepaRequest Current Stripe environment is " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
1838 dol_syslog(
"makeStripeSepaRequest Current Saved Stripe environment is ".$savstripearrayofkeysbyenv[$servicestatus][
'publishable_key']);
1840 $foundalternativestripeaccount =
'';
1841 $stripearrayofkeys = array();
1844 if (! empty($forcestripe)) {
1845 dol_syslog(
"makeStripeSepaRequest A dedicated stripe account was forced, so we switch to it.");
1847 $tmparray = explode(
'@', $forcestripe);
1848 if (! empty($tmparray[1])) {
1849 $tmparray2 = explode(
':', $tmparray[1]);
1850 if (! empty($tmparray2[1])) {
1851 $stripearrayofkeysbyenv[$servicestatus][
"publishable_key"] = $tmparray2[0];
1852 $stripearrayofkeysbyenv[$servicestatus][
"secret_key"] = $tmparray2[1];
1854 $stripearrayofkeys = $stripearrayofkeysbyenv[$servicestatus];
1855 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1857 $foundalternativestripeaccount = $tmparray[0];
1859 dol_syslog(
"makeStripeSepaRequest We use now customer=".$foundalternativestripeaccount.
" publishable_key=".$stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1863 if (! $foundalternativestripeaccount) {
1864 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1866 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1867 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1868 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);
1871 $stripearrayofkeysbyenv = $savstripearrayofkeysbyenv;
1873 $stripearrayofkeys = $savstripearrayofkeysbyenv[$servicestatus];
1874 \Stripe\Stripe::setApiKey($stripearrayofkeys[
'secret_key']);
1875 dol_syslog(
"makeStripeSepaRequest No dedicated Stripe Account requested, so we use global one, so ".$stripearrayofkeys[
'publishable_key'], LOG_DEBUG);
1878 $stripeacc = $stripe->getStripeAccount($service, $this->socid);
1880 if ($foundalternativestripeaccount) {
1881 if (empty($stripeacc)) {
1882 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'));
1884 $customer = \Stripe\Customer::retrieve(array(
'id' =>
"$foundalternativestripeaccount",
'expand[]' =>
'sources'), array(
"stripe_account" => $stripeacc));
1887 $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 0);
1888 if (empty($customer) && ! empty($stripe->error)) {
1889 $this->error = $stripe->error;
1890 $this->errors[] = $this->error;
1901 $postactionmessages = [];
1903 if ($resultthirdparty > 0 && !empty($customer)) {
1906 if ($companypaymentmode->type ==
'ban') {
1910 $stripecard = $stripe->sepaStripe($customer, $companypaymentmode, $stripeacc, $servicestatus, 0);
1913 $this->error =
'The payment mode type is not "ban"';
1917 $FULLTAG =
'DID='.$did.
'-INV=' . $this->
id .
'-CUS=' . $thirdparty->id;
1918 $description =
'Stripe payment from makeStripeSepaRequest: ' . $FULLTAG .
' did='.$did.
' ref=' . $this->ref;
1920 $stripefailurecode =
'';
1921 $stripefailuremessage =
'';
1922 $stripefailuredeclinecode =
'';
1925 dol_syslog(
"* Create payment on SEPA " . $stripecard->id .
", amounttopay=" . $amounttopay .
", amountstripe=" . $amountstripe .
", FULLTAG=" . $FULLTAG, LOG_DEBUG);
1928 $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $this, $customer->id, $stripeacc, $servicestatus, 0,
'automatic',
true, $stripecard->id, 1, 1, $did);
1932 if ($paymentintent->status ===
'succeeded' || $paymentintent->status ===
'processing') {
1933 $charge->status =
'ok';
1934 $charge->id = $paymentintent->id;
1935 $charge->customer = $customer->id;
1936 } elseif ($paymentintent->status ===
'requires_action') {
1940 $charge->status =
'failed';
1941 $charge->customer = $customer->id;
1942 $charge->failure_code = $stripe->code;
1943 $charge->failure_message = $stripe->error;
1944 $charge->failure_declinecode = $stripe->declinecode;
1945 $stripefailurecode = $stripe->code;
1946 $stripefailuremessage =
'Action required. Contact the support at ';
1947 $stripefailuredeclinecode = $stripe->declinecode;
1951 $charge->status =
'failed';
1952 $charge->customer = $customer->id;
1953 $charge->failure_code = $stripe->code;
1954 $charge->failure_message = $stripe->error;
1955 $charge->failure_declinecode = $stripe->declinecode;
1956 $stripefailurecode = $stripe->code;
1957 $stripefailuremessage = $stripe->error;
1958 $stripefailuredeclinecode = $stripe->declinecode;
1966 if (empty($charge) || $charge->status ==
'failed') {
1967 dol_syslog(
'Failed to charge payment mode ' . $stripecard->id .
' stripefailurecode=' . $stripefailurecode .
' stripefailuremessage=' . $stripefailuremessage .
' stripefailuredeclinecode=' . $stripefailuredeclinecode, LOG_WARNING);
1970 $this->stripechargeerror++;
1974 $errmsg = $langs->trans(
"FailedToChargeSEPA");
1975 if (!empty($charge)) {
1976 if ($stripefailuredeclinecode ==
'authentication_required') {
1977 $errauthenticationmessage = $langs->trans(
"ErrSCAAuthentication");
1978 $errmsg = $errauthenticationmessage;
1979 } elseif (in_array($stripefailuredeclinecode, [
'insufficient_funds',
'generic_decline'])) {
1980 $errmsg .=
': ' . $charge->failure_code;
1981 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' ' . $charge->failure_message;
1982 if (empty($stripefailurecode)) {
1983 $stripefailurecode = $charge->failure_code;
1985 if (empty($stripefailuremessage)) {
1986 $stripefailuremessage = $charge->failure_message;
1989 $errmsg .=
': failure_code=' . $charge->failure_code;
1990 $errmsg .= ($charge->failure_message ?
' - ' :
'') .
' failure_message=' . $charge->failure_message;
1991 if (empty($stripefailurecode)) {
1992 $stripefailurecode = $charge->failure_code;
1994 if (empty($stripefailuremessage)) {
1995 $stripefailuremessage = $charge->failure_message;
1999 $errmsg .=
': ' . $stripefailurecode .
' - ' . $stripefailuremessage;
2000 $errmsg .= ($stripefailuredeclinecode ?
' - ' . $stripefailuredeclinecode :
'');
2003 $description =
'Stripe payment ERROR from makeStripeSepaRequest: ' . $FULLTAG;
2004 $postactionmessages[] = $errmsg .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
2006 $this->error = $errmsg;
2007 $this->errors[] = $this->error;
2009 dol_syslog(
'Successfuly request '.$type.
' '.$stripecard->id);
2011 $postactionmessages[] =
'Success to request '.$type.
' (' . $charge->id .
' with ' . $stripearrayofkeys[
'publishable_key'] .
')';
2015 $this->stripechargedone++;
2018 $description =
'Stripe payment request OK (' . $charge->id .
') from makeStripeSepaRequest: ' . $FULLTAG;
2024 if (empty($charge) || $charge->status ==
'failed') {
2025 $actioncode =
'PAYMENT_STRIPE_KO';
2026 $extraparams = $stripefailurecode;
2027 $extraparams .= (($extraparams && $stripefailuremessage) ?
' - ' :
'') . $stripefailuremessage;
2028 $extraparams .= (($extraparams && $stripefailuredeclinecode) ?
' - ' :
'') . $stripefailuredeclinecode;
2030 $actioncode =
'PAYMENT_STRIPE_OK';
2031 $extraparams = array();
2036 dol_syslog(
"No ban payment method found for this stripe customer " . $customer->id, LOG_WARNING);
2038 $this->error =
'Failed to get direct debit payment method for stripe customer = ' . $customer->id;
2039 $this->errors[] = $this->error;
2041 $description =
'Failed to find or use the payment mode - no ban defined for the thirdparty account';
2042 $stripefailurecode =
'BADPAYMENTMODE';
2043 $stripefailuremessage =
'Failed to find or use the payment mode - no ban defined for the thirdparty account';
2044 $postactionmessages[] = $description .
' (' . $stripearrayofkeys[
'publishable_key'] .
')';
2048 $actioncode =
'PAYMENT_STRIPE_KO';
2049 $extraparams = array();
2054 $stripefailurecode =
'';
2055 $stripefailuremessage =
'';
2060 $extraparams = array();
2063 if ($resultthirdparty <= 0) {
2064 dol_syslog(
'SellYourSaasUtils Failed to load customer for thirdparty_id = ' . $thirdparty->id, LOG_WARNING);
2065 $this->error =
'Failed to load Stripe account for thirdparty_id = ' . $thirdparty->id;
2066 $this->errors[] = $this->error;
2068 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);
2069 $this->error =
'Failed to get Stripe account id for thirdparty_id = ' . $thirdparty->id .
" in mode " . $servicestatus .
" in Stripe env " . $stripearrayofkeysbyenv[$servicestatus][
'publishable_key'];
2070 $this->errors[] = $this->error;
2075 $description =
'Failed to find or use your payment mode (no payment mode for this customer id)';
2076 $stripefailurecode =
'BADPAYMENTMODE';
2077 $stripefailuremessage =
'Failed to find or use your payment mode (no payment mode for this customer id)';
2078 $postactionmessages = [];
2082 $actioncode =
'PAYMENT_STRIPE_KO';
2083 $extraparams = array();
2087 dol_syslog(
"* Record event for credit transfer or direct debit request result - " . $description);
2088 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2093 $actioncomm->type_code =
'AC_OTH_AUTO';
2094 $actioncomm->code =
'AC_' . $actioncode;
2095 $actioncomm->label = $description;
2096 $actioncomm->note_private = implode(
",\n", $postactionmessages);
2097 $actioncomm->fk_project = $this->fk_project;
2098 $actioncomm->datep = $now;
2099 $actioncomm->datef = $now;
2100 $actioncomm->percentage = -1;
2101 $actioncomm->socid = $thirdparty->id;
2102 $actioncomm->contactid = 0;
2103 $actioncomm->authorid = $user->id;
2104 $actioncomm->userownerid = $user->id;
2114 $actioncomm->fk_element = $this->id;
2115 $actioncomm->elementid = $this->id;
2116 $actioncomm->elementtype = $this->element;
2117 $actioncomm->extraparams = $extraparams;
2119 $actioncomm->create($user);
2123 $this->postactionmessages = $postactionmessages;
2127 dol_syslog(
'Error ' . $e->getMessage(), LOG_ERR);
2128 $this->error =
'Error ' . $e->getMessage();
2129 $this->errors[] = $this->error;
2134 dol_syslog(
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->
ref .
". Why is the invoice not classified 'Paid' ?", LOG_WARNING);
2135 $this->error =
"Remain to pay is null for the invoice " . $this->
id .
" " . $this->ref .
". Why is the invoice not classified 'Paid' ?";
2136 $this->errors[] = $this->error;
2141 if (!$error && !$errorforinvoice) {
2142 $result = $bon->set_infotrans($user, $now, 3);
2146 dol_syslog(
"Error on BonPrelevement creation", LOG_ERR);
2147 $this->error =
"Error on BonPrelevement creation";
2148 $this->errors[] = $this->error;
2152 if (!$error && !$errorforinvoice && $paymentintent !==
null) {
2154 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET";
2155 $sql .=
" ext_payment_id = '".$this->db->escape($paymentintent->id).
"',";
2156 $sql .=
" ext_payment_site = '".$this->db->escape($service).
"'";
2157 $sql .=
" WHERE rowid = ".((int) $did);
2159 dol_syslog(get_class($this).
"::makeStripeSepaRequest update to save stripe paymentintent ids", LOG_DEBUG);
2160 $resql = $this->db->query($sql);
2162 $this->error = $this->db->lasterror();
2163 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur');
2168 if (!$error && !$errorforinvoice) {
2169 $this->db->commit();
2171 $this->db->rollback();
2174 $this->error =
'WithdrawRequestErrorNilAmount';
2175 dol_syslog(get_class($this).
'::makeStripeSepaRequest WithdrawRequestErrorNilAmount');
2193 $this->error = $this->db->error();
2194 dol_syslog(get_class($this).
'::makeStripeSepaRequest Erreur -2');
2198 $this->error =
"Status of invoice does not allow this";
2199 dol_syslog(get_class($this).
"::makeStripeSepaRequest ".$this->error.
" ".$this->status.
" ,".$this->paye.
", ".$this->mode_reglement_id, LOG_WARNING);
2371 $tmplang->setDefaultLang(
'en_US');
2372 $tmplang->load(
"main");
2374 $pricewithtaxstring =
price2num($this->total_ttc, 2, 1);
2375 $pricetaxstring =
price2num($this->total_tva, 2, 1);
2377 $complementaryinfo =
'';
2391 $complementaryinfo =
'//S1/10/'.str_replace(
'/',
'', $this->
ref).
'/11/'.$datestring;
2392 if ($this->ref_client) {
2393 $complementaryinfo .=
'/20/'.$this->ref_client;
2395 if ($this->thirdparty->tva_intra) {
2396 $complementaryinfo .=
'/30/'.$this->thirdparty->tva_intra;
2399 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
2400 $bankaccount =
new Account($this->db);
2408 if ($this->fk_account > 0) {
2410 $bankaccount->fetch($this->fk_account);
2411 $s .= $bankaccount->iban.
"\n";
2415 if ($bankaccount->id > 0 &&
getDolGlobalString(
'PDF_SWISS_QRCODE_USE_OWNER_OF_ACCOUNT_AS_CREDITOR')) {
2419 $s .=
dol_trunc($bankaccount->owner_name, 70,
'right',
'UTF-8', 1).
"\n";
2420 $addresslinearray = explode(
"\n", $bankaccount->owner_address);
2421 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2422 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
2429 $addresslinearray = explode(
"\n",
$mysoc->address);
2430 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2431 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
2445 $s .=
price($pricewithtaxstring, 0,
'none', 0, 0, 2).
"\n";
2446 $s .= ($this->multicurrency_code ? $this->multicurrency_code :
$conf->currency).
"\n";
2449 $s .=
dol_trunc((
string) $this->thirdparty->name, 70,
'right',
'UTF-8', 1).
"\n";
2450 $addresslinearray = explode(
"\n", $this->thirdparty->address);
2451 $s .=
dol_trunc(empty($addresslinearray[1]) ?
'' : $addresslinearray[1], 70,
'right',
'UTF-8', 1).
"\n";
2452 $s .=
dol_trunc(empty($addresslinearray[2]) ?
'' : $addresslinearray[2], 70,
'right',
'UTF-8', 1).
"\n";
2453 $s .=
dol_trunc($this->thirdparty->zip, 16,
'right',
'UTF-8', 1).
"\n";
2454 $s .=
dol_trunc($this->thirdparty->town, 35,
'right',
'UTF-8', 1).
"\n";
2455 $s .=
dol_trunc($this->thirdparty->country_code, 2,
'right',
'UTF-8', 1).
"\n";
2460 if ($complementaryinfo) {
2461 $s .= $complementaryinfo.
"\n";
2467 if ($complementaryinfo) {
2468 $s .= $complementaryinfo.
"\n";