Fix deletion of stripe card

This commit is contained in:
Laurent Destailleur 2018-05-17 13:51:17 +02:00
parent 200af6ea5c
commit 1645c14e25

View File

@ -119,13 +119,13 @@ class InterfaceStripe
$langs->load("mails"); $langs->load("mails");
$langs->load('other'); $langs->load('other');
$ok = 0;
require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
$stripe = new Stripe($db); $stripe = new Stripe($db);
if (empty($conf->stripe->enabled)) return 0; if (empty($conf->stripe->enabled)) return 0;
$ok = 1;
$service = 'StripeTest'; $service = 'StripeTest';
$servicestatus = 0; $servicestatus = 0;
if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox', 'alpha')) if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox', 'alpha'))
@ -175,10 +175,18 @@ class InterfaceStripe
if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') { if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') {
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);
if (! empty($object->stripe_card_ref))
{
$stripeacc = $stripe->getStripeAccount($service); // No need of network access for this $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this
$stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this
if ($stripecu) { if (empty($stripeacc))
{
$ok = -1;
$this->error = "Stripe API keys are not defined into Stripe module setup for mode ".$service;
}
elseif ($stripecu)
{
// Get customer (required to get a card) // Get customer (required to get a card)
if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
$customer = \Stripe\Customer::retrieve($stripecu); $customer = \Stripe\Customer::retrieve($stripecu);
@ -196,19 +204,27 @@ class InterfaceStripe
} }
catch(Exception $e) catch(Exception $e)
{ {
$ok = -1;
$this->error = $e->getMessages(); $this->error = $e->getMessages();
} }
} }
} }
} }
} }
}
if ($action == 'COMPANYPAYMENTMODE_DELETE' && $object->type == 'card') { if ($action == 'COMPANYPAYMENTMODE_DELETE' && $object->type == 'card') {
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);
if (! empty($object->stripe_card_ref))
{
$stripeacc = $stripe->getStripeAccount($service); // No need of network access for this $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this
$stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this
if (empty($stripeacc))
if ($stripecu) {
$ok = -1;
$this->error = "Stripe API keys are not defined into Stripe module setup for mode ".$service;
}
elseif ($stripecu)
{ {
// Get customer (required to get a card) // Get customer (required to get a card)
if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
@ -227,6 +243,7 @@ class InterfaceStripe
} }
} }
} }
}
return $ok; return $ok;
} }