dolibarr 24.0.0-beta
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-2025 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 $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 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 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 if ($object->thirdparty instanceOf Societe) {
115 $customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service)); // @phan-suppress-current-line PhanTypeMismatchArgumentNullable
116 $this->resprints .= $customer->id;
117 }
118 } else {
119 $this->resprints .= $langs->trans("NoStripe");
120 }
121 $this->resprints .= '</td></tr>';
122
123 $this->resprints .= '<tr><td>';
124 $this->resprints .= '<table 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) { // @phan-suppress-current-line PhanPluginBothLiteralsBinaryOp
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 }
140 return 0;
141 }
142
151 public function addMoreActionsButtons($parameters, &$object, &$action)
152 {
153 global $conf, $langs;
154
155 if (is_object($object) && $object->element == 'facture') {
156 // Verify if the invoice has payments
157 $sql = 'SELECT pf.amount';
158 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
159 $sql .= ' WHERE pf.fk_facture = '.((int) $object->id);
160
161 $totalpaid = 0;
162
163 $result = $this->db->query($sql);
164 if ($result) {
165 $i = 0;
166 $num = $this->db->num_rows($result);
167
168 while ($i < $num) {
169 $objp = $this->db->fetch_object($result);
170 $totalpaid += $objp->amount;
171 $i++;
172 }
173 } else {
174 dol_print_error($this->db, '');
175 }
176
177 $resteapayer = $object->total_ttc - $totalpaid;
178 // Request a direct debit order
179 if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0) {
180 $stripe = new Stripe($this->db);
181 if ($resteapayer > 0) {
182 if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE')/* || GETPOST('forcesandbox', 'alpha') */)) {
183 $service = 'StripeTest';
184 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning');
185 } else {
186 $service = 'StripeLive';
187 }
188
189 if ($stripe->getStripeAccount($service, 0, $conf->entity)) { // To modify with stripe authorizations
190 $langs->load("withdrawals");
191 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>';
192 } else {
193 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
194 }
195 } elseif ($resteapayer == 0) {
196 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
197 }
198 } else {
199 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
200 }
201 } elseif (is_object($object) && $object->element == 'invoice_supplier') {
202 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
203 } elseif (is_object($object) && $object->element == 'member') {
204 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
205 }
206 return 0;
207 }
208}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
Class to manage third parties objects (customers, suppliers, prospects...)
Stripe class @TODO No reason to extend CommonObject.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
isModEnabled($module)
Is Dolibarr module enabled.
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...