diff --git a/htdocs/langs/en_US/paybox.lang b/htdocs/langs/en_US/paybox.lang
index c0a55888e7c4ffad1ae691ad8fa8c3fcb0ab2005..91fe071627c000f8a6b7958b1510afd8b8af8f8d 100644
--- a/htdocs/langs/en_US/paybox.lang
+++ b/htdocs/langs/en_US/paybox.lang
@@ -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
diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php
index 1ea8e7385eafc8773aaedfe92256516143da2b51..744f477782e2b0cb3f225d7a48fc9385aaf673ae 100644
--- a/htdocs/public/payment/newpayment.php
+++ b/htdocs/public/payment/newpayment.php
@@ -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';
+        // 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").'">';
+        	}
+        }
     
-    	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->paybox->enabled))
+        {
+        
+            
+        }
+        
+        // TODO Other methods
     }
-
-    if (! empty($conf->paypal->enabled))
+    else
     {
-    
-        
+    	dol_print_error_email('ERRORNEWPAYMENTPAYPAL');
     }
-    
-    // TODO Other methods
 }
 else
 {
-	dol_print_error_email('ERRORNEWPAYMENTPAYPAL');
+    // Print
 }
 
 print '</td></tr>'."\n";
diff --git a/htdocs/public/paypal/newpayment.php b/htdocs/public/paypal/newpayment.php
index cd963eec7988b2fce6bc105795bcfd1ad27e39e2..c9cedcfd32d50416e5f106b4f33eb45108bd6015 100644
--- a/htdocs/public/paypal/newpayment.php
+++ b/htdocs/public/paypal/newpayment.php
@@ -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);
diff --git a/htdocs/public/stripe/index.php b/htdocs/public/stripe/index.php
index 0b7ad1c82e4e927fc615d6dffb273e5b7de6b56c..6a86f3ed88ec7b0242d0fd95e613b88dea3c31fe 100644
--- a/htdocs/public/stripe/index.php
+++ b/htdocs/public/stripe/index.php
@@ -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
diff --git a/htdocs/public/stripe/newpayment.php b/htdocs/public/stripe/newpayment.php
index 0d6cefd357a6b3f14baaf61caa2066a7a6cf7dee..95f0f9f2134b6a30cabb766e6906bb9d997cb676 100644
--- a/htdocs/public/stripe/newpayment.php
+++ b/htdocs/public/stripe/newpayment.php
@@ -23,213 +23,1145 @@
 *  \brief      Page to do payment with Stripe
 */
 
-define("NOLOGIN",1);
-define("NOCSRFCHECK",1);
+define("NOLOGIN",1);		// This means this output page does not require to be logged.
+define("NOCSRFCHECK",1);	// We accept to go on this page from external web site.
+
+// For MultiCompany module.
+// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
+// TODO This should be useless. Because entity must be retreive from object ref and not from url.
+$entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
+if (is_numeric($entity)) define("DOLENTITY", $entity);
 
 require '../../main.inc.php';
+
+require_once DOL_DOCUMENT_ROOT.'/stripe/config.php';
+/* included into config.php
+require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.lib.php';
-require_once DOL_DOCUMENT_ROOT.'/public/stripe/config.php';
 require_once DOL_DOCUMENT_ROOT.'/includes/stripe/init.php';
+*/
 
 // Security check
 if (empty($conf->stripe->enabled)) accessforbidden('',0,0,1);
 
 $langs->load("main");
+$langs->load("companies");
 $langs->load("other");
 $langs->load("paybox");     // File with generic data
 $langs->load("stripe");
 
