Merge remote-tracking branch 'upstream/develop' into new_branch_10_10_2018

This commit is contained in:
Philippe GRAND 2018-10-13 09:49:23 +02:00
commit d8b62f0808
5 changed files with 104 additions and 71 deletions

View File

@ -17,7 +17,7 @@
*/ */
/** /**
* \file htdocs/core/triggers/interface_50_modStripe_Stripe.class.php * \file htdocs/core/triggers/interface_80_modStripe_Stripe.class.php
* \ingroup core * \ingroup core
* \brief Fichier * \brief Fichier
* \remarks Son propre fichier d'actions peut etre cree par recopie de celui-ci: * \remarks Son propre fichier d'actions peut etre cree par recopie de celui-ci:
@ -147,22 +147,33 @@ class InterfaceStripe
if ($customer) if ($customer)
{ {
$namecleaned = $object->name ? $object->name : null; $namecleaned = $object->name ? $object->name : null;
$vatcleaned = array( $vatcleaned = $object->tva_intra ? $object->tva_intra : null;
"tax_id" => $object->tva_intra ? $object->tva_intra : null, // We force data to "null" if empty as expected by Stripe
"type" => 'vat', $taxinfo = array('type'=>'vat');
); if ($vatcleaned)
{
$taxinfo["tax_id"] = $vatcleaned;
}
// We force data to "null" if not defined as expected by Stripe
if (empty($vatcleaned)) $taxinfo=null;
// Detect if we change a Stripe info (email, description, vat id) // Detect if we change a Stripe info (email, description, vat id)
$changerequested = 0; $changerequested = 0;
if (! empty($object->email) && $object->email != $customer->email) $changerequested++; if (! empty($object->email) && $object->email != $customer->email) $changerequested++;
if ($namecleaned != $customer->description) $changerequested++; if ($namecleaned != $customer->description) $changerequested++;
if ($vatcleaned != $customer->tax_info) $changerequested++; if (! isset($customer->tax_info['tax_id']) && ! is_null($vatcleaned)) $changerequested++;
elseif (isset($customer->tax_info['tax_id']) && is_null($vatcleaned)) $changerequested++;
elseif (isset($customer->tax_info['tax_id']) && ! is_null($vatcleaned))
{
if ($vatcleaned != $customer->tax_info['tax_id']) $changerequested++;
}
if ($changerequested) if ($changerequested)
{ {
if (! empty($object->email)) $customer->email = $object->email; if (! empty($object->email)) $customer->email = $object->email;
$customer->description = $namecleaned; $customer->description = $namecleaned;
$customer->tax_info = $vatcleaned; if (empty($taxinfo)) $customer->tax_info = array('type'=>'vat', 'tax_id'=>null);
else $customer->tax_info = $taxinfo;
$customer->save(); $customer->save();
} }

View File

@ -363,6 +363,8 @@ class ActionsDatapolicies
global $conf, $user, $langs; global $conf, $user, $langs;
$langs->load('datapolicies@datapolicies'); $langs->load('datapolicies@datapolicies');
if (! empty($conf->global->DATAPOLICIES_ENABLE_EMAILS))
{
$dialog = '<div id="dialogdatapolicies" style="display:none;" title="' . $langs->trans('DATAPOLICIES_PORTABILITE_TITLE') . '">'; $dialog = '<div id="dialogdatapolicies" style="display:none;" title="' . $langs->trans('DATAPOLICIES_PORTABILITE_TITLE') . '">';
$dialog .= '<div class="confirmmessage">' . img_help('', '') . ' ' . $langs->trans('DATAPOLICIES_PORTABILITE_CONFIRMATION') . '</div>'; $dialog .= '<div class="confirmmessage">' . img_help('', '') . ' ' . $langs->trans('DATAPOLICIES_PORTABILITE_CONFIRMATION') . '</div>';
$dialog .= "</div>"; $dialog .= "</div>";
@ -404,6 +406,7 @@ class ActionsDatapolicies
echo '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . "?id=" . $object->id . '&action=send_datapolicies" title="' . $langs->trans('DATAPOLICIES_SEND') . '">' . $langs->trans("DATAPOLICIES_SEND") . '</a></div>'; echo '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . "?id=" . $object->id . '&action=send_datapolicies" title="' . $langs->trans('DATAPOLICIES_SEND') . '">' . $langs->trans("DATAPOLICIES_SEND") . '</a></div>';
} }
} }
}
/** /**
* printCommonFooter * printCommonFooter

View File

@ -40,10 +40,13 @@ function datapoliciesAdminPrepareHead()
$head[$h][2] = 'settings'; $head[$h][2] = 'settings';
$h++; $h++;
if (! empty($conf->global->DATAPOLICIES_ENABLE_EMAILS))
{
$head[$h][0] = dol_buildpath("/datapolicies/admin/setupmail.php", 1); $head[$h][0] = dol_buildpath("/datapolicies/admin/setupmail.php", 1);
$head[$h][1] = $langs->trans("DATAPOLICIESMail"); $head[$h][1] = $langs->trans("DATAPOLICIESMail");
$head[$h][2] = 'settings'; $head[$h][2] = 'settings';
$h++; $h++;
}
complete_head_from_modules($conf, $langs, $object, $head, $h, 'datapolicies'); complete_head_from_modules($conf, $langs, $object, $head, $h, 'datapolicies');

View File

@ -413,12 +413,12 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
$dol_type=(GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha')); $dol_type=(GETPOST('s', 'alpha') ? GETPOST('s', 'alpha') : GETPOST('source', 'alpha'));
$dol_id=GETPOST('dol_id', 'int'); $dol_id=GETPOST('dol_id', 'int');
$vatnumber = GETPOST('vatnumber','alpha'); $vatnumber = GETPOST('vatnumber','alpha');
$savesource=GETPOST('savesource', 'int'); $savesource=GETPOSTISSET('savesource')?GETPOST('savesource', 'int'):1;
dol_syslog("stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_stripe'); dol_syslog("POST stripeToken = ".$stripeToken, LOG_DEBUG, 0, '_stripe');
dol_syslog("email = ".$email, LOG_DEBUG, 0, '_stripe'); dol_syslog("POST email = ".$email, LOG_DEBUG, 0, '_stripe');
dol_syslog("thirdparty_id = ".$thirdparty_id, LOG_DEBUG, 0, '_stripe'); dol_syslog("POST thirdparty_id = ".$thirdparty_id, LOG_DEBUG, 0, '_stripe');
dol_syslog("vatnumber = ".$vatnumber, LOG_DEBUG, 0, '_stripe'); dol_syslog("POST vatnumber = ".$vatnumber, LOG_DEBUG, 0, '_stripe');
$error = 0; $error = 0;
@ -444,7 +444,6 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
$servicestatus = 1; $servicestatus = 1;
} }
$thirdparty = new Societe($db); $thirdparty = new Societe($db);
$thirdparty->fetch($thirdparty_id); $thirdparty->fetch($thirdparty_id);
@ -455,9 +454,11 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
$customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1); $customer = $stripe->customerStripe($thirdparty, $stripeacc, $servicestatus, 1);
// Create Stripe card from Token // Create Stripe card from Token
if (! empty($savesource)) { if ($savesource) {
$card = $customer->sources->create(array("source" => $stripeToken, "metadata" => $metadata)); $card = $customer->sources->create(array("source" => $stripeToken, "metadata" => $metadata));
} else { $card = $stripeToken; } } else {
$card = $stripeToken;
}
if (empty($card)) if (empty($card))
{ {
@ -495,12 +496,22 @@ if ($action == 'charge' && ! empty($conf->stripe->enabled))
} }
else else
{ {
$vatcleaned = $vatnumber ? $vatnumber : null;
$taxinfo = array('type'=>'vat');
if ($vatcleaned)
{
$taxinfo["tax_id"] = $vatcleaned;
}
// We force data to "null" if not defined as expected by Stripe
if (empty($vatcleaned)) $taxinfo=null;
dol_syslog("Create anonymous customer card profile", LOG_DEBUG, 0, '_stripe'); dol_syslog("Create anonymous customer card profile", LOG_DEBUG, 0, '_stripe');
$customer = \Stripe\Customer::create(array( $customer = \Stripe\Customer::create(array(
'email' => $email, 'email' => $email,
'description' => ($email?'Anonymous customer for '.$email:'Anonymous customer'), 'description' => ($email?'Anonymous customer for '.$email:'Anonymous customer'),
'metadata' => $metadata, 'metadata' => $metadata,
'business_vat_id' => ($vatnumber?$vatnumber:null), 'tax_info' => $taxinfo,
'source' => $stripeToken // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?) 'source' => $stripeToken // source can be a token OR array('object'=>'card', 'exp_month'=>xx, 'exp_year'=>xxxx, 'number'=>xxxxxxx, 'cvc'=>xxx, 'name'=>'Cardholder's full name', zip ?)
)); ));
// Return $customer = array('id'=>'cus_XXXX', ...) // Return $customer = array('id'=>'cus_XXXX', ...)

View File

@ -193,12 +193,17 @@ class Stripe extends CommonObject
"metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR'])) "metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']))
); );
if ($object->tva_intra!=null) $vatcleaned = $object->tva_intra ? $object->tva_intra : null;
$taxinfo = array('type'=>'vat');
if ($vatcleaned)
{ {
$dataforcustomer["tax_info"] = array( $taxinfo["tax_id"] = $vatcleaned;
"tax_id" => $object->tva_intra,
"type" => 'vat');
} }
// We force data to "null" if not defined as expected by Stripe
if (empty($vatcleaned)) $taxinfo=null;
$dataforcustomer["tax_info"] = $taxinfo;
//$a = \Stripe\Stripe::getApiKey(); //$a = \Stripe\Stripe::getApiKey();
//var_dump($a);var_dump($key);exit; //var_dump($a);var_dump($key);exit;