Skip to content

Commit

Permalink
Fix to select correct record with compatibility with old record
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Dec 15, 2019
1 parent 95fc144 commit a373639
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions htdocs/stripe/class/stripe.class.php
Expand Up @@ -159,12 +159,17 @@ public function customerStripe(Societe $object, $key = '', $status = 0, $createi

$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);
Expand All @@ -175,10 +180,6 @@ public function customerStripe(Societe $object, $key = '', $status = 0, $createi
$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 {
Expand Down

0 comments on commit a373639

Please sign in to comment.