31 require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
48 $this->
name = preg_replace(
'/^Interface/i',
'', get_class($this));
49 $this->family =
'stripe';
50 $this->
description =
"Triggers of the module Stripe";
51 $this->version = self::VERSIONS[
'prod'];
52 $this->picto =
'stripe';
71 global $langs, $db, $conf;
73 if (empty($conf->stripe) || empty($conf->stripe->enabled)) {
77 require_once DOL_DOCUMENT_ROOT.
'/stripe/class/stripe.class.php';
82 $service =
'StripeTest';
85 $service =
'StripeLive';
91 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
93 $stripeacc = $stripe->getStripeAccount($service);
96 $customer = $stripe->customerStripe(
$object, $stripeacc, $servicestatus);
101 $taxexemptcleaned =
$object->tva_assuj ?
'none' :
'exempt';
102 $langcleaned =
$object->default_lang ? array(substr(
$object->default_lang, 0, 2)) :
null;
112 $changerequested = 0;
113 if (!empty(
$object->email) &&
$object->email != $customer->email) {
123 if ($namecleaned != $customer->name) {
126 if ($desccleaned != $customer->description) {
129 if (($customer->tax_exempt ==
'exempt' && !
$object->tva_assuj) || (!$customer->tax_exempt ==
'exempt' && empty(
$object->tva_assuj))) {
132 if (!isset($customer->tax_ids->data) && !is_null($vatcleaned)) {
134 } elseif (isset($customer->tax_ids->data)) {
135 $taxinfo = reset($customer->tax_ids->data);
136 if (empty($taxinfo) && !empty($vatcleaned)) {
139 if (isset($taxinfo->value) && $vatcleaned != $taxinfo->value) {
144 if ($changerequested) {
149 $customer->name = $namecleaned;
150 $customer->description = $desccleaned;
151 $customer->preferred_locales = $langcleaned;
152 $customer->tax_exempt = $taxexemptcleaned;
157 if (!empty($vatcleaned)) {
159 if (
$object->country_code && $isineec) {
161 $customer->createTaxId($customer->id, array(
'type' =>
'eu_vat',
'value' => $vatcleaned));
164 $taxids = $customer->allTaxIds($customer->id);
165 if (is_array($taxids->data)) {
166 foreach ($taxids->data as $taxidobj) {
168 $customer->deleteTaxId($customer->id, $taxidobj->id);
179 $this->errors[] = $e->getMessage();
187 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
191 $stripeacc = $stripe->getStripeAccount($service);
193 $customer = $stripe->customerStripe(
$object, $stripeacc, $servicestatus);
198 dol_syslog(
"Failed to delete Stripe customer ".$e->getMessage(), LOG_WARNING);
203 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_account";
204 $sql .=
" WHERE site='stripe' AND fk_soc = ".((int)
$object->id);
205 $this->db->query(
$sql);
209 if ($action ==
'COMPANYPAYMENTMODE_CREATE' &&
$object->type ==
'card') {
213 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
215 if (!empty(
$object->stripe_card_ref)) {
216 $stripeacc = $stripe->getStripeAccount($service);
217 $stripecu = $stripe->getStripeCustomerAccount(
$object->fk_soc);
221 if (empty($stripeacc)) {
222 $customer = \Stripe\Customer::retrieve($stripecu);
224 $customer = \Stripe\Customer::retrieve($stripecu, array(
"stripe_account" => $stripeacc));
228 dol_syslog(
"We got the customer, so now we update the credit card", LOG_DEBUG);
229 $card = $stripe->cardStripe($customer,
$object, $stripeacc, $servicestatus);
232 $card->metadata = array(
'dol_id' =>
$object->id,
'dol_version' => DOL_VERSION,
'dol_entity' => $conf->entity,
'ipaddress' => (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']));
238 $this->errors[] = $e->getMessages();
246 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
248 if (!empty(
$object->stripe_card_ref)) {
249 $stripeacc = $stripe->getStripeAccount($service);
250 $stripecu = $stripe->getStripeCustomerAccount(
$object->fk_soc);
254 if (empty($stripeacc)) {
255 $customer = \Stripe\Customer::retrieve($stripecu);
257 $customer = \Stripe\Customer::retrieve($stripecu, array(
"stripe_account" => $stripeacc));
261 $card = $stripe->cardStripe($customer,
$object, $stripeacc, $servicestatus);
263 if (method_exists($card,
'detach')) {
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class for CompanyPaymentMode.
Class to stock current configuration.
Class that all triggers must inherit.
Class of triggers for stripe module.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarr business event is done.
__construct($db)
Constructor.
Class to manage third parties objects (customers, suppliers, prospects...)
Stripe class @TODO No reason to extends CommonObject.
Class to manage translations.
Class to manage Dolibarr users.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.