dolibarr 22.0.5
transaction.php
1<?php
2/* Copyright (C) 2018-2019 Thibault FOUCART <support@ptibogxiv.net>
3 * Copyright (C) 2021-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
43// Load translation files required by the page
44$langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe'));
45
46// Security check
47$socid = GETPOSTINT("socid");
48if ($user->socid) {
49 $socid = $user->socid;
50}
51//$result = restrictedArea($user, 'salaries', '', '', '');
52
53$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
54$rowid = GETPOST("rowid", 'alpha');
55$sortfield = GETPOST('sortfield', 'aZ09comma');
56$sortorder = GETPOST('sortorder', 'aZ09comma');
57$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
58if (empty($page) || $page == -1) {
59 $page = 0;
60} // If $page is not defined, or '' or -1
61$offset = $limit * $page;
62$pageprev = $page - 1;
63$pagenext = $page + 1;
64$optioncss = GETPOST('optioncss', 'alpha');
65$param = "";
66$num = 0;
67$totalnboflines = 0;
68$result = restrictedArea($user, 'banque');
69
70
71/*
72 * View
73 */
74
75$stripe = new Stripe($db);
76
77llxHeader('', $langs->trans("StripeTransactionList"));
78
79if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE')/* || GETPOST('forcesandbox', 'alpha') */)) {
80 $service = 'StripeTest';
81 $servicestatus = '0';
82 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning');
83} else {
84 $service = 'StripeLive';
85 $servicestatus = '1';
86}
87$stripeacc = $stripe->getStripeAccount($service);
88/*if (empty($stripeaccount))
89{
90 print $langs->trans('ErrorStripeAccountNotDefined');
91}*/
92
93if (!$rowid) {
94 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
95 if ($optioncss != '') {
96 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
97 }
98 print '<input type="hidden" name="token" value="'.newToken().'">';
99 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
100 print '<input type="hidden" name="action" value="list">';
101 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
102 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
103 print '<input type="hidden" name="page" value="'.$page.'">';
104
105 $title = $langs->trans("StripeTransactionList");
106 $title .= (!empty($stripeacc) ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
107
108 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
109
110 $moreforfilter = '';
111
112 print '<div class="div-table-responsive">';
113 print '<table class="tagtable liste">'."\n";
114
115 print '<tr class="liste_titre">';
116 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
117 print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
118 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'left ');
119 print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
120 print_liste_field_titre("Fee", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
121 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", '', '', '', 'right ');
122 print "</tr>\n";
123 $connect = "";
124
125 try {
126 if ($stripeacc) {
127 $txn_all = \Stripe\BalanceTransaction::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
128 } else {
129 $txn_all = \Stripe\BalanceTransaction::all(array("limit" => $limit));
130 }
131 '@phan-var-force \Stripe\BalanceTransaction $txn_all'; // TStripeObject is 'template' of StripeObject
132
133 foreach ($txn_all->data as $txn) {
134 '@phan-var-force \Stripe\BalanceTransaction $txn'; // TStripeObject is 'template' of StripeObject
135 //$charge = $txn;
136 //var_dump($txn);
137
138 // The metadata FULLTAG is defined by the online payment page
139 /*$FULLTAG=$charge->metadata->FULLTAG;
140
141 // Save into $tmparray all metadata
142 $tmparray = dolExplodeIntoArray($FULLTAG,'.','=');
143 // Load origin object according to metadata
144 if (!empty($tmparray['CUS']))
145 {
146 $societestatic->fetch($tmparray['CUS']);
147 }
148 else
149 {
150 $societestatic->id = 0;
151 }
152 if (!empty($tmparray['MEM']))
153 {
154 $memberstatic->fetch($tmparray['MEM']);
155 }
156 else
157 {
158 $memberstatic->id = 0;
159 }
160
161 $societestatic->fetch($charge->metadata->idcustomer);
162 $societestatic->id = $charge->metadata->idcustomer;
163 $societestatic->lastname = $obj->lastname;
164 $societestatic->firstname = $obj->firstname;
165 $societestatic->admin = $obj->admin;
166 $societestatic->login = $obj->login;
167 $societestatic->email = $obj->email;
168 $societestatic->societe_id = $obj->fk_soc;*/
169
170 print '<tr class="oddeven">';
171
172 // Ref
173 if (!empty($stripeacc)) {
174 $connect = $stripeacc.'/';
175 }
176
177 // Ref
178 if (preg_match('/po_/i', $txn->source)) {
179 $origin = "payouts";
180 } elseif (preg_match('/fee_/i', $txn->source)) {
181 $origin = "connect/application_fees";
182 } else {
183 $origin = "payments";
184 }
185
186 $url = 'https://dashboard.stripe.com/'.$connect.'test/'.$origin.'/'.$txn->source;
187 if ($servicestatus) {
188 $url = 'https://dashboard.stripe.com/'.$connect.$origin.'/'.$txn->source;
189 }
190 if ($txn->type == 'stripe_fee' || $txn->type == 'reserve_transaction') {
191 print "<td>".$txn->type."</td>";
192 } else {
193 print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')." ".$txn->source."</a></td>\n";
194 }
195
196 // Stripe customer
197 //print "<td>".$charge->customer."</td>\n";
198 // Link
199 /*print "<td>";
200 if ($societestatic->id > 0) {
201 print $societestatic->getNomUrl(1);
202 }
203 if ($memberstatic->id > 0) {
204 print $memberstatic->getNomUrl(1);
205 }
206 print "</td>\n";*/
207 // Origine
208 //print "<td>";
210 // $object = new Commande($db);
211 // $object->fetch($charge->metadata->dol_id);
212 // print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->dol_id."'>".img_picto('', 'object_order')." ".$object->ref."</a>";
213 //} elseif ($charge->metadata->dol_type=="invoice"){
214 // $object = new Facture($db);
215 // $object->fetch($charge->metadata->dol_id);
216 // print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</a>";
217 //}
218 //print "</td>\n";
219 // Date payment
220 print '<td class="center">'.dol_print_date($txn->created, 'dayhour', 'gmt')." GMT</td>\n";
221 // Type
222 print '<td>'.dolPrintHTML($txn->type).'</td>';
223 // Amount
224 print '<td class="right"><span class="amount">'.price(($txn->amount) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency))."</span></td>";
225 print '<td class="right"><span class="amount">'.price(($txn->fee) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency))."</span></td>";
226 // Status
227 print '<td class="center">';
228 //var_dump($txn->status);
229 if ($txn->status == 'available') {
230 print img_picto($langs->trans($txn->status), 'statut4');
231 } elseif ($txn->status == 'pending') { // Warning, even when charge is ok on page charge, we have here 'pending'. Don't know why.
232 print img_picto($langs->trans($txn->status), 'statut7');
233 } elseif ($txn->status == 'failed') {
234 print img_picto($langs->trans($txn->status), 'statut8');
235 }
236 print '</td>';
237 print "</tr>\n";
238 }
239 } catch (Exception $e) {
240 print '<tr><td colspan="6">'.$e->getMessage().'</td></td>';
241 }
242 print "</table>";
243 print '</div>';
244 print '</form>';
245}
246
247// End of page
248llxFooter();
249$db->close();
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
Stripe class @TODO No reason to extend CommonObject.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.