push with ipn not working
This commit is contained in:
parent
1115f9c0c9
commit
b5ffe6204f
@ -106,7 +106,7 @@ class BonPrelevement extends CommonObject
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
global $conf, $langs;
|
||||
global $conf, $langs, $db;
|
||||
|
||||
$this->db = $db;
|
||||
|
||||
|
||||
@ -92,10 +92,6 @@ abstract class CommonInvoice extends CommonObject
|
||||
*/
|
||||
const STATUS_ABANDONED = 3;
|
||||
|
||||
/**
|
||||
* Classified processing because payment requested
|
||||
*/
|
||||
const STATUS_PROCESSING = 4;
|
||||
|
||||
public $totalpaid; // duplicate with sumpayed
|
||||
public $totaldeposits; // duplicate with sumdeposit
|
||||
@ -618,10 +614,6 @@ abstract class CommonInvoice extends CommonObject
|
||||
$labelStatus = $langs->transnoentitiesnoconv('BillStatusClosedPaidPartially');
|
||||
$labelStatusShort = $langs->transnoentitiesnoconv('Bill'.$prefix.'StatusClosedPaidPartially');
|
||||
$statusType = 'status9';
|
||||
} elseif ($status == 4) {
|
||||
$labelStatus = $langs->transnoentitiesnoconv('BillStatusRequestProcessing');
|
||||
$labelStatusShort = $langs->transnoentitiesnoconv('Bill'.$prefix.'StatusRequestProcessing');
|
||||
$statusType = 'status3';
|
||||
} elseif ($alreadypaid == 0) {
|
||||
$labelStatus = $langs->transnoentitiesnoconv('BillStatusNotPaid');
|
||||
$labelStatusShort = $langs->transnoentitiesnoconv('Bill'.$prefix.'StatusNotPaid');
|
||||
@ -1197,13 +1189,6 @@ abstract class CommonInvoice extends CommonObject
|
||||
|
||||
// Default description used for label of event. Will be overwrite by another value later.
|
||||
$description = 'Stripe payment request OK (' . $charge->id . ') from makeStripeSepaRequest: ' . $FULLTAG;
|
||||
|
||||
$result =$this->setStatut($this::STATUS_PROCESSING);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$errorforinvoice++;
|
||||
$this->errors[] = 'Error on invoice status change to processing';
|
||||
}
|
||||
}
|
||||
|
||||
$object = $this;
|
||||
@ -1457,24 +1442,42 @@ abstract class CommonInvoice extends CommonObject
|
||||
}
|
||||
|
||||
// TODO Create a prelevement_bon and set its status to sent instead of this
|
||||
$idtransferfile = 0;
|
||||
|
||||
// Update the direct debit payment request of the processed invoice to save the id of the prelevement_bon
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_demande SET";
|
||||
$sql .= " traite = 1,"; // TODO Remove this
|
||||
$sql .= " date_traite = '".$this->db->idate(dol_now())."'"; // TODO Remove this
|
||||
if ($idtransferfile > 0) {
|
||||
$sql .= " fk_prelevement_bons = ".((int) $idtransferfile);
|
||||
}
|
||||
$sql .= " WHERE rowid = ".((int) $did);
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::makeStripeSepaRequest", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
$this->error = $this->db->lasterror();
|
||||
dol_syslog(get_class($this).'::makeStripeSepaRequest Erreur');
|
||||
$bon = new BonPrelevement($db);
|
||||
$nbinvoices = $bon->create();
|
||||
if ($nbinvoices <= 0) {
|
||||
$error++;
|
||||
$errorforinvoice++;
|
||||
dol_syslog("Error on BonPrelevement creation", LOG_ERR);
|
||||
$this->errors[] = "Error on BonPrelevement creation";
|
||||
}
|
||||
|
||||
$result = $bon->set_infotrans($user, $now, 'internet');
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$errorforinvoice++;
|
||||
dol_syslog("Error on BonPrelevement creation", LOG_ERR);
|
||||
$this->errors[] = "Error on BonPrelevement creation";
|
||||
}
|
||||
|
||||
if (!$errorforinvoice) {
|
||||
$idtransferfile = $bon->id;
|
||||
// Update the direct debit payment request of the processed invoice to save the id of the prelevement_bon
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_demande SET";
|
||||
$sql .= " traite = 1,"; // TODO Remove this
|
||||
$sql .= " date_traite = '".$this->db->idate(dol_now())."',"; // TODO Remove this
|
||||
if ($idtransferfile > 0) {
|
||||
$sql .= " fk_prelevement_bons = ".((int) $idtransferfile);
|
||||
}
|
||||
$sql .= " WHERE rowid = ".((int) $did);
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::makeStripeSepaRequest", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) {
|
||||
$this->error = $this->db->lasterror();
|
||||
dol_syslog(get_class($this).'::makeStripeSepaRequest Erreur');
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->error = 'WithdrawRequestErrorNilAmount';
|
||||
|
||||
@ -148,8 +148,6 @@ BillShortStatusNotPaid=Not paid
|
||||
BillShortStatusNotRefunded=Not refunded
|
||||
BillShortStatusClosedUnpaid=Closed
|
||||
BillShortStatusClosedPaidPartially=Paid (partially)
|
||||
BillStatusRequestProcessing=Payment request processing
|
||||
BillShortStatusRequestProcessing=Processing
|
||||
PaymentStatusToValidShort=To validate
|
||||
ErrorVATIntraNotConfigured=Intra-Community VAT number not yet defined
|
||||
ErrorNoPaiementModeConfigured=No default payment type defined. Go to Invoice module setup to fix this.
|
||||
|
||||
@ -43,9 +43,9 @@ require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/stripe/stripe-php/init.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
|
||||
|
||||
@ -399,6 +399,52 @@ if ($event->type == 'payout.created') {
|
||||
$errorforinvoice++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$errorforinvoice && isModEnabled('prelevement')) { //TEST IPN
|
||||
$bon = new BonPrelevement($db);
|
||||
$idbon = 0;
|
||||
$sql = "SELECT dp.fk_prelevement_bons as idbon";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as dp";
|
||||
$sql .= " WHERE dp.fk_facture = '".$db->escape($invoice_id)."'";
|
||||
$sql .= " AND dp.sourcetype = 'facture'";
|
||||
$sql .= " AND dp.traite = 1";
|
||||
$result = $db->query($sql);
|
||||
if ($result) {
|
||||
if ($db->num_rows($result)) {
|
||||
$obj = $db->fetch_object($result);
|
||||
$idbon = $obj->idbon;
|
||||
}
|
||||
} else {
|
||||
$postactionmessages[] = $db->lasterror();
|
||||
$ispostactionok = -1;
|
||||
$error++;
|
||||
$errorforinvoice++;
|
||||
}
|
||||
|
||||
if (!empty($idbon)) {
|
||||
$bon->fetch($idbon);
|
||||
$sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons ";
|
||||
$sql .= " SET fk_user_credit = ".$user->id;
|
||||
$sql .= ", statut = ".$bon::STATUS_CREDITED;
|
||||
$sql .= ", date_credit = '".$db->idate($now)."'";
|
||||
$sql .= ", credite = 1";
|
||||
$sql .= " WHERE rowid=".((int) $bon->id);
|
||||
$sql .= " AND entity = ".((int) $bon->entity);
|
||||
$sql .= " AND statut = ".$bon::STATUS_TRANSFERED;
|
||||
|
||||
$db->begin();
|
||||
$result = $db->query($sql);
|
||||
if (!$result) {
|
||||
$db->rollback();
|
||||
$postactionmessages[] = $db->lasterror();
|
||||
$ispostactionok = -1;
|
||||
$error++;
|
||||
$errorforinvoice++;
|
||||
} else {
|
||||
$db->commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($event->type == 'payment_intent.payment_failed') {
|
||||
// TODO: Redirect to paymentko.php
|
||||
} elseif ($event->type == 'checkout.session.completed') { // Called when making payment with new Checkout method ($conf->global->STRIPE_USE_NEW_CHECKOUT is on).
|
||||
|
||||
Loading…
Reference in New Issue
Block a user