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
PaymentCode=Payment code
PayBoxDoPayment=Go on payment
ToPay=Do payment
YouWillBeRedirectedOnPayBox=You will be redirected on secured Paybox page to input you credit card information
Continue=Next
ToOfferALinkForOnlinePayment=URL for %s payment

View File

@ -1,6 +1,6 @@
<?php
/* 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>
*
* This program is free software; you can redistribute it and/or modify
@ -24,7 +24,6 @@
* \file htdocs/public/payment/newpayment.php
* \ingroup core
* \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.
@ -43,7 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
// 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("other");
@ -502,10 +501,13 @@ if (GETPOST("source") == 'order')
$result=$order->fetch_thirdparty($order->socid);
}
$amount=$order->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$order->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
}
$fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id;
//$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," ");
if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
@ -609,10 +611,13 @@ if (GETPOST("source") == 'invoice')
$result=$invoice->fetch_thirdparty($invoice->socid);
}
$amount=price2num($invoice->total_ttc - $invoice->getSommePaiement());
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=price2num($invoice->total_ttc - $invoice->getSommePaiement());
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
}
$fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id;
//$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," ");
if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
@ -733,35 +738,38 @@ if (GETPOST("source") == 'contractline')
}
}
$amount=$contractline->total_ttc;
if ($contractline->fk_product)
{
$product=new Product($db);
$result=$product->fetch($contractline->fk_product);
// We define price for product (TODO Put this in a method in product class)
if (! empty($conf->global->PRODUIT_MULTIPRICES))
{
$pu_ht = $product->multiprices[$contract->thirdparty->price_level];
$pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level];
$price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level];
}
else
{
$pu_ht = $product->price;
$pu_ttc = $product->price_ttc;
$price_base_type = $product->price_base_type;
}
$amount=$pu_ttc;
if (empty($amount))
{
dol_print_error('','ErrorNoPriceDefinedForThisProduct');
exit;
}
}
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$contractline->total_ttc;
if ($contractline->fk_product)
{
$product=new Product($db);
$result=$product->fetch($contractline->fk_product);
// We define price for product (TODO Put this in a method in product class)
if (! empty($conf->global->PRODUIT_MULTIPRICES))
{
$pu_ht = $product->multiprices[$contract->thirdparty->price_level];
$pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level];
$price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level];
}
else
{
$pu_ht = $product->price;
$pu_ttc = $product->price_ttc;
$price_base_type = $product->price_base_type;
}
$amount=$pu_ttc;
if (empty($amount))
{
dol_print_error('','ErrorNoPriceDefinedForThisProduct');
exit;
}
}
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$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.='.NAM='.strtr($contract->thirdparty->name,"-"," ");
@ -911,10 +919,13 @@ if (GETPOST("source") == 'membersubscription')
$subscription=new Subscription($db);
}
$amount=$subscription->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$subscription->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
}
$fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M');
if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
$fulltag=dol_string_unaccent($fulltag);
@ -1035,35 +1046,42 @@ if ($mesg) print '<tr><td align="center" colspan="2"><br><div class="warning">'.
print '</table>'."\n";
print "\n";
if ($found && ! $error) // We are in a management option and no error
if ($action != 'dopayment')
{
// Buttons for all payments registration methods
if (! empty($conf->paypal->enabled))
if ($found && ! $error) // We are in a management option and no error
{
if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral')
{
print '<br><input class="button" type="submit" name="dopayment_paypal" value="'.$langs->trans("PaypalOrCBDoPayment").'">';
}
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
{
print '<br><input class="button" type="submit" name="dopayment_paypal" value="'.$langs->trans("PaypalDoPayment").'">';
}
}
if (! empty($conf->paypal->enabled))
{
// Buttons for all payments registration methods
}
if (! empty($conf->paypal->enabled))
{
if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral')
{
print '<br><input class="button" type="submit" name="dopayment_paypal" value="'.$langs->trans("PaypalOrCBDoPayment").'">';
}
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
{
print '<br><input class="button" type="submit" name="dopayment_paypal" value="'.$langs->trans("PaypalDoPayment").'">';
}
}
// TODO Other methods
if (! empty($conf->paybox->enabled))
{
}
// TODO Other methods
}
else
{
dol_print_error_email('ERRORNEWPAYMENTPAYPAL');
}
}
else
{
dol_print_error_email('ERRORNEWPAYMENTPAYPAL');
// Print
}
print '</td></tr>'."\n";

View File

@ -418,10 +418,13 @@ if (GETPOST("source") == 'order')
$result=$order->fetch_thirdparty($order->socid);
}
$amount=$order->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$order->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
}
$fulltag='ORD='.$order->ref.'.CUS='.$order->thirdparty->id;
//$fulltag.='.NAM='.strtr($order->thirdparty->name,"-"," ");
if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
@ -525,10 +528,13 @@ if (GETPOST("source") == 'invoice')
$result=$invoice->fetch_thirdparty($invoice->socid);
}
$amount=price2num($invoice->total_ttc - $invoice->getSommePaiement());
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=price2num($invoice->total_ttc - $invoice->getSommePaiement());
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
}
$fulltag='INV='.$invoice->ref.'.CUS='.$invoice->thirdparty->id;
//$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," ");
if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
@ -649,35 +655,38 @@ if (GETPOST("source") == 'contractline')
}
}
$amount=$contractline->total_ttc;
if ($contractline->fk_product)
{
$product=new Product($db);
$result=$product->fetch($contractline->fk_product);
// We define price for product (TODO Put this in a method in product class)
if (! empty($conf->global->PRODUIT_MULTIPRICES))
{
$pu_ht = $product->multiprices[$contract->thirdparty->price_level];
$pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level];
$price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level];
}
else
{
$pu_ht = $product->price;
$pu_ttc = $product->price_ttc;
$price_base_type = $product->price_base_type;
}
$amount=$pu_ttc;
if (empty($amount))
{
dol_print_error('','ErrorNoPriceDefinedForThisProduct');
exit;
}
}
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$contractline->total_ttc;
if ($contractline->fk_product)
{
$product=new Product($db);
$result=$product->fetch($contractline->fk_product);
// We define price for product (TODO Put this in a method in product class)
if (! empty($conf->global->PRODUIT_MULTIPRICES))
{
$pu_ht = $product->multiprices[$contract->thirdparty->price_level];
$pu_ttc = $product->multiprices_ttc[$contract->thirdparty->price_level];
$price_base_type = $product->multiprices_base_type[$contract->thirdparty->price_level];
}
else
{
$pu_ht = $product->price;
$pu_ttc = $product->price_ttc;
$price_base_type = $product->price_base_type;
}
$amount=$pu_ttc;
if (empty($amount))
{
dol_print_error('','ErrorNoPriceDefinedForThisProduct');
exit;
}
}
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$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.='.NAM='.strtr($contract->thirdparty->name,"-"," ");
@ -827,10 +836,13 @@ if (GETPOST("source") == 'membersubscription')
$subscription=new Subscription($db);
}
$amount=$subscription->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
if ($action != 'dopayment') // Do not change amount if we just click on first dopayment
{
$amount=$subscription->total_ttc;
if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
$amount=price2num($amount);
}
$fulltag='MEM='.$member->id.'.DAT='.dol_print_date(dol_now(),'%Y%m%d%H%M');
if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
$fulltag=dol_string_unaccent($fulltag);

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -47,15 +47,15 @@ if ($action == 'setvalue' && $user->admin)
$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++;
$result=dolibarr_set_const($db, "STRIPE_TEST_PUBLISHABLE_KEY",GETPOST('STRIPE_TEST_PUBLISHABLE_KEY','alpha'),'chaine',0,'',$conf->entity);
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++;
$result=dolibarr_set_const($db, "STRIPE_LIVE_PUBLISHABLE_KEY",GETPOST('STRIPE_LIVE_PUBLISHABLE_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_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);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "STRIPE_CSS_URL",GETPOST('STRIPE_CSS_URL','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
@ -97,15 +97,15 @@ if ($action=="setlive")
$form=new Form($db);
$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;
$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;
//$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;
//$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;
$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;
$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;
//$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;
//$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;
llxHeader('',$langs->trans("StripeSetup"));
@ -145,30 +145,30 @@ else
}
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 '<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 '</td></tr>';
print '<tr class="oddeven"><td>';
print '<span class="fieldrequired">'.$langs->trans("STRIPE_LIVE_SECRET_KEY").'</span></td><td>';
print '<input size="32" type="text" name="STRIPE_LIVE_SECRET_KEY" value="'.$conf->global->STRIPE_LIVE_SECRET_KEY.'">';
print '<br>'.$langs->trans("Example").': sk_live_xxxxxxxxxxxxxxxxxxxxxxxx';
print '<span class="titlefield fieldrequired">'.$langs->trans("STRIPE_TEST_SECRET_KEY").'</span></td><td>';
print '<input class="minwidth300" 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 '<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 '</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 '<br>';

View File

@ -17,21 +17,22 @@
*/
/**
* \file stripe/config.php
* \file htdocs/public/stripe/config.php
* \ingroup Stripe
* \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.'/stripe/lib/stripe.lib.php';
require_once DOL_DOCUMENT_ROOT.'/includes/stripe/init.php';
global $stripe;
global $conf;
//use \includes\stripe as stripe;
$stripe = array();
if(empty($conf->global->SKYPE_LIVE))
if (empty($conf->global->SKYPE_LIVE))
{
$stripe = array(
"secret_key" => $conf->global->STRIPE_TEST_SECRET_KEY,
@ -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']);