Merge pull request #8370 from ptibogxiv/patch-15

FIX with new database llx_societe_account
This commit is contained in:
Laurent Destailleur 2018-03-13 14:02:24 +01:00 committed by GitHub
commit 72d4b0dcf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,8 +126,8 @@ class Stripe extends CommonObject
/** /**
* customerStripe * customerStripe
* *
* @param int $id ??? * @param int $id Id of third party
* @param string $key ??? * @return string Stripe account ref 'acc_xxxxxxxxxxxxx'
* @return \Stripe\StripeObject|\Stripe\ApiResource * @return \Stripe\StripeObject|\Stripe\ApiResource
*/ */
public function customerStripe($id,$key) public function customerStripe($id,$key)
@ -142,10 +142,11 @@ class Stripe extends CommonObject
$mode = $conf->global->STRIPE_LIVE; $mode = $conf->global->STRIPE_LIVE;
} }
} }
$sql = "SELECT rowid,fk_soc,fk_key,mode,entity"; $sql = "SELECT sa.key_account as key_account, sa.entity";
$sql .= " FROM " . MAIN_DB_PREFIX . "societe_stripe"; $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
$sql .= " WHERE fk_soc = " . $id . " "; $sql.= " WHERE sa.fk_soc = " . $id;
$sql .= " AND mode=" . $mode . " AND entity IN (" . getEntity('stripe') . ")"; $sql.= " AND sa.entity IN (".getEntity('societe').")";
$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -155,7 +156,7 @@ class Stripe extends CommonObject
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
if ($num) { if ($num) {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$tiers = $obj->fk_key; $tiers = $obj->key_account;
if ($conf->entity == 1) { if ($conf->entity == 1) {
$customer = \Stripe\Customer::retrieve("$tiers"); $customer = \Stripe\Customer::retrieve("$tiers");
} else { } else {
@ -178,8 +179,8 @@ class Stripe extends CommonObject
)); ));
} }
$customer_id = "" . $customer->id . ""; $customer_id = "" . $customer->id . "";
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_stripe (fk_soc,fk_key,mode,entity)"; $sql = "INSERT INTO " . MAIN_DB_PREFIX . "societe_account (fk_soc,key_account,site,status,entity)";
$sql .= " VALUES ($id,'$customer_id'," . $mode . "," . $conf->entity . ")"; $sql .= " VALUES ($id,'$customer_id','stripe'," . $mode . "," . $conf->entity . ")";
dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG); dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
} }
@ -188,44 +189,41 @@ class Stripe extends CommonObject
} }
/** /**
* createPaymentStripe * createPaymentStripe Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API
* *
* @param unknown $amount ??? * @param int $amount amount to pay
* @param unknown $currency ??? * @param string $currency EUR, GPB...
* @param unknown $origin ??? * @param string $origin order, invoice, contract...
* @param unknown $item ??? * @param int $item if of element to pay
* @param unknown $source ??? * @param string $source src_xxxxx or card_xxxxx or ac_xxxxx
* @param unknown $customer ??? * @param string $customer Stripe account ref 'cu_xxxxxxxxxxxxx' via customerStripe()
* @param unknown $account ??? * @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount()
* @param int $status Status
* @return Stripe * @return Stripe
*/ */
public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account) public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0)
{ {
global $conf; global $conf;
if (empty($conf->global->STRIPECONNECT_LIVE)) { $sql = "SELECT sa.key_account as key_account, sa.entity";
$mode = 0; $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa";
} else { $sql.= " WHERE sa.key_account = " . $customer;
if (empty($conf->global->STRIPE_LIVE)) { //$sql.= " AND sa.entity IN (".getEntity('societe').")";
$mode = 0; $sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
} else {
$mode = $conf->global->STRIPE_LIVE;
}
}
$sql = "SELECT fk_soc,fk_key,mode,entity";
$sql .= " FROM " . MAIN_DB_PREFIX . "societe_stripe";
$sql .= " WHERE fk_key = '$customer' ";
$sql .= " AND mode=" . $mode . " ";
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
if ($this->db->num_rows($result)) { if ($this->db->num_rows($result)) {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
$entite = $obj->entity; $key = $obj->fk_soc;
$fksoc = $obj->fk_soc; } else {
$key = NULL;
} }
} else {
$key = NULL;
} }
$stripeamount = round($amount * 100); $stripeamount = round($amount * 100);
$societe = new Societe($this->db); $societe = new Societe($this->db);
$societe->fetch($fksoc); $societe->fetch($fksoc);