dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23// TODO File of hooks not used yet. To remove ?
24
31require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
33
34
39{
43 public $db;
44
45 private $config = array(); // @phpstan-ignore-line
46
47
53 public function __construct($db)
54 {
55 $this->db = $db;
56 }
57
58
67 public function formObjectOptions($parameters, &$object, &$action)
68 {
69 global $conf, $langs;
70
71 if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
72 $service = 'StripeTest';
73 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning');
74 } else {
75 $service = 'StripeLive';
76 }
77
78 if (is_array($parameters) && !empty($parameters)) {
79 foreach ($parameters as $key => $value) {
80 $key = $value;
81 }
82 }
83
84 if (is_object($object) && $object->element == 'societe') {
85 '@phan-var-force Societe $object';
86 $this->resprints .= '<tr><td>';
87 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
88 $this->resprints .= $langs->trans('StripeCustomer');
89 $this->resprints .= '<td><td class="right">';
90 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
91 $this->resprints .= '</td></tr></table>';
92 $this->resprints .= '</td>';
93 $this->resprints .= '<td colspan="3">';
94 $stripe = new Stripe($this->db);
95 if ($stripe->getStripeAccount($service) && $object->client != 0) {
96 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
97 $this->resprints .= $customer->id;
98 } else {
99 $this->resprints .= $langs->trans("NoStripe");
100 }
101 $this->resprints .= '</td></tr>';
102 } elseif ($object instanceof CommonObject && $object->element == 'member') {
103 '@phan-var-force Adherent $object';
104 $this->resprints .= '<tr><td>';
105 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
106 $this->resprints .= $langs->trans('StripeCustomer');
107 $this->resprints .= '<td><td class="right">';
108 $this->resprints .= '</td></tr></table>';
109 $this->resprints .= '</td>';
110 $this->resprints .= '<td colspan="3">';
111 $stripe = new Stripe($this->db);
112 if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
113 $object->fetch_thirdparty();
114 $customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
115 $this->resprints .= $customer->id;
116 } else {
117 $this->resprints .= $langs->trans("NoStripe");
118 }
119 $this->resprints .= '</td></tr>';
120
121 $this->resprints .= '<tr><td>';
122 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
123 $this->resprints .= $langs->trans('SubscriptionStripe');
124 $this->resprints .= '<td><td class="right">';
125 $this->resprints .= '</td></tr></table>';
126 $this->resprints .= '</td>';
127 $this->resprints .= '<td colspan="3">';
128 $stripe = new Stripe($this->db);
129 if (7 == 4) {
130 $object->fetch_thirdparty();
131 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
132 $this->resprints .= $customer->id;
133 } else {
134 $this->resprints .= $langs->trans("NoStripe");
135 }
136 $this->resprints .= '</td></tr>';
137 } elseif ($object instanceof CommonObject && $object->element == 'adherent_type') {
138 '@phan-var-force Adherent $object';
139 $this->resprints .= '<tr><td>';
140 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
141 $this->resprints .= $langs->trans('PlanStripe');
142 $this->resprints .= '<td><td class="right">';
143 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
144 $this->resprints .= '</td></tr></table>';
145 $this->resprints .= '</td>';
146 $this->resprints .= '<td colspan="3">';
147 $stripe = new Stripe($this->db);
148 if (7 == 4) {
149 $object->fetch_thirdparty();
150 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
151 $this->resprints .= $customer->id;
152 } else {
153 $this->resprints .= $langs->trans("NoStripe");
154 }
155 $this->resprints .= '</td></tr>';
156 }
157 return 0;
158 }
159
168 public function addMoreActionsButtons($parameters, &$object, &$action)
169 {
170 global $conf, $langs;
171
172 if (is_object($object) && $object->element == 'facture') {
173 // Verify if the invoice has payments
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}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class Actions Stripe Connect.
addMoreActionsButtons($parameters, &$object, &$action)
addMoreActionsButtons
formObjectOptions($parameters, &$object, &$action)
formObjectOptions
Parent class of all other hook actions classes.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
const STATUS_DRAFT
Draft status.
const STATUS_ABANDONED
Classified abandoned and no payment done.
Stripe class @TODO No reason to extends CommonObject.
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 formatted messages to output (Used to show messages on html output).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...