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') {
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();
}
}
}
}

View File

@ -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');

View File

@ -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);
}
}
}