dolibarr  13.0.2
actions_stripe.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2009-2016 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
4  * Copyright (C) 2014 Philippe Grand <philippe.grand@atoo-net.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 
21 // TODO File not used. To remove.
22 
28 require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
29 
30 
31 $langs->load("stripe@stripe");
32 
33 
38 {
42  public $db;
43 
44  private $config = array();
45 
46  // For Hookmanager return
47  public $resprints;
48  public $results = array();
49 
50 
56  public function __construct($db)
57  {
58  $this->db = $db;
59  }
60 
61 
70  public function formObjectOptions($parameters, &$object, &$action)
71  {
72  global $db, $conf, $user, $langs, $form;
73 
74  if (!empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha')))
75  {
76  $service = 'StripeTest';
77  dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
78  } else {
79  $service = 'StripeLive';
80  }
81 
82  if (is_array($parameters) && !empty($parameters))
83  {
84  foreach ($parameters as $key=>$value)
85  {
86  $key = $value;
87  }
88  }
89 
90 
91  if (is_object($object) && $object->element == 'societe')
92  {
93  $this->resprints .= '<tr><td>';
94  $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
95  $this->resprints .= $langs->trans('StripeCustomer');
96  $this->resprints .= '<td><td class="right">';
97  // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
98  $this->resprints .= '</td></tr></table>';
99  $this->resprints .= '</td>';
100  $this->resprints .= '<td colspan="3">';
101  $stripe = new Stripe($this->db);
102  if ($stripe->getStripeAccount($service) && $object->client != 0) {
103  $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
104  $this->resprints .= $customer->id;
105  } else {
106  $this->resprints .= $langs->trans("NoStripe");
107  }
108  $this->resprints .= '</td></tr>';
109  } elseif (is_object($object) && $object->element == 'member') {
110  $this->resprints .= '<tr><td>';
111  $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
112  $this->resprints .= $langs->trans('StripeCustomer');
113  $this->resprints .= '<td><td class="right">';
114  $this->resprints .= '</td></tr></table>';
115  $this->resprints .= '</td>';
116  $this->resprints .= '<td colspan="3">';
117  $stripe = new Stripe($this->db);
118  if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
119  $object->fetch_thirdparty();
120  $customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
121  $this->resprints .= $customer->id;
122  } else {
123  $this->resprints .= $langs->trans("NoStripe");
124  }
125  $this->resprints .= '</td></tr>';
126 
127  $this->resprints .= '<tr><td>';
128  $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
129  $this->resprints .= $langs->trans('SubscriptionStripe');
130  $this->resprints .= '<td><td class="right">';
131  $this->resprints .= '</td></tr></table>';
132  $this->resprints .= '</td>';
133  $this->resprints .= '<td colspan="3">';
134  $stripe = new Stripe($this->db);
135  if (7 == 4) {
136  $object->fetch_thirdparty();
137  $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
138  $this->resprints .= $customer->id;
139  } else {
140  $this->resprints .= $langs->trans("NoStripe");
141  }
142  $this->resprints .= '</td></tr>';
143  } elseif (is_object($object) && $object->element == 'adherent_type') {
144  $this->resprints .= '<tr><td>';
145  $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
146  $this->resprints .= $langs->trans('PlanStripe');
147  $this->resprints .= '<td><td class="right">';
148  // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
149  $this->resprints .= '</td></tr></table>';
150  $this->resprints .= '</td>';
151  $this->resprints .= '<td colspan="3">';
152  $stripe = new Stripe($this->db);
153  if (7 == 4) {
154  $object->fetch_thirdparty();
155  $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
156  $this->resprints .= $customer->id;
157  } else {
158  $this->resprints .= $langs->trans("NoStripe");
159  }
160  $this->resprints .= '</td></tr>';
161  }
162  return 0;
163  }
164 
173  public function addMoreActionsButtons($parameters, &$object, &$action)
174  {
175  global $db, $conf, $user, $langs, $form;
176  if (is_object($object) && $object->element == 'facture') {
177  // On verifie si la facture a des paiements
178  $sql = 'SELECT pf.amount';
179  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
180  $sql .= ' WHERE pf.fk_facture = '.$object->id;
181 
182  $result = $this->db->query($sql);
183  if ($result) {
184  $i = 0;
185  $num = $this->db->num_rows($result);
186 
187  while ($i < $num) {
188  $objp = $this->db->fetch_object($result);
189  $totalpaye += $objp->amount;
190  $i++;
191  }
192  } else {
193  dol_print_error($this->db, '');
194  }
195 
196  $resteapayer = $object->total_ttc - $totalpaye;
197  // Request a direct debit order
198  if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0)
199  {
200  $stripe = new Stripe($this->db);
201  if ($resteapayer > 0)
202  {
203  if ($stripe->getStripeAccount($conf->entity)) // a modifier avec droit stripe
204  {
205  $langs->load("withdrawals");
206  print '<a class="butActionDelete" href="'.dol_buildpath('/stripeconnect/payment.php?facid='.$object->id.'&action=create', 1).'" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
207  } else {
208  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
209  }
210  } elseif ($resteapayer == 0)
211  {
212  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
213  }
214  } else {
215  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
216  }
217  } elseif (is_object($object) && $object->element == 'invoice_supplier') {
218  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
219  } elseif (is_object($object) && $object->element == 'member') {
220  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
221  }
222  return 0;
223  }
224 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Stripe class.
Class Actions Stripe Connect.
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db)
Constructor.
formObjectOptions($parameters, &$object, &$action)
formObjectOptions
const STATUS_DRAFT
Draft status.
addMoreActionsButtons($parameters, &$object, &$action)
addMoreActionsButtons
const STATUS_ABANDONED
Classified abandoned and no payment done.
dol_htmloutput_mesg($mesgstring= '', $mesgarray=array(), $style= 'ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...