From a3736399da92db76ab8810f982873d3bedf21c31 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 15 Dec 2019 17:44:05 +0100 Subject: [PATCH] Fix to select correct record with compatibility with old record --- htdocs/stripe/class/stripe.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index e425b54de6f..13b16d258d1 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -159,12 +159,17 @@ class Stripe extends CommonObject $customer = null; + // Force to use the correct API key + global $stripearrayofkeysbyenv; + \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']); + $sql = "SELECT sa.key_account as key_account, sa.entity"; // key_account is cus_.... $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa"; $sql .= " WHERE sa.fk_soc = ".$object->id; $sql .= " AND sa.entity IN (".getEntity('societe').")"; $sql .= " AND sa.site = 'stripe' AND sa.status = ".((int) $status); - $sql .= " AND key_account IS NOT NULL AND key_account <> ''"; + $sql .= " AND (sa.site_account IS NULL OR sa.site_account = '' OR sa.site_account = '".$this->db->escape($stripearrayofkeysbyenv[$status]['publishable_key'])."'"; + $sql .= " AND sa.key_account IS NOT NULL AND sa.key_account <> ''"; dol_syslog(get_class($this)."::customerStripe search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG); $resql = $this->db->query($sql); @@ -175,10 +180,6 @@ class Stripe extends CommonObject $obj = $this->db->fetch_object($resql); $tiers = $obj->key_account; - // Force to use the correct API key - global $stripearrayofkeysbyenv; - \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']); - dol_syslog(get_class($this)."::customerStripe found stripe customer key_account = ".$tiers.". We will try to read it on Stripe with publishable_key = ".$stripearrayofkeysbyenv[$status]['publishable_key']); try {