-$source=GETPOST("source",'alpha');
-$ref=GETPOST('ref','alpha');
+$action=GETPOST('action','alpha');
+
+// Input are:
+// type ('invoice','order','contractline'),
+// id (object id),
+// amount (required if id is empty),
+// tag (a free text, required if type is empty)
+// currency (iso code)
+
+$suffix=GETPOST("suffix",'alpha');
+$amount=price2num(GETPOST("amount"));
+if (! GETPOST("currency",'alpha')) $currency=$conf->currency;
+else $currency=GETPOST("currency",'alpha');
+
+if (! $action)
+{
+    if (! GETPOST("amount") && ! GETPOST("source"))
+    {
+        dol_print_error('',$langs->trans('ErrorBadParameters')." - amount or source");
+        exit;
+    }
+    if (is_numeric($amount) && ! GETPOST("tag") && ! GETPOST("source"))
+    {
+        dol_print_error('',$langs->trans('ErrorBadParameters')." - tag or source");
+        exit;
+    }
+    if (GETPOST("source") && ! GETPOST("ref"))
+    {
+        dol_print_error('',$langs->trans('ErrorBadParameters')." - ref");
+        exit;
+    }
+}
+
+// Define $urlwithroot
+//$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
+//$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
+$urlwithroot=DOL_MAIN_URL_ROOT;						// This is to use same domain name than current
+
+$urlok=$urlwithroot.'/public/paypal/paymentok.php?';
+$urlko=$urlwithroot.'/public/paypal/paymentko.php?';
+
+// Complete urls for post treatment
+$SOURCE=GETPOST("source",'alpha');
+$ref=$REF=GETPOST('ref','alpha');
+$TAG=GETPOST("tag",'alpha');
+$FULLTAG=GETPOST("fulltag",'alpha');		// fulltag is tag with more informations
+$SECUREKEY=GETPOST("securekey");	        // Secure key
+$FULLTAG.=($FULLTAG?'.':'').'PM=stripe';
+
+if (! empty($SOURCE))
+{
+    $urlok.='source='.urlencode($SOURCE).'&';
+    $urlko.='source='.urlencode($SOURCE).'&';
+}
+if (! empty($REF))
+{
+    $urlok.='ref='.urlencode($REF).'&';
+    $urlko.='ref='.urlencode($REF).'&';
+}
+if (! empty($TAG))
+{
+    $urlok.='tag='.urlencode($TAG).'&';
+    $urlko.='tag='.urlencode($TAG).'&';
+}
+if (! empty($FULLTAG))
+{
+    $urlok.='fulltag='.urlencode($FULLTAG).'&';
+    $urlko.='fulltag='.urlencode($FULLTAG).'&';
+}
+if (! empty($SECUREKEY))
+{
+    $urlok.='securekey='.urlencode($SECUREKEY).'&';
+    $urlko.='securekey='.urlencode($SECUREKEY).'&';
+}
+if (! empty($entity))
+{
+    $urlok.='entity='.urlencode($entity).'&';
+    $urlko.='entity='.urlencode($entity).'&';
+}
+$urlok=preg_replace('/&$/','',$urlok);  // Remove last &
+$urlko=preg_replace('/&$/','',$urlko);  // Remove last &
+
+// Check parameters
+/*
+$STRIPE_API_OK="";
+if ($urlok) $STRIPE_API_OK=$urlok;
+$STRIPE_API_KO="";
+if ($urlko) $STRIPE_API_KO=$urlko;
+if (empty($STRIPE_API_USER))
+{
+    dol_print_error('',"Paypal setup param STRIPE_API_USER not defined");
+    return -1;
+}
+if (empty($STRIPE_API_PASSWORD))
+{
+    dol_print_error('',"Paypal setup param STRIPE_API_PASSWORD not defined");
+    return -1;
+}
+if (empty($STRIPE_API_SIGNATURE))
+{
+    dol_print_error('',"Paypal setup param STRIPE_API_SIGNATURE not defined");
+    return -1;
+}
+*/
+
+
+// Check security token
+$valid=true;
+if (! empty($conf->global->STRIPE_SECURITY_TOKEN))
+{
+    if (! empty($conf->global->STRIPE_SECURITY_TOKEN_UNIQUE))
+    {
+        if ($SOURCE && $REF) $token = dol_hash($conf->global->STRIPE_SECURITY_TOKEN . $SOURCE . $REF, 2);    // Use the source in the hash to avoid duplicates if the references are identical
+        else $token = dol_hash($conf->global->STRIPE_SECURITY_TOKEN, 2);
+    }
+    else
+    {
+        $token = $conf->global->STRIPE_SECURITY_TOKEN;
+    }
+    if ($SECUREKEY != $token) $valid=false;
+
+    if (! $valid)
+    {
+        print '<div class="error">Bad value for key.</div>';
+        //print 'SECUREKEY='.$SECUREKEY.' token='.$token.' valid='.$valid;
+        exit;
+    }
+}
+
+
+/*
+ * Actions
+ */
+
+if ($action == 'dopayment')    // We click on button Create payment that lead on this page
+{
+    if (GETPOST('newamount')) $amount = GETPOST('newamount');
+    else 
+    {
+        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
+        $action = '';
+    }
+}
+
+if ($action == 'charge')
+{
+    dol_syslog("POST keys  : ".join(',', array_keys($_POST)));
+    dol_syslog("POST values: ".join(',', $_POST));
+    
+    $token = GETPOST("stripeToken");
+    $email = GETPOST("stripeEmail");
+
+    try {
+        $customer = \Stripe\Customer::create(array(
+            'email' => $email,
+            'card'  => $token
+            // TODO
+        ));
+         
+        $charge = \Stripe\Charge::create(array(
+            'customer' => $customer->id,
+            'amount'   => price2num($amount, 'MU'),
+            'currency' => $conf->currency,
+            // TODO
+            'description' => 'Invoice payment N: '.$ref
+        ));
+    } catch(\Stripe\Error\Card $e) {
+        // Since it's a decline, \Stripe\Error\Card will be caught
+        $body = $e->getJsonBody();
+        $err  = $body['error'];
+    
+        print('Status is:' . $e->getHttpStatus() . "\n");
+        print('Type is:' . $err['type'] . "\n");
+        print('Code is:' . $err['code'] . "\n");
+        // param is '' in this case
+        print('Param is:' . $err['param'] . "\n");
+        print('Message is:' . $err['message'] . "\n");
+    
+        setEventMessages($e->getMessage(), null, 'errors');
+        $action='';
+    } catch (\Stripe\Error\RateLimit $e) {
+        // Too many requests made to the API too quickly
+        setEventMessages($e->getMessage(), null, 'errors');
+        $action='';
+    } catch (\Stripe\Error\InvalidRequest $e) {
+        // Invalid parameters were supplied to Stripe's API
+        setEventMessages($e->getMessage(), null, 'errors');
+        $action='';
+    } catch (\Stripe\Error\Authentication $e) {
+        // Authentication with Stripe's API failed
+        // (maybe you changed API keys recently)
+        setEventMessages($e->getMessage(), null, 'errors');
+        $action='';
+    } catch (\Stripe\Error\ApiConnection $e) {
+        // Network communication with Stripe failed
+        setEventMessages($e->getMessage(), null, 'errors');
+        $action='';
+    } catch (\Stripe\Error\Base $e) {
+        // Display a very generic error to the user, and maybe send
+        // yourself an email
+        setEventMessages($e->getMessage(), null, 'errors');
+        $action='';
+    } catch (Exception $e) {
+        // Something else happened, completely unrelated to Stripe
+        setEventMessages($e->getMessage(), null, 'errors');
+        $action='';
+    }
+        
+    // TODO
+    dol_syslog("Action  Pay.");
+    
+    
+}
+
+
+/*
+ * View
+ */
+
+$head='';
+if (! empty($conf->global->STRIPE_CSS_URL)) $head='<link rel="stylesheet" type="text/css" href="'.$conf->global->STRIPE_CSS_URL.'?lang='.$langs->defaultlang.'">'."\n";
+
+$conf->dol_hide_topmenu=1;
+$conf->dol_hide_leftmenu=1;
+
+llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody');
+
+if (! empty($STRIPE_API_SANDBOX))
+{
+    dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning');
+}
+
+// Common variables
+$creditor=$mysoc->name;
+$paramcreditor='STRIPE_CREDITOR_'.$suffix;
+if (! empty($conf->global->$paramcreditor)) $creditor=$conf->global->$paramcreditor;
+else if (! empty($conf->global->STRIPE_CREDITOR)) $creditor=$conf->global->STRIPE_CREDITOR;
+
+print '<span id="dolpaymentspan"></span>'."\n";
+print '<div class="center">'."\n";
+print '<form id="dolpaymentform" class="center" name="paymentform" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
+print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n";
+print '<input type="hidden" name="action" value="dopayment">'."\n";
+print '<input type="hidden" name="tag" value="'.GETPOST("tag",'alpha').'">'."\n";
+print '<input type="hidden" name="suffix" value="'.GETPOST("suffix",'alpha').'">'."\n";
+print '<input type="hidden" name="securekey" value="'.$SECUREKEY.'">'."\n";
+print '<input type="hidden" name="entity" value="'.$entity.'" />';
+print "\n";
+print '<!-- Form to send a Stripe payment -->'."\n";
+print '<!-- STRIPE_API_SANDBOX = '.$conf->global->STRIPE_API_SANDBOX.' -->'."\n";
+print '<!-- creditor = '.$creditor.' -->'."\n";
+print '<!-- urlok = '.$urlok.' -->'."\n";
+print '<!-- urlko = '.$urlko.' -->'."\n";
+print "\n";
+
+print '<table id="dolpaymenttable" summary="Payment form" class="center">'."\n";
+
+// Show logo (search order: logo defined by PAYBOX_LOGO_suffix, then PAYBOX_LOGO, then small company logo, large company logo, theme logo, common logo)
+$width=0;
+// Define logo and logosmall
+$logosmall=$mysoc->logo_small;
+$logo=$mysoc->logo;
+$paramlogo='STRIPE_LOGO_'.$suffix;
+if (! empty($conf->global->$paramlogo)) $logosmall=$conf->global->$paramlogo;
+else if (! empty($conf->global->STRIPE_LOGO)) $logosmall=$conf->global->STRIPE_LOGO;
+//print '<!-- Show logo (logosmall='.$logosmall.' logo='.$logo.') -->'."\n";
+// Define urllogo
+$urllogo='';
+if (! empty($logosmall) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$logosmall))
+{
+    $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;file='.urlencode('thumbs/'.$logosmall);
+}
+elseif (! empty($logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$logo))
+{
+    $urllogo=DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;file='.urlencode($logo);
+    $width=96;
+}
+// Output html code for logo
+if ($urllogo)
+{
+    print '<tr>';
+    print '<td align="center"><img id="dolpaymentlogo" title="'.$title.'" src="'.$urllogo.'"';
+    if ($width) print ' width="'.$width.'"';
+    print '></td>';
+    print '</tr>'."\n";
+}
+
+// Output introduction text
+$text='';
+if (! empty($conf->global->STRIPE_NEWFORM_TEXT))
+{
+    $langs->load("members");
+    if (preg_match('/^\((.*)\)$/',$conf->global->STRIPE_NEWFORM_TEXT,$reg)) $text.=$langs->trans($reg[1])."<br>\n";
+    else $text.=$conf->global->STRIPE_NEWFORM_TEXT."<br>\n";
+    $text='<tr><td align="center"><br>'.$text.'<br></td></tr>'."\n";
+}
+if (empty($text))
+{
+    $text.='<tr><td class="textpublicpayment"><br><strong>'.$langs->trans("WelcomeOnPaymentPage").'</strong><br></td></tr>'."\n";
+    $text.='<tr><td class="textpublicpayment"><br>'.$langs->trans("ThisScreenAllowsYouToPay",$creditor).'<br><br></td></tr>'."\n";
+}
+print $text;
+
+// Output payment summary form
+print '<tr><td align="center">';
+print '<table with="100%" id="tablepublicpayment">';
+print '<tr class="liste_total"><td align="left" colspan="2">'.$langs->trans("ThisIsInformationOnPayment").' :</td></tr>'."\n";
+
+$found=false;
+$error=0;
+$var=false;
+
+// Free payment
+if (! GETPOST("source"))
+{
+    $found=true;
+    $tag=GETPOST("tag");
+    $fulltag=$tag;
+    
+    // Creditor
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
+    print '<input type="hidden" name="creditor" value="'.$creditor.'">';
+    print '</td></tr>'."\n";
+
+    // Amount
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
+    if (empty($amount)) print ' ('.$langs->trans("ToComplete").')';
+    print '</td><td class="CTableRow'.($var?'1':'2').'">';
+    if (empty($amount) || ! is_numeric($amount))
+    {
+        print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
+        print '<input class="flat" size=8 type="text" name="newamount" value="'.GETPOST("newamount","int").'">';
+    }
+    else {
+        print '<b>'.price($amount).'</b>';
+        print '<input type="hidden" name="amount" value="'.$amount.'">';
+        print '<input type="hidden" name="newamount" value="'.$amount.'">';
+    }
+    // Currency
+    print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+    print '<input type="hidden" name="currency" value="'.$currency.'">';
+    print '</td></tr>'."\n";
+
+    // Tag
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
+    print '<input type="hidden" name="tag" value="'.$tag.'">';
+    print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
+    print '</td></tr>'."\n";
+
+    // We do not add fields shipToName, shipToStreet, shipToCity, shipToState, shipToCountryCode, shipToZip, shipToStreet2, phoneNum
+    // as they don't exists (buyer is unknown, tag is free).
+}
+
+
+// Payment on customer order
+if (GETPOST("source") == 'order')
+{
+    $found=true;
+    $langs->load("orders");
+
+    require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
+
+    $order=new Commande($db);
+    $result=$order->fetch('',$ref);
+    if ($result < 0)
+    {
+        $mesg=$order->error;
+        $error++;
+    }
+    else
+    {
+        $result=$order->fetch_thirdparty($order->socid);
+    }
+
+    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; }
+    $fulltag=dol_string_unaccent($fulltag);
+
+    // Creditor
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
+    print '<input type="hidden" name="creditor" value="'.$creditor.'">';
+    print '</td></tr>'."\n";
 
