Better MVC
This commit is contained in:
parent
9c92e09295
commit
a955e74329
@ -69,6 +69,21 @@ $hookmanager->initHooks(array('thirdpartybancard','globalcard'));
|
|||||||
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
|
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
|
||||||
$hookmanager->initHooks(array('thirdpartybancard'));
|
$hookmanager->initHooks(array('thirdpartybancard'));
|
||||||
|
|
||||||
|
if (! empty($conf->stripe->enabled))
|
||||||
|
{
|
||||||
|
$service = 'StripeTest';
|
||||||
|
$servicestatus = 0;
|
||||||
|
if (! empty($conf->global->STRIPE_LIVE) && ! GETPOST('forcesandbox','alpha'))
|
||||||
|
{
|
||||||
|
$service = 'StripeLive';
|
||||||
|
$servicestatus = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stripe = new Stripe($db);
|
||||||
|
$stripeacc = $stripe->getStripeAccount($service); // Stripe OAuth connect account of dolibarr user (no network access here)
|
||||||
|
$stripecu = $stripe->getStripeCustomerAccount($object->id, $servicestatus); // Get thirdparty cu_...
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -91,7 +106,6 @@ if (empty($reshook))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($action == 'update' && ! $_POST["cancel"])
|
if ($action == 'update' && ! $_POST["cancel"])
|
||||||
{
|
{
|
||||||
// Modification
|
// Modification
|
||||||
@ -332,32 +346,29 @@ if (empty($reshook))
|
|||||||
$id = $savid;
|
$id = $savid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Action for stripe
|
||||||
if (! empty($conf->stripe->enabled) && class_exists('Stripe'))
|
if (! empty($conf->stripe->enabled) && class_exists('Stripe'))
|
||||||
{
|
{
|
||||||
$stripe=new Stripe($db);
|
|
||||||
|
|
||||||
if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest';
|
|
||||||
else $service = 'StripeLive';
|
|
||||||
|
|
||||||
$customerstripe=$stripe->customerStripe($socid, $stripe->getStripeAccount($service));
|
|
||||||
if ($customerstripe->id) {
|
|
||||||
$cu = \Stripe\Customer::retrieve("".$customerstripe->id."");}
|
|
||||||
|
|
||||||
$url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
|
|
||||||
if ($action == 'setassourcedefault')
|
if ($action == 'setassourcedefault')
|
||||||
{
|
{
|
||||||
$cu->default_source = "$source"; // obtained with Stripe.js
|
$cu = \Stripe\Customer::retrieve($stripecu);
|
||||||
$cu->save();
|
|
||||||
|
|
||||||
header('Location: '.$url);
|
$cu->default_source = "$source"; // obtained with Stripe.js
|
||||||
exit;
|
$cu->save();
|
||||||
|
|
||||||
|
$url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
|
||||||
|
header('Location: '.$url);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
elseif ($action == 'delete')
|
elseif ($action == 'delete')
|
||||||
{
|
{
|
||||||
$cu->sources->retrieve("$source")->detach();
|
$cu = \Stripe\Customer::retrieve($stripecu);
|
||||||
|
|
||||||
header('Location: '.$url);
|
$cu->sources->retrieve("$source")->detach();
|
||||||
exit;
|
|
||||||
|
$url=DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$object->id;
|
||||||
|
header('Location: '.$url);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,13 +457,13 @@ if ($socid && $action != 'edit' && $action != "create")
|
|||||||
if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts');
|
if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! (empty($conf->stripe->enabled)))
|
if (! empty($conf->stripe->enabled))
|
||||||
{
|
{
|
||||||
$stripe = new Stripe($db);
|
|
||||||
|
|
||||||
// Prospect/Customer
|
|
||||||
|
// Stripe customer key 'cu_....' stored into llx_societe_account
|
||||||
print '<tr><td class="titlefield">'.$langs->trans('StripeCustomerId').'</td><td>';
|
print '<tr><td class="titlefield">'.$langs->trans('StripeCustomerId').'</td><td>';
|
||||||
print $stripe->getStripeCustomerAccount($object->id);
|
print $stripecu;
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -460,22 +471,23 @@ if ($socid && $action != 'edit' && $action != "create")
|
|||||||
print '</table>';
|
print '</table>';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
|
print '<br>';
|
||||||
|
|
||||||
if (! (empty($conf->stripe->enabled)))
|
if (! (empty($conf->stripe->enabled)))
|
||||||
{
|
{
|
||||||
print load_fiche_titre($langs->trans('StripeGateways'), '', '');
|
print load_fiche_titre($langs->trans('StripeGateways').($stripeacc ? ' ('.$stripeacc.')':''), '', '');
|
||||||
|
|
||||||
if (empty($conf->global->STRIPE_LIVE) || empty($conf->global->STRIPECONNECT_LIVE) || GETPOST('forcesandbox','alpha')) $service = 'StripeTest';
|
$listofsources = array();
|
||||||
else $service = 'StripeLive';
|
if (is_object($stripe) && $stripeacc)
|
||||||
|
|
||||||
if (is_object($stripe) && $stripe->getStripeAccount($service))
|
|
||||||
{
|
{
|
||||||
$customerstripe=$stripe->customerStripe($object->id,$stripe->getStripeAccount($service));
|
$customerstripe=$stripe->customerStripe($object->id, $stripeacc, $servicestatus);
|
||||||
}
|
|
||||||
|
if ($customerstripe->id) {
|
||||||
if ($customerstripe->id) {
|
$listofsources=$customerstripe->sources->data;
|
||||||
$input=$customerstripe->sources->data;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
|
||||||
print '<table class="liste" width="100%">'."\n";
|
print '<table class="liste" width="100%">'."\n";
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print '<td align="left">'.$langs->trans('Type').'</td>';
|
print '<td align="left">'.$langs->trans('Type').'</td>';
|
||||||
@ -484,9 +496,9 @@ if ($socid && $action != 'edit' && $action != "create")
|
|||||||
print '<td align="center">'.$langs->trans('Default').'</td>';
|
print '<td align="center">'.$langs->trans('Default').'</td>';
|
||||||
print "<td></td></tr>\n";
|
print "<td></td></tr>\n";
|
||||||
|
|
||||||
if (is_array($input))
|
if (is_array($listofsources))
|
||||||
{
|
{
|
||||||
foreach ($input as $src)
|
foreach ($listofsources as $src)
|
||||||
{
|
{
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
@ -581,11 +593,12 @@ if ($socid && $action != 'edit' && $action != "create")
|
|||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($input))
|
if (empty($listofsources))
|
||||||
{
|
{
|
||||||
print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("NoSource").'</td></tr>';
|
print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("NoSource").'</td></tr>';
|
||||||
}
|
}
|
||||||
print "</table>";
|
print "</table>";
|
||||||
|
print "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -599,7 +612,7 @@ if ($socid && $action != 'edit' && $action != "create")
|
|||||||
$var = false;
|
$var = false;
|
||||||
if (is_array($rib_list))
|
if (is_array($rib_list))
|
||||||
{
|
{
|
||||||
print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
|
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
|
||||||
print '<table class="liste" width="100%">';
|
print '<table class="liste" width="100%">';
|
||||||
|
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
|
|||||||
@ -55,7 +55,7 @@ class Stripe extends CommonObject
|
|||||||
* Return main company OAuth Connect stripe account
|
* Return main company OAuth Connect stripe account
|
||||||
*
|
*
|
||||||
* @param string $mode 'StripeTest' or 'StripeLive'
|
* @param string $mode 'StripeTest' or 'StripeLive'
|
||||||
* @return int ???
|
* @return string Stripe account 'acc_....'
|
||||||
*/
|
*/
|
||||||
public function getStripeAccount($mode='StripeTest')
|
public function getStripeAccount($mode='StripeTest')
|
||||||
{
|
{
|
||||||
@ -106,7 +106,7 @@ class Stripe extends CommonObject
|
|||||||
$sql.= " AND sa.entity IN (".getEntity('societe').")";
|
$sql.= " AND sa.entity IN (".getEntity('societe').")";
|
||||||
$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
|
$sql.= " AND sa.site = 'stripe' AND sa.status = ".((int) $status);
|
||||||
|
|
||||||
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
|
dol_syslog(get_class($this) . "::getStripeCustomerAccount Try to find the cu_.... of thirdparty id=".$id, LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
if ($this->db->num_rows($result)) {
|
if ($this->db->num_rows($result)) {
|
||||||
@ -145,10 +145,9 @@ class Stripe extends CommonObject
|
|||||||
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
|
dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$soc = new Societe($this->db);
|
|
||||||
$soc->fetch($id);
|
|
||||||
$num = $this->db->num_rows($resql);
|
$num = $this->db->num_rows($resql);
|
||||||
if ($num) {
|
if ($num)
|
||||||
|
{
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
$tiers = $obj->key_account;
|
$tiers = $obj->key_account;
|
||||||
if ($conf->entity == 1) {
|
if ($conf->entity == 1) {
|
||||||
@ -159,8 +158,11 @@ class Stripe extends CommonObject
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
elseif ($createifnotlinkedtostripe)
|
||||||
{
|
{
|
||||||
|
$soc = new Societe($this->db);
|
||||||
|
$soc->fetch($id);
|
||||||
|
|
||||||
if ($conf->entity == 1) {
|
if ($conf->entity == 1) {
|
||||||
$customer = \Stripe\Customer::create(array(
|
$customer = \Stripe\Customer::create(array(
|
||||||
"email" => $soc->email,
|
"email" => $soc->email,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user