New: Can use "unique" url for each paypal payment page

This commit is contained in:
Laurent Destailleur 2011-09-05 22:52:17 +00:00
parent ac5b36a797
commit a05578134a
8 changed files with 213 additions and 42 deletions

View File

@ -129,6 +129,7 @@ class FormFile
/**
* Show the box with list of available documents for object
*
* @param modulepart propal, facture, facture_fourn, ...
* @param filename Sub dir to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if filedir already complete)
* @param filedir Dir to scan
@ -157,7 +158,8 @@ class FormFile
/**
* Return a string to show the box with list of available documents for object.
* This also set the property $this->numoffiles.
* This also set the property $this->numoffiles
*
* @param modulepart propal, facture, facture_fourn, ...
* @param filename Sub dir to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if filedir already complete)
* @param filedir Dir to scan

View File

@ -189,6 +189,7 @@ class FormMail
/**
* Show the form to input an email
* this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files
*
* @param addfileaction Name of action when posting file attachments
* @param removefileaction Name of action when removing file attachments
*/
@ -200,6 +201,7 @@ class FormMail
/**
* Get the form to input an email
* this->withfile: 0=No attaches files, 1=Show attached files, 2=Can add new attached files
*
* @param addfileaction Name of action when posting file attachments
* @param removefileaction Name of action when removing file attachments
*/
@ -563,12 +565,12 @@ class FormMail
if ($this->param["models"]=='order_send')
{
$url=getPaypalPaymentUrl('order',$this->substit['__ORDERREF__']);
$url=getPaypalPaymentUrl(0,'order',$this->substit['__ORDERREF__']);
$defaultmessage=$langs->transnoentities("PredefinedMailContentSendOrderWithPaypalLink",$url);
}
if ($this->param["models"]=='facture_send')
{
$url=getPaypalPaymentUrl('invoice',$this->substit['__FACREF__']);
$url=getPaypalPaymentUrl(0,'invoice',$this->substit['__FACREF__']);
$defaultmessage=$langs->transnoentities("PredefinedMailContentSendInvoiceWithPaypalLink",$url);
}
}

View File

@ -306,12 +306,16 @@ ConnectionTimeout=Connexion timeout
ResponseTimeout=Response timeout
SmsTestMessage=Test message from __PHONEFROM__ to __PHONETO__
ModuleMustBeEnabledFirst=Module <b>%s</b> must be enabled first before using this feature.
SecurityToken=Key to encrypt urls
SecurityToken=Key to secure URLs
NoSmsEngine=No SMS sender manager available. SMS sender manager are not installed with default distribution (because they depends on an external supplier) but you can find some on http://www.dolistore.com
PDF=PDF
PDFDesc=You can set each global options related to the PDF generation
PDFAddressForging=Rules to forge address boxes
HideAnyVATInformationOnPDF=Hide all information related to VAT on generated PDF
UrlGenerationParameters=Parameters to secure URLs
SecurityTokenIsUnique=Use a unique securekey parameter for each URL
EnterRefToBuildUrl=Enter reference for object %s
GetSecuredUrl=Get calculated URL
# Modules
Module0Name=Users & groups

View File

@ -15,8 +15,8 @@ PayBoxDoPayment=Go on payment
YouWillBeRedirectedOnPayBox=You will be redirected on secured Paybox page to input you credit card information
PleaseBePatient=Please, be patient
Continue=Next
ToOfferALinkForOnlinePaymentOnOrder=URL to offer a %s online payment user interface for an order
ToOfferALinkForOnlinePaymentOnInvoice=URL to offer a %s online payment user interface for an invoice
ToOfferALinkForOnlinePaymentOnOrder=URL to offer a %s online payment user interface for a customer order
ToOfferALinkForOnlinePaymentOnInvoice=URL to offer a %s online payment user interface for a customer invoice
ToOfferALinkForOnlinePaymentOnContractLine=URL to offer a %s online payment user interface for a contract line
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

View File

