diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php
index d2d138b8478..3f07066bf2e 100644
--- a/htdocs/core/class/html.formother.class.php
+++ b/htdocs/core/class/html.formother.class.php
@@ -815,13 +815,14 @@ class FormOther
/**
* Return HTML combo list of month
*
- * @param string $selected Preselected value
- * @param string $htmlname Name of HTML select object
- * @param int $useempty Show empty in list
- * @param int $longlabel Show long label
+ * @param string $selected Preselected value
+ * @param string $htmlname Name of HTML select object
+ * @param int $useempty Show empty in list
+ * @param int $longlabel Show long label
+ * @param string $morecss More Css
* @return string
*/
- function select_month($selected='',$htmlname='monthid',$useempty=0,$longlabel=0)
+ function select_month($selected='', $htmlname='monthid', $useempty=0, $longlabel=0, $morecss='')
{
global $langs;
@@ -830,7 +831,7 @@ class FormOther
if ($longlabel) $montharray = monthArray($langs, 0); // Get array
else $montharray = monthArray($langs, 1);
- $select_month = '';
+ $select_month = '';
if ($useempty)
{
$select_month .= ' ';
diff --git a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php
index 495f439eb09..13c5b7ece00 100644
--- a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php
+++ b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php
@@ -123,49 +123,91 @@ class InterfaceStripe
$stripe = new Stripe($db);
if (empty($conf->stripe->enabled)) return 0;
- if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))
- {
- $service = 'StripeTest';
- }
- else
+ $service = 'StripeTest';
+ $servicestatus = 0;
+ if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox', 'alpha'))
{
$service = 'StripeLive';
+ $servicestatus = 1;
}
+ // If customer is linked to Strip, we update/delete Stripe too
if ($action == 'COMPANY_MODIFY') {
dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
- if ($stripe->getStripeAccount($service) && $object->client != 0) {
- $cu = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
- if ($cu) {
- if ($conf->entity == '1') {
- $customer = \Stripe\Customer::retrieve("$cu->id");
- } else {
- $customer = \Stripe\Customer::retrieve("$cu->id", array(
- "stripe_account" => $stripe->getStripeAccount($service)
- ));
+
+ $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this
+
+ if ($object->client != 0) {
+ $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus);
+ if ($customer) {
+ if (! empty($object->email))
+ {
+ $customer->email = $object->email;
}
- if (! empty($object->email)) {
- $customer->email = "$object->email";
- }
- $customer->description = "$object->name";
+ $customer->description = $object->name;
+ // TODO More data
+ //$customer->vat = $object->tva_intra
+
$customer->save();
}
}
- } elseif ($action == 'COMPANY_DELETE') {
+ }
+ if ($action == 'COMPANY_DELETE') {
dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
- $cu = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
- if ($cu) {
- if ($conf->entity == 1) {
- $customer = \Stripe\Customer::retrieve("$cu->id");
- } else {
- $customer = \Stripe\Customer::retrieve("$cu->id", array(
- "stripe_account" => $stripe->getStripeAccount($service)
- ));
- }
+
+ $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this
+
+ $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus);
+ if ($customer) {
$customer->delete();
}
}
+ // If payment mode is linked to Strip, we update/delete Stripe too
+ if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') {
+
+ // For creation of credit card, we do not create in Stripe automatically
+
+ }
+ if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') {
+ dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
+
+ $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this
+
+ $thirdparty=new Societe($this->db);
+ $thirdparty->fetch($object->fk_soc);
+
+ if ($object->client != 0) {
+ $card = $stripe->cardStripe($thirdparty, $object, $stripeacc, $servicestatus);
+ if (card) {
+ /*if (! empty($object->email))
+ {
+ $customer->email = $object->email;
+ }
+ $customer->description = $object->name;
+ // TODO More data
+ //$customer->vat = $object->tva_intra
+
+ card->save();
+ */
+ }
+ }
+ }
+ if ($action == 'COMPANYPAYMENTMODE_DELETE' && $object->type == 'card') {
+ dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
+
+ $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this
+
+ $thirdparty=new Societe($this->db);
+ $thirdparty->fetch($object->fk_soc);
+
+ $card = $stripe->cardStripe($thirdparty, $object, $stripeacc, $servicestatus);
+ if ($card) {
+ if (method_exists($card, 'detach')) $card->detach();
+ else $card->delete();
+ }
+ }
+
return $ok;
}
}
diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php
index 83ba4c7a899..7f373c8de4e 100644
--- a/htdocs/societe/paymentmodes.php
+++ b/htdocs/societe/paymentmodes.php
@@ -69,9 +69,6 @@ $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$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';
@@ -368,8 +365,8 @@ if (empty($reshook))
$companypaymentmode->datec = dol_now();
$companypaymentmode->default_rib = 0;
$companypaymentmode->type = 'card';
- $companypaymentmode->country_code = $mysoc->country_code;
- $companypaymentmode->status = 1;
+ $companypaymentmode->country_code = $object->country_code;
+ $companypaymentmode->status = $servicestatus;
$companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref','alpha');
diff --git a/htdocs/societe/societecontact.php b/htdocs/societe/societecontact.php
index 67a44d87ccf..6b3e833abb0 100644
--- a/htdocs/societe/societecontact.php
+++ b/htdocs/societe/societecontact.php
@@ -45,6 +45,9 @@ $result = restrictedArea($user, 'societe', $id,'');
$object = new Societe($db);
+// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
+$hookmanager->initHooks(array('contactthirdparty','globalcard'));
+
/*
* Actions
diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php
index fe973e3b603..329f26ca40e 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 string Stripe account 'acc_....'
+ * @return string Stripe account 'acc_....' or '' if no OAuth token found
*/
public function getStripeAccount($mode='StripeTest')
{