Debug last stripe PR

This commit is contained in:
Laurent Destailleur 2018-03-07 15:05:49 +01:00
parent e242dbad88
commit 1419eaf15f
4 changed files with 157 additions and 128 deletions

View File

@ -175,14 +175,21 @@ function societe_prepare_head(Societe $object)
$h++; $h++;
} }
// Bank accounrs // Bank accounts
if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT)) if (empty($conf->global->SOCIETE_DISABLE_BANKACCOUNT))
{ {
$langs->load("banks"); $langs->load("banks");
$title = $langs->trans("BankAccounts");
if (! empty($conf->stripe->enabled))
{
$langs->load("stripe");
$title = $langs->trans("BankAccountsAndGateways");
}
$nbBankAccount=0; $nbBankAccount=0;
$head[$h][0] = DOL_URL_ROOT .'/societe/gateway.php?socid='.$object->id; $head[$h][0] = DOL_URL_ROOT .'/societe/paymentmodes.php?socid='.$object->id;
$head[$h][1] = $langs->trans("Gateways"); $head[$h][1] = $title;
$sql = "SELECT COUNT(n.rowid) as nb"; $sql = "SELECT COUNT(n.rowid) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib as n"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib as n";
$sql.= " WHERE fk_soc = ".$object->id; $sql.= " WHERE fk_soc = ".$object->id;

View File

@ -7,6 +7,7 @@ BankName=Bank name
FinancialAccount=Account FinancialAccount=Account
BankAccount=Bank account BankAccount=Bank account
BankAccounts=Bank accounts BankAccounts=Bank accounts
BankAccountsAndGateways=Bank accounts | Gateways
ShowAccount=Show Account ShowAccount=Show Account
AccountRef=Financial account ref AccountRef=Financial account ref
AccountLabel=Financial account label AccountLabel=Financial account label

View File

@ -43,3 +43,4 @@ ONLINE_PAYMENT_WAREHOUSE=Stock to use for stock decrease when payment online pay
StripeLiveEnabled=Stripe live enabled (otherwise test/sandbox mode) StripeLiveEnabled=Stripe live enabled (otherwise test/sandbox mode)
StripeImportPayment=Import Stripe payments StripeImportPayment=Import Stripe payments
ExampleOfTestCreditCard=Example of credit card for test: %s (valid), %s (error CVC), %s (expired), %s (charge fails) ExampleOfTestCreditCard=Example of credit card for test: %s (valid), %s (error CVC), %s (expired), %s (charge fails)
StripeGateways=Stripe gateways

View File

@ -33,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; //require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php';
$langs->load("companies"); $langs->load("companies");
$langs->load("commercial"); $langs->load("commercial");
@ -331,25 +331,28 @@ if (empty($reshook))
$id = $savid; $id = $savid;
} }
$stripeconnect=new StripeConnexion($db); if (class_exists('StripeConnexion'))
$customer=$stripeconnect->CustomerStripe($socid,$stripeconnect->GetStripeAccount($conf->entity));
if ($customer->id) {
$cu = \Stripe\Customer::retrieve("".$customer->id."",array("stripe_account" => $stripeconnect->GetStripeAccount($conf->entity)));}
$url=DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id;
if ($action == 'setasdefault')
{ {
$cu->default_source = "$source"; // obtained with Stripe.js $stripeconnect=new StripeConnexion($db);
$cu->save(); $customerstripe=$stripeconnect->CustomerStripe($socid,$stripeconnect->GetStripeAccount($conf->entity));
if ($customerstripe->id) {
$cu = \Stripe\Customer::retrieve("".$customerstripe->id."",array("stripe_account" => $stripeconnect->GetStripeAccount($conf->entity)));}
$url=DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id;
if ($action == 'setasdefault')
{
$cu->default_source = "$source"; // obtained with Stripe.js
$cu->save();
header('Location: '.$url); header('Location: '.$url);
exit; exit;
} }
elseif ($action == 'delete') elseif ($action == 'delete')
{ {
$cu->sources->retrieve("$source")->delete(); $cu->sources->retrieve("$source")->delete();
header('Location: '.$url); header('Location: '.$url);
exit; exit;
}
} }
@ -403,55 +406,66 @@ if ($socid && $action != 'edit' && $action != "create")
dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom');
if (! (empty($conf->stripe->enabled))){
print '<tr><td class="titlefield">';
print $langs->trans('StripeGateways').'</td><td colspan="3">';
if ($stripeconnect->GetStripeAccount($conf->entity)) {
$customer=$stripeconnect->CustomerStripe($object->id,$stripeconnect->GetStripeAccount($conf->entity));
}
if ($customer->id) { if (! (empty($conf->stripe->enabled)))
$input=$customer->sources->data; {
} print load_fiche_titre($langs->trans('StripeGateways'), '', '');
print '<table class="liste" width="100%">'."\n";
print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans('Type').'</td>';
print '<td align="left">'.$langs->trans('Informations').'</td>';
print '<td align="left"></td>';
print '<td align="center">'.$langs->trans('Default').'</td>';
print "<td></td></tr>\n";
foreach ($input as $src) { if (is_object($stripeconnect) && $stripeconnect->GetStripeAccount($conf->entity))
print '<tr>'; {
print '<td>'; $customerstripe=$stripeconnect->CustomerStripe($object->id,$stripeconnect->GetStripeAccount($conf->entity));
if ($src->object=='card'){ }
if ($src->brand == 'Visa') {$brand='cc-visa';}
elseif ($src->brand == 'MasterCard') {$brand='cc-mastercard';}
elseif ($src->brand == 'American Express') {$brand='cc-amex';}
elseif ($src->brand == 'Discover') {$brand='cc-discover';}
elseif ($src->brand == 'JCB') {$brand='cc-jcb';}
elseif ($src->brand == 'Diners Club') {$brand='cc-diners-club';}
else {$brand='credit-card';}
print '<span class="fa fa-'.$brand.' fa-3x fa-fw"></span>';
}
elseif ($src->object=='source' && $src->type=='card'){
if ($src->card->brand == 'Visa') {$brand='cc-visa';}
elseif ($src->card->brand == 'MasterCard') {$brand='cc-mastercard';}
elseif ($src->card->brand == 'American Express') {$brand='cc-amex';}
elseif ($src->card->brand == 'Discover') {$brand='cc-discover';}
elseif ($src->card->brand == 'JCB') {$brand='cc-jcb';}
elseif ($src->card->brand == 'Diners Club') {$brand='cc-diners-club';}
else {$brand='credit-card';}
print '<span class="fa fa-'.$brand.' fa-3x fa-fw"></span>'; if ($customerstripe->id) {
} $input=$customerstripe->sources->data;
elseif ($src->object=='source' && $src->type=='sepa_debit'){ }
print '<span class="fa fa-university fa-3x fa-fw"></span>';
} print '<table class="liste" width="100%">'."\n";
print'</td><td valign="middle">'; print '<tr class="liste_titre">';
if ($src->object=='card'){ print '<td align="left">'.$langs->trans('Type').'</td>';
print '**** '.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.''; print '<td align="left">'.$langs->trans('Informations').'</td>';
print '</td><td>'; print '<td align="left"></td>';
print '<td align="center">'.$langs->trans('Default').'</td>';
print "<td></td></tr>\n";
if (is_array($input))
{
foreach ($input as $src)
{
print '<tr>';
print '<td>';
if ($src->object=='card')
{
if ($src->brand == 'Visa') {$brand='cc-visa';}
elseif ($src->brand == 'MasterCard') {$brand='cc-mastercard';}
elseif ($src->brand == 'American Express') {$brand='cc-amex';}
elseif ($src->brand == 'Discover') {$brand='cc-discover';}
elseif ($src->brand == 'JCB') {$brand='cc-jcb';}
elseif ($src->brand == 'Diners Club') {$brand='cc-diners-club';}
else {$brand='credit-card';}
print '<span class="fa fa-'.$brand.' fa-3x fa-fw"></span>';
}
elseif ($src->object=='source' && $src->type=='card')
{
if ($src->card->brand == 'Visa') {$brand='cc-visa';}
elseif ($src->card->brand == 'MasterCard') {$brand='cc-mastercard';}
elseif ($src->card->brand == 'American Express') {$brand='cc-amex';}
elseif ($src->card->brand == 'Discover') {$brand='cc-discover';}
elseif ($src->card->brand == 'JCB') {$brand='cc-jcb';}
elseif ($src->card->brand == 'Diners Club') {$brand='cc-diners-club';}
else {$brand='credit-card';}
print '<span class="fa fa-'.$brand.' fa-3x fa-fw"></span>';
}
elseif ($src->object=='source' && $src->type=='sepa_debit')
{
print '<span class="fa fa-university fa-3x fa-fw"></span>';
}
print'</td><td valign="middle">';
if ($src->object=='card')
{
print '**** '.$src->last4.' - '.$src->exp_month.'/'.$src->exp_year.'';
print '</td><td>';
if ($src->country) if ($src->country)
{ {
$img=picto_from_langcode($src->country); $img=picto_from_langcode($src->country);
@ -459,10 +473,12 @@ print '</td><td>';
print getCountry($src->country,1); print getCountry($src->country,1);
} }
else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>'; else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
} }
elseif ($src->object=='source' && $src->type=='card'){ elseif ($src->object=='source' && $src->type=='card')
print $src->owner->name.'<br>**** '.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.''; {
print '</td><td>'; print $src->owner->name.'<br>**** '.$src->card->last4.' - '.$src->card->exp_month.'/'.$src->card->exp_year.'';
print '</td><td>';
if ($src->card->country) if ($src->card->country)
{ {
$img=picto_from_langcode($src->card->country); $img=picto_from_langcode($src->card->country);
@ -470,10 +486,11 @@ print '</td><td>';
print getCountry($src->card->country,1); print getCountry($src->card->country,1);
} }
else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>'; else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
} }
elseif ($src->object=='source' && $src->type=='sepa_debit'){ elseif ($src->object=='source' && $src->type=='sepa_debit')
print 'info sepa'; {
print '</td><td>'; print 'info sepa';
print '</td><td>';
if ($src->sepa_debit->country) if ($src->sepa_debit->country)
{ {
$img=picto_from_langcode($src->sepa_debit->country); $img=picto_from_langcode($src->sepa_debit->country);
@ -481,11 +498,12 @@ print '</td><td>';
print getCountry($src->sepa_debit->country,1); print getCountry($src->sepa_debit->country,1);
} }
else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>'; else print img_warning().' <font class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("CompanyCountry")).'</font>';
} }
print '</td>'; print '</td>';
// Default // Default
print '<td align="center" width="50">'; print '<td align="center" width="50">';
if (($cu->default_source!=$src->id)) { if (($cu->default_source!=$src->id))
{
print '<a href="' . DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id.'&source='.$src->id.'&action=setasdefault">'; print '<a href="' . DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id.'&source='.$src->id.'&action=setasdefault">';
print "<SPAN class='fa fa-circle fa-2x'></SPAN>"; print "<SPAN class='fa fa-circle fa-2x'></SPAN>";
print '</a>'; print '</a>';
@ -493,25 +511,27 @@ print '</td>';
print "<SPAN class=' fa fa-check-circle fa-2x'></SPAN>"; print "<SPAN class=' fa fa-check-circle fa-2x'></SPAN>";
} }
print '</td>'; print '</td>';
print '<td align="center">'; print '<td align="center">';
if ($user->rights->societe->creer) if ($user->rights->societe->creer)
{ {
// print '<a href="' . DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id.'&id='.$src->id.'&action=edit">'; // print '<a href="' . DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id.'&id='.$src->id.'&action=edit">';
// print img_picto($langs->trans("Modify"),'edit'); // print img_picto($langs->trans("Modify"),'edit');
// print '</a>'; // print '</a>';
// print '&nbsp;'; // print '&nbsp;';
print '<a href="' . DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id.'&source='.$src->id.'&action=delete">'; print '<a href="' . DOL_URL_ROOT.'/societe/gateway.php?socid='.$object->id.'&source='.$src->id.'&action=delete">';
print "<SPAN class='fa fa-trash fa-2x'></SPAN>"; print "<SPAN class='fa fa-trash fa-2x'></SPAN>";
print '</a>'; print '</a>';
} }
print '</td></tr>'; print '</td></tr>';
} }
if (empty($input)) }
{ if (empty($input))
print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("NoSource").'</td></tr>'; {
} print '<tr><td class="opacitymedium" colspan="5">'.$langs->trans("NoSource").'</td></tr>';
print "</table>"; }
} print "</table>";
}
// List of bank accounts // List of bank accounts