Triggers for Strips payment modes

This commit is contained in:
Laurent Destailleur 2018-03-16 16:42:26 +01:00
parent f258d31a98
commit 1a70e7a7c4
3 changed files with 45 additions and 25 deletions

View File

@ -172,39 +172,56 @@ 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);
$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); if ($stripecu) {
$thirdparty->fetch($object->fk_soc); // 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) { if ($customer)
$card = $stripe->cardStripe($thirdparty, $object, $stripeacc, $servicestatus); {
if (card) { $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus);
/*if (! empty($object->email)) 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']));
$customer->email = $object->email; 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') { 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);
$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); if ($stripecu)
$thirdparty->fetch($object->fk_soc); {
// 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 ($customer)
if ($card) { {
if (method_exists($card, 'detach')) $card->detach(); $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus);
else $card->delete(); if ($card) {
if (method_exists($card, 'detach')) $card->detach();
else $card->delete();
}
}
} }
} }

View File

@ -210,7 +210,7 @@ if (empty($reshook))
$companypaymentmode->exp_date_month = GETPOST('exp_date_month','int'); $companypaymentmode->exp_date_month = GETPOST('exp_date_month','int');
$companypaymentmode->exp_date_year = GETPOST('exp_date_year','int'); $companypaymentmode->exp_date_year = GETPOST('exp_date_year','int');
$companypaymentmode->cvn = GETPOST('cvn','alpha'); $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'); $companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref','alpha');

View File

@ -223,15 +223,17 @@ class Stripe extends CommonObject
{ {
try { try {
if (empty($key)) { // If the Stripe connect account not set, we use common API usage 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 { } else {
$card = \Stripe\Card::retrieve("$cardref", array("stripe_account" => $key)); $card = $cu->sources->retrieve($cardref, array("stripe_account" => $key));
} }
} }
catch(Exception $e) catch(Exception $e)
{ {
$this->error = $e->getMessage(); $this->error = $e->getMessage();
dol_syslog($this->error, LOG_WARNING);
} }
} }
elseif ($createifnotlinkedtostripe) elseif ($createifnotlinkedtostripe)
{ {
@ -277,6 +279,7 @@ class Stripe extends CommonObject
catch(Exception $e) catch(Exception $e)
{ {
$this->error = $e->getMessage(); $this->error = $e->getMessage();
dol_syslog($this->error, LOG_WARNING);
} }
} }
} }