Fix syntax

This commit is contained in:
Laurent Destailleur 2018-03-13 14:48:01 +01:00
parent f7dd7e89de
commit 9c92e09295

View File

@ -102,68 +102,69 @@ class InterfaceStripe
* All functions "runTrigger" are triggered if file * All functions "runTrigger" are triggered if file
* is inside directory core/triggers * is inside directory core/triggers
* *
* @param string $action Event action code * @param string $action Event action code
* @param CommonObject $object Object * @param CommonObject $object Object
* @param User $user Object user * @param User $user Object user
* @param Translate $langs Object langs * @param Translate $langs Object langs
* @param Conf $conf Object conf * @param Conf $conf Object conf
* @return int <0 if KO, 0 if no triggered ran, >0 if OK * @return int <0 if KO, 0 if no triggered ran, >0 if OK
*/ */
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
{ {
// Put here code you want to execute when a Dolibarr business events occurs. // Put here code you want to execute when a Dolibarr business events occurs.
// Data and type of action are stored into $object and $action // Data and type of action are stored into $object and $action
global $langs,$db,$conf; global $langs, $db, $conf;
$langs->load("members"); $langs->load("members");
$langs->load("users"); $langs->load("users");
$langs->load("mails"); $langs->load("mails");
$langs->load('other'); $langs->load('other');
/** Users */
$ok=0;
$stripe=new Stripe($db);
if (empty($conf->stripe->enabled)) return 0;
if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) $ok = 0;
{ $stripe = new Stripe($db);
$service = 'StripeTest'; if (empty($conf->stripe->enabled)) return 0;
}
else
{
$service = 'StripeLive';
}
if ($action == 'COMPANY_MODIFY') { if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))
dol_syslog( {
"Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id $service = 'StripeTest';
); }
if ($stripe->getStripeAccount($service) && $object->client!=0) { else
$cu=$stripe->CustomerStripe($object->id,$stripe->getStripeAccount($service)); {
if ($cu) { $service = 'StripeLive';
if ($conf->entity=='1'){ }
$customer = \Stripe\Customer::retrieve("$cu->id");
}else{ if ($action == 'COMPANY_MODIFY') {
$customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->getStripeAccount($service))); dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
} if ($stripe->getStripeAccount($service) && $object->client != 0) {
if (!empty($object->email)) {$customer->email = "$object->email";} $cu = $stripe->customerStripe($object->id, $stripe->getStripeAccount($service));
$customer->description = "$object->name"; if ($cu) {
$customer->save(); if ($conf->entity == '1') {
}} $customer = \Stripe\Customer::retrieve("$cu->id");
} } else {
elseif ($action == 'COMPANY_DELETE') { $customer = \Stripe\Customer::retrieve("$cu->id", array(
dol_syslog( "stripe_account" => $stripe->getStripeAccount($service)
"Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id ));
); }
$cu=$stripe->CustomerStripe($object->id,$stripe->getStripeAccount($service)); if (! empty($object->email)) {
if ($cu) { $customer->email = "$object->email";
if ($conf->entity==1){ }
$customer = \Stripe\Customer::retrieve("$cu->id"); $customer->description = "$object->name";
}else{ $customer->save();
$customer = \Stripe\Customer::retrieve("$cu->id",array("stripe_account" => $stripe->getStripeAccount($service))); }
} }
$customer->delete(); } elseif ($action == 'COMPANY_DELETE') {
} dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
} $cu = $stripe->customerStripe($object->id, $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)
));
}
$customer->delete();
}
}
return $ok; return $ok;
} }