Enhance module stripe

This commit is contained in:
Laurent Destailleur 2017-05-14 05:26:19 +02:00
parent 169e63d49a
commit 9e4e72baee
7 changed files with 1276 additions and 309 deletions

View File

@ -11,6 +11,7 @@ YourEMail=Email to receive payment confirmation
Creditor=Creditor Creditor=Creditor
PaymentCode=Payment code PaymentCode=Payment code
PayBoxDoPayment=Go on payment PayBoxDoPayment=Go on payment
ToPay=Do payment
YouWillBeRedirectedOnPayBox=You will be redirected on secured Paybox page to input you credit card information YouWillBeRedirectedOnPayBox=You will be redirected on secured Paybox page to input you credit card information
Continue=Next Continue=Next
ToOfferALinkForOnlinePayment=URL for %s payment ToOfferALinkForOnlinePayment=URL for %s payment

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -24,7 +24,6 @@
* \file htdocs/public/payment/newpayment.php * \file htdocs/public/payment/newpayment.php
* \ingroup core * \ingroup core
* \brief File to offer a way to make a payment for a particular Dolibarr entity * \brief File to offer a way to make a payment for a particular Dolibarr entity
* \author Laurent Destailleur
*/ */
define("NOLOGIN",1); // This means this output page does not require to be logged. define("NOLOGIN",1); // This means this output page does not require to be logged.
@ -43,7 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
// Security check // Security check
//if (empty($conf->paypal->enabled)) accessforbidden('',0,0,1); // No check on module enabled. Done later according to $validpaymentmethod
$langs->load("main"); $langs->load("main");
$langs->load("other"); $langs->load("other");
@ -502,9 +501,12 @@ if (GETPOST("source") == 'order')
$result=$order->fetch_thirdparty($order->socid); $result=$order->fetch_thirdparty($order->socid);
} }
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$order->total_ttc; $amount=$order->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount); $amount=price2num($amount);
}
$fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id; $fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id;
//$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," "); //$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," ");
@ -609,9 +611,12 @@ if (GETPOST("source") == 'invoice')
$result=$invoice->fetch_thirdparty($invoice->socid); $result=$invoice->fetch_thirdparty($invoice->socid);
} }
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=price2num($invoice->total_ttc - $invoice->getSommePaiement()); $amount=price2num($invoice->total_ttc - $invoice->getSommePaiement());
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount); $amount=price2num($amount);
}
$fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id; $fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id;
//$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," "); //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," ");
@ -733,6 +738,8 @@ if (GETPOST("source") == 'contractline')
} }
} }
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$contractline->total_ttc; $amount=$contractline->total_ttc;
if ($contractline->fk_product) if ($contractline->fk_product)
{ {
@ -762,6 +769,7 @@ if (GETPOST("source") == 'contractline')
} }
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount); $amount=price2num($amount);
}
$fulltag='COL='.$contractline->ref.'.CON='.$contract->ref.'.CUS='.$contract->thirdparty->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); $fulltag='COL='.$contractline->ref.'.CON='.$contract->ref.'.CUS='.$contract->thirdparty->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M');
//$fulltag.='.NAM='.strtr($contract->thirdparty->name,"-"," "); //$fulltag.='.NAM='.strtr($contract->thirdparty->name,"-"," ");
@ -911,9 +919,12 @@ if (GETPOST("source") == 'membersubscription')
$subscription=new Subscription($db); $subscription=new Subscription($db);
} }
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$subscription->total_ttc; $amount=$subscription->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount); $amount=price2num($amount);
}
$fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); $fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M');
if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
@ -1035,6 +1046,8 @@ if ($mesg) print '<tr><td align="center" colspan="2"><br><div class="warning">'.
print '</table>'."\n"; print '</table>'."\n";
print "\n"; print "\n";
if ($action != 'dopayment')
{
if ($found && ! $error) // We are in a management option and no error if ($found && ! $error) // We are in a management option and no error
{ {
// Buttons for all payments registration methods // Buttons for all payments registration methods
@ -1053,7 +1066,7 @@ if ($found && ! $error) // We are in a management option and no error
} }
} }
if (! empty($conf->paypal->enabled)) if (! empty($conf->paybox->enabled))
{ {
@ -1065,6 +1078,11 @@ else
{ {
dol_print_error_email('ERRORNEWPAYMENTPAYPAL'); dol_print_error_email('ERRORNEWPAYMENTPAYPAL');
} }
}
else
{
// Print
}
print '</td></tr>'."\n"; print '</td></tr>'."\n";

View File

@ -418,9 +418,12 @@ if (GETPOST("source") == 'order')
$result=$order->fetch_thirdparty($order->socid); $result=$order->fetch_thirdparty($order->socid);
} }
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$order->total_ttc; $amount=$order->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount); $amount=price2num($amount);
}
$fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id; $fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id;
//$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," "); //$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," ");
@ -525,9 +528,12 @@ if (GETPOST("source") == 'invoice')
$result=$invoice->fetch_thirdparty($invoice->socid); $result=$invoice->fetch_thirdparty($invoice->socid);
} }
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=price2num($invoice->total_ttc - $invoice->getSommePaiement()); $amount=price2num($invoice->total_ttc - $invoice->getSommePaiement());
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount); $amount=price2num($amount);
}
$fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id; $fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id;
//$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," "); //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," ");
@ -649,6 +655,8 @@ if (GETPOST("source") == 'contractline')
} }
} }
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$contractline->total_ttc; $amount=$contractline->total_ttc;
if ($contractline->fk_product) if ($contractline->fk_product)
{ {
@ -678,6 +686,7 @@ if (GETPOST("source") == 'contractline')
} }
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount); $amount=price2num($amount);
}
$fulltag='COL='.$contractline->ref.'.CON='.$contract->ref.'.CUS='.$contract->thirdparty->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); $fulltag='COL='.$contractline->ref.'.CON='.$contract->ref.'.CUS='.$contract->thirdparty->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M');
//$fulltag.='.NAM='.strtr($contract->thirdparty->name,"-"," "); //$fulltag.='.NAM='.strtr($contract->thirdparty->name,"-"," ");
@ -827,9 +836,12 @@ if (GETPOST("source") == 'membersubscription')
$subscription=new Subscription($db); $subscription=new Subscription($db);
} }
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$subscription->total_ttc; $amount=$subscription->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int'); if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount); $amount=price2num($amount);
}
$fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M'); $fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M');
if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; } if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }

