dolibarr 20.0.0
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22// TODO File of hooks not used yet. To remove ?
23
30require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
32
33
38{
42 public $db;
43
44 private $config = array();
45
46
52 public function __construct($db)
53 {
54 $this->db = $db;
55 }
56
57
66 public function formObjectOptions($parameters, &$object, &$action)
67 {
68 global $conf, $langs;
69
70 if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
71 $service = 'StripeTest';
72 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
73 } else {
74 $service = 'StripeLive';
75 }
76
77 if (is_array($parameters) && !empty($parameters)) {
78 foreach ($parameters as $key => $value) {
79 $key = $value;
80 }
81 }
82
83 if (is_object($object) && $object->element == 'societe') {
84 $this->resprints .= '<tr><td>';
85 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
86 $this->resprints .= $langs->trans('StripeCustomer');
87 $this->resprints .= '<td><td class="right">';
88 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
89 $this->resprints .= '</td></tr></table>';
90 $this->resprints .= '</td>';
91 $this->resprints .= '<td colspan="3">';
92 $stripe = new Stripe($this->db);
93 if ($stripe->getStripeAccount($service) && $object->client != 0) {
94 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
95 $this->resprints .= $customer->id;
96 } else {
97 $this->resprints .= $langs->trans("NoStripe");
98 }
99 $this->resprints .= '</td></tr>';
100 } elseif ($object instanceof CommonObject && $object->element == 'member') {
101 $this->resprints .= '<tr><td>';
102 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
103 $this->resprints .= $langs->trans('StripeCustomer');
104 $this->resprints .= '<td><td class="right">';
105 $this->resprints .= '</td></tr></table>';
106 $this->resprints .= '</td>';
107 $this->resprints .= '<td colspan="3">';
108 $stripe = new Stripe($this->db);
109 if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
110 $object->fetch_thirdparty();
111 $customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
112 $this->resprints .= $customer->id;
113 } else {
114 $this->resprints .= $langs->trans("NoStripe");
115 }
116 $this->resprints .= '</td></tr>';
117
118 $this->resprints .= '<tr><td>';
119 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
120 $this->resprints .= $langs->trans('SubscriptionStripe');
121 $this->resprints .= '<td><td class="right">';
122 $this->resprints .= '</td></tr></table>';
123 $this->resprints .= '</td>';
124 $this->resprints .= '<td colspan="3">';
125 $stripe = new Stripe($this->db);
126 if (7 == 4) {
127 $object->fetch_thirdparty();
128 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
129 $this->resprints .= $customer->id;
130 } else {
131 $this->resprints .= $langs->trans("NoStripe");
132 }
133 $this->resprints .= '</td></tr>';
134 } elseif ($object instanceof CommonObject && $object->element == 'adherent_type') {
135 $this->resprints .= '<tr><td>';
136 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
137 $this->resprints .= $langs->trans('PlanStripe');
138 $this->resprints .= '<td><td class="right">';
139 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
140 $this->resprints .= '</td></tr></table>';
141 $this->resprints .= '</td>';
142 $this->resprints .= '<td colspan="3">';
143 $stripe = new Stripe($this->db);
144 if (7 == 4) {
145 $object->fetch_thirdparty();
146 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
147 $this->resprints .= $customer->id;
148 } else {
149 $this->resprints .= $langs->trans("NoStripe");
150 }
151 $this->resprints .= '</td></tr>';
152 }
153 return 0;
154 }
155
164 public function addMoreActionsButtons($parameters, &$object, &$action)
165 {
166 global $conf, $langs;
167
168 if (is_object($object) && $object->element == 'facture') {
169 // Verify if the invoice has payments
170 $sql = 'SELECT pf.amount';
171 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
172 $sql .= ' WHERE pf.fk_facture = '.((int) $object->id);
173
174 $totalpaid = 0;
175
176 $result = $this->db->query($sql);
177 if ($result) {
178 $i = 0;
179 $num = $this->db->num_rows($result);
180
181 while ($i < $num) {
182 $objp = $this->db->fetch_object($result);
183 $totalpaid += $objp->amount;
184 $i++;
185 }
186 } else {
187 dol_print_error($this->db, '');
188 }
189
190 $resteapayer = $object->total_ttc - $totalpaid;
191 // Request a direct debit order
192 if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0) {
193 $stripe = new Stripe($this->db);
194 if ($resteapayer > 0) {
195 if ($stripe->getStripeAccount($conf->entity)) { // a modifier avec droit stripe
196 $langs->load("withdrawals");
197 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>';
198 } else {
199 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
200 }
201 } elseif ($resteapayer == 0) {
202 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
203 }
204 } else {
205 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
206 }
207 } elseif (is_object($object) && $object->element == 'invoice_supplier') {
208 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
209 } elseif (is_object($object) && $object->element == 'member') {
210 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
211 }
212 return 0;
213 }
214}
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...