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 $this->resprints .= '<tr><td>';
86 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
87 $this->resprints .= $langs->trans('StripeCustomer');
88 $this->resprints .= '<td><td class="right">';
89 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
90 $this->resprints .= '</td></tr></table>';
91 $this->resprints .= '</td>';
92 $this->resprints .= '<td colspan="3">';
93 $stripe = new Stripe($this->db);
94 if ($stripe->getStripeAccount($service) && $object->client != 0) {
95 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
96 $this->resprints .= $customer->id;
97 } else {
98 $this->resprints .= $langs->trans("NoStripe");
99 }
100 $this->resprints .= '</td></tr>';
101 } elseif ($object instanceof CommonObject && $object->element == 'member') {
102 $this->resprints .= '<tr><td>';
103 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
104 $this->resprints .= $langs->trans('StripeCustomer');
105 $this->resprints .= '<td><td class="right">';
106 $this->resprints .= '</td></tr></table>';
107 $this->resprints .= '</td>';
108 $this->resprints .= '<td colspan="3">';
109 $stripe = new Stripe($this->db);
110 if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
111 $object->fetch_thirdparty();
112 $customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
113 $this->resprints .= $customer->id;
114 } else {
115 $this->resprints .= $langs->trans("NoStripe");
116 }
117 $this->resprints .= '</td></tr>';
118
119 $this->resprints .= '<tr><td>';
120 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
121 $this->resprints .= $langs->trans('SubscriptionStripe');
122 $this->resprints .= '<td><td class="right">';
123 $this->resprints .= '</td></tr></table>';
124 $this->resprints .= '</td>';
125 $this->resprints .= '<td colspan="3">';
126 $stripe = new Stripe($this->db);
127 if (7 == 4) {
128 $object->fetch_thirdparty();
129 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
130 $this->resprints .= $customer->id;
131 } else {
132 $this->resprints .= $langs->trans("NoStripe");
133 }
134 $this->resprints .= '</td></tr>';
135 } elseif ($object instanceof CommonObject && $object->element == 'adherent_type') {
136 $this->resprints .= '<tr><td>';
137 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
138 $this->resprints .= $langs->trans('PlanStripe');
139 $this->resprints .= '<td><td class="right">';
140 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
141 $this->resprints .= '</td></tr></table>';
142 $this->resprints .= '</td>';
143 $this->resprints .= '<td colspan="3">';
144 $stripe = new Stripe($this->db);
145 if (7 == 4) {
146 $object->fetch_thirdparty();
147 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
148 $this->resprints .= $customer->id;
149 } else {
150 $this->resprints .= $langs->trans("NoStripe");
151 }
152 $this->resprints .= '</td></tr>';
153 }
154 return 0;
155 }
156
165 public function addMoreActionsButtons($parameters, &$object, &$action)
166 {
167 global $conf, $langs;
168
169 if (is_object($object) && $object->element == 'facture') {
170 // Verify if the invoice has payments
171 $sql = 'SELECT pf.amount';
172 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
173 $sql .= ' WHERE pf.fk_facture = '.((int) $object->id);
174
175 $totalpaid = 0;
176
177 $result = $this->db->query($sql);
178 if ($result) {
179 $i = 0;
180 $num = $this->db->num_rows($result);
181
182 while ($i < $num) {
183 $objp = $this->db->fetch_object($result);
184 $totalpaid += $objp->amount;
185 $i++;
186 }
187 } else {
188 dol_print_error($this->db, '');
189 }
190
191 $resteapayer = $object->total_ttc - $totalpaid;
192 // Request a direct debit order
193 if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0) {
194 $stripe = new Stripe($this->db);
195 if ($resteapayer > 0) {
196 if ($stripe->getStripeAccount($conf->entity)) { // a modifier avec droit stripe
197 $langs->load("withdrawals");
198 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>';
199 } else {
200 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
201 }
202 } elseif ($resteapayer == 0) {
203 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
204 }
205 } else {
206 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
207 }
208 } elseif (is_object($object) && $object->element == 'invoice_supplier') {
209 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
210 } elseif (is_object($object) && $object->element == 'member') {
211 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
212 }
213 return 0;
214 }
215}
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 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...