dolibarr/htdocs/stripe/transaction.php

236 lines
8.6 KiB
PHP
Raw Normal View History

2018-03-05 20:01:55 +01:00
<?php
2018-09-21 09:52:27 +02:00
/* Copyright (C) 2018 Thibault FOUCART <support@ptibogxiv.net>
2018-09-21 09:52:08 +02:00
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
2018-03-05 20:01:55 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Put here all includes required by your class file
require '../main.inc.php';
2018-04-06 14:19:11 +02:00
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
2018-03-05 20:01:55 +01:00
require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
//require_once DOL_DOCUMENT_ROOT.'/core/lib/stripe.lib.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
2018-09-21 09:49:13 +02:00
if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php';
2018-03-05 20:01:55 +01:00
2018-05-26 16:35:29 +02:00
// Load translation files required by the page
$langs->loadLangs(array('compta', 'salaries', 'bills', 'hrm', 'stripe'));
2018-03-05 20:01:55 +01:00
// Security check
$socid = GETPOST("socid","int");
if ($user->societe_id) $socid=$user->societe_id;
//$result = restrictedArea($user, 'salaries', '', '', '');
2018-04-21 12:16:12 +02:00
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
2018-03-05 20:01:55 +01:00
$rowid = GETPOST("rowid",'alpha');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int');
if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
2018-04-06 14:19:11 +02:00
/*
* View
*/
2018-04-06 14:19:11 +02:00
2018-03-05 20:01:55 +01:00
$form = new Form($db);
2018-04-06 14:19:11 +02:00
$societestatic = new Societe($db);
$memberstatic = new Adherent($db);
2018-03-05 20:01:55 +01:00
$acc = new Account($db);
$stripe = new Stripe($db);
2018-04-06 14:19:11 +02:00
llxHeader('', $langs->trans("StripeTransactionList"));
if (! empty($conf->stripe->enabled) && (empty($conf->global->STRIPE_LIVE) || GETPOST('forcesandbox','alpha')))
2018-03-05 20:01:55 +01:00
{
$service = 'StripeTest';
2018-09-21 09:49:13 +02:00
$servicestatus = '0';
dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode', 'Stripe'), '', 'warning');
}
else
{
2018-09-19 18:59:32 +02:00
$service = 'StripeLive';
2018-09-21 09:49:13 +02:00
$servicestatus = '1';
2018-03-05 20:01:55 +01:00
}
2018-09-21 09:49:13 +02:00
$stripeacc = $stripe->getStripeAccount($service);
2018-04-06 14:19:11 +02:00
/*if (empty($stripeaccount))
{
print $langs->trans('ErrorStripeAccountNotDefined');
2018-04-06 14:19:11 +02:00
}*/
2018-04-06 14:05:07 +02:00
if (! $rowid) {
2018-09-16 23:13:24 +02:00
print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">';
2018-09-21 09:49:13 +02:00
if ($optioncss != '')
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
2018-09-16 23:13:24 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
print '<input type="hidden" name="page" value="' . $page . '">';
2018-04-06 14:05:07 +02:00
$title=$langs->trans("StripeTransactionList");
2018-09-21 09:49:13 +02:00
$title.=($stripeaccount?' (Stripe connection with Stripe OAuth Connect account '.$stripeacc.')':' (Stripe connection with keys from Stripe module setup)');
2018-04-06 14:05:07 +02:00
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit);
2018-09-16 23:13:24 +02:00
print '<div class="div-table-responsive">';
print '<table class="tagtable liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
2018-09-16 23:13:24 +02:00
print '<tr class="liste_titre">';
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
2018-04-06 14:19:11 +02:00
//print_liste_field_titre("StripeCustomerId",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
//print_liste_field_titre("CustomerId", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
//print_liste_field_titre("Origin", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "", "", "", 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "", "", "", 'align="left"', $sortfield, $sortorder);
print_liste_field_titre("Paid", $_SERVER["PHP_SELF"], "", "", "", 'align="right"', $sortfield, $sortorder);
print_liste_field_titre("Fee", $_SERVER["PHP_SELF"], "", "", "", 'align="right"', $sortfield, $sortorder);
2018-04-06 14:19:11 +02:00
print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "", "", "", 'align="right"');
2018-09-16 23:13:24 +02:00
print "</tr>\n";
2018-09-16 23:13:24 +02:00
print "</tr>\n";
2018-09-21 09:49:13 +02:00
if ($stripeacc)
2018-04-06 14:05:07 +02:00
{
2018-09-21 09:49:13 +02:00
$txn = \Stripe\BalanceTransaction::all(array("limit" => $limit), array("stripe_account" => $stripeacc));
2018-04-06 14:05:07 +02:00
}
else
{
$txn = \Stripe\BalanceTransaction::all(array("limit" => $limit));
}
2018-09-16 23:13:24 +02:00
foreach ($txn->data as $txn)
2018-04-06 14:19:11 +02:00
{
2018-09-19 18:59:32 +02:00
//$charge = $txn;
//var_dump($txn);
2018-09-21 09:54:07 +02:00
2018-09-19 18:59:32 +02:00
// The metadata FULLTAG is defined by the online payment page
/*$FULLTAG=$charge->metadata->FULLTAG;
2018-09-21 09:54:07 +02:00
2018-09-19 18:59:32 +02:00
// Save into $tmparray all metadata
$tmparray = dolExplodeIntoArray($FULLTAG,'.','=');
// Load origin object according to metadata
if (! empty($tmparray['CUS']))
{
$societestatic->fetch($tmparray['CUS']);
}
else
{
$societestatic->id = 0;
}
if (! empty($tmparray['MEM']))
{
$memberstatic->fetch($tmparray['MEM']);
}
else
{
$memberstatic->id = 0;
}*/
2018-09-21 09:54:07 +02:00
$societestatic->fetch($charge->metadata->idcustomer);
$societestatic->id = $charge->metadata->idcustomer;
$societestatic->lastname = $obj->lastname;
$societestatic->firstname = $obj->firstname;
$societestatic->admin = $obj->admin;
$societestatic->login = $obj->login;
$societestatic->email = $obj->email;
$societestatic->societe_id = $obj->fk_soc;
2018-09-16 23:13:24 +02:00
print '<tr class="oddeven">';
2018-09-21 14:52:06 +02:00
2018-09-21 09:49:13 +02:00
// Ref
2018-09-21 12:19:59 +02:00
if (!empty($stripeacc)) $connect=$stripeacc.'/';
2018-09-21 09:49:13 +02:00
2018-09-16 22:39:38 +02:00
// Ref
2018-09-21 12:19:59 +02:00
if (preg_match('/po_/i', $txn->source)){
$origin="payouts";
} elseif (preg_match('/fee_/i', $txn->source)) {
$origin="connect/application_fees";
} else {
$origin="payments";
}
2018-09-21 09:54:07 +02:00
2018-09-19 19:05:46 +02:00
$url='https://dashboard.stripe.com/'.$connect.'test/'.$origin.'/'.$txn->source;
2018-09-22 10:20:02 +02:00
if ($servicestatus) {
2018-09-21 12:19:59 +02:00
$url='https://dashboard.stripe.com/'.$connect.$origin.'/'.$txn->source;
}
if ($txn->type == 'stripe_fee' || $txn->type == 'reserve_transaction') {
print "<td>".$txn->type."</td>";
} else {
print "<td><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'object_globe')." " . $txn->source . "</a></td>\n";
}
2018-09-21 09:49:13 +02:00
2018-09-19 18:59:32 +02:00
// Stripe customer
//print "<td>".$charge->customer."</td>\n";
// Link
/*print "<td>";
if ($societestatic->id > 0)
{
print $societestatic->getNomUrl(1);
}
if ($memberstatic->id > 0)
{
print $memberstatic->getNomUrl(1);
}
print "</td>\n";*/
// Origine
//print "<td>";
////if ($charge->metadata->dol_type=="order"){
// $object = new Commande($db);
// $object->fetch($charge->metadata->dol_id);
2018-09-21 09:49:13 +02:00
// print "<a href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->dol_id."'>".img_picto('', 'object_order')." ".$object->ref."</a>";
2018-09-19 18:59:32 +02:00
//} elseif ($charge->metadata->dol_type=="invoice"){
// $object = new Facture($db);
// $object->fetch($charge->metadata->dol_id);
2018-09-21 09:49:13 +02:00
// print "<a href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</a>";
2018-09-19 18:59:32 +02:00
//}
//print "</td>\n";
2018-03-05 20:01:55 +01:00
// Date payment
2018-09-13 13:57:01 +02:00
print '<td align="center">' . dol_print_date($txn->created, '%d/%m/%Y %H:%M') . "</td>\n";
// Type
2018-09-13 13:57:01 +02:00
print '<td>' . $txn->type . '</td>';
// Amount
print "<td align=\"right\">" . price(($txn->amount) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency)) . "</td>";
print "<td align=\"right\">" . price(($txn->fee) / 100, 0, '', 1, - 1, - 1, strtoupper($txn->currency)) . "</td>";
2018-04-06 14:19:11 +02:00
// Status
2018-09-13 13:57:01 +02:00
print "<td align='right'>";
2018-09-21 09:55:24 +02:00
if ($txn->status=='available')
2018-09-21 12:19:59 +02:00
{print img_picto($langs->trans("".$txn->status.""),'statut4');}
2018-09-21 09:55:24 +02:00
elseif ($txn->status=='pending')
{print img_picto($langs->trans("".$txn->status.""),'statut7');}
elseif ($txn->status=='failed')
2018-09-21 12:19:59 +02:00
{print img_picto($langs->trans("".$txn->status.""),'statut8');}
2018-09-13 13:57:01 +02:00
print '</td>';
print "</tr>\n";
}
2018-09-13 13:57:01 +02:00
print "</table>";
print '</div>';
print '</form>';
2018-09-21 09:52:27 +02:00
}
2018-03-05 20:01:55 +01:00
2018-09-21 09:54:07 +02:00
// End of page
2018-03-05 20:01:55 +01:00
llxFooter();
$db->close();