dolibarr 19.0.3
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 of hooks not used yet. To remove ?
22
29require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/commonhookactions.class.php';
31
32
37{
41 public $db;
42
43 private $config = array();
44
45
51 public function __construct($db)
52 {
53 $this->db = $db;
54 }
55
56
65 public function formObjectOptions($parameters, &$object, &$action)
66 {
67 global $conf, $langs;
68
69 if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
70 $service = 'StripeTest';
71 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
72 } else {
73 $service = 'StripeLive';
74 }
75
76 if (is_array($parameters) && !empty($parameters)) {
77 foreach ($parameters as $key => $value) {
78 $key = $value;
79 }
80 }
81
82 if (is_object($object) && $object->element == 'societe') {
83 $this->resprints .= '<tr><td>';
84 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
85 $this->resprints .= $langs->trans('StripeCustomer');
86 $this->resprints .= '<td><td class="right">';
87 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
88 $this->resprints .= '</td></tr></table>';
89 $this->resprints .= '</td>';
90 $this->resprints .= '<td colspan="3">';
91 $stripe = new Stripe($this->db);
92 if ($stripe->getStripeAccount($service) && $object->client != 0) {
93 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
94 $this->resprints .= $customer->id;
95 } else {
96 $this->resprints .= $langs->trans("NoStripe");
97 }
98 $this->resprints .= '</td></tr>';
99 } elseif (is_object($object) && $object->element == 'member') {
100 $this->resprints .= '<tr><td>';
101 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
102 $this->resprints .= $langs->trans('StripeCustomer');
103 $this->resprints .= '<td><td class="right">';
104 $this->resprints .= '</td></tr></table>';
105 $this->resprints .= '</td>';
106 $this->resprints .= '<td colspan="3">';
107 $stripe = new Stripe($this->db);
108 if ($stripe->getStripeAccount($service) && $object->fk_soc > 0) {
109 $object->fetch_thirdparty();
110 $customer = $stripe->customerStripe($object->thirdparty, $stripe->getStripeAccount($service));
111 $this->resprints .= $customer->id;
112 } else {
113 $this->resprints .= $langs->trans("NoStripe");
114 }
115 $this->resprints .= '</td></tr>';
116
117 $this->resprints .= '<tr><td>';
118 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
119 $this->resprints .= $langs->trans('SubscriptionStripe');
120 $this->resprints .= '<td><td class="right">';
121 $this->resprints .= '</td></tr></table>';
122 $this->resprints .= '</td>';
123 $this->resprints .= '<td colspan="3">';
124 $stripe = new Stripe($this->db);
125 if (7 == 4) {
126 $object->fetch_thirdparty();
127 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
128 $this->resprints .= $customer->id;
129 } else {
130 $this->resprints .= $langs->trans("NoStripe");
131 }
132 $this->resprints .= '</td></tr>';
133 } elseif (is_object($object) && $object->element == 'adherent_type') {
134 $this->resprints .= '<tr><td>';
135 $this->resprints .= '<table width="100%" class="nobordernopadding"><tr><td>';
136 $this->resprints .= $langs->trans('PlanStripe');
137 $this->resprints .= '<td><td class="right">';
138 // $this->resprints.= '<a class="editfielda" href="'.$dolibarr_main_url_root.dol_buildpath('/dolipress/card.php?socid='.$object->id, 1).'">'.img_edit().'</a>';
139 $this->resprints .= '</td></tr></table>';
140 $this->resprints .= '</td>';
141 $this->resprints .= '<td colspan="3">';
142 $stripe = new Stripe($this->db);
143 if (7 == 4) {
144 $object->fetch_thirdparty();
145 $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service));
146 $this->resprints .= $customer->id;
147 } else {
148 $this->resprints .= $langs->trans("NoStripe");
149 }
150 $this->resprints .= '</td></tr>';
151 }
152 return 0;
153 }
154
163 public function addMoreActionsButtons($parameters, &$object, &$action)
164 {
165 global $conf, $langs;
166
167 if (is_object($object) && $object->element == 'facture') {
168 // On verifie si la facture a des paiements
169 $sql = 'SELECT pf.amount';
170 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
171 $sql .= ' WHERE pf.fk_facture = '.((int) $object->id);
172
173 $totalpaid = 0;
174
175 $result = $this->db->query($sql);
176 if ($result) {
177 $i = 0;
178 $num = $this->db->num_rows($result);
179
180 while ($i < $num) {
181 $objp = $this->db->fetch_object($result);
182 $totalpaid += $objp->amount;
183 $i++;
184 }
185 } else {
186 dol_print_error($this->db, '');
187 }
188
189 $resteapayer = $object->total_ttc - $totalpaid;
190 // Request a direct debit order
191 if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0) {
192 $stripe = new Stripe($this->db);
193 if ($resteapayer > 0) {
194 if ($stripe->getStripeAccount($conf->entity)) { // a modifier avec droit stripe
195 $langs->load("withdrawals");
196 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>';
197 } else {
198 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
199 }
200 } elseif ($resteapayer == 0) {
201 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
202 }
203 } else {
204 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("StripeConnectPay").'</a>';
205 }
206 } elseif (is_object($object) && $object->element == 'invoice_supplier') {
207 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeConnectPay")).'">'.$langs->trans("StripeConnectPay").'</a>';
208 } elseif (is_object($object) && $object->element == 'member') {
209 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("StripeAutoSubscription")).'">'.$langs->trans("StripeAutoSubscription").'</a>';
210 }
211 return 0;
212 }
213}
Class Actions Stripe Connect.
addMoreActionsButtons($parameters, &$object, &$action)
addMoreActionsButtons
formObjectOptions($parameters, &$object, &$action)
formObjectOptions
Parent class of all other hook actions classes.
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).
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...