diff --git a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php index 13c5b7ece00..b6428c51b28 100644 --- a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php @@ -172,39 +172,56 @@ class InterfaceStripe if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') { 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 + $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this + $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this - $thirdparty=new Societe($this->db); - $thirdparty->fetch($object->fk_soc); + if ($stripecu) { + // Get customer (required to get a card) + if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage + $customer = \Stripe\Customer::retrieve($stripecu); + } else { + $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); + } - if ($object->client != 0) { - $card = $stripe->cardStripe($thirdparty, $object, $stripeacc, $servicestatus); - if (card) { - /*if (! empty($object->email)) - { - $customer->email = $object->email; + if ($customer) + { + $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); + if ($card) { + $card->metadata=array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])); + try { + $card->save($dataforcard); + } + catch(Exception $e) + { + $this->error = $e->getMessages(); + } } - $customer->description = $object->name; - // TODO More data - //$customer->vat = $object->tva_intra - - card->save(); - */ } } } if ($action == 'COMPANYPAYMENTMODE_DELETE' && $object->type == 'card') { 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 + $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this + $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this - $thirdparty=new Societe($this->db); - $thirdparty->fetch($object->fk_soc); + if ($stripecu) + { + // Get customer (required to get a card) + if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage + $customer = \Stripe\Customer::retrieve($stripecu); + } else { + $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); + } - $card = $stripe->cardStripe($thirdparty, $object, $stripeacc, $servicestatus); - if ($card) { - if (method_exists($card, 'detach')) $card->detach(); - else $card->delete(); + if ($customer) + { + $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); + if ($card) { + if (method_exists($card, 'detach')) $card->detach(); + else $card->delete(); + } + } } } diff --git a/htdocs/societe/paymentmodes.php b/htdocs/societe/paymentmodes.php index 7f373c8de4e..8d0d1891b84 100644 --- a/htdocs/societe/paymentmodes.php +++ b/htdocs/societe/paymentmodes.php @@ -210,7 +210,7 @@ if (empty($reshook)) $companypaymentmode->exp_date_month = GETPOST('exp_date_month','int'); $companypaymentmode->exp_date_year = GETPOST('exp_date_year','int'); $companypaymentmode->cvn = GETPOST('cvn','alpha'); - $companypaymentmode->country_code = $mysoc->country_code; + $companypaymentmode->country_code = $object->country_code; $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref','alpha'); diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 329f26ca40e..e093e93521a 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -223,15 +223,17 @@ class Stripe extends CommonObject { try { if (empty($key)) { // If the Stripe connect account not set, we use common API usage - $card = \Stripe\Card::retrieve("$cardref"); + $card = $cu->sources->retrieve($cardref); } else { - $card = \Stripe\Card::retrieve("$cardref", array("stripe_account" => $key)); + $card = $cu->sources->retrieve($cardref, array("stripe_account" => $key)); } } catch(Exception $e) { $this->error = $e->getMessage(); + dol_syslog($this->error, LOG_WARNING); } + } elseif ($createifnotlinkedtostripe) { @@ -277,6 +279,7 @@ class Stripe extends CommonObject catch(Exception $e) { $this->error = $e->getMessage(); + dol_syslog($this->error, LOG_WARNING); } } }