View File

@ -16,7 +16,7 @@
*/ */
/** /**
* \file htdocs/public/paybox/index.php * \file htdocs/public/stripe/index.php
* \ingroup core * \ingroup core
* \brief A redirect page to an error * \brief A redirect page to an error
* \author Laurent Destailleur * \author Laurent Destailleur

File diff suppressed because it is too large Load Diff

View File

@ -46,15 +46,15 @@ if ($action == 'setvalue' && $user->admin)
$db->begin(); $db->begin();
$result=dolibarr_set_const($db, "STRIPE_LIVE",GETPOST('STRIPE_LIVE','alpha'),'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "STRIPE_LIVE",GETPOST('STRIPE_LIVE','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY",GETPOST('STRIPE_TEST_SECRET_KEY','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++; if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY",GETPOST('STRIPE_TEST_PUBLISHABLE_KEY','alpha'),'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY",GETPOST('STRIPE_TEST_PUBLISHABLE_KEY','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++; if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY",GETPOST('STRIPE_LIVE_SECRET_KEY','alpha'),'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY",GETPOST('STRIPE_TEST_SECRET_KEY','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++; if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY",GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY','alpha'),'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY",GETPOST('STRIPE_LIVE_PUBLISHABLE_KEY','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++; if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "STRIPE_LIVE_SECRET_KEY",GETPOST('STRIPE_LIVE_SECRET_KEY','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "STRIPE_CREDITOR",GETPOST('STRIPE_CREDITOR','alpha'),'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "STRIPE_CREDITOR",GETPOST('STRIPE_CREDITOR','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++; if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "STRIPE_CSS_URL",GETPOST('STRIPE_CSS_URL','alpha'),'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "STRIPE_CSS_URL",GETPOST('STRIPE_CSS_URL','alpha'),'chaine',0,'',$conf->entity);
@ -97,15 +97,15 @@ if ($action=="setlive")
$form=new Form($db); $form=new Form($db);
$SECRET_TEST_KEY="sk_test_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe test secret key //$SECRET_TEST_KEY="sk_test_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe test secret key
if (empty($conf->global->STRIPE_TEST_SECRET_KEY)) $conf->global->STRIPE_TEST_SECRET_KEY = $SECRET_TEST_KEY; //if (empty($conf->global->STRIPE_TEST_SECRET_KEY)) $conf->global->STRIPE_TEST_SECRET_KEY = $SECRET_TEST_KEY;
$PUBLISHABLE_TEST_KEY="pk_test_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe test publishable key //$PUBLISHABLE_TEST_KEY="pk_test_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe test publishable key
if (empty($conf->global->STRIPE_TEST_PUBLISHABLE_KEY)) $conf->global->STRIPE_TEST_PUBLISHABLE_KEY = $PUBLISHABLE_TEST_KEY; //if (empty($conf->global->STRIPE_TEST_PUBLISHABLE_KEY)) $conf->global->STRIPE_TEST_PUBLISHABLE_KEY = $PUBLISHABLE_TEST_KEY;
$SECRET_LIVE_KEY="sk_live_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe live secret key //$SECRET_LIVE_KEY="sk_live_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe live secret key
if (empty($conf->global->STRIPE_LIVE_SECRET_KEY)) $conf->global->STRIPE_LIVE_SECRET_KEY = $SECRET_LIVE_KEY; //if (empty($conf->global->STRIPE_LIVE_SECRET_KEY)) $conf->global->STRIPE_LIVE_SECRET_KEY = $SECRET_LIVE_KEY;
$PUBLISHABLE_LIVE_KEY="pk_live_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe live publishable key //$PUBLISHABLE_LIVE_KEY="pk_live_xxxxxxxxxxxxxxxxxxxxxxxx"; // Stripe live publishable key
if (empty($conf->global->STRIPE_LIVE_PUBLISHABLE_KEY)) $conf->global->STRIPE_LIVE_PUBLISHABLE_KEY = $PUBLISHABLE_LIVE_KEY; //if (empty($conf->global->STRIPE_LIVE_PUBLISHABLE_KEY)) $conf->global->STRIPE_LIVE_PUBLISHABLE_KEY = $PUBLISHABLE_LIVE_KEY;
llxHeader('',$langs->trans("StripeSetup")); llxHeader('',$langs->trans("StripeSetup"));
@ -145,30 +145,30 @@ else
} }
print '</td></tr>'; print '</td></tr>';
print '<tr class="oddeven"><td>';
print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
print '<input size="32" type="text" name="STRIPE_TEST_SECRET_KEY" value="'.$conf->global->STRIPE_TEST_SECRET_KEY.'">';
print '<br>'.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
print '</td></tr>';
print '<tr class="oddeven"><td>'; print '<tr class="oddeven"><td>';
print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>'; print '<span class="fieldrequired">'.$langs->trans("STRIPE_TEST_PUBLISHABLE_KEY").'</span></td><td>';
print '<input size="32" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY.'">'; print '<input class="minwidth300" type="text" name="STRIPE_TEST_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_TEST_PUBLISHABLE_KEY.'">';
print '<br>'.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx'; print '<br>'.$langs->trans("Example").': pk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
print '</td></tr>'; print '</td></tr>';
print '<tr class="oddeven"><td>'; print '<tr class="oddeven"><td>';
print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>'; print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
print '<input size="32" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.$conf->global->STRIPE_LIVE_SECRET_KEY.'">'; print '<input class="minwidth300" type="text" name="STRIPE_TEST_SECRET_KEY" value="'.$conf->global->STRIPE_TEST_SECRET_KEY.'">';
print '<br>'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx'; print '<br>'.$langs->trans("Example").': sk_test_xxxxxxxxxxxxxxxxxxxxxxxx';
print '</td></tr>'; print '</td></tr>';
print '<tr class="oddeven"><td>'; print '<tr class="oddeven"><td>';
print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>'; print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_PUBLISHABLE_KEY").'</span></td><td>';
print '<input size="32" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY.'">'; print '<input class="minwidth300" type="text" name="STRIPE_LIVE_PUBLISHABLE_KEY" value="'.$conf->global->STRIPE_LIVE_PUBLISHABLE_KEY.'">';
print '<br>'.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx'; print '<br>'.$langs->trans("Example").': pk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
print '</td></tr>'; print '</td></tr>';
print '<tr class="oddeven"><td>';
print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
print '<input class="minwidth300" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.$conf->global->STRIPE_LIVE_SECRET_KEY.'">';
print '<br>'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
print '</td></tr>';
print '</table>'; print '</table>';
print '<br>'; print '<br>';

View File

@ -17,17 +17,18 @@
*/ */
/** /**
* \file stripe/config.php * \file htdocs/public/stripe/config.php
* \ingroup Stripe * \ingroup Stripe
* \brief Page to move config in api * \brief Page to move config in api
*/ */
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.lib.php'; require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.lib.php';
require_once DOL_DOCUMENT_ROOT.'/includes/stripe/init.php'; require_once DOL_DOCUMENT_ROOT.'/includes/stripe/init.php';
global $stripe;
global $conf;
//use \includes\stripe as stripe; //use \includes\stripe as stripe;
$stripe = array(); $stripe = array();
@ -46,4 +47,7 @@ else
); );
} }
\includes\stripe::setApiKey($stripe['secret_key']); require_once DOL_DOCUMENT_ROOT."/includes/stripe/lib/Stripe.php";
require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
\Stripe\Stripe::setApiKey($stripe['secret_key']);