diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 447b713ebe6..d0cb88a4f20 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -474,6 +474,26 @@ class FormMail if ($this->param["models"]=='order_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierOrder"); } if ($this->param["models"]=='invoice_supplier_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendSupplierInvoice"); } if ($this->param["models"]=='shipping_send') { $defaultmessage=$langs->transnoentities("PredefinedMailContentSendShipping"); } + + if ($conf->paypal->enabled && $conf->global->PAYPAL_ADD_PAYMENT_URL) + { + require_once(DOL_DOCUMENT_ROOT."/lib/security.lib.php"); + require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypal.lib.php"); + + $langs->load('paypal'); + + if ($this->param["models"]=='order_send') + { + $url=getPaymentUrl('order',$this->substit['__ORDERREF__']); + $defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrderWithPaypalLink",$url); + } + if ($this->param["models"]=='facture_send') + { + $url=getPaymentUrl('invoice',$this->substit['__FACREF__']); + $defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoiceWithPaypalLink",$url); + } + } + $defaultmessage=make_substitutions($defaultmessage,$this->substit); if (isset($_POST["message"])) $defaultmessage=$_POST["message"]; $defaultmessage=str_replace('\n',"\n",$defaultmessage); diff --git a/htdocs/paypal/lib/paypal.lib.php b/htdocs/paypal/lib/paypal.lib.php index 2c2b018b787..e7d21e89831 100755 --- a/htdocs/paypal/lib/paypal.lib.php +++ b/htdocs/paypal/lib/paypal.lib.php @@ -150,6 +150,27 @@ function paypaladmin_prepare_head() return $head; } +/** + * + */ +function getPaymentUrl($source='',$ref='',$amount=0,$freetag='') +{ + global $conf; + + if (! empty($source) && ! empty($ref)) + { + $token=''; + if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) $token='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$ref, 2); + + if ($source == 'commande') $source = 'order'; + if ($source == 'facture') $source = 'invoice'; + + $url = DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source='.$source.'&ref='.$ref.$token; + + return $url; + } +} + /** * Send redirect to paypal to browser *