Fix use correct stripe env

This commit is contained in:
Laurent Destailleur 2018-05-17 16:07:44 +02:00
parent 4f6b0fead6
commit ffb6a5db81
2 changed files with 40 additions and 20 deletions

View File

@ -135,7 +135,7 @@ class Stripe extends CommonObject
$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
$sql.= " AND key_account IS NOT NULL AND key_account <> ''";
dol_syslog(get_class($this) . "::fetch search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG);
dol_syslog(get_class($this) . "::customerStripe search stripe customer id for thirdparty id=".$object->id, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
@ -143,6 +143,13 @@ class Stripe extends CommonObject
{
$obj = $this->db->fetch_object($resql);
$tiers = $obj->key_account;
dol_syslog(get_class($this) . "::customerStripe found stripe customer key_account = ".$tiers);
// Force to use the correct API key
global $stripearrayofkeysbyenv;
\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
try {
if (empty($key)) { // If the Stripe connect account not set, we use common API usage
$customer = \Stripe\Customer::retrieve("$tiers");
@ -167,6 +174,10 @@ class Stripe extends CommonObject
//$a = \Stripe\Stripe::getApiKey();
//var_dump($a);var_dump($key);exit;
try {
// Force to use the correct API key
global $stripearrayofkeysbyenv;
\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
if (empty($key)) { // If the Stripe connect account not set, we use common API usage
$customer = \Stripe\Customer::create($dataforcustomer);
} else {
@ -373,6 +384,10 @@ class Stripe extends CommonObject
);
$return = new Stripe($this->db);
try {
// Force to use the correct API key
global $stripearrayofkeysbyenv;
\Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']);
if (empty($conf->stripeconnect->enabled))
{
if (preg_match('/acct_/i', $source))
@ -410,17 +425,17 @@ class Stripe extends CommonObject
}
$charge = \Stripe\Charge::create(array(
"amount" => "$stripeamount",
"currency" => "$currency",
// "statement_descriptor" => " ",
"description" => "$description",
"metadata" => $metadata,
"source" => "$source",
"customer" => "$customer",
"application_fee" => "$fee"
), array(
"idempotency_key" => "$ref",
"stripe_account" => "$account"
"amount" => "$stripeamount",
"currency" => "$currency",
// "statement_descriptor" => " ",
"description" => "$description",
"metadata" => $metadata,
"source" => "$source",
"customer" => "$customer",
"application_fee" => "$fee"
), array(
"idempotency_key" => "$ref",
"stripe_account" => "$account"
));
}
if (isset($charge->id)) {}

View File

@ -30,22 +30,27 @@ require_once DOL_DOCUMENT_ROOT.'/includes/stripe/lib/Stripe.php';
global $stripe;
global $conf;
global $stripearrayofkeysbyenv;
$stripearrayofkeysbyenv = array(
0=>array(
"secret_key" => $conf->global->STRIPE_TEST_SECRET_KEY,
"publishable_key" => $conf->global->STRIPE_TEST_PUBLISHABLE_KEY
),
1=>array(
"secret_key" => $conf->global->STRIPE_LIVE_SECRET_KEY,
"publishable_key" => $conf->global->STRIPE_LIVE_PUBLISHABLE_KEY
)
);
$stripearrayofkeys = array();
if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))
{
$stripearrayofkeys = array(
"secret_key" => $conf->global->STRIPE_TEST_SECRET_KEY,
"publishable_key" => $conf->global->STRIPE_TEST_PUBLISHABLE_KEY
);
$stripearrayofkeys = $stripearrayofkeysbyenv[0];
}
else
{
$stripearrayofkeys = array(
"secret_key" => $conf->global->STRIPE_LIVE_SECRET_KEY,
"publishable_key" => $conf->global->STRIPE_LIVE_PUBLISHABLE_KEY
);
$stripearrayofkeys = $stripearrayofkeysbyenv[1];
}
\Stripe\Stripe::setApiKey($stripearrayofkeys['secret_key']);