mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-16 14:31:29 +01:00
Try to fix conflict of several stripe accounts
This commit is contained in:
@@ -59,6 +59,8 @@ ALTER TABLE llx_emailcollector_emailcollectoraction ADD COLUMN position integer
|
|||||||
|
|
||||||
-- For v11
|
-- For v11
|
||||||
|
|
||||||
|
ALTER TABLE llx_societe_account ADD COLUMN site_account varchar(128);
|
||||||
|
|
||||||
UPDATE llx_holiday SET ref = rowid WHERE ref IS NULL;
|
UPDATE llx_holiday SET ref = rowid WHERE ref IS NULL;
|
||||||
-- VMYSQL4.3 ALTER TABLE llx_holiday MODIFY COLUMN ref varchar(30) NOT NULL;
|
-- VMYSQL4.3 ALTER TABLE llx_holiday MODIFY COLUMN ref varchar(30) NOT NULL;
|
||||||
-- VPGSQL8.2 ALTER TABLE llx_holiday ALTER COLUMN ref SET NOT NULL;
|
-- VPGSQL8.2 ALTER TABLE llx_holiday ALTER COLUMN ref SET NOT NULL;
|
||||||
|
|||||||
@@ -20,13 +20,14 @@ CREATE TABLE llx_societe_account(
|
|||||||
-- BEGIN MODULEBUILDER FIELDS
|
-- BEGIN MODULEBUILDER FIELDS
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL,
|
rowid integer AUTO_INCREMENT PRIMARY KEY NOT NULL,
|
||||||
entity integer DEFAULT 1,
|
entity integer DEFAULT 1,
|
||||||
key_account varchar(128),
|
key_account varchar(128), -- the id of third party in external web site (for site_account if site_account defined)
|
||||||
login varchar(128) NOT NULL,
|
login varchar(128) NOT NULL,
|
||||||
pass_encoding varchar(24),
|
pass_encoding varchar(24),
|
||||||
pass_crypted varchar(128),
|
pass_crypted varchar(128),
|
||||||
pass_temp varchar(128), -- temporary password when asked for forget password
|
pass_temp varchar(128), -- temporary password when asked for forget password
|
||||||
fk_soc integer,
|
fk_soc integer,
|
||||||
site varchar(128), -- name of external web site
|
site varchar(128), -- name of external web site
|
||||||
|
site_account varchar(128), -- a key to identify the account on external web site
|
||||||
fk_website integer, -- id of local web site
|
fk_website integer, -- id of local web site
|
||||||
note_private text,
|
note_private text,
|
||||||
date_last_login datetime,
|
date_last_login datetime,
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ class SocieteAccount extends CommonObject
|
|||||||
'pass_temp' => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,),
|
'pass_temp' => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,),
|
||||||
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1),
|
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1),
|
||||||
'site' => array('type'=>'varchar(128)', 'label'=>'Site', 'visible'=>-1, 'enabled'=>1, 'position'=>41),
|
'site' => array('type'=>'varchar(128)', 'label'=>'Site', 'visible'=>-1, 'enabled'=>1, 'position'=>41),
|
||||||
'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'index'=>1),
|
'site_account' => array('type'=>'varchar(128)', 'label'=>'SiteAccount', 'visible'=>-1, 'enabled'=>1, 'position'=>42, 'help'=>'A key to identify the account on external web site'),
|
||||||
|
'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>43, 'notnull'=>-1, 'index'=>1),
|
||||||
'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,),
|
'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,),
|
||||||
'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,),
|
'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,),
|
||||||
//'note_public' => array('type'=>'text', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,),
|
//'note_public' => array('type'=>'text', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,),
|
||||||
@@ -121,6 +122,7 @@ class SocieteAccount extends CommonObject
|
|||||||
public $fk_soc;
|
public $fk_soc;
|
||||||
|
|
||||||
public $site;
|
public $site;
|
||||||
|
public $site_account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var integer|string date_last_login
|
* @var integer|string date_last_login
|
||||||
@@ -297,18 +299,19 @@ class SocieteAccount extends CommonObject
|
|||||||
* @param int $id Id of third party
|
* @param int $id Id of third party
|
||||||
* @param string $site Site (example: 'stripe', '...')
|
* @param string $site Site (example: 'stripe', '...')
|
||||||
* @param int $status Status (0=test, 1=live)
|
* @param int $status Status (0=test, 1=live)
|
||||||
|
* @param string $site_account Value to use to identify with account to use on site when site can offer several accounts. For example: 'pk_live_123456' when using Stripe service.
|
||||||
* @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
|
* @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
|
||||||
* @see getThirdPartyID()
|
* @see getThirdPartyID()
|
||||||
*/
|
*/
|
||||||
public function getCustomerAccount($id, $site, $status = 0)
|
public function getCustomerAccount($id, $site, $status = 0, $site_account = '')
|
||||||
{
|
{
|
||||||
$sql = "SELECT sa.key_account as key_account, sa.entity";
|
$sql = "SELECT sa.key_account as key_account, sa.entity";
|
||||||
$sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
|
$sql .= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
|
||||||
$sql.= " WHERE sa.fk_soc = " . $id;
|
$sql .= " WHERE sa.fk_soc = " . $id;
|
||||||
$sql.= " AND sa.entity IN (".getEntity('societe').")";
|
$sql .= " AND sa.entity IN (".getEntity('societe').")";
|
||||||
$sql.= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
|
$sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
|
||||||
$sql.= " AND key_account IS NOT NULL AND key_account <> ''";
|
$sql .= " AND key_account IS NOT NULL AND key_account <> ''";
|
||||||
//$sql.= " ORDER BY sa.key_account DESC";
|
$sql .= " ORDER BY sa.site_account DESC"; // To get the entry with a site_account defined in priority
|
||||||
|
|
||||||
dol_syslog(get_class($this) . "::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG);
|
dol_syslog(get_class($this) . "::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
@@ -327,7 +330,7 @@ class SocieteAccount extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to find the thirdparty id for an another site/system external id.
|
* Try to find the thirdparty id from an another site/system external id.
|
||||||
*
|
*
|
||||||
* @param string $id Id of customer in external system (example: 'cu_xxxxxxxxxxxxx', ...)
|
* @param string $id Id of customer in external system (example: 'cu_xxxxxxxxxxxxx', ...)
|
||||||
* @param string $site Site (example: 'stripe', '...')
|
* @param string $site Site (example: 'stripe', '...')
|
||||||
|
|||||||
@@ -79,9 +79,14 @@ if (!empty($conf->stripe->enabled))
|
|||||||
$servicestatus = 1;
|
$servicestatus = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Force to use the correct API key
|
||||||
|
global $stripearrayofkeysbyenv;
|
||||||
|
$site_account = $stripearrayofkeysbyenv[$servicestatus]['public_key'];
|
||||||
|
//var_dump($site_account);
|
||||||
|
|
||||||
$stripe = new Stripe($db);
|
$stripe = new Stripe($db);
|
||||||
$stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account (no network access here)
|
$stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account (no remote access to Stripe here)
|
||||||
$stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus); // Get remote Stripe customer 'cus_...' (no network access here)
|
$stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus, $site_account); // Get remote Stripe customer 'cus_...' (no remote access to Stripe here)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -127,13 +127,14 @@ class Stripe extends CommonObject
|
|||||||
*
|
*
|
||||||
* @param int $id Id of third party
|
* @param int $id Id of third party
|
||||||
* @param int $status Status
|
* @param int $status Status
|
||||||
|
* @param string $site_account Value to use to identify with account to use on site when site can offer several accounts. For example: 'pk_live_123456' when using Stripe service.
|
||||||
* @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
|
* @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
|
||||||
*/
|
*/
|
||||||
public function getStripeCustomerAccount($id, $status = 0)
|
public function getStripeCustomerAccount($id, $status = 0, $site_account = '')
|
||||||
{
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
|
||||||
$societeaccount = new SocieteAccount($this->db);
|
$societeaccount = new SocieteAccount($this->db);
|
||||||
return $societeaccount->getCustomerAccount($id, 'stripe', $status); // Get thirdparty cus_...
|
return $societeaccount->getCustomerAccount($id, 'stripe', $status, $site_account); // Get thirdparty cus_...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user