From 85059eeedb0c3e2dc956d3cf5114fa90b65cefc4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Apr 2019 02:05:57 +0200 Subject: [PATCH] Debug method getPaymentIntent --- htdocs/stripe/class/stripe.class.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 0ebef813429..fd28cd94b8a 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -265,14 +265,14 @@ class Stripe extends CommonObject $paymentintent = null; - $sql = "SELECT pi.ext_payment_id, pi.entity, pi.fk_facture, pi.sourcetype, pi.ext_payment_site"; // key_account is cus_.... + $sql = "SELECT pi.ext_payment_id, pi.entity, pi.fk_facture, pi.sourcetype, pi.ext_payment_site"; $sql.= " FROM " . MAIN_DB_PREFIX . "prelevement_facture_demande as pi"; $sql.= " WHERE pi.fk_facture = " . $object->id; $sql.= " AND pi.sourcetype = '" . $object->element . "'"; $sql.= " AND pi.entity IN (".getEntity('societe').")"; $sql.= " AND pi.ext_payment_site = '" . $service . "'"; - dol_syslog(get_class($this) . "::customerStripe search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG); + dol_syslog(get_class($this) . "::getPaymentIntent search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -281,7 +281,7 @@ class Stripe extends CommonObject $obj = $this->db->fetch_object($resql); $intent = $obj->ext_payment_id; - dol_syslog(get_class($this) . "::customerStripe found record"); + dol_syslog(get_class($this) . "::getPaymentIntent found existing payment intent record"); // Force to use the correct API key global $stripearrayofkeysbyenv; @@ -312,7 +312,10 @@ class Stripe extends CommonObject $fee = round($conf->global->STRIPE_APPLICATION_FEE_MINIMAL * 100); } - $description=$object->element.$object->ref; + $ipaddress=getUserRemoteIP(); + // Not enough space for a ref so we store id. Also with multicompany we can have same ref for 2 different + // object and we need a unique (this is used later as idempotency_key) + $description=$object->element.$object->id; $dataforintent = array( "amount" => $stripeamount, @@ -320,7 +323,7 @@ class Stripe extends CommonObject "customer" => $customer, "allowed_source_types" => ["card"], "statement_descriptor" => dol_trunc($description, 10, 'right', 'UTF-8', 1), // 22 chars that appears on bank receipt (company + description) - "metadata" => array('dol_type'=>$object->element, 'dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])) + "metadata" => array('dol_type'=>$object->element, 'dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>$ipaddress) ); if ($conf->entity!=$conf->global->STRIPECONNECT_PRINCIPAL && $fee>0) @@ -344,12 +347,12 @@ class Stripe extends CommonObject } $now=dol_now(); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_facture_demande (fk_soc, date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site)"; - $sql .= " VALUES ('".$object->socid."','".$this->db->idate($now)."', '0', '".$this->db->escape($paymentintent->id)."', ".$object->id.", '".$object->element."', " . $conf->entity . ", '" . $service . "')"; + $sql .= " VALUES ('".$object->socid."','".$this->db->idate($now)."', '0', '".$this->db->escape($paymentintent->id)."', ".$object->id.", '".$this->db->escape($object->element)."', " . $conf->entity . ", '" . $service . "')"; $resql = $this->db->query($sql); if (! $resql) { $this->error = $this->db->lasterror(); - dol_syslog(get_class($this) . "::PaymentIntent not insert with id=".$paymentintent->id); + dol_syslog(get_class($this) . "::PaymentIntent failed to insert paymentintent with id=".$paymentintent->id." into database."); } } catch(Exception $e)