diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php
index f4d9f1b6173..53f714b414c 100644
--- a/htdocs/societe/paymentmodes.php
+++ b/htdocs/societe/paymentmodes.php
@@ -69,6 +69,21 @@ $hookmanager->initHooks(array('thirdpartybancard','globalcard'));
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('thirdpartybancard'));
+if (! empty($conf->stripe->enabled))
+{
+ $service = 'StripeTest';
+ $servicestatus = 0;
+ if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha'))
+ {
+ $service = 'StripeLive';
+ $servicestatus = 0;
+ }
+
+ $stripe = new Stripe($db);
+ $stripeacc = $stripe->getStripeAccount($service); // Stripe OAuth connect account of dolibarr user (no network access here)
+ $stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus); // Get thirdparty cu_...
+}
+
/*
@@ -91,7 +106,6 @@ if (empty($reshook))
}
}
-
if ($action == 'update' && ! $_POST["cancel"])
{
// Modification
@@ -332,32 +346,29 @@ if (empty($reshook))
$id = $savid;
}
+// Action for stripe
if (! empty($conf->stripe->enabled) && class_exists('Stripe'))
{
- $stripe=new Stripe($db);
-
- if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest';
- else $service = 'StripeLive';
-
- $customerstripe=$stripe->customerStripe($socid, $stripe->getStripeAccount($service));
- if ($customerstripe->id) {
- $cu = \Stripe\Customer::retrieve("".$customerstripe->id."");}
-
- $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
if ($action == 'setassourcedefault')
{
- $cu->default_source = "$source"; // obtained with Stripe.js
- $cu->save();
+ $cu = \Stripe\Customer::retrieve($stripecu);
- header('Location: '.$url);
- exit;
+ $cu->default_source = "$source"; // obtained with Stripe.js
+ $cu->save();
+
+ $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
+ header('Location: '.$url);
+ exit;
}
elseif ($action == 'delete')
{
- $cu->sources->retrieve("$source")->detach();
+ $cu = \Stripe\Customer::retrieve($stripecu);
- header('Location: '.$url);
- exit;
+ $cu->sources->retrieve("$source")->detach();
+
+ $url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
+ header('Location: '.$url);
+ exit;
}
}
@@ -446,13 +457,13 @@ if ($socid && $action != 'edit' && $action != "create")
if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts');
}
- if (! (empty($conf->stripe->enabled)))
+ if (! empty($conf->stripe->enabled))
{
- $stripe = new Stripe($db);
- // Prospect/Customer
+
+ // Stripe customer key 'cu_....' stored into llx_societe_account
print '
| '.$langs->trans('StripeCustomerId').' | ';
- print $stripe->getStripeCustomerAccount($object->id);
+ print $stripecu;
print ' |
';
}
@@ -460,22 +471,23 @@ if ($socid && $action != 'edit' && $action != "create")
print '';
print '';
+ print '
';
+
if (! (empty($conf->stripe->enabled)))
{
- print load_fiche_titre($langs->trans('StripeGateways'), '', '');
+ print load_fiche_titre($langs->trans('StripeGateways').($stripeacc ? ' ('.$stripeacc.')':''), '', '');
- if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest';
- else $service = 'StripeLive';
-
- if (is_object($stripe) && $stripe->getStripeAccount($service))
+ $listofsources = array();
+ if (is_object($stripe) && $stripeacc)
{
- $customerstripe=$stripe->customerStripe($object->id,$stripe->getStripeAccount($service));
- }
-
- if ($customerstripe->id) {
- $input=$customerstripe->sources->data;
+ $customerstripe=$stripe->customerStripe($object->id, $stripeacc, $servicestatus);
+
+ if ($customerstripe->id) {
+ $listofsources=$customerstripe->sources->data;
+ }
}
+ print ''; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '
'."\n";
print '';
print '| '.$langs->trans('Type').' | ';
@@ -484,9 +496,9 @@ if ($socid && $action != 'edit' && $action != "create")
print ''.$langs->trans('Default').' | ';
print " |
\n";
- if (is_array($input))
+ if (is_array($listofsources))
{
- foreach ($input as $src)
+ foreach ($listofsources as $src)
{
print '';
print '| ';
@@ -581,11 +593,12 @@ if ($socid && $action != 'edit' && $action != "create")
print ' |
';
}
}
- if (empty($input))
+ if (empty($listofsources))
{
print '| '.$langs->trans("NoSource").' |
';
}
print "
";
+ print "
";
}
@@ -599,7 +612,7 @@ if ($socid && $action != 'edit' && $action != "create")
$var = false;
if (is_array($rib_list))
{
- print ''; // You can use div-table-responsive-no-min if you dont need reserved height for your table
+ print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '
';
print '';
diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php
index a0f6008b6f8..dfecc56a172 100644
--- a/htdocs/stripe/class/stripe.class.php
+++ b/htdocs/stripe/class/stripe.class.php
@@ -55,7 +55,7 @@ class Stripe extends CommonObject
* Return main company OAuth Connect stripe account
*
* @param string $mode 'StripeTest' or 'StripeLive'
- * @return int ???
+ * @return string Stripe account 'acc_....'
*/
public function getStripeAccount($mode='StripeTest')
{
@@ -106,7 +106,7 @@ class Stripe extends CommonObject
$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) . "::getStripeCustomerAccount Try to find the cu_.... of thirdparty id=".$id, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
if ($this->db->num_rows($result)) {
@@ -145,10 +145,9 @@ class Stripe extends CommonObject
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
- $soc = new Societe($this->db);
- $soc->fetch($id);
$num = $this->db->num_rows($resql);
- if ($num) {
+ if ($num)
+ {
$obj = $this->db->fetch_object($resql);
$tiers = $obj->key_account;
if ($conf->entity == 1) {
@@ -159,8 +158,11 @@ class Stripe extends CommonObject
));
}
}
- else
+ elseif ($createifnotlinkedtostripe)
{
+ $soc = new Societe($this->db);
+ $soc->fetch($id);
+
if ($conf->entity == 1) {
$customer = \Stripe\Customer::create(array(
"email" => $soc->email,