change errors to error

This commit is contained in:
hystepik 2023-03-21 11:12:43 +01:00
parent 3c9b6c47dd
commit 9d460db1ef

View File

@ -317,7 +317,7 @@ if ($event->type == 'payout.created') {
dol_syslog("object = ".var_export($event->data, true)); dol_syslog("object = ".var_export($event->data, true));
include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; //TOTEST include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; //TOTEST
global $stripearrayofkeysbyenv; global $stripearrayofkeysbyenv;
$errors = 0; $error = 0;
$object = $event->data->object; $object = $event->data->object;
$TRANSACTIONID = $object->id; $TRANSACTIONID = $object->id;
$ipaddress = $object->metadata->ipaddress; $ipaddress = $object->metadata->ipaddress;
@ -345,8 +345,7 @@ if ($event->type == 'payout.created') {
$paymentTypeId = $obj->type; $paymentTypeId = $obj->type;
} }
} else { } else {
$error = $db->lasterror(); $postactionmessages[] = $db->lasterror();
$postactionmessages[] = $error;
http_response_code(500); http_response_code(500);
return -1; return -1;
} }
@ -377,7 +376,7 @@ if ($event->type == 'payout.created') {
$postactionmessages[] = 'Payment was done in a different currency than currency expected of company'; $postactionmessages[] = 'Payment was done in a different currency than currency expected of company';
$ispostactionok = -1; $ispostactionok = -1;
// Not yet supported, so error // Not yet supported, so error
$errors++; $error++;
} }
$paiement->paiementid = $paymentTypeId; $paiement->paiementid = $paymentTypeId;
$paiement->num_payment = ''; $paiement->num_payment = '';
@ -387,22 +386,22 @@ if ($event->type == 'payout.created') {
$paiement->ext_payment_site = $service; $paiement->ext_payment_site = $service;
$db->begin(); $db->begin();
if (!$errors) { if (!$error) {
dol_syslog('* Record payment for invoice id ' . $invoice_id . '. It includes closing of invoice and regenerating document'); dol_syslog('* Record payment for invoice id ' . $invoice_id . '. It includes closing of invoice and regenerating document');
// This include closing invoices to 'paid' (and trigger including unsuspending) and regenerating document // This include closing invoices to 'paid' (and trigger including unsuspending) and regenerating document
$paiement_id = $paiement->create($user, 1); $paiement_id = $paiement->create($user, 1);
if ($paiement_id < 0) { if ($paiement_id < 0) {
$postactionmessages[] = $paiement->error . ($paiement->error ? ' ' : '') . join("<br>\n", $paiement->errors); $postactionmessages[] = $paiement->error . ($paiement->error ? ' ' : '') . join("<br>\n", $paiement->error);
$ispostactionok = -1; $ispostactionok = -1;
$errors++; $error++;
} else { } else {
$postactionmessages[] = 'Payment created'; $postactionmessages[] = 'Payment created';
} }
dol_syslog("The payment has been created for invoice id " . $invoice_id); dol_syslog("The payment has been created for invoice id " . $invoice_id);
} }
if (!$errors && isModEnabled('banque')) { if (!$error && isModEnabled('banque')) {
dol_syslog('* Add payment to bank'); dol_syslog('* Add payment to bank');
// The bank used is the one defined into Stripe setup // The bank used is the one defined into Stripe setup
@ -414,18 +413,18 @@ if ($event->type == 'payout.created') {
if ($result < 0) { if ($result < 0) {
$postactionmessages[] = $paiement->error . ($paiement->error ? ' ' : '') . join("<br>\n", $paiement->errors); $postactionmessages[] = $paiement->error . ($paiement->error ? ' ' : '') . join("<br>\n", $paiement->errors);
$ispostactionok = -1; $ispostactionok = -1;
$errors++; $error++;
} else { } else {
$postactionmessages[] = 'Bank transaction of payment created (by makeStripeSepaRequest)'; $postactionmessages[] = 'Bank transaction of payment created (by makeStripeSepaRequest)';
} }
} else { } else {
$postactionmessages[] = 'Setup of bank account to use in module ' . $paymentmethod . ' was not set. No way to record the payment.'; $postactionmessages[] = 'Setup of bank account to use in module ' . $paymentmethod . ' was not set. No way to record the payment.';
$ispostactionok = -1; $ispostactionok = -1;
$errors++; $error++;
} }
} }
if (!$errors && isModEnabled('prelevement')) { if (!$error && isModEnabled('prelevement')) {
dol_syslog('* Set prelevement to credite'); dol_syslog('* Set prelevement to credite');
$bon = new BonPrelevement($db); $bon = new BonPrelevement($db);
$idbon = 0; $idbon = 0;
@ -444,10 +443,10 @@ if ($event->type == 'payout.created') {
} else { } else {
$postactionmessages[] = $db->lasterror(); $postactionmessages[] = $db->lasterror();
$ispostactionok = -1; $ispostactionok = -1;
$errors++; $error++;
} }
if (!$errors && !empty($idbon)) { if (!$error && !empty($idbon)) {
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons";
$sql .= " SET fk_user_credit = ".$user->id; $sql .= " SET fk_user_credit = ".$user->id;
$sql .= ", statut = '".$db->escape($bon::STATUS_CREDITED)."'"; $sql .= ", statut = '".$db->escape($bon::STATUS_CREDITED)."'";
@ -460,11 +459,11 @@ if ($event->type == 'payout.created') {
if (!$result) { if (!$result) {
$postactionmessages[] = $db->lasterror(); $postactionmessages[] = $db->lasterror();
$ispostactionok = -1; $ispostactionok = -1;
$errors++; $error++;
} }
} }
if (!$errors && !empty($idbon)) { if (!$error && !empty($idbon)) {
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_lignes"; $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_lignes";
$sql .= " SET statut = 2"; $sql .= " SET statut = 2";
$sql .= " WHERE fk_prelevement_bons = '".$db->escape($idbon)."'"; $sql .= " WHERE fk_prelevement_bons = '".$db->escape($idbon)."'";
@ -472,12 +471,12 @@ if ($event->type == 'payout.created') {
if (!$result) { if (!$result) {
$postactionmessages[] = $db->lasterror(); $postactionmessages[] = $db->lasterror();
$ispostactionok = -1; $ispostactionok = -1;
$errors++; $error++;
} }
} }
} }
if (!$errors) { if (!$error) {
$db->commit(); $db->commit();
http_response_code(200); http_response_code(200);
return 1; return 1;