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->getMessage();
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')) {