From 194a094d23006088c8c3d2612c047b3306a1a4c4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 22 Jun 2020 11:32:58 +0200 Subject: [PATCH] Fix deletion of a thirdparty must not delete the stripe account. --- .../interface_80_modStripe_Stripe.class.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php index 5c0f17dd90d..fc9db9cd937 100644 --- a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php @@ -204,16 +204,19 @@ class InterfaceStripe extends DolibarrTriggers if ($action == 'COMPANY_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. + if (! empty($conf->global->STRIPE_DELETE_STRIPE_ACCIUNT_WHEN_DELETING_THIRPARTY)) { + // By default, we do not delete the stripe account. We may need to reuse it with its payment_intent, for example if delete is for a merge of thirdparties. + $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. - $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); - if ($customer) - { - try { - $customer->delete(); - } catch (Exception $e) + $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); + if ($customer) { - dol_syslog("Failed to delete Stripe customer ".$e->getMessage(), LOG_WARNING); + try { + $customer->delete(); + } catch (Exception $e) + { + dol_syslog("Failed to delete Stripe customer ".$e->getMessage(), LOG_WARNING); + } } }