@ -307,12 +307,16 @@ ConnectionTimeout=Timeout de connexion
ResponseTimeout=Timeout de réponse
SmsTestMessage=Message de test de __PHONEFROM__ vers __PHONETO__
ModuleMustBeEnabledFirst=Le module <b>%s</b> doit etre activé pour utiliser cette fonction.
SecurityToken=Clé de cryptage des url
SecurityToken=Clé de sécurisation des URLs
NoSmsEngine=Aucun gestionnaire d'envoi de SMS n'est disponible. Les gestionnaires d'envois SMS ne sont pas installés en standard (car dépendent d'un fournisseur) mais vous pourrez en trouver depuis la plateforme http://www.dolistore.com
PDF=PDF
PDFDesc=Vous pouvez définir ici des options globales sur la génération des PDF
PDFAddressForging=Règle de fabrication des zones adresses
HideAnyVATInformationOnPDF=Cacher toutes les informations en rapport avec la TVA sur les PDF générés
UrlGenerationParameters=Sécurisation des URLs
SecurityTokenIsUnique=Utiliser un paramètre securekey unique pour chaque URL ?
EnterRefToBuildUrl=Entrez la référence pour l'objet %s
GetSecuredUrl=Obtenir l'URL calculée
# Modules= undefined
Module0Name= Utilisateurs & groupes

View File

@ -16,7 +16,7 @@ YouWillBeRedirectedOnPayBox=Vous serez redirigé vers la page sécurisée Paybox
PleaseBePatient=Merci de patientez quelques secondes
Continue=Continuer
ToOfferALinkForOnlinePaymentOnOrder=URL offrant une interface de paiement en ligne %s sur la base du montant d'une commande client
ToOfferALinkForOnlinePaymentOnInvoice=URL offrant une interface de paiement en ligne %s sur la base du montant d'une facture
ToOfferALinkForOnlinePaymentOnInvoice=URL offrant une interface de paiement en ligne %s sur la base du montant d'une facture client
ToOfferALinkForOnlinePaymentOnContractLine=URL offrant une interface de paiement en ligne %s sur la base du montant d'une ligne de contrat
ToOfferALinkForOnlinePaymentOnFreeAmount=URL offrant une interface de paiement en ligne %s pour un montant libre
ToOfferALinkForOnlinePaymentOnMemberSubscription=URL offrant une interface de paiement en ligne %s sur la base d'une cotisation d'adhérent

View File

