Fix to select correct record with compatibility with old record

This commit is contained in:
Laurent Destailleur 2019-12-15 17:44:05 +01:00
parent 95fc14475c
commit a3736399da

View File

@ -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 {