From 9c92e092954b927efcbd251c7e445388e41a7e50 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Mar 2018 14:48:01 +0100 Subject: [PATCH] Fix syntax --- .../interface_80_modStripe_Stripe.class.php | 117 +++++++++--------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php index f639695cc40..a41ade1e01b 100644 --- a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php @@ -29,7 +29,7 @@ */ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; dol_include_once('/stripe/class/stripe.class.php'); -$path=dirname(__FILE__).'/'; +$path=dirname(__FILE__).'/'; /** * Class of triggers for stripe module */ @@ -102,69 +102,70 @@ class InterfaceStripe * All functions "runTrigger" are triggered if file * is inside directory core/triggers * - * @param string $action Event action code - * @param CommonObject $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param Conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK + * @param string $action Event action code + * @param CommonObject $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param Conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK */ - public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) { // Put here code you want to execute when a Dolibarr business events occurs. // Data and type of action are stored into $object and $action -global $langs,$db,$conf; -$langs->load("members"); -$langs->load("users"); -$langs->load("mails"); -$langs->load('other'); -/** Users */ -$ok=0; -$stripe=new Stripe($db); -if (empty($conf->stripe->enabled)) return 0; + global $langs, $db, $conf; + $langs->load("members"); + $langs->load("users"); + $langs->load("mails"); + $langs->load('other'); + + $ok = 0; + $stripe = new Stripe($db); + if (empty($conf->stripe->enabled)) return 0; + + if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha')) + { + $service = 'StripeTest'; + } + else + { + $service = 'StripeLive'; + } + + 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->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) + )); + } + if (! empty($object->email)) { + $customer->email = "$object->email"; + } + $customer->description = "$object->name"; + $customer->save(); + } + } + } 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(); + } + } -if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha'))) -{ - $service = 'StripeTest'; -} -else -{ - $service = 'StripeLive'; -} - -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->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))); - } -if (!empty($object->email)) {$customer->email = "$object->email";} -$customer->description = "$object->name"; -$customer->save(); -}} - } -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; } }