-$form = new Form($db);
+    // Debitor
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("ThirdParty");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$order->thirdparty->name.'</b>';
+
+    // Object
+
+    $text='<b>'.$langs->trans("PaymentOrderRef",$order->ref).'</b>';
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Designation");
+    print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
+    print '<input type="hidden" name="source" value="'.GETPOST("source",'alpha').'">';
+    print '<input type="hidden" name="ref" value="'.$order->ref.'">';
+    print '</td></tr>'."\n";
+
+    // Amount
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
+    if (empty($amount)) print ' ('.$langs->trans("ToComplete").')';
+    print '</td><td class="CTableRow'.($var?'1':'2').'">';
+    if (empty($amount) || ! is_numeric($amount))
+    {
+        print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
+        print '<input class="flat" size=8 type="text" name="newamount" value="'.GETPOST("newamount","int").'">';
+    }
+    else {
+        print '<b>'.price($amount).'</b>';
+        print '<input type="hidden" name="amount" value="'.$amount.'">';
+        print '<input type="hidden" name="newamount" value="'.$amount.'">';
+    }
+    // Currency
+    print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+    print '<input type="hidden" name="currency" value="'.$currency.'">';
+    print '</td></tr>'."\n";
+
+    // Tag
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
+    print '<input type="hidden" name="tag" value="'.$tag.'">';
+    print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
+    print '</td></tr>'."\n";
+
+    // Shipping address
+    $shipToName=$order->thirdparty->name;
+    $shipToStreet=$order->thirdparty->address;
+    $shipToCity=$order->thirdparty->town;
+    $shipToState=$order->thirdparty->state_code;
+    $shipToCountryCode=$order->thirdparty->country_code;
+    $shipToZip=$order->thirdparty->zip;
+    $shipToStreet2='';
+    $phoneNum=$order->thirdparty->phone;
+    if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip)
+    {
+        print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
+        print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
+        print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
+        print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
+        print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
+        print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
+        print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
+        print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
+    }
+    else
+    {
+        print '<!-- Shipping address not complete, so we don t use it -->'."\n";
+    }
+    print '<input type="hidden" name="email" value="'.$order->thirdparty->email.'">'."\n";
+    print '<input type="hidden" name="desc" value="'.$langs->trans("Order").' '.$order->ref.'">'."\n";
+}
 
