瀏覽代碼

Merge remote-tracking branch 'upstream/develop' into camelCaps2

Frédéric FRANCE 6 年之前
父節點
當前提交
ce76a2e714

+ 2 - 2
htdocs/admin/barcode.php

@@ -306,7 +306,7 @@ if (! empty($conf->product->enabled))
 	print '<tr class="oddeven">';
 	print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
 	print '<td width="60" align="right">';
-	$formbarcode->select_barcode_type($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE,"PRODUIT_DEFAULT_BARCODE_TYPE",1);
+	print $formbarcode->selectBarcodeType($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE, "PRODUIT_DEFAULT_BARCODE_TYPE", 1);
 	print '</td></tr>';
 }
 
@@ -317,7 +317,7 @@ if (! empty($conf->societe->enabled))
 	print '<tr class="oddeven">';
 	print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
 	print '<td width="60" align="right">';
-	print $formbarcode->select_barcode_type($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY,"GENBARCODE_BARCODETYPE_THIRDPARTY",1);
+	print $formbarcode->selectBarcodeType($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY, "GENBARCODE_BARCODETYPE_THIRDPARTY", 1);
 	print '</td></tr>';
 }
 

+ 14 - 14
htdocs/barcode/printsheet.php

@@ -178,19 +178,19 @@ if ($action == 'builddoc')
 	{
 		// List of values to scan for a replacement
 		$substitutionarray = array (
-		'%LOGIN%'=>$user->login,
-		'%COMPANY%'=>$mysoc->name,
-		'%ADDRESS%'=>$mysoc->address,
-		'%ZIP%'=>$mysoc->zip,
-		'%TOWN%'=>$mysoc->town,
-		'%COUNTRY%'=>$mysoc->country,
-		'%COUNTRY_CODE%'=>$mysoc->country_code,
-		'%EMAIL%'=>$mysoc->email,
-		'%YEAR%'=>$year,
-		'%MONTH%'=>$month,
-		'%DAY%'=>$day,
-		'%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT,
-		'%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/"
+		    '%LOGIN%' => $user->login,
+		    '%COMPANY%' => $mysoc->name,
+		    '%ADDRESS%' => $mysoc->address,
+		    '%ZIP%' => $mysoc->zip,
+		    '%TOWN%' => $mysoc->town,
+		    '%COUNTRY%' => $mysoc->country,
+		    '%COUNTRY_CODE%' => $mysoc->country_code,
+		    '%EMAIL%' => $mysoc->email,
+		    '%YEAR%' => $year,
+		    '%MONTH%' => $month,
+		    '%DAY%' => $day,
+		    '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT,
+		    '%SERVER%' => "http://".$_SERVER["SERVER_NAME"]."/",
 		);
 		complete_substitutions_array($substitutionarray, $langs);
 
@@ -416,7 +416,7 @@ print $langs->trans("BarcodeType").' &nbsp; ';
 print '</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
 $formbarcode = new FormBarCode($db);
-$formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
+print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
 print '</div></div>';
 
 // Barcode value

+ 1 - 1
htdocs/compta/bank/class/account.class.php

@@ -346,7 +346,7 @@ class Account extends CommonObject
 	 *      @param  int         $fk_bank    To search using bank transaction id
 	 *      @param  int         $url_id     To search using link to
 	 *      @param  string      $type       To search using type
-	 *      @return array|-1                Array of links array('url'=>, 'url_id'=>, 'label'=>, 'type'=> 'fk_bank'=> ) or -1 on error
+	 *      @return array|int               Array of links array('url'=>, 'url_id'=>, 'label'=>, 'type'=> 'fk_bank'=> ) or -1 on error
 	 */
 	function get_url($fk_bank='', $url_id='', $type='')
 	{

+ 85 - 60
htdocs/core/class/html.formbarcode.class.php

@@ -1,21 +1,22 @@
 <?php
-/* Copyright (C) 2007-2012	Regis Houssin		<regis.houssin@capnetworks.com>
- * Copyright (C) 2008-2012	Laurent Destailleur	<eldy@users.sourceforge.net>
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-*/
+/* Copyright (C) 2007-2012  Regis Houssin           <regis.houssin@capnetworks.com>
+ * Copyright (C) 2008-2012  Laurent Destailleur     <eldy@users.sourceforge.net>
+ * Copyright (C) 2018       Frédéric France         <frederic.france@netlogic.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
 
 /**
  *      \file       htdocs/core/class/html.formbarcode.class.php
@@ -105,17 +106,33 @@ class FormBarCode
 
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
     /**
-     *	Return form to select type of barcode
+     *  Print form to select type of barcode
      *
-     *	@param	int		$selected          Id code pre-selected
-     *  @param	string	$htmlname          Name of HTML select field
-     *  @param  int		$useempty          Affiche valeur vide dans liste
-     *  @return	void
+     *  @param  int     $selected          Id code pre-selected
+     *  @param  string  $htmlname          Name of HTML select field
+     *  @param  int     $useempty          Affiche valeur vide dans liste
+     *  @return void
+     *  @deprecated
      */
-    function select_barcode_type($selected='',$htmlname='barcodetype_id',$useempty=0)
+    function select_barcode_type($selected='', $htmlname='barcodetype_id', $useempty=0)
     {
         // phpcs:enable
-        global $langs,$conf;
+        print $this->selectBarcodeType($selected, $htmlname, $useempty);
+    }
+
+    /**
+     *  Return html form to select type of barcode
+     *
+     *  @param  int     $selected          Id code pre-selected
+     *  @param  string  $htmlname          Name of HTML select field
+     *  @param  int     $useempty          Display empty value in select
+     *  @return string
+     */
+    function selectBarcodeType($selected='', $htmlname='barcodetype_id', $useempty=0)
+    {
+        global $langs, $conf;
+
+        $out = '';
 
         $sql = "SELECT rowid, code, libelle";
         $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
@@ -124,44 +141,37 @@ class FormBarCode
         $sql.= " ORDER BY code";
 
         $result = $this->db->query($sql);
-        if ($result)
-        {
+        if ($result) {
             $num = $this->db->num_rows($result);
             $i = 0;
 
-            if ($useempty && $num > 0)
-            {
-                print '<select class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">';
-                print '<option value="0">&nbsp;</option>';
-            }
-            else
-            {
+            if ($useempty && $num > 0) {
+                $out .= '<select class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">';
+                $out .= '<option value="0">&nbsp;</option>';
+            } else {
                 $langs->load("errors");
-                print '<select disabled class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">';
-                print '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>';
+                $out .= '<select disabled class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">';
+                $out .= '<option value="0" selected>' . $langs->trans('ErrorNoActivatedBarcode') . '</option>';
             }
 
-            while ($i < $num)
-            {
+            while ($i < $num) {
                 $obj = $this->db->fetch_object($result);
-                if ($selected == $obj->rowid)
-                {
-                    print '<option value="'.$obj->rowid.'" selected>';
-                }
-                else
-                {
-                    print '<option value="'.$obj->rowid.'">';
+                if ($selected == $obj->rowid) {
+                    $out .= '<option value="' . $obj->rowid . '" selected>';
+                } else {
+                    $out .= '<option value="' . $obj->rowid . '">';
                 }
-                print $obj->libelle;
-                print '</option>';
+                $out .= $obj->libelle;
+                $out .= '</option>';
                 $i++;
             }
-            print "</select>";
-            print ajax_combobox("select_".$htmlname);
+            $out .= "</select>";
+            $out .= ajax_combobox("select_".$htmlname);
         }
         else {
             dol_print_error($this->db);
         }
+        return $out;
     }
 
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -172,22 +182,37 @@ class FormBarCode
      *  @param  int			$selected    	Id condition preselected
      *  @param  string		$htmlname    	Nom du formulaire select
      *  @return	void
+     *  @deprecated
      */
     function form_barcode_type($page, $selected='', $htmlname='barcodetype_id')
     {
         // phpcs:enable
-        global $langs,$conf;
-        if ($htmlname != "none")
-        {
-            print '<form method="post" action="'.$page.'">';
-            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-            print '<input type="hidden" name="action" value="set'.$htmlname.'">';
-            print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
-            print '<tr><td>';
-            $this->select_barcode_type($selected, $htmlname, 1);
-            print '</td>';
-            print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">';
-            print '</td></tr></table></form>';
+        print $this->formBarcodeType($page, $selected, $htmlname);
+    }
+
+    /**
+     *  Return html form to select type of barcode
+     *
+     *  @param  string      $page           Page
+     *  @param  int         $selected       Id condition preselected
+     *  @param  string      $htmlname       Nom du formulaire select
+     *  @return string
+     */
+    function formBarcodeType($page, $selected='', $htmlname='barcodetype_id')
+    {
+        global $langs, $conf;
+        $out = '';
+        if ($htmlname != "none") {
+            $out .= '<form method="post" action="' . $page . '">';
+            $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
+            $out .= '<input type="hidden" name="action" value="set'.$htmlname.'">';
+            $out .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
+            $out .= '<tr><td>';
+            $out .= $this->selectBarcodeType($selected, $htmlname, 1);
+            $out .= '</td>';
+            $out .= '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
+            $out .= '</td></tr></table></form>';
         }
+        return $out;
     }
 }

+ 1 - 1
htdocs/core/modules/modAgenda.class.php

@@ -90,7 +90,7 @@ class modAgenda extends DolibarrModules
 		$resql = $this->db->query($sqlreadactions);
 		if ($resql)
 		{
-		    while ($obj = $this->db->fetch_object($sqlreadactions))
+		    while ($obj = $this->db->fetch_object($resql))
 		    {
 		        //if (preg_match('/_CREATE$/',$obj->code) && (! in_array($obj->code, array('COMPANY_CREATE','PRODUCT_CREATE','TASK_CREATE')))) continue;    // We don't track such events (*_CREATE) by default, we prefer validation (except thirdparty/product/task creation because there is no validation).
 		        if (preg_match('/^TASK_/',$obj->code)) continue;      // We don't track such events by default.

+ 3 - 2
htdocs/langs/en_US/stripe.lang

@@ -22,7 +22,7 @@ ToOfferALinkForOnlinePaymentOnContractLine=URL to offer a %s online payment user
 ToOfferALinkForOnlinePaymentOnFreeAmount=URL to offer a %s online payment user interface for a free amount
 ToOfferALinkForOnlinePaymentOnMemberSubscription=URL to offer a %s online payment user interface for a member subscription
 YouCanAddTagOnUrl=You can also add url parameter <b>&tag=<i>value</i></b> to any of those URL (required only for free payment) to add your own payment comment tag.
-SetupStripeToHavePaymentCreatedAutomatically=Setup your Stripe with url <b>%s</b> to have payment created automatically when validated by Stripe. 
+SetupStripeToHavePaymentCreatedAutomatically=Setup your Stripe with url <b>%s</b> to have payment created automatically when validated by Stripe.
 AccountParameter=Account parameters
 UsageParameter=Usage parameters
 InformationToFindParameters=Help to find your %s account information
@@ -60,4 +60,5 @@ DeleteACard=Delete Card
 ConfirmDeleteCard=Are you sure you want to delete this Credit or Debit card?
 CreateCustomerOnStripe=Create customer on Stripe
 CreateCardOnStripe=Create card on Stripe
-ShowInStripe=Show in Stripe
+ShowInStripe=Show in Stripe
+StripeUserAccountForActions=User account to use for some emails notification of Stripe events (Stripe payouts)

+ 3 - 3
htdocs/product/card.php

@@ -977,7 +977,7 @@ else
 	        }
 	        require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
             $formbarcode = new FormBarCode($db);
-	        print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
+            print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
 	        print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
 	        $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
 	        if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
@@ -1343,7 +1343,7 @@ else
 		        }
 		        require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
 	            $formbarcode = new FormBarCode($db);
-		        print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
+                print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
 		        print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
 		        $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
 		        if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
@@ -1639,7 +1639,7 @@ else
 				}
                 if ($action == 'editbarcodetype')
                 {
-                    $formbarcode->form_barcode_type($_SERVER['PHP_SELF'].'?id='.$object->id,$object->barcode_type,'fk_barcode_type');
+                    print $formbarcode->formBarcodeType($_SERVER['PHP_SELF'].'?id='.$object->id, $object->barcode_type, 'fk_barcode_type');
                 }
                 else
                 {

+ 38 - 8
htdocs/public/stripe/ipn.php

@@ -1,5 +1,6 @@
 <?php
-/* Copyright (C) 2018 	Thibault FOUCART        <support@ptibogxiv.net>
+/* Copyright (C) 2018       Thibault FOUCART        <support@ptibogxiv.net>
+ * Copyright (C) 2018       Frédéric France         <frederic.france@netlogic.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
+require_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php';
 
 // You can find your endpoint's secret in your webhook settings
 if (isset($_GET['connect'])){
@@ -86,9 +88,12 @@ catch(\UnexpectedValueException $e) {
 // Do something with $event
 
 http_response_code(200); // PHP 5.4 or greater
+
 $langs->load("main");
+
+// TODO Do we really need a user in setup just to have an name to fill an email topic when it is a technical system notification email
 $user = new User($db);
-$user->fetch(5);
+$user->fetch($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS);
 $user->getrights();
 
 if (! empty($conf->multicompany->enabled) && ! empty($conf->stripeconnect->enabled) && is_object($mc)) {
@@ -126,12 +131,37 @@ if ($event->type == 'payout.created') {
 
 	if ($result > 0)
 	{
-		// TODO Use CMail and translation
-		$body = "Un virement de ".price2num($event->data->object->amount/100)." ".$event->data->object->currency." est attendu sur votre compte le ".date('d-m-Y H:i:s',$event->data->object->arrival_date);
-		$subject = '[NOTIFICATION] Virement programmée';
-		$headers = 'From: "'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; // TODO  convert in dolibarr standard
-		mail(''.$conf->global->MAIN_INFO_SOCIETE_MAIL.'', $subject, $body, $headers);
-		return 1;
+        $subject = '[NOTIFICATION] Payment out scheduled';
+        if (!empty($user->email)) {
+            $sendto = dolGetFirstLastname($user->firstname, $user->lastname) . " <".$user->email.">";
+        } else {
+            $sendto = $conf->global->MAIN_INFO_SOCIETE_MAIL.'" <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>';
+        }
+        $replyto = $sendto;
+        $sendtocc = '';
+        if (!empty($conf->global->ONLINE_PAYMENT_SENDEMAIL)) {
+            $sendtocc = $conf->global->ONLINE_PAYMENT_SENDEMAIL.'" <'.$conf->global->ONLINE_PAYMENT_SENDEMAIL.'>';
+        }
+
+        $message = "A bank transfer of ".price2num($event->data->object->amount/100)." ".$event->data->object->currency." should arrive in your account the ".dol_print_date($event->data->object->arrival_date, 'dayhour');
+
+        $mailfile = new CMailFile(
+            $subject,
+            $sendto,
+            $replyto,
+            $message,
+            array(),
+            array(),
+            array(),
+            $sendtocc,
+            '',
+            0,
+            -1
+        );
+
+        $ret = $mailfile->sendfile();
+
+        return 1;
 	}
 	else
 	{

+ 14 - 7
htdocs/stripe/admin/stripe.php

@@ -3,6 +3,7 @@
  * Copyright (C) 2017		Olivier Geffroy			<jeff@jeffinfo.com>
  * Copyright (C) 2017		Saasprov				<saasprov@gmail.com>
  * Copyright (C) 2018		ptibogxiv				<support@ptibogxiv.net>
+ * Copyright (C) 2018       Frédéric France         <frederic.france@netlogic.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -70,10 +71,14 @@ if ($action == 'setvalue' && $user->admin)
 	$result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_PAYMENTS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 'int'), 'chaine', 0, '', $conf->entity);
 	if (! $result > 0)
 		$error ++;
-	$result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity);
+    $result = dolibarr_set_const($db, "STRIPE_USER_ACCOUNT_FOR_ACTIONS", GETPOST('STRIPE_USER_ACCOUNT_FOR_ACTIONS', 'int'), 'chaine', 0, '', $conf->entity);
+    if (! $result > 0) {
+        $error ++;
+    }
+    $result = dolibarr_set_const($db, "STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS", GETPOST('STRIPE_BANK_ACCOUNT_FOR_BANKTRANSFERS', 'int'), 'chaine', 0, '', $conf->entity);
 	if (! $result > 0)
 		$error ++;
-  $result = dolibarr_set_const($db, "STRIPE_MINIMAL_3DSECURE", GETPOST('STRIPE_MINIMAL_3DSECURE', 'int'), 'chaine', 0, '', $conf->entity);
+    $result = dolibarr_set_const($db, "STRIPE_MINIMAL_3DSECURE", GETPOST('STRIPE_MINIMAL_3DSECURE', 'int'), 'chaine', 0, '', $conf->entity);
 	if (! $result > 0)
 		$error ++;
 	$result = dolibarr_set_const($db, "ONLINE_PAYMENT_CSS_URL", GETPOST('ONLINE_PAYMENT_CSS_URL', 'alpha'), 'chaine', 0, '', $conf->entity);
@@ -116,10 +121,8 @@ if ($action == 'setvalue' && $user->admin)
 if ($action=="setlive")
 {
 	$liveenable = GETPOST('value','int');
-	$res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable,'yesno',0,'',$conf->entity);
-	if (! $res > 0) $error++;
-	if (! $error)
-	{
+	$res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable, 'yesno', 0, '', $conf->entity);
+	if ($res > 0) {
 		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
 	}
 	else
@@ -251,6 +254,11 @@ print '<input size="64" type="text" name="ONLINE_PAYMENT_CREDITOR" value="'.$con
 print ' &nbsp; '.$langs->trans("Example").': '.$mysoc->name;
 print '</td></tr>';
 
+print '<tr class="oddeven"><td>';
+print $langs->trans("StripeUserAccountForActions").'</td><td>';
+print $form->select_dolusers($conf->global->STRIPE_USER_ACCOUNT_FOR_ACTIONS, 'STRIPE_USER_ACCOUNT_FOR_ACTIONS', 0);
+print '</td></tr>';
+
 print '<tr class="oddeven"><td>';
 print $langs->trans("BankAccount").'</td><td>';
 print $form->select_comptes($conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS, 'STRIPE_BANK_ACCOUNT_FOR_PAYMENTS', 0, '', 1);
@@ -357,4 +365,3 @@ if (! empty($conf->use_javascript_ajax))
 // End of page
 llxFooter();
 $db->close();
-

+ 31 - 17
htdocs/stripe/charge.php

@@ -125,15 +125,19 @@ if (!$rowid)
 		// Save into $tmparray all metadata
 		$tmparray = dolExplodeIntoArray($FULLTAG,'.','=');
 		// Load origin object according to metadata
-		if (! empty($tmparray['CUS']))
+		if (! empty($tmparray['CUS']) && $tmparray['CUS'] > 0)
 		{
 			$societestatic->fetch($tmparray['CUS']);
 		}
+		elseif (! empty($charge->metadata->dol_thirdparty_id) && $charge->metadata->dol_thirdparty_id > 0)
+		{
+			$societestatic->fetch($charge->metadata->dol_thirdparty_id);
+		}
 		else
 		{
 			$societestatic->id = 0;
 		}
-		if (! empty($tmparray['MEM']))
+		if (! empty($tmparray['MEM']) && $tmparray['MEM'] > 0)
 		{
 			$memberstatic->fetch($tmparray['MEM']);
 		}
@@ -142,9 +146,14 @@ if (!$rowid)
 			$memberstatic->id = 0;
 		}
 
-	    print '<TR class="oddeven">';
-	    // Ref
-		print "<TD><A href='".DOL_URL_ROOT."/stripe/charge.php?rowid=".$charge->id."'>".$charge->id."</A></TD>\n";
+		print '<TR class="oddeven">';
+		// Ref
+		$url='https://dashboard.stripe.com/test/payments/'.$charge->id;
+			if ($servicestatus)
+			{
+				$url='https://dashboard.stripe.com/payments/'.$charge->id;
+			}
+		print "<TD><a href='".$url."' target='_stripe'>".img_picto($langs->trans('ShowInStripe'), 'object_globe')." ".$charge->id."</a></TD>\n";
 		// Stripe customer
 		print "<TD>".$charge->customer."</TD>\n";
 		// Link
@@ -153,23 +162,26 @@ if (!$rowid)
 		{
 			print $societestatic->getNomUrl(1);
 		}
-		if ($memberstatic->id > 0)
+		elseif ($memberstatic->id > 0)
 		{
 			print $memberstatic->getNomUrl(1);
 		}
 		print "</TD>\n";
 		// Origine
 		print "<TD>";
-		print $FULLTAG;
-		if ($charge->metadata->source=="order"){
+		if ($charge->metadata->dol_type=="order"){
 			$object = new Commande($db);
-			$object->fetch($charge->metadata->idsource);
-			print "<A href='".DOL_URL_ROOT."/commande/card.php?id=".$charge->metadata->idsource."'>".img_picto('', 'object_order')." ".$object->ref."</A>";
-		} elseif ($charge->metadata->source=="invoice"){
+			$object->fetch($charge->metadata->dol_id);
+      if ($object->id > 0) {
+			print "<A href='".DOL_URL_ROOT."/commande/card.php?id=".$object->id."'>".img_picto('', 'object_order')." ".$object->ref."</A>";
+      } else print $FULLTAG;
+		} elseif ($charge->metadata->dol_type=="invoice"){
 			$object = new Facture($db);
-			$object->fetch($charge->metadata->idsource);
-		    print "<A href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->idsource."'>".img_picto('', 'object_invoice')." ".$object->ref."</A>";
-		}
+			$object->fetch($charge->metadata->dol_id);
+      if ($object->id > 0) {
+		  print "<A href='".DOL_URL_ROOT."/compta/facture/card.php?facid=".$charge->metadata->dol_id."'>".img_picto('', 'object_invoice')." ".$object->ref."</A>";
+      } else print $FULLTAG;
+		} else print $FULLTAG;
 	    print "</TD>\n";
 		// Date payment
 	    print '<TD align="center">'.dol_print_date($charge->created,'%d/%m/%Y %H:%M')."</TD>\n";
@@ -190,14 +202,16 @@ if (!$rowid)
 	    // Status
 	    print '<TD align="right">';
 	    if ($charge->refunded=='1'){
-	    	print $langs->trans("refunded");
+	    	print img_picto($langs->trans("refunded"),'statut6');
 	    } elseif ($charge->paid=='1'){
-	    	print $langs->trans("".$charge->status."");
+
+        print img_picto($langs->trans("".$charge->status.""),'statut4');
+             
 	    } else {
 	    	$label="Message: ".$charge->failure_message."<br>";
 	    	$label.="Réseau: ".$charge->outcome->network_status."<br>";
 	    	$label.="Statut: ".$langs->trans("".$charge->outcome->seller_message."");
-	    	print $form->textwithpicto($langs->trans("".$charge->status.""),$label,1);
+	    	print $form->textwithpicto(img_picto($langs->trans("".$charge->status.""),'statut8'),$label,1);
 	    }
 	    print "</TD>\n";
 

+ 16 - 15
htdocs/stripe/class/stripe.class.php

@@ -335,18 +335,19 @@ class Stripe extends CommonObject
 	/**
 	 * Create charge with public/payment/newpayment.php, stripe/card.php, cronjobs or REST API
 	 *
-	 * @param int 		$amount									Amount to pay
-	 * @param string 	$currency								EUR, GPB...
-	 * @param string 	$origin									Object type to pay (order, invoice, contract...)
-	 * @param int 		$item									Object id to pay
-	 * @param string 	$source									src_xxxxx or card_xxxxx
-	 * @param string 	$customer								Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe()
-	 * @param string 	$account								Stripe account ref 'acc_xxxxxxxxxxxxx' via  getStripeAccount()
+	 * @param	int 	$amount									Amount to pay
+	 * @param	string 	$currency								EUR, GPB...
+	 * @param	string 	$origin									Object type to pay (order, invoice, contract...)
+	 * @param	int 	$item									Object id to pay
+	 * @param	string 	$source									src_xxxxx or card_xxxxx
+	 * @param	string 	$customer								Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe()
+	 * @param	string 	$account								Stripe account ref 'acc_xxxxxxxxxxxxx' via  getStripeAccount()
 	 * @param	int		$status									Status (0=test, 1=live)
 	 * @param	int		$usethirdpartyemailforreceiptemail		Use thirdparty email as receipt email
+	 * @param	boolean	$capture								Set capture flag to true (take payment) or false (wait)
 	 * @return Stripe
 	 */
-	public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0, $usethirdpartyemailforreceiptemail=0)
+	public function createPaymentStripe($amount, $currency, $origin, $item, $source, $customer, $account, $status=0, $usethirdpartyemailforreceiptemail=0, $capture=true)
 	{
 		global $conf;
 
@@ -417,9 +418,9 @@ class Stripe extends CommonObject
 					$charge = \Stripe\Charge::create(array(
 						"amount" => "$stripeamount",
 						"currency" => "$currency",
-                                                "capture"  => true,
 						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
- 					        "description" => "Stripe payment: ".$description,
+						"description" => "Stripe payment: ".$description,
+						"capture"  => $capture,
 						"metadata" => $metadata,
 						"source" => "$source"
 					));
@@ -427,9 +428,9 @@ class Stripe extends CommonObject
 					$paymentarray = array(
 						"amount" => "$stripeamount",
 						"currency" => "$currency",
-                                                "capture"  => true,
-					        "statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
-					        "description" => "Stripe payment: ".$description,
+						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
+						"description" => "Stripe payment: ".$description,
+						"capture"  => $capture,
 						"metadata" => $metadata,
 						"source" => "$source",
 						"customer" => "$customer"
@@ -452,9 +453,9 @@ class Stripe extends CommonObject
         		$paymentarray = array(
 						"amount" => "$stripeamount",
 						"currency" => "$currency",
-                                                "capture"  => true,
 						"statement_descriptor" => dol_trunc(dol_trunc(dol_string_unaccent($mysoc->name), 8, 'right', 'UTF-8', 1).' '.$description, 22, 'right', 'UTF-8', 1),     // 22 chars that appears on bank receipt
-					        "description" => "Stripe payment: ".$description,
+						"description" => "Stripe payment: ".$description,
+						"capture"  => $capture,
 						"metadata" => $metadata,
 						"source" => "$source",
 						"customer" => "$customer"