Fix syntax
This commit is contained in:
parent
f7dd7e89de
commit
9c92e09295
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user