-$invoice = null;
 
 // Payment on customer invoice
-if ($source == 'invoice')
-{
-	$found=true;
-	$langs->load("bills");
-
-	require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
-
-	$invoice=new Facture($db);
-	$result=$invoice->fetch('',$ref);
-	if ($result < 0)
-	{
-		$mesg=$invoice->error;
-		$error++;
-	}
-	else
-	{
-		$result=$invoice->fetch_thirdparty($invoice->socid);
-	}
-}
-
-$pay = false;
-$ttc = $invoice->total_ttc ;
-$ttc = $ttc * 100;
-if (GETPOST("action") == 'charge')
-{
-  $token = GETPOST("stripeToken");
-  $email = GETPOST("stripeEmail");
-
-  $customer = \stripe\Customer::create(array(
-      'email' => $email,
-      'card'  => $token
-  ));
-	
-	$ttc = round($ttc, 2);
-  $charge = \stripe\Charge::create(array(
-      'customer' => $customer->id,
-      'amount'   => $ttc,
-      'currency' => $conf->currency,
-      'description' => 'Invoice payment N: '.$ref
-  ));
-
-	$pay = true;
-	
-}
-
-
-
-?>
-
-<!doctype html>
-<html>
-<head>
-    <meta charset="utf-8">
-    <title><?php echo $langs->trans('PaymentForm'); ?></title>
-    <link rel='stylesheet' type='text/css' href='css/style.css' />
-</head>
-
-<body>
-    <div class="invoice-box">		
-        <table cellpadding="0" cellspacing="0">
-            <tr class="top">
-                <td colspan="2">
-                    <table>
-                        <tr>
-                            <td class="title">                                
-								<?php 
-									if(empty($pay)):
-									print '<form  action="' . $_SERVER['REQUEST_URI'] . '" method="POST">';
-									print '<input type="hidden" name="action" value="charge" />';
-									
-								?>
-								  <script src="https://checkout.stripe.com/checkout.js" 
-										class="stripe-button"
-										data-key="<?php echo $stripe['publishable_key']; ?>"
-										data-amount="<?php echo $ttc; ?>"
-										data-currency="<?php echo $conf->currency; ?>"
-										data-description="<?php echo 'Invoice payment N: '.$ref; ?>">
-									</script>
-								</form>
-								<?php endif; ?>
-                            </td>
-                            
-                            <td>
-                                <?php echo $langs->trans("Invoice") . ' : ' . $invoice->ref; ?><br>
-                                <?php echo $langs->trans('Date') . ' : ' . dol_print_date($invoice->date, 'day'); ?><br>
-                                <?php echo $langs->trans('DateMaxPayment') . ' : ' . dol_print_date($invoice->date_validation, 'day'); ?>
-                            </td>
-                        </tr>
-                    </table>
-                </td>
-            </tr>
-            
-            <tr class="information">
-                <td colspan="2">
-                    <table>
-                        <tr>
-                            <td>
-                                <?php echo $invoice->thirdparty->name; ?><br>
-                                <?php echo $invoice->thirdparty->address; ?><br>
-								<?php echo $invoice->thirdparty->zip . ', ' . $invoice->thirdparty->town .' '. $invoice->thirdparty->country_code ; ?>
-                            </td>
-                            
-                            <td>
-                               
-                            </td>
-                        </tr>
-                    </table>
-                </td>
-            </tr>
-            
-            <tr class="heading">
-                <td>
-                    <?php echo $langs->trans('PaymentConditionsShort'); ?>
-                </td>
-                
-                <td>
-                    <?php echo $form->form_conditions_reglement('', $invoice->cond_reglement_id, 'none'); ?>
-                </td>
-            </tr>
-            
-            
-            <tr class="heading">
-                <td>
-                    TOTAL
-                </td>
-                
-                <td>
-                </td>
-            </tr>
-            
-            <tr class="item">
-                <td>
-                   <?php echo $langs->trans('AmountHT'); ?>
-                </td>
-                
-                <td>
-                    <?php echo price($invoice->total_ht, 1, '', 1, - 1, - 1, $conf->currency); ?>
-                </td>
-            </tr>
-            
-            <tr class="item">
-                <td>
-                    <?php echo $langs->trans('AmountVAT'); ?>
-                </td>
-                
-                <td>
-                    <?php echo price($invoice->total_tva, 1, '', 1, - 1, - 1, $conf->currency); ?>
-                </td>
-            </tr>
-            
-            <tr class="item last">
-                <td>
-                    <?php echo $langs->trans('AmountTTC'); ?>
-                </td>
-                
-                <td>
-                   <?php echo price($invoice->total_ttc, 1, '', 1, - 1, - 1, $conf->currency); ?>
-                </td>
-            </tr>
-            
-            <tr class="total">
-                <td></td>
-                
-                <td>
-                   Total: <?php echo price($invoice->total_ttc, 1, '', 1, - 1, - 1, $conf->currency); ?>
-                </td>
-            </tr>
-			
-			
-        </table>
-		<?php //var_dump($mysoc); ?>
-		
-		<span class="center">
-			<?php html_print_stripe_footer($mysoc,$langs); ?>
-		</span>
-		
-		<?php //echo var_dump($mysoc); ?>
-		
+if (GETPOST("source") == 'invoice')
+{
+    $found=true;
+    $langs->load("bills");
+
+    require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
+
+    $invoice=new Facture($db);
+    $result=$invoice->fetch('',$ref);
+    if ($result < 0)
+    {
+        $mesg=$invoice->error;
+        $error++;
+    }
+    else
+    {
+        $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());
+        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; }
+    $fulltag=dol_string_unaccent($fulltag);
+    
+    // Creditor
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
+    print '<input type="hidden" name="creditor" value="'.$creditor.'">';
+    print '</td></tr>'."\n";
+
+    // Debitor
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("ThirdParty");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$invoice->thirdparty->name.'</b>';
+
+    // Object
+
+    $text='<b>'.$langs->trans("PaymentInvoiceRef",$invoice->ref).'</b>';
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Designation");
+    print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
+    print '<input type="hidden" name="source" value="'.GETPOST("source",'alpha').'">';
+    print '<input type="hidden" name="ref" value="'.$invoice->ref.'">';
+    print '</td></tr>'."\n";
+
+    // Amount
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
+    if (empty($amount)) print ' ('.$langs->trans("ToComplete").')';
+    print '</td><td class="CTableRow'.($var?'1':'2').'">';
+    if (empty($amount) || ! is_numeric($amount))
+    {
+        print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
+        print '<input class="flat" size=8 type="text" name="newamount" value="'.GETPOST("newamount","int").'">';
+    }
+    else {
+        print '<b>'.price($amount).'</b>';
+        print '<input type="hidden" name="amount" value="'.$amount.'">';
+        print '<input type="hidden" name="newamount" value="'.$amount.'">';
+    }
+    // Currency
+    print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+    print '<input type="hidden" name="currency" value="'.$currency.'">';
+    print '</td></tr>'."\n";
+
+    // Tag
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
+    print '<input type="hidden" name="tag" value="'.$tag.'">';
+    print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
+    print '</td></tr>'."\n";
+
+    // Shipping address
+    $shipToName=$invoice->thirdparty->name;
+    $shipToStreet=$invoice->thirdparty->address;
+    $shipToCity=$invoice->thirdparty->town;
+    $shipToState=$invoice->thirdparty->state_code;
+    $shipToCountryCode=$invoice->thirdparty->country_code;
+    $shipToZip=$invoice->thirdparty->zip;
+    $shipToStreet2='';
+    $phoneNum=$invoice->thirdparty->phone;
+    if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip)
+    {
+        print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
+        print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
+        print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
+        print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
+        print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
+        print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
+        print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
+        print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
+    }
+    else
+    {
+        print '<!-- Shipping address not complete, so we don t use it -->'."\n";
+    }
+    print '<input type="hidden" name="email" value="'.$invoice->thirdparty->email.'">'."\n";
+    print '<input type="hidden" name="desc" value="'.$langs->trans("Invoice").' '.$invoice->ref.'">'."\n";
+}
+
+// Payment on contract line
+if (GETPOST("source") == 'contractline')
+{
+    $found=true;
+    $langs->load("contracts");
+
+    require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
+
+    $contractline=new ContratLigne($db);
+    $result=$contractline->fetch('',$ref);
+    if ($result < 0)
+    {
+        $mesg=$contractline->error;
+        $error++;
+    }
+    else
+    {
+        if ($contractline->fk_contrat > 0)
+        {
+            $contract=new Contrat($db);
+            $result=$contract->fetch($contractline->fk_contrat);
+            if ($result > 0)
+            {
+                $result=$contract->fetch_thirdparty($contract->socid);
+            }
+            else
+            {
+                $mesg=$contract->error;
+                $error++;
+            }
+        }
+        else
+        {
+            $mesg='ErrorRecordNotFound';
+            $error++;
+        }
+    }
+
+    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,"-"," ");
+    if (! empty($TAG)) { $tag=$TAG; $fulltag.='.TAG='.$TAG; }
+    $fulltag=dol_string_unaccent($fulltag);
+
+    $qty=1;
+    if (GETPOST('qty')) $qty=GETPOST('qty');
+
+    // Creditor
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
+    print '<input type="hidden" name="creditor" value="'.$creditor.'">';
+    print '</td></tr>'."\n";
+
+    // Debitor
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("ThirdParty");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$contract->thirdparty->name.'</b>';
+
+    // Object
+
+    $text='<b>'.$langs->trans("PaymentRenewContractId",$contract->ref,$contractline->ref).'</b>';
+    if ($contractline->fk_product)
+    {
+        $text.='<br>'.$product->ref.($product->label?' - '.$product->label:'');
+    }
+    if ($contractline->description) $text.='<br>'.dol_htmlentitiesbr($contractline->description);
+    //if ($contractline->date_fin_validite) {
+    //	$text.='<br>'.$langs->trans("DateEndPlanned").': ';
+    //	$text.=dol_print_date($contractline->date_fin_validite);
+    //}
+    if ($contractline->date_fin_validite)
+    {
+        $text.='<br>'.$langs->trans("ExpiredSince").': '.dol_print_date($contractline->date_fin_validite);
+    }
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Designation");
+    print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
+    print '<input type="hidden" name="source" value="'.GETPOST("source",'alpha').'">';
+    print '<input type="hidden" name="ref" value="'.$contractline->ref.'">';
+    print '</td></tr>'."\n";
+
+    // Quantity
+
+    $label=$langs->trans("Quantity");
+    $qty=1;
+    $duration='';
+    if ($contractline->fk_product)
+    {
+        if ($product->isService() && $product->duration_value > 0)
+        {
+            $label=$langs->trans("Duration");
+
+            // TODO Put this in a global method
+            if ($product->duration_value > 1)
+            {
+                $dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("DurationDays"),"w"=>$langs->trans("DurationWeeks"),"m"=>$langs->trans("DurationMonths"),"y"=>$langs->trans("DurationYears"));
+            }
+            else
+            {
+                $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("DurationDay"),"w"=>$langs->trans("DurationWeek"),"m"=>$langs->trans("DurationMonth"),"y"=>$langs->trans("DurationYear"));
+            }
+            $duration=$product->duration_value.' '.$dur[$product->duration_unit];
+        }
+    }
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$label.'</td>';
+    print '<td class="CTableRow'.($var?'1':'2').'"><b>'.($duration?$duration:$qty).'</b>';
+    print '<input type="hidden" name="newqty" value="'.dol_escape_htmltag($qty).'">';
+    print '</b></td></tr>'."\n";
+
+    // Amount
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
+    if (empty($amount)) print ' ('.$langs->trans("ToComplete").')';
+    print '</td><td class="CTableRow'.($var?'1':'2').'">';
+    if (empty($amount) || ! is_numeric($amount))
+    {
+        print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
+        print '<input class="flat" size=8 type="text" name="newamount" value="'.GETPOST("newamount","int").'">';
+    }
+    else {
+        print '<b>'.price($amount).'</b>';
+        print '<input type="hidden" name="amount" value="'.$amount.'">';
+        print '<input type="hidden" name="newamount" value="'.$amount.'">';
+    }
+    // Currency
+    print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+    print '<input type="hidden" name="currency" value="'.$currency.'">';
+    print '</td></tr>'."\n";
+
+    // Tag
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
+    print '<input type="hidden" name="tag" value="'.$tag.'">';
+    print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
+    print '</td></tr>'."\n";
+
+    // Shipping address
+    $shipToName=$contract->thirdparty->name;
+    $shipToStreet=$contract->thirdparty->address;
+    $shipToCity=$contract->thirdparty->town;
+    $shipToState=$contract->thirdparty->state_code;
+    $shipToCountryCode=$contract->thirdparty->country_code;
+    $shipToZip=$contract->thirdparty->zip;
+    $shipToStreet2='';
+    $phoneNum=$contract->thirdparty->phone;
+    if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip)
+    {
+        print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
+        print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
+        print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
+        print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
+        print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
+        print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
+        print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
+        print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
+    }
+    else
+    {
+        print '<!-- Shipping address not complete, so we don t use it -->'."\n";
+    }
+    print '<input type="hidden" name="email" value="'.$contract->thirdparty->email.'">'."\n";
+    print '<input type="hidden" name="desc" value="'.$langs->trans("Contract").' '.$contract->ref.'">'."\n";
+}
+
+// Payment on member subscription
+if (GETPOST("source") == 'membersubscription')
+{
+    $found=true;
+    $langs->load("members");
+
+    require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
+    require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
+
+    $member=new Adherent($db);
+    $result=$member->fetch('',$ref);
+    if ($result < 0)
+    {
+        $mesg=$member->error;
+        $error++;
+    }
+    else
+    {
+        $subscription=new Subscription($db);
+    }
+
+    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);
+
+    // Creditor
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Creditor");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$creditor.'</b>';
+    print '<input type="hidden" name="creditor" value="'.$creditor.'">';
+    print '</td></tr>'."\n";
+
+    // Debitor
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Member");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>';
+    if ($member->morphy == 'mor' && ! empty($member->societe)) print $member->societe;
+    else print $member->getFullName($langs);
+    print '</b>';
+
+    // Object
+
+    $text='<b>'.$langs->trans("PaymentSubscription").'</b>';
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Designation");
+    print '</td><td class="CTableRow'.($var?'1':'2').'">'.$text;
+    print '<input type="hidden" name="source" value="'.GETPOST("source",'alpha').'">';
+    print '<input type="hidden" name="ref" value="'.$member->ref.'">';
+    print '</td></tr>'."\n";
+
+    if ($member->last_subscription_date || $member->last_subscription_amount)
+    {
+        // Last subscription date
+
+        print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("LastSubscriptionDate");
+        print '</td><td class="CTableRow'.($var?'1':'2').'">'.dol_print_date($member->last_subscription_date,'day');
+        print '</td></tr>'."\n";
+
+        // Last subscription amount
+
+        print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("LastSubscriptionAmount");
+        print '</td><td class="CTableRow'.($var?'1':'2').'">'.price($member->last_subscription_amount);
+        print '</td></tr>'."\n";
+
+        if (empty($amount) && ! GETPOST('newamount')) $_GET['newamount']=$member->last_subscription_amount;
+    }
+
+    // Amount
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("Amount");
+    if (empty($amount))
+    {
+        print ' ('.$langs->trans("ToComplete");
+        if (! empty($conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO)) print ' - <a href="'.$conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO.'" rel="external" target="_blank">'.$langs->trans("SeeHere").'</a>';
+        print ')';
+    }
+    print '</td><td class="CTableRow'.($var?'1':'2').'">';
+    if (empty($amount) || ! is_numeric($amount))
+    {
+        $valtoshow=GETPOST("newamount",'int');
+        if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow);
+        print '<input type="hidden" name="amount" value="'.GETPOST("amount",'int').'">';
+        print '<input class="flat" size="8" type="text" name="newamount" value="'.$valtoshow.'">';
+    }
+    else {
+        $valtoshow=$amount;
+        if (! empty($conf->global->MEMBER_MIN_AMOUNT) && $valtoshow) $valtoshow=max($conf->global->MEMBER_MIN_AMOUNT,$valtoshow);
+        print '<b>'.price($valtoshow).'</b>';
+        print '<input type="hidden" name="amount" value="'.$valtoshow.'">';
+        print '<input type="hidden" name="newamount" value="'.$valtoshow.'">';
+    }
+    // Currency
+    print ' <b>'.$langs->trans("Currency".$currency).'</b>';
+    print '<input type="hidden" name="currency" value="'.$currency.'">';
+    print '</td></tr>'."\n";
+
+    // Tag
+
+    print '<tr class="CTableRow'.($var?'1':'2').'"><td class="CTableRow'.($var?'1':'2').'">'.$langs->trans("PaymentCode");
+    print '</td><td class="CTableRow'.($var?'1':'2').'"><b>'.$fulltag.'</b>';
+    print '<input type="hidden" name="tag" value="'.$tag.'">';
+    print '<input type="hidden" name="fulltag" value="'.$fulltag.'">';
+    print '</td></tr>'."\n";
+
+    // Shipping address
+    $shipToName=$member->getFullName($langs);
+    $shipToStreet=$member->address;
+    $shipToCity=$member->town;
+    $shipToState=$member->state_code;
+    $shipToCountryCode=$member->country_code;
+    $shipToZip=$member->zip;
+    $shipToStreet2='';
+    $phoneNum=$member->phone;
+    if ($shipToName && $shipToStreet && $shipToCity && $shipToCountryCode && $shipToZip)
+    {
+        print '<input type="hidden" name="shipToName" value="'.$shipToName.'">'."\n";
+        print '<input type="hidden" name="shipToStreet" value="'.$shipToStreet.'">'."\n";
+        print '<input type="hidden" name="shipToCity" value="'.$shipToCity.'">'."\n";
+        print '<input type="hidden" name="shipToState" value="'.$shipToState.'">'."\n";
+        print '<input type="hidden" name="shipToCountryCode" value="'.$shipToCountryCode.'">'."\n";
+        print '<input type="hidden" name="shipToZip" value="'.$shipToZip.'">'."\n";
+        print '<input type="hidden" name="shipToStreet2" value="'.$shipToStreet2.'">'."\n";
+        print '<input type="hidden" name="phoneNum" value="'.$phoneNum.'">'."\n";
+    }
+    else
+    {
+        print '<!-- Shipping address not complete, so we don t use it -->'."\n";
+    }
+    print '<input type="hidden" name="email" value="'.$member->email.'">'."\n";
+    print '<input type="hidden" name="desc" value="'.$langs->trans("PaymentSubscription").'">'."\n";
+}
+
+
+
+if (! $found && ! $mesg) $mesg=$langs->trans("ErrorBadParameters");
+
+if ($mesg) print '<tr><td align="center" colspan="2"><br><div class="warning">'.$mesg.'</div></td></tr>'."\n";
+
+print '</table>'."\n";
+print "\n";
+
+
+if ($action != 'dopayment')
+{
+    if ($found && ! $error)	// We are in a management option and no error
+    {
+        print '<br><input class="button" type="submit" name="dopayment_stripe" value="'.$langs->trans("StripeDoPayment").'">';
+    }
+    else
+    {
+        dol_print_error_email('ERRORNEWPAYMENTSTRIPE');
+    }
+}
+
+
+print '</td></tr>'."\n";
+
+print '</table>'."\n";
+print '</form>'."\n";
+print '</div>'."\n";
+print '<br>';
+
+
+// Add more content on page for some services
+if (preg_match('/^dopayment/',$action))
+{
+    // Simple checkout
+    /*
+     print '<script src="https://checkout.stripe.com/checkout.js"
+     class="stripe-button"
+     data-key="'.$stripe['publishable_key'].'"
+     data-amount="'.$ttc.'"
+     data-currency="'.$conf->currency.'"
+     data-description="'.$ref.'">
+     </script>';
+     */
+    
+    // Personalized checkout
+    print '<style>
+    /**
+     * The CSS shown here will not be introduced in the Quickstart guide, but shows
+     * how you can use CSS to style your Element s container.
+     */
+    .StripeElement {
+        background-color: white;
+        padding: 8px 12px;
+        border-radius: 4px;
+        border: 1px solid transparent;
+        box-shadow: 0 1px 3px 0 #e6ebf1;
+        -webkit-transition: box-shadow 150ms ease;
+        transition: box-shadow 150ms ease;
+    }
+    
+    .StripeElement--focus {
+        box-shadow: 0 1px 3px 0 #cfd7df;
+    }
+    
+    .StripeElement--invalid {
+        border-color: #fa755a;
+    }
+    
+    .StripeElement--webkit-autofill {
+        background-color: #fefde5 !important;
+    }
+    </style>';
+    
+    print '
+    
+    <br>
+    <form action="'.$_SERVER['REQUEST_URI'].'" method="POST" id="payment-form">';
+
+    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n";
+    print '<input type="hidden" name="dopayment_stripe" value="1">'."\n";
+    print '<input type="hidden" name="action" value="charge">'."\n";
+    print '<input type="hidden" name="tag" value="'.GETPOST("tag",'alpha').'">'."\n";
+    print '<input type="hidden" name="suffix" value="'.GETPOST("suffix",'alpha').'">'."\n";
+    print '<input type="hidden" name="securekey" value="'.$SECUREKEY.'">'."\n";
+    print '<input type="hidden" name="entity" value="'.$entity.'" />';
+        
+    print '
+    <table id="dolpaymenttable" summary="Payment form" class="center">
+    <tbody><tr><td class="textpublicpayment">
+                    
+    <div class="form-row left">
+    <label for="card-element">
+    Credit or debit card
+    </label>
+    <div id="card-element">
+    <!-- a Stripe Element will be inserted here. -->
+    </div>
+    
+    <!-- Used to display form errors -->
+    <div id="card-errors" role="alert"></div>
     </div>
+    <br>
+    <button>'.$langs->trans("ToPay").'</button>
+    
+    </td></tr></tbody></table>
+        
+    </form>
+
+        
+    <script src="https://js.stripe.com/v2/"></script>
+    <script src="https://js.stripe.com/v3/"></script>
+    
+    <script type="text/javascript" language="javascript">';
+    ?>
+    
+        // Create a Stripe client
+        var stripe = Stripe('<?php echo $stripe['publishable_key']; ?>');
+        
+        // Create an instance of Elements
+        var elements = stripe.elements();
+        
+        // Custom styling can be passed to options when creating an Element.
+        // (Note that this demo uses a wider set of styles than the guide below.)
+        var style = {
+          base: {
+            color: '#32325d',
+            lineHeight: '24px',
+            fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
+            fontSmoothing: 'antialiased',
+            fontSize: '16px',
+            '::placeholder': {
+              color: '#aab7c4'
+            }
+          },
+          invalid: {
+            color: '#fa755a',
+            iconColor: '#fa755a'
+          }
+        };
+        
+        // Create an instance of the card Element
+        var card = elements.create('card', {style: style});
+        
+        // Add an instance of the card Element into the `card-element` <div>
+        card.mount('#card-element');
+        
+        // Handle real-time validation errors from the card Element.
+        card.addEventListener('change', function(event) {
+          var displayError = document.getElementById('card-errors');
+          if (event.error) {
+            displayError.textContent = event.error.message;
+          } else {
+            displayError.textContent = '';
+          }
+        });
+        
+        // Handle form submission
+        var form = document.getElementById('payment-form');
+        console.log(form);
+        form.addEventListener('submit', function(event) {
+          event.preventDefault();
+        
+          stripe.createToken(card).then(function(result) {
+            if (result.error) {
+              // Inform the user if there was an error
+              var errorElement = document.getElementById('card-errors');
+              errorElement.textContent = result.error.message;
+            } else {
+              // Send the token to your server
+              stripeTokenHandler(result.token);
+            }
+          });
+        });
+        
+        function stripeTokenHandler(token) {
+          // Insert the token ID into the form so it gets submitted to the server
+          var form = document.getElementById('payment-form');
+          var hiddenInput = document.createElement('input');
+          hiddenInput.setAttribute('type', 'hidden');
+          hiddenInput.setAttribute('name', 'stripeToken');
+          hiddenInput.setAttribute('value', token.id);
+          form.appendChild(hiddenInput);
+        
+          // Submit the form
+          console.log("submit");
+          form.submit();
+        }        
+    
+    <?php
+        print '</script>';    
+}
+
 
-</body>
-</html>
 
+htmlPrintOnlinePaymentFooter($mysoc,$langs);
 
+llxFooter('', 'public');
 
+$db->close();
 
diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php
index 3dd238b2f1dbae78d457057a26fb7c42c90d3abd..484b75377552e6a4fb5b504a7b9ecd85c800d0a1 100644
--- a/htdocs/stripe/admin/stripe.php
+++ b/htdocs/stripe/admin/stripe.php
@@ -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>';
diff --git a/htdocs/public/stripe/config.php b/htdocs/stripe/config.php
similarity index 82%
rename from htdocs/public/stripe/config.php
rename to htdocs/stripe/config.php
index dfd0ea6aa1adf99028e369d1e5e442be6fa2fada..0cc15c7fb609e5e63401d2816e334555767c05db 100644
--- a/htdocs/public/stripe/config.php
+++ b/htdocs/stripe/config.php
@@ -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']);
\ No newline at end of file
+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']);