dolibarr 24.0.0-beta
charge.php
1<?php
2/* Copyright (C) 2018-2022 Thibault FOUCART <support@ptibogxiv.net>
3 * Copyright (C) 2019-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.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, see <https://www.gnu.org/licenses/>.
18 */
19
20// Put here all includes required by your class file
21
22// Load Dolibarr environment
23require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
32require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
33require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
34//require_once DOL_DOCUMENT_ROOT.'/core/lib/stripe.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
36require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
38if (isModEnabled('accounting')) {
39 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
40}
41
42// Load translation files required by the page
43$langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe'));
44
45// Security check
46$socid = GETPOSTINT("socid");
47if ($user->socid) {
48 $socid = $user->socid;
49}
50//restrictedArea($user, 'salaries', '', '', '');
51
52$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
53$rowid = GETPOST("rowid", 'alpha');
54$sortfield = GETPOST('sortfield', 'aZ09comma');
55$sortorder = GETPOST('sortorder', 'aZ09comma');
56$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
57if (empty($page) || $page == -1) {
58 $page = 0;
59} // If $page is not defined, or '' or -1
60$offset = $limit * $page;
61$pageprev = $page - 1;
62$pagenext = $page + 1;
63
64$result = restrictedArea($user, 'banque');
65$optioncss = GETPOST('optioncss', 'alpha');
66
67
68/*
69 * View
70 */
71
72$form = new Form($db);
73$societestatic = new Societe($db);
74$memberstatic = new Adherent($db);
75$acc = new Account($db);
76$stripe = new Stripe($db);
77
78llxHeader('', $langs->trans("StripeChargeList"));
79
80if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE')/* || GETPOST('forcesandbox', 'alpha') */)) {
81 $service = 'StripeTest';
82 $servicestatus = '0';
83 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning');
84} else {
85 $service = 'StripeLive';
86 $servicestatus = '1';
87}
88
89$stripeacc = $stripe->getStripeAccount($service);
90/*if (empty($stripeaccount))
91{
92 print $langs->trans('ErrorStripeAccountNotDefined');
93}*/
94
95if (!$rowid) {
96 $option = array('limit' => $limit + 1);
97 $num = 0;
98
99 $param = '';
100 $totalnboflines = '';
101 $moreforfilter = '';
102 $list = null;
103 if (GETPOSTISSET('starting_after_'.$page)) {
104 $option['starting_after'] = GETPOST('starting_after_'.$page, 'alphanohtml');
105 }
106 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
107 if ($optioncss != '') {
108 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
109 }
110
111 print '<input type="hidden" name="token" value="'.newToken().'">';
112 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
113 print '<input type="hidden" name="action" value="list">';
114 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
115 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
116 print '<input type="hidden" name="page" value="'.$page.'">';
117
118 $title = $langs->trans("StripeChargeList");
119 $title .= $form->textwithpicto('', $stripeacc ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
120
121 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', 'hidepaginationprevious', $limit);
122
123 print '<div class="div-table-responsive">';
124 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
125
126 print '<tr class="liste_titre">';
127 print_liste_field_titre("StripePaymentId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
128 print_liste_field_titre("StripeCustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
129 print_liste_field_titre("Customer", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
130 print_liste_field_titre("Origin", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
131 print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
132 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'left ');
133 print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
134 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", '', '', '', 'center ');
135 print "</tr>\n";
136
137 try {
138 if ($stripeacc) {
139 $list = \Stripe\Charge::all($option, array("stripe_account" => $stripeacc));
140 } else {
141 $list = \Stripe\Charge::all($option);
142 }
143
144 '@phan-var-force \Stripe\Charge $list'; // TStripeObject suggested, but is a template
145 $num = count($list->data);
146
147
148 //if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
149 if ($limit > 0 && $limit != $conf->liste_limit) {
150 $param .= '&limit='.((int) $limit);
151 }
152 $param .= '&starting_after_'.($page + 1).'='.$list->data[($limit - 1)]->id;
153 //$param.='&ending_before_'.($page+1).'='.$list->data[($limit-1)]->id;
154 } catch (Exception $e) {
155 print '<tr><td colspan="8">'.$e->getMessage().'</td></td>';
156 }
157
158 //print $list;
159 $i = 0;
160 if (!empty($list)) {
161 foreach ($list->data as $charge) {
162 '@phan-var-force \Stripe\Charge $charge'; // TStripeObject suggested, but is a template
163 if ($i >= $limit) {
164 break;
165 }
166
167 $label = '';
168 if ($charge->refunded == '1') {
169 $status = img_picto($langs->trans("refunded"), 'statut6');
170 } elseif ($charge->paid == '1') {
171 $status = img_picto($langs->trans((string) $charge->status), 'statut4');
172 } elseif (empty($charge->failure_message)) {
173 $label .= $langs->trans("Network").": ".$charge->outcome->network_status."<br>";
174 $label .= $langs->trans("Status").": ".$langs->trans((string) $charge->outcome->seller_message);
175 $status = $form->textwithpicto(img_picto($langs->trans((string) $charge->status), 'statut4'), $label, 1);
176 } else {
177 $label .= $langs->trans("Error").": ".$charge->failure_message."<br>";
178 $label .= $langs->trans("Network").": ".$charge->outcome->network_status."<br>";
179 $label .= $langs->trans("Status").": ".$langs->trans((string) $charge->outcome->seller_message);
180 $status = $form->textwithpicto(img_picto($langs->trans((string) $charge->status), 'statut8'), $label, 1);
181 }
182
183 if (isset($charge->payment_method_details->type) && $charge->payment_method_details->type == 'card') {
184 $type = $langs->trans("card");
185 } elseif (isset($charge->source->type) && $charge->source->type == 'card') {
186 $type = $langs->trans("card");
187 } elseif (isset($charge->payment_method_details->type) && $charge->payment_method_details->type == 'three_d_secure') {
188 $type = $langs->trans("card3DS");
189 } elseif (isset($charge->payment_method_details->type) && $charge->payment_method_details->type == 'sepa_debit') {
190 $type = $langs->trans("sepadebit");
191 } elseif (isset($charge->payment_method_details->type) && $charge->payment_method_details->type == 'ideal') {
192 $type = $langs->trans("iDEAL");
193 } else {
194 $type = '';
195 }
196
197 // Why this ?
198 /*if (!empty($charge->payment_intent)) {
199 if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
200 $charge = \Stripe\PaymentIntent::retrieve($charge->payment_intent);
201 } else {
202 $charge = \Stripe\PaymentIntent::retrieve($charge->payment_intent, array("stripe_account" => $stripeacc));
203 }
204 }*/
205
206 // The metadata FULLTAG is defined by the online payment page
207 $FULLTAG = $charge->metadata->FULLTAG;
208
209 // Save into $tmparray all metadata
210 $tmparray = dolExplodeIntoArray($FULLTAG, '.', '=');
211 // Load origin object according to metadata
212 if (!empty($tmparray['CUS']) && (int) $tmparray['CUS'] > 0) {
213 $societestatic->fetch((int) $tmparray['CUS']);
214 } elseif (!empty($charge->metadata->dol_thirdparty_id) && $charge->metadata->dol_thirdparty_id > 0) {
215 $societestatic->fetch($charge->metadata->dol_thirdparty_id);
216 } else {
217 $societestatic->id = 0;
218 }
219 if (!empty($tmparray['MEM']) && (int) $tmparray['MEM'] > 0) {
220 $memberstatic->fetch((int) $tmparray['MEM']);
221 } else {
222 $memberstatic->id = 0;
223 }
224
225 print '<tr class="oddeven">';
226
227 if (!empty($stripeacc)) {
228 $connect = $stripeacc.'/';
229 } else {
230 $connect = '';
231 }
232
233 // Ref
234 $url = 'https://dashboard.stripe.com/'.$connect.'test/payments/'.$charge->id;
235 if ($servicestatus) {
236 $url = 'https://dashboard.stripe.com/'.$connect.'payments/'.$charge->id;
237 }
238 print '<td class="tdoverflowmax150">';
239 print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')." ".$charge->id."</a>";
240 if ($charge->payment_intent) {
241 print '<br><span class="opacitymedium">'.$charge->payment_intent.'</span>';
242 }
243 print "</td>\n";
244
245 // Stripe customer
246 print '<td class="tdoverflowmax150">';
247 if (isModEnabled('stripe') && !empty($stripeacc)) {
248 $connect = $stripeacc.'/';
249 }
250 $url = 'https://dashboard.stripe.com/'.$connect.'test/customers/'.$charge->customer;
251 if ($servicestatus) {
252 $url = 'https://dashboard.stripe.com/'.$connect.'customers/'.$charge->customer;
253 }
254 if (!empty($charge->customer)) {
255 print '<a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe'), 'globe').' '.$charge->customer.'</a>';
256 }
257 print "</td>\n";
258
259 // Link
260 print '<td class="tdoverflowmax200">';
261 if ($societestatic->id > 0) {
262 print $societestatic->getNomUrl(1);
263 } elseif ($memberstatic->id > 0) {
264 print $memberstatic->getNomUrl(1);
265 }
266 print "</td>\n";
267
268 // Origin
269 print '<td class="nowraponall">';
270 if ($charge->metadata->dol_type == "order" || $charge->metadata->dol_type == "commande") {
271 $object = new Commande($db);
272 $object->fetch($charge->metadata->dol_id);
273 if ($object->id > 0) {
274 print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$object->id."'>".img_picto('', 'order')." ".$object->ref."</a>";
275 } else {
276 print $FULLTAG;
277 }
278 } elseif ($charge->metadata->dol_type == "invoice" || $charge->metadata->dol_type == "facture") {
279 $object = new Facture($db);
280 $object->fetch($charge->metadata->dol_id);
281 if ($object->id > 0) {
282 print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'bill')." ".$object->ref."</a>";
283 } else {
284 print $FULLTAG;
285 }
286 } else {
287 print $FULLTAG;
288 }
289 print "</td>\n";
290
291 // Date payment
292 print '<td class="center nowraponall">'.dol_print_date($charge->created, 'dayhour')."</td>\n";
293 // Type
294 print '<td>';
295 print $type;
296 print '</td>';
297 // Amount
298 print '<td class="right"><span class="amount">'.price(($charge->amount - $charge->amount_refunded) / 100, 0, '', 1, - 1, - 1, strtoupper($charge->currency))."</span></td>";
299 // Status
300 print '<td class="nowraponall center">';
301 print $status;
302 print "</td>\n";
303
304 print "</tr>\n";
305
306 $i++;
307 }
308 }
309
310 print '</table>';
311 print '</div>';
312 print '</form>';
313}
314
315// End of page
316llxFooter();
317$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage bank accounts.
Class to manage members of a foundation.
Class to manage customers orders.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
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:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.