diff --git a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql index 4f70af3b566..9ffda1e9132 100644 --- a/htdocs/install/mysql/migration/10.0.0-11.0.0.sql +++ b/htdocs/install/mysql/migration/10.0.0-11.0.0.sql @@ -76,3 +76,5 @@ ALTER TABLE llx_c_price_expression MODIFY COLUMN expression varchar(255) NOT NUL UPDATE llx_bank_url set url = REPLACE( url, 'compta/salaries/', 'salaries/'); ALTER TABLE llx_stock_mouvement ADD COLUMN fk_projet INTEGER NOT NULL DEFAULT 0 AFTER model_pdf; + +ALTER TABLE llx_oauth_token ADD COLUMN fk_soc integer DEFAULT NULL after token; diff --git a/htdocs/install/mysql/tables/llx_oauth_token.sql b/htdocs/install/mysql/tables/llx_oauth_token.sql index 81ae99c6ce6..6698335c07e 100644 --- a/htdocs/install/mysql/tables/llx_oauth_token.sql +++ b/htdocs/install/mysql/tables/llx_oauth_token.sql @@ -20,6 +20,7 @@ CREATE TABLE llx_oauth_token ( service varchar(36), token text, -- token in serialize() format, of an object StdOAuth2Token of library phpoauth2 tokenstring text, -- token in json format '{"access_token": "sk_test_cccc", "refresh_token": "rt_aaa", "token_type": "bearer", ..., "scope": "read_write"} + fk_soc integer, fk_user integer, fk_adherent integer, entity integer DEFAULT 1 diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index c6df1206d0f..5dda24a763e 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -78,9 +78,10 @@ class Stripe extends CommonObject * Return main company OAuth Connect stripe account * * @param string $mode 'StripeTest' or 'StripeLive' + * @param int $fk_soc Id of thirdparty * @return string Stripe account 'acc_....' or '' if no OAuth token found */ - public function getStripeAccount($mode = 'StripeTest') + public function getStripeAccount($mode = 'StripeTest', $fk_soc = 0) { global $conf; @@ -88,6 +89,13 @@ class Stripe extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."oauth_token"; $sql.= " WHERE entity = ".$conf->entity; $sql.= " AND service = '".$mode."'"; + if ($fk_soc > 0) { + $sql.= " AND fk_soc = ".$fk_soc; + } + else { + $sql.= " AND fk_soc IS NULL"; + } + $sql.= " AND fk_user IS NULL AND fk_adherent IS NULL"; dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); $result = $this->db->query($sql);