dolibarr 21.0.0-alpha
charge.php
1<?php
2/* Copyright (C) 2018-2022 Thibault FOUCART <support@ptibogxiv.net>
3 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 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';
24require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
25require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
26require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
27//require_once DOL_DOCUMENT_ROOT.'/core/lib/stripe.lib.php';
28require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
29require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
30require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
31if (isModEnabled('accounting')) {
32 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
33}
34
35// Load translation files required by the page
36$langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe'));
37
38// Security check
39$socid = GETPOSTINT("socid");
40if ($user->socid) {
41 $socid = $user->socid;
42}
43//$result = restrictedArea($user, 'salaries', '', '', '');
44
45$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
46$rowid = GETPOST("rowid", 'alpha');
47$sortfield = GETPOST('sortfield', 'aZ09comma');
48$sortorder = GETPOST('sortorder', 'aZ09comma');
49$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
50if (empty($page) || $page == -1) {
51 $page = 0;
52} // If $page is not defined, or '' or -1
53$offset = $limit * $page;
54$pageprev = $page - 1;
55$pagenext = $page + 1;
56
57$result = restrictedArea($user, 'banque');
58$optioncss = GETPOST('optioncss', 'alpha');
59
60/*
61 * View
62 */
63
64$form = new Form($db);
65$societestatic = new Societe($db);
66$memberstatic = new Adherent($db);
67$acc = new Account($db);
68$stripe = new Stripe($db);
69
70llxHeader('', $langs->trans("StripeChargeList"));
71
72if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
73 $service = 'StripeTest';
74 $servicestatus = '0';
75 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning');
76} else {
77 $service = 'StripeLive';
78 $servicestatus = '1';
79}
80
81$stripeacc = $stripe->getStripeAccount($service);
82/*if (empty($stripeaccount))
83{
84 print $langs->trans('ErrorStripeAccountNotDefined');
85}*/
86
87if (!$rowid) {
88 $option = array('limit' => $limit + 1);
89 $num = 0;
90
91 $param = '';
92 $totalnboflines = '';
93 $moreforfilter = '';
94 $list = null;
95 if (GETPOSTISSET('starting_after_'.$page)) {
96 $option['starting_after'] = GETPOST('starting_after_'.$page, 'alphanohtml');
97 }
98 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
99 if ($optioncss != '') {
100 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
101 }
102
103 print '<input type="hidden" name="token" value="'.newToken().'">';
104 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
105 print '<input type="hidden" name="action" value="list">';
106 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
107 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
108 print '<input type="hidden" name="page" value="'.$page.'">';
109
110 $title = $langs->trans("StripeChargeList");
111 $title .= ($stripeacc ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
112
113 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', 'hidepaginationprevious', $limit);
114
115 print '<div class="div-table-responsive">';
116 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
117
118 print '<tr class="liste_titre">';
119 print_liste_field_titre("StripePaymentId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
120 print_liste_field_titre("StripeCustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
121 print_liste_field_titre("Customer", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
122 print_liste_field_titre("Origin", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
123 print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
124 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'left ');
125 print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
126 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", '', '', '', 'right ');
127 print "</tr>\n";
128
129 try {
130 if ($stripeacc) {
131 $list = \Stripe\Charge::all($option, array("stripe_account" => $stripeacc));
132 } else {
133 $list = \Stripe\Charge::all($option);
134 }
135
136 '@phan-var-force \Stripe\Charge $list'; // TStripeObject suggested, but is a template
137 $num = count($list->data);
138
139
140 //if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
141 if ($limit > 0 && $limit != $conf->liste_limit) {
142 $param .= '&limit='.((int) $limit);
143 }
144 $param .= '&starting_after_'.($page + 1).'='.$list->data[($limit - 1)]->id;
145 //$param.='&ending_before_'.($page+1).'='.$list->data[($limit-1)]->id;
146 } catch (Exception $e) {
147 print '<tr><td colspan="8">'.$e->getMessage().'</td></td>';
148 }
149
150 //print $list;
151 $i = 0;
152 if (!empty($list)) {
153 foreach ($list->data as $charge) {
154 '@phan-var-force \Stripe\Charge $charge'; // TStripeObject suggested, but is a template
155 if ($i >= $limit) {
156 break;
157 }
158
159 if ($charge->refunded == '1') {
160 $status = img_picto($langs->trans("refunded"), 'statut6');
161 } elseif ($charge->paid == '1') {
162 $status = img_picto($langs->trans((string) $charge->status), 'statut4');
163 } else {
164 $label = $langs->trans("Message").": ".$charge->failure_message."<br>";
165 $label .= $langs->trans("Network").": ".$charge->outcome->network_status."<br>";
166 $label .= $langs->trans("Status").": ".$langs->trans((string) $charge->outcome->seller_message);
167 $status = $form->textwithpicto(img_picto($langs->trans((string) $charge->status), 'statut8'), $label, -1);
168 }
169
170 if (isset($charge->payment_method_details->type) && $charge->payment_method_details->type == 'card') {
171 $type = $langs->trans("card");
172 } elseif (isset($charge->source->type) && $charge->source->type == 'card') {
173 $type = $langs->trans("card");
174 } elseif (isset($charge->payment_method_details->type) && $charge->payment_method_details->type == 'three_d_secure') {
175 $type = $langs->trans("card3DS");
176 } elseif (isset($charge->payment_method_details->type) && $charge->payment_method_details->type == 'sepa_debit') {
177 $type = $langs->trans("sepadebit");
178 } elseif (isset($charge->payment_method_details->type) && $charge->payment_method_details->type == 'ideal') {
179 $type = $langs->trans("iDEAL");
180 }
181
182 // Why this ?
183 /*if (!empty($charge->payment_intent)) {
184 if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage
185 $charge = \Stripe\PaymentIntent::retrieve($charge->payment_intent);
186 } else {
187 $charge = \Stripe\PaymentIntent::retrieve($charge->payment_intent, array("stripe_account" => $stripeacc));
188 }
189 }*/
190
191 // The metadata FULLTAG is defined by the online payment page
192 $FULLTAG = $charge->metadata->FULLTAG;
193
194 // Save into $tmparray all metadata
195 $tmparray = dolExplodeIntoArray($FULLTAG, '.', '=');
196 // Load origin object according to metadata
197 if (!empty($tmparray['CUS']) && $tmparray['CUS'] > 0) {
198 $societestatic->fetch($tmparray['CUS']);
199 } elseif (!empty($charge->metadata->dol_thirdparty_id) && $charge->metadata->dol_thirdparty_id > 0) {
200 $societestatic->fetch($charge->metadata->dol_thirdparty_id);
201 } else {
202 $societestatic->id = 0;
203 }
204 if (!empty($tmparray['MEM']) && $tmparray['MEM'] > 0) {
205 $memberstatic->fetch($tmparray['MEM']);
206 } else {
207 $memberstatic->id = 0;
208 }
209
210 print '<tr class="oddeven">';
211
212 if (!empty($stripeacc)) {
213 $connect = $stripeacc.'/';
214 } else {
215 $connect = '';
216 }
217
218 // Ref
219 $url = 'https://dashboard.stripe.com/'.$connect.'test/payments/'.$charge->id;
220 if ($servicestatus) {
221 $url = 'https://dashboard.stripe.com/'.$connect.'payments/'.$charge->id;
222 }
223 print "<td>";
224 print "<a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')." ".$charge->id."</a>";
225 if ($charge->payment_intent) {
226 print '<br><span class="opacitymedium">'.$charge->payment_intent.'</span>';
227 }
228 print "</td>\n";
229
230 // Stripe customer
231 print "<td>";
232 if (isModEnabled('stripe') && !empty($stripeacc)) {
233 $connect = $stripeacc.'/';
234 }
235 $url = 'https://dashboard.stripe.com/'.$connect.'test/customers/'.$charge->customer;
236 if ($servicestatus) {
237 $url = 'https://dashboard.stripe.com/'.$connect.'customers/'.$charge->customer;
238 }
239 if (!empty($charge->customer)) {
240 print '<a href="'.$url.'" target="_stripe">'.img_picto($langs->trans('ShowInStripe'), 'globe').' '.$charge->customer.'</a>';
241 }
242 print "</td>\n";
243
244 // Link
245 print "<td>";
246 if ($societestatic->id > 0) {
247 print $societestatic->getNomUrl(1);
248 } elseif ($memberstatic->id > 0) {
249 print $memberstatic->getNomUrl(1);
250 }
251 print "</td>\n";
252
253 // Origin
254 print "<td>";
255 if ($charge->metadata->dol_type == "order" || $charge->metadata->dol_type == "commande") {
256 $object = new Commande($db);
257 $object->fetch($charge->metadata->dol_id);
258 if ($object->id > 0) {
259 print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$object->id."'>".img_picto('', 'order')." ".$object->ref."</a>";
260 } else {
261 print $FULLTAG;
262 }
263 } elseif ($charge->metadata->dol_type == "invoice" || $charge->metadata->dol_type == "facture") {
264 $object = new Facture($db);
265 $object->fetch($charge->metadata->dol_id);
266 if ($object->id > 0) {
267 print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'bill')." ".$object->ref."</a>";
268 } else {
269 print $FULLTAG;
270 }
271 } else {
272 print $FULLTAG;
273 }
274 print "</td>\n";
275
276 // Date payment
277 print '<td class="center">'.dol_print_date($charge->created, 'dayhour')."</td>\n";
278 // Type
279 print '<td>';
280 print $type;
281 print '</td>';
282 // Amount
283 print '<td class="right"><span class="amount">'.price(($charge->amount - $charge->amount_refunded) / 100, 0, '', 1, - 1, - 1, strtoupper($charge->currency))."</span></td>";
284 // Status
285 print '<td class="right">';
286 print $status;
287 print "</td>\n";
288
289 print "</tr>\n";
290
291 $i++;
292 }
293 }
294
295 print '</table>';
296 print '</div>';
297 print '</form>';
298}
299
300// End of page
301llxFooter();
302$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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:70
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 extends CommonObject.
llxFooter()
Footer empty.
Definition document.php:107
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key 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)
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.
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.