Fix for new stripe API 2018-08-23

Fix break with change API
This commit is contained in:
ptibogxiv 2018-08-28 13:32:38 +02:00 committed by GitHub
parent 50d50c2e10
commit 523b03e132
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,7 +136,6 @@ class InterfaceStripe
$service = 'StripeLive'; $service = 'StripeLive';
$servicestatus = 1; $servicestatus = 1;
} }
// If customer is linked to Strip, we update/delete Stripe too // If customer is linked to Strip, we update/delete Stripe too
if ($action == 'COMPANY_MODIFY') { if ($action == 'COMPANY_MODIFY') {
dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
@ -148,19 +147,22 @@ class InterfaceStripe
if ($customer) if ($customer)
{ {
$namecleaned = $object->name ? $object->name : null; $namecleaned = $object->name ? $object->name : null;
$vatcleaned = $object->tva_intra ? $object->tva_intra : null; // We force data to "null" if empty as expected by Stripe $vatcleaned = array(
"tax_id" => $object->tva_intra ? $object->tva_intra : null, // We force data to "null" if empty as expected by Stripe
"type" => 'vat',
);
// Detect if we change a Stripe info (email, description, vat id) // Detect if we change a Stripe info (email, description, vat id)
$changerequested = 0; $changerequested = 0;
if (! empty($object->email) && $object->email != $customer->email) $changerequested++; if (! empty($object->email) && $object->email != $customer->email) $changerequested++;
if ($namecleaned != $customer->description) $changerequested++; if ($namecleaned != $customer->description) $changerequested++;
if ($vatcleaned != $customer->business_vat_id) $changerequested++; if ($vatcleaned != $customer->tax_info) $changerequested++;
if ($changerequested) if ($changerequested)
{ {
if (! empty($object->email)) $customer->email = $object->email; if (! empty($object->email)) $customer->email = $object->email;
$customer->description = $namecleaned; $customer->description = $namecleaned;
$customer->business_vat_id = $vatcleaned; $customer->tax_info = $vatcleaned;
$customer->save(); $customer->save();
} }