Fix creation of duplicate payment intents

This commit is contained in:
Laurent Destailleur 2019-05-17 00:26:39 +02:00
parent ae3a20d6ff
commit 8bcc7cb370

View File

@ -377,6 +377,29 @@ class Stripe extends CommonObject
// Store the payment intent // Store the payment intent
if (is_object($object)) if (is_object($object))
{
$paymentintentalreadyexists = 0;
// Check that payment intent $paymentintent->id is not already recorded.
$sql = "SELECT pi.rowid";
$sql.= " FROM " . MAIN_DB_PREFIX . "prelevement_facture_demande as pi";
$sql.= " WHERE pi.entity IN (".getEntity('societe').")";
$sql.= " AND pi.ext_payment_site = '" . $service . "'";
$sql.= " AND pi.ext_payment_id = '".$this->db->escape($paymentintent->id)."'";
dol_syslog(get_class($this) . "::getPaymentIntent search if payment intent already in prelevement_facture_demande", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num)
{
$obj = $this->db->fetch_object($resql);
if ($obj) $paymentintentalreadyexists++;
}
}
else dol_print_error($this->db);
// If not, we create it.
if (! $paymentintentalreadyexists)
{ {
$now=dol_now(); $now=dol_now();
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_facture_demande (date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site)"; $sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_facture_demande (date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site)";
@ -389,6 +412,7 @@ class Stripe extends CommonObject
dol_syslog(get_class($this) . "::PaymentIntent failed to insert paymentintent with id=".$paymentintent->id." into database."); dol_syslog(get_class($this) . "::PaymentIntent failed to insert paymentintent with id=".$paymentintent->id." into database.");
} }
} }
}
else else
{ {
$_SESSION["stripe_payment_intent"] = $paymentintent; $_SESSION["stripe_payment_intent"] = $paymentintent;