From 9eaca045e465151b3cb0209bfe4ee3fab71e2263 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 27 Jun 2018 11:34:40 +0200 Subject: [PATCH] Fix default message with online payment link must be hidden when no online payment mode exists. --- htdocs/core/class/html.formmail.class.php | 19 +++++++++++++---- htdocs/core/lib/payments.lib.php | 26 +++++++++++++++++++++++ htdocs/langs/en_US/other.lang | 5 +++-- htdocs/langs/en_US/paypal.lang | 1 - htdocs/public/payment/newpayment.php | 2 ++ 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 4dd07f13313..d1132bb642c 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -917,7 +917,7 @@ class FormMail extends Form } // Complete substitution array with the url to make online payment - $paymenturl=''; + $paymenturl=''; $validpaymentmethod=array(); if (empty($this->substit['__REF__'])) { $paymenturl=''; @@ -926,16 +926,27 @@ class FormMail extends Form { // Set the online payment url link into __ONLINE_PAYMENT_URL__ key require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; - $langs->load('paypal'); + $langs->loadLangs(array('paypal','other')); $typeforonlinepayment='free'; if ($this->param["models"]=='order' || $this->param["models"]=='order_send') $typeforonlinepayment='order'; // TODO use detection on something else than template if ($this->param["models"]=='invoice' || $this->param["models"]=='facture_send') $typeforonlinepayment='invoice'; // TODO use detection on something else than template if ($this->param["models"]=='member') $typeforonlinepayment='member'; // TODO use detection on something else than template $url=getOnlinePaymentUrl(0, $typeforonlinepayment, $this->substit['__REF__']); $paymenturl=$url; + + $validpaymentmethod = getValidOnlinePaymentMethods($paymentmethod); + } + var_dump($validpaymentmethod); + if (count($validpaymentmethod) > 0) + { + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']=($paymenturl?$langs->trans("PredefinedMailContentLink", $paymenturl):''); + $this->substit['__ONLINE_PAYMENT_URL__']=$paymenturl; + } + else + { + $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']=''; + $this->substit['__ONLINE_PAYMENT_URL__']=''; } - $this->substit['__ONLINE_PAYMENT_TEXT_AND_URL__']=($paymenturl?$langs->trans("PredefinedMailContentLink", $paymenturl):''); - $this->substit['__ONLINE_PAYMENT_URL__']=$paymenturl; //Add lines substitution key from each line $lines = ''; diff --git a/htdocs/core/lib/payments.lib.php b/htdocs/core/lib/payments.lib.php index df97b133522..d56a7e2311c 100644 --- a/htdocs/core/lib/payments.lib.php +++ b/htdocs/core/lib/payments.lib.php @@ -87,6 +87,32 @@ function payment_supplier_prepare_head(Paiement $object) { return $head; } +/** + * Return array of valid payment mode + * + * @param string $paymentmethod Filter on this payment method + * @return array Array of valid payment method + */ +function getValidOnlinePaymentMethods($paymentmethod='') +{ + global $conf; + + $validpaymentmethod=array(); + + if ((empty($paymentmethod) || $paymentmethod == 'paypal') && ! empty($conf->paypal->enabled)) + { + $validpaymentmethod['paypal']='valid'; + } + if ((empty($paymentmethod) || $paymentmethod == 'paybox') && ! empty($conf->paybox->enabled)) + { + $validpaymentmethod['paybox']='valid'; + } + if ((empty($paymentmethod) || $paymentmethod == 'stripe') && ! empty($conf->stripe->enabled)) + { + $validpaymentmethod['stripe']='valid'; + } + return $validpaymentmethod; +} /** * Return string with full Url diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index fa98516c989..10ca033662d 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -80,8 +80,8 @@ LinkedObject=Linked object NbOfActiveNotifications=Number of notifications (nb of recipient emails) PredefinedMailTest=__(Hello)__\nThis is a test mail sent to __EMAIL__.\nThe two lines are separated by a carriage return.\n\n__USER_SIGNATURE__ PredefinedMailTestHtml=__(Hello)__\nThis is a test mail (the word test must be in bold).
The two lines are separated by a carriage return.

__USER_SIGNATURE__ -PredefinedMailContentSendInvoice=__(Hello)__\n\nYou will find here the invoice __REF__\n\nThis is the link to make your online payment if this invoice is not already payed:\n__ONLINE_PAYMENT_URL__\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ -PredefinedMailContentSendInvoiceReminder=__(Hello)__\n\nWe would like to warn you that the invoice __REF__ seems to not be payed. So this is the invoice in attachment again, as a reminder.\n\nThis is the link to make your online payment:\n__ONLINE_PAYMENT_URL__\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ +PredefinedMailContentSendInvoice=__(Hello)__\n\nYou will find here the invoice __REF__\n\n__ONLINE_PAYMENT_TEXT_AND_URL__\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ +PredefinedMailContentSendInvoiceReminder=__(Hello)__\n\nWe would like to warn you that the invoice __REF__ seems to not be payed. So this is the invoice in attachment again, as a reminder.\n\n__ONLINE_PAYMENT_TEXT_AND_URL__\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentSendProposal=__(Hello)__\n\nYou will find here the commercial proposal __REF__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentSendSupplierProposal=__(Hello)__\n\nYou will find here the price request __REF__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentSendOrder=__(Hello)__\n\nYou will find here the order __REF__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ @@ -91,6 +91,7 @@ PredefinedMailContentSendShipping=__(Hello)__\n\nYou will find here the shipping PredefinedMailContentSendFichInter=__(Hello)__\n\nYou will find here the intervention __REF__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentThirdparty=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ PredefinedMailContentUser=__(Hello)__\n\n\n__(Sincerely)__\n\n__USER_SIGNATURE__ +PredefinedMailContentLink=You can click on the link below to make your payment if it is not already done.

%s

DemoDesc=Dolibarr is a compact ERP/CRM supporting several business modules. A demo showcasing all modules makes no sense as this scenario never occurs (several hundred available). So, several demo profiles are available. ChooseYourDemoProfil=Choose the demo profile that best suits your needs... ChooseYourDemoProfilMore=...or build your own profile
(manual module selection) diff --git a/htdocs/langs/en_US/paypal.lang b/htdocs/langs/en_US/paypal.lang index 2cbe4289654..547b188b4a5 100644 --- a/htdocs/langs/en_US/paypal.lang +++ b/htdocs/langs/en_US/paypal.lang @@ -14,7 +14,6 @@ PaypalModeOnlyPaypal=PayPal only ONLINE_PAYMENT_CSS_URL=Optionnal URL of CSS style sheet on online payment page ThisIsTransactionId=This is id of transaction: %s PAYPAL_ADD_PAYMENT_URL=Add the url of Paypal payment when you send a document by mail -PredefinedMailContentLink=You can click on the link below to make your payment if it is not already done.

%s

YouAreCurrentlyInSandboxMode=You are currently in the %s "sandbox" mode NewOnlinePaymentReceived=New online payment received NewOnlinePaymentFailed=New online payment tried but failed diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index ec2f43841f5..a189781c8c1 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -208,6 +208,8 @@ if ((empty($paymentmethod) || $paymentmethod == 'stripe') && ! empty($conf->stri $validpaymentmethod['stripe']='valid'; } +// TODO Replace previous set of $validpaymentmethod with this line: +//$validpaymentmethod = getValidOnlinePaymentMethods($paymentmethod); // Check security token