@ -51,6 +51,8 @@ if ($_POST["action"] == 'setvalue' && $user->admin)
$result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY",$_POST["PAYPAL_API_INTEGRAL_OR_PAYPALONLY"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_CSS_URL",$_POST["PAYPAL_CSS_URL"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_SECURITY_TOKEN",$_POST["PAYPAL_SECURITY_TOKEN"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_SECURITY_TOKEN_UNIQUE",$_POST["PAYPAL_SECURITY_TOKEN_UNIQUE"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL",$_POST["PAYPAL_ADD_PAYMENT_URL"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_MESSAGE_OK",$_POST["PAYPAL_MESSAGE_OK"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_MESSAGE_KO",$_POST["PAYPAL_MESSAGE_KO"],'chaine',0,'',$conf->entity);
@ -183,13 +185,6 @@ print '<input size="64" type="text" name="PAYPAL_CSS_URL" value="'.$conf->global
print ' &nbsp; '.$langs->trans("Example").': http://mysite/mycss.css';
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print $langs->trans("SecurityToken").'</td><td>';
print '<input size="48" type="text" id="PAYPAL_SECURITY_TOKEN" name="PAYPAL_SECURITY_TOKEN" value="'.$conf->global->PAYPAL_SECURITY_TOKEN.'">';
print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
@ -210,8 +205,30 @@ $doleditor=new DolEditor('PAYPAL_MESSAGE_KO',$conf->global->PAYPAL_MESSAGE_KO,''
$doleditor->Create();
print '</td></tr>';
$var=true;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print "</tr>\n";
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print $langs->trans("SecurityToken").'</td><td>';
print '<input size="48" type="text" id="PAYPAL_SECURITY_TOKEN" name="PAYPAL_SECURITY_TOKEN" value="'.$conf->global->PAYPAL_SECURITY_TOKEN.'">';
print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
print '</td></tr>';
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print $langs->trans("SecurityTokenIsUnique").'</td><td>';
print $form->selectyesno("PAYPAL_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYPAL_SECURITY_TOKEN)?0:$conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE),1);
print '</td></tr>';
print '<tr><td colspan="2" align="center"><br><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
print '</table></form>';
print '</table>';
print '</form>';
dol_fiche_end();
@ -240,32 +257,95 @@ print '</div>';
print '<br><br>';
$token='';
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) $token='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
// Url list
print '<u>'.$langs->trans("FollowingUrlAreAvailableToMakePayments").':</u><br>';
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnFreeAmount",$servicename).':<br>';
print '<strong>'.DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount=<em>9.99</em>&tag=<em>your_free_tag'.$token.'</em></strong>'."<br>\n";
print '<strong>'.getPaypalPaymentUrl(1,'free')."</strong><br>\n";
if ($conf->commande->enabled)
{
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder",$servicename).':<br>';
print '<strong>'.DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref=<em>order_ref'.$token.'</em></strong>'."<br>\n";
print '<strong>'.getPaypalPaymentUrl(1,'order')."</strong><br>\n";
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
{
$langs->load("orders");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Order")).': ';
print '<input type="text class="flat" id="generate_order_ref" name="generate_order_ref" value="'.GETPOST('generate_order_ref').'" size="10">';
print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_order_ref'))
{
print ' -> <strong>';
$url=getPaypalPaymentUrl(0,'order',GETPOST('generate_order_ref'));
print $url;
print "</strong><br>\n";
}
print '</form>';
}
}
if ($conf->facture->enabled)
{
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice",$servicename).':<br>';
print '<strong>'.DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref=<em>invoice_ref'.$token.'</em></strong>'."<br>\n";
// print $langs->trans("SetupPaypalToHavePaymentCreatedAutomatically",$langs->transnoentitiesnoconv("FeatureNotYetAvailable"))."<br>\n";
print '<strong>'.getPaypalPaymentUrl(1,'invoice')."</strong><br>\n";
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
{
$langs->load("bills");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Invoice")).': ';
print '<input type="text class="flat" id="generate_invoice_ref" name="generate_invoice_ref" value="'.GETPOST('generate_invoice_ref').'" size="10">';
print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_invoice_ref'))
{
print ' -> <strong>';
$url=getPaypalPaymentUrl(0,'invoice',GETPOST('generate_invoice_ref'));
print $url;
print "</strong><br>\n";
}
print '</form>';
}
}
if ($conf->contrat->enabled)
{
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine",$servicename).':<br>';
print '<strong>'.DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref=<em>contractline_ref'.$token.'</em></strong>'."<br>\n";
print '<strong>'.getPaypalPaymentUrl(1,'contractline')."</strong><br>\n";
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
{
$langs->load("contract");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Contract")).': ';
print '<input type="text class="flat" id="generate_contract_ref" name="generate_contract_ref" value="'.GETPOST('generate_contract_ref').'" size="10">';
print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_contract_ref'))
{
print ' -> <strong>';
$url=getPaypalPaymentUrl(0,'contractline',GETPOST('generate_contract_ref'));
print $url;
print "</strong><br>\n";
}
print '</form>';
}
}
if ($conf->adherent->enabled)
{
print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription",$servicename).':<br>';
print '<strong>'.DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref=<em>member_ref'.$token.'</em></strong>'."<br>\n";
print '<strong>'.getPaypalPaymentUrl(1,'membersubscription')."</strong><br>\n";
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
{
$langs->load("members");
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Member")).': ';
print '<input type="text class="flat" id="generate_member_ref" name="generate_member_ref" value="'.GETPOST('generate_member_ref').'" size="10">';
print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
if (GETPOST('generate_member_ref'))
{
print ' -> <strong>';
$url=getPaypalPaymentUrl(0,'membersubscription',GETPOST('generate_member_ref'));
print $url;
print "</strong><br>\n";
}
print '</form>';
}
}
print "<br>";

View File

@ -21,6 +21,10 @@
* \ingroup paypal
* \brief Library for common paypal functions
*/
function llxHeaderPaypal($title, $head = "")
{
global $user, $conf, $langs;
@ -56,6 +60,7 @@ function llxFooterPaypal()
print "</html>\n";
}
/**
* Show footer of company in HTML pages
*
@ -147,29 +152,103 @@ function paypaladmin_prepare_head()
return $head;
}
/**
* Return string with full Url
*
* @param int $mode 0=True url, 1=Url formated with colors
* @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...)
* @param string $ref Ref of object
* @param int $amount Amount
* @param string $freetag Free tag
* @return string Url string
*/
function getPaypalPaymentUrl($source='',$ref='',$amount=0,$freetag='')
function getPaypalPaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag')
{
global $conf;
require_once(DOL_DOCUMENT_ROOT."/lib/security.lib.php");
if (! empty($source) && ! empty($ref))
{
$token='';
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) $token='&securekey='.dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.$source.$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;
}
if ($type == 'free')
{
$out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':'');
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
}
if ($type == 'order')
{
$out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='order_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
{
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
else
{
$out.='&securekey='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.="md5('".$conf->global->PAYPAL_SECURITY_TOKEN."'+order_ref)";
if ($mode == 0) $out.= md5($conf->global->PAYPAL_SECURITY_TOKEN.$ref);
$out.=($mode?'</font>':'');
}
}
}
if ($type == 'invoice')
{
$out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='invoice_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
{
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
else
{
$out.='&securekey='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.="md5('".$conf->global->PAYPAL_SECURITY_TOKEN."'+invoice_ref)";
if ($mode == 0) $out.= md5($conf->global->PAYPAL_SECURITY_TOKEN.$ref);
$out.=($mode?'</font>':'');
}
}
}
if ($type == 'contractline')
{
$out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='contractline_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
{
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
else
{
$out.='&securekey='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.="md5('".$conf->global->PAYPAL_SECURITY_TOKEN."'+contractline_ref)";
if ($mode == 0) $out.= md5($conf->global->PAYPAL_SECURITY_TOKEN.$ref);
$out.=($mode?'</font>':'');
}
}
}
if ($type == 'membersubscription')
{
$out=DOL_MAIN_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.='member_ref';
if ($mode == 0) $out.=urlencode($ref);
$out.=($mode?'</font>':'');
if (! empty($conf->global->PAYPAL_SECURITY_TOKEN))
{
if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYPAL_SECURITY_TOKEN;
else
{
$out.='&securekey='.($mode?'<font color="#666666">':'');
if ($mode == 1) $out.="md5('".$conf->global->PAYPAL_SECURITY_TOKEN."'+member_ref)";
if ($mode == 0) $out.= md5($conf->global->PAYPAL_SECURITY_TOKEN.$ref);
$out.=($mode?'</font>':'');
}
}
}
return $out;
}
/**
* Send redirect to paypal to browser
*
@ -244,11 +323,11 @@ function print_paypal_redirect($paymentAmount,$currencyCodeType,$paymentType,$re
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
echo "SetExpressCheckout API call failed. \n";
echo "Detailed Error Message: " . $ErrorLongMsg." \n";
echo "Short Error Message: " . $ErrorShortMsg." \n";
echo "Error Code: " . $ErrorCode." \n";
echo "Error Severity Code: " . $ErrorSeverityCode." \n";
echo "SetExpressCheckout API call failed. <br>\n";
echo "Detailed Error Message: " . $ErrorLongMsg." <br>\n";
echo "Short Error Message: " . $ErrorShortMsg." <br>\n";
echo "Error Code: " . $ErrorCode." <br>\n";
echo "Error Severity Code: " . $ErrorSeverityCode." <br>\n";
}
}