dolibarr 21.0.0-beta
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$form = new Form($db);
76$societestatic = new Societe($db);
77$memberstatic = new Adherent($db);
78$acc = new Account($db);
79$stripe = new Stripe($db);
80
81llxHeader('', $langs->trans("StripeTransactionList"));
82
83if (isModEnabled('stripe') && (!getDolGlobalString('STRIPE_LIVE') || GETPOST('forcesandbox', 'alpha'))) {
84 $service = 'StripeTest';
85 $servicestatus = '0';
86 dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), [], 'warning');
87} else {
88 $service = 'StripeLive';
89 $servicestatus = '1';
90}
91$stripeacc = $stripe->getStripeAccount($service);
92/*if (empty($stripeaccount))
93{
94 print $langs->trans('ErrorStripeAccountNotDefined');
95}*/
96
97if (!$rowid) {
98 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
99 if ($optioncss != '') {
100 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
101 }
102 print '<input type="hidden" name="token" value="'.newToken().'">';
103 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
104 print '<input type="hidden" name="action" value="list">';
105 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
106 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
107 print '<input type="hidden" name="page" value="'.$page.'">';
108
109 $title = $langs->trans("StripeTransactionList");
110 $title .= (!empty($stripeacc) ? ' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')' : ' (Stripe connection with keys from Stripe module setup)');
111
112 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
113
114 print '<div class="div-table-responsive">';
115 print '<table class="tagtable liste'.(!empty($moreforfilter) ? " listwithfilterbefore" : "").'">'."\n";
116
117 print '<tr class="liste_titre">';
118 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
119 print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'center ');
120 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'left ');
121 print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
122 print_liste_field_titre("Fee", $_SERVER["PHP_SELF"], "", "", "", '', $sortfield, $sortorder, 'right ');
123 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", '', '', '', 'right ');
124 print "</tr>\n";
125 $connect = "";
126
127 try {
128 if ($stripeacc) {
129 $txn_all = \Stripe\BalanceTransaction::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
130 } else {
131 $txn_all = \Stripe\BalanceTransaction::all(array("limit" => $limit));
132 }
133 '@phan-var-force \Stripe\BalanceTransaction $txn_all'; // TStripeObject is 'template' of StripeObject
134
135 foreach ($txn_all->data as $txn) {
136 '@phan-var-force \Stripe\BalanceTransaction $txn'; // TStripeObject is 'template' of StripeObject
137 //$charge = $txn;
138 //var_dump($txn);
139
140 // The metadata FULLTAG is defined by the online payment page
141 /*$FULLTAG=$charge->metadata->FULLTAG;
142
143 // Save into $tmparray all metadata
144 $tmparray = dolExplodeIntoArray($FULLTAG,'.','=');
145 // Load origin object according to metadata
146 if (!empty($tmparray['CUS']))
147 {
148 $societestatic->fetch($tmparray['CUS']);
149 }
150 else
151 {
152 $societestatic->id = 0;
153 }
154 if (!empty($tmparray['MEM']))
155 {
156 $memberstatic->fetch($tmparray['MEM']);
157 }
158 else
159 {
160 $memberstatic->id = 0;
161 }
162
163 $societestatic->fetch($charge->metadata->idcustomer);
164 $societestatic->id = $charge->metadata->idcustomer;
165 $societestatic->lastname = $obj->lastname;
166 $societestatic->firstname = $obj->firstname;
167 $societestatic->admin = $obj->admin;
168 $societestatic->login = $obj->login;
169 $societestatic->email = $obj->email;
170 $societestatic->societe_id = $obj->fk_soc;*/
171
172 print '<tr class="oddeven">';
173
174 // Ref
175 if (!empty($stripeacc)) {
176 $connect = $stripeacc.'/';
177 }
178
179 // Ref
180 if (preg_match('/po_/i', $txn->source)) {
181 $origin = "payouts";
182 } elseif (preg_match('/fee_/i', $txn->source)) {
183 $origin = "connect/application_fees";
184 } else {
185 $origin = "payments";
186 }
187
188 $url = 'https://dashboard.stripe.com/'.$connect.'test/'.$origin.'/'.$txn->source;
189 if ($servicestatus) {
190 $url = 'https://dashboard.stripe.com/'.$connect.$origin.'/'.$txn->source;
191 }
192 if ($txn->type == 'stripe_fee' || $txn->type == 'reserve_transaction') {
193 print "<td>".$txn->type."</td>";
194 } else {
195 print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'globe')." ".$txn->source."</a></td>\n";
196 }
197
198 // Stripe customer
199 //print "<td>".$charge->customer."</td>\n";
200 // Link
201 /*print "<td>";
202 if ($societestatic->id > 0) {
203 print $societestatic->getNomUrl(1);
204 }
205 if ($memberstatic->id > 0) {
206 print $memberstatic->getNomUrl(1);
207 }
208 print "</td>\n";*/
209 // Origine
210 //print "<td>";
212 // $object = new Commande($db);
213 // $object->fetch($charge->metadata->dol_id);
214 // print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->dol_id."'>".img_picto('', 'object_order')." ".$object->ref."</a>";
215 //} elseif ($charge->metadata->dol_type=="invoice"){
216 // $object = new Facture($db);
217 // $object->fetch($charge->metadata->dol_id);
218 // print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</a>";
219 //}
220 //print "</td>\n";
221 // Date payment
222 print '<td class="center">'.dol_print_date($txn->created, 'dayhour')."</td>\n";
223 // Type
224 print '<td>'.$txn->type.'</td>';
225 // Amount
226 print '<td class="right"><span class="amount">'.price(($txn->amount) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency))."</span></td>";
227 print '<td class="right"><span class="amount">'.price(($txn->fee) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency))."</span></td>";
228 // Status
229 print "<td class='right'>";
230 if ($txn->status == 'available') {
231 print img_picto($langs->trans($txn->status), 'statut4');
232 } elseif ($txn->status == 'pending') {
233 print img_picto($langs->trans($txn->status), 'statut7');
234 } elseif ($txn->status == 'failed') {
235 print img_picto($langs->trans($txn->status), 'statut8');
236 }
237 print '</td>';
238 print "</tr>\n";
239 }
240 } catch (Exception $e) {
241 print '<tr><td colspan="6">'.$e->getMessage().'</td></td>';
242 }
243 print "</table>";
244 print '</div>';
245 print '</form>';
246}
247
248// End of page
249llxFooter();
250$db->close();
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:71
Class to manage bank accounts.
Class to manage members of a foundation.
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
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.
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.