dolibarr 18.0.6
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
28require_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 (isModEnabled('stripe') && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox', 'alpha'))) {
75 $service = 'StripeTest';
76 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
77 } else {
78 $service = 'StripeLive';
79 }
80
81 if (is_array($parameters) && !empty($parameters)) {
82 foreach ($parameters as $key => $value) {
83 $key = $value;
84 }
85 }
86
87
88 if (is_object($object) && $object->element == 'societe') {
89 $this->resprints .= '<tr><td>';
90 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
91 $this->resprints .= $langs->trans('StripeCustomer');
92 $this->resprints .= '<td><td class="right">';
93 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
94 $this->resprints .= '</td></tr></table>';
95 $this->resprints .= '</td>';
96 $this->resprints .= '<td colspan="3">';
97 $stripe = new Stripe($this->db);
98 if ($stripe->getStripeAccount($service) && $object->client != 0) {
99 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
100 $this->resprints .= $customer->id;
101 } else {
102 $this->resprints .= $langs->trans("NoStripe");
103 }
104 $this->resprints .= '</td></tr>';
105 } elseif (is_object($object) && $object->element == 'member') {
106 $this->resprints .= '<tr><td>';
107 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
108 $this->resprints .= $langs->trans('StripeCustomer');
109 $this->resprints .= '<td><td class="right">';
110 $this->resprints .= '</td></tr></table>';
111 $this->resprints .= '</td>';
112 $this->resprints .= '<td colspan="3">';
113 $stripe = new Stripe($this->db);
114 if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
115 $object->fetch_thirdparty();
116 $customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
117 $this->resprints .= $customer->id;
118 } else {
119 $this->resprints .= $langs->trans("NoStripe");
120 }
121 $this->resprints .= '</td></tr>';
122
123 $this->resprints .= '<tr><td>';
124 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
125 $this->resprints .= $langs->trans('SubscriptionStripe');
126 $this->resprints .= '<td><td class="right">';
127 $this->resprints .= '</td></tr></table>';
128 $this->resprints .= '</td>';
129 $this->resprints .= '<td colspan="3">';
130 $stripe = new Stripe($this->db);
131 if (7 == 4) {
132 $object->fetch_thirdparty();
133 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
134 $this->resprints .= $customer->id;
135 } else {
136 $this->resprints .= $langs->trans("NoStripe");
137 }
138 $this->resprints .= '</td></tr>';
139 } elseif (is_object($object) && $object->element == 'adherent_type') {
140 $this->resprints .= '<tr><td>';
141 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
142 $this->resprints .= $langs->trans('PlanStripe');
143 $this->resprints .= '<td><td class="right">';
144 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
145 $this->resprints .= '</td></tr></table>';
146 $this->resprints .= '</td>';
147 $this->resprints .= '<td colspan="3">';
148 $stripe = new Stripe($this->db);
149 if (7 == 4) {
150 $object->fetch_thirdparty();
151 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
152 $this->resprints .= $customer->id;
153 } else {
154 $this->resprints .= $langs->trans("NoStripe");
155 }
156 $this->resprints .= '</td></tr>';
157 }
158 return 0;
159 }
160
169 public function addMoreActionsButtons($parameters, &$object, &$action)
170 {
171 global $db, $conf, $user, $langs, $form;
172 if (is_object($object) && $object->element == 'facture') {
173 // On verifie si la facture a des paiements
174 $sql = 'SELECT pf.amount';
175 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
176 $sql .= ' WHERE pf.fk_facture = '.((int) $object->id);
177
178 $totalpaid = 0;
179
180 $result = $this->db->query($sql);
181 if ($result) {
182 $i = 0;
183 $num = $this->db->num_rows($result);
184
185 while ($i < $num) {
186 $objp = $this->db->fetch_object($result);
187 $totalpaid += $objp->amount;
188 $i++;
189 }
190 } else {
191 dol_print_error($this->db, '');
192 }
193
194 $resteapayer = $object->total_ttc - $totalpaid;
195 // Request a direct debit order
196 if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0) {
197 $stripe = new Stripe($this->db);
198 if ($resteapayer > 0) {
199 if ($stripe->getStripeAccount($conf->entity)) { // a modifier avec droit stripe
200 $langs->load("withdrawals");
201 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>';
202 } else {
203 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
204 }
205 } elseif ($resteapayer == 0) {
206 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
207 }
208 } else {
209 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
210 }
211 } elseif (is_object($object) && $object->element == 'invoice_supplier') {
212 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
213 } elseif (is_object($object) && $object->element == 'member') {
214 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
215 }
216 return 0;
217 }
218}
Class Actions Stripe Connect.
addMoreActionsButtons($parameters, &$object, &$action)
addMoreActionsButtons
formObjectOptions($parameters, &$object, &$action)
formObjectOptions
const STATUS_DRAFT
Draft status.
const STATUS_ABANDONED
Classified abandoned and no payment done.
Stripe class.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formated messages to output (Used to show messages on html output).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...