Triggers for Strips payment modes

This commit is contained in:
Laurent Destailleur 2018-03-16 16:10:04 +01:00
parent 9997a6c787
commit f258d31a98
5 changed files with 83 additions and 40 deletions

View File

@ -815,13 +815,14 @@ class FormOther
/**
* Return HTML combo list of month
*
* @param string $selected Preselected value
* @param string $htmlname Name of HTML select object
* @param int $useempty Show empty in list
* @param int $longlabel Show long label
* @param string $selected Preselected value
* @param string $htmlname Name of HTML select object
* @param int $useempty Show empty in list
* @param int $longlabel Show long label
* @param string $morecss More Css
* @return string
*/
function select_month($selected='',$htmlname='monthid',$useempty=0,$longlabel=0)
function select_month($selected='', $htmlname='monthid', $useempty=0, $longlabel=0, $morecss='')
{
global $langs;
@ -830,7 +831,7 @@ class FormOther
if ($longlabel) $montharray = monthArray($langs, 0); // Get array
else $montharray = monthArray($langs, 1);
$select_month = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
$select_month = '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
if ($useempty)
{
$select_month .= '<option value="0">&nbsp;</option>';

View File

@ -123,49 +123,91 @@ class InterfaceStripe
$stripe = new Stripe($db);
if (empty($conf->stripe->enabled)) return 0;
if (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))
{
$service = 'StripeTest';
}
else
$service = 'StripeTest';
$servicestatus = 0;
if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox', 'alpha'))
{
$service = 'StripeLive';
$servicestatus = 1;
}
// If customer is linked to Strip, we update/delete Stripe too
if ($action == 'COMPANY_MODIFY') {
dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
if ($stripe->getStripeAccount($service) && $object->client != 0) {
$cu = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
if ($cu) {
if ($conf->entity == '1') {
$customer = \Stripe\Customer::retrieve("$cu->id");
} else {
$customer = \Stripe\Customer::retrieve("$cu->id", array(
"stripe_account" => $stripe->getStripeAccount($service)
));
$stripeacc = $stripe->getStripeAccount($service); // No need of network access for this
if ($object->client != 0) {
$customer = $stripe->customerStripe($object, $stripeacc, $servicestatus);
if ($customer) {
if (! empty($object->email))
{
$customer->email = $object->email;
}
if (! empty($object->email)) {
$customer->email = "$object->email";
}
$customer->description = "$object->name";
$customer->description = $object->name;
// TODO More data
//$customer->vat = $object->tva_intra
$customer->save();
}
}
} elseif ($action == 'COMPANY_DELETE') {
}
if ($action == 'COMPANY_DELETE') {
dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
$cu = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
if ($cu) {
if ($conf->entity == 1) {
$customer = \Stripe\Customer::retrieve("$cu->id");
} else {
$customer = \Stripe\Customer::retrieve("$cu->id", array(
"stripe_account" => $stripe->getStripeAccount($service)
));
}
$stripeacc = $stripe->getStripeAccount($service); // No need of network access for this
$customer = $stripe->customerStripe($object, $stripeacc, $servicestatus);
if ($customer) {
$customer->delete();
}
}
// If payment mode is linked to Strip, we update/delete Stripe too
if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') {
// For creation of credit card, we do not create in Stripe automatically
}
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
$thirdparty=new Societe($this->db);
$thirdparty->fetch($object->fk_soc);
if ($object->client != 0) {
$card = $stripe->cardStripe($thirdparty, $object, $stripeacc, $servicestatus);
if (card) {
/*if (! empty($object->email))
{
$customer->email = $object->email;
}
$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
$thirdparty=new Societe($this->db);
$thirdparty->fetch($object->fk_soc);
$card = $stripe->cardStripe($thirdparty, $object, $stripeacc, $servicestatus);
if ($card) {
if (method_exists($card, 'detach')) $card->detach();
else $card->delete();
}
}
return $ok;
}
}

View File

@ -69,9 +69,6 @@ $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$hookmanager->initHooks(array('thirdpartybancard','globalcard'));
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('thirdpartybancard'));
if (! empty($conf->stripe->enabled))
{
$service = 'StripeTest';
@ -368,8 +365,8 @@ if (empty($reshook))
$companypaymentmode->datec = dol_now();
$companypaymentmode->default_rib = 0;
$companypaymentmode->type = 'card';
$companypaymentmode->country_code = $mysoc->country_code;
$companypaymentmode->status = 1;
$companypaymentmode->country_code = $object->country_code;
$companypaymentmode->status = $servicestatus;
$companypaymentmode->stripe_card_ref = GETPOST('stripe_card_ref','alpha');

View File

@ -45,6 +45,9 @@ $result = restrictedArea($user, 'societe', $id,'');
$object = new Societe($db);
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('contactthirdparty','globalcard'));
/*
* Actions

View File

@ -55,7 +55,7 @@ class Stripe extends CommonObject
* Return main company OAuth Connect stripe account
*
* @param string $mode 'StripeTest' or 'StripeLive'
* @return string Stripe account 'acc_....'
* @return string Stripe account 'acc_....' or '' if no OAuth token found
*/
public function getStripeAccount($mode='StripeTest')
{