Work on paypal module

This commit is contained in:
Laurent Destailleur 2010-10-03 23:20:49 +00:00
parent 705c675933
commit 5497bfc1bb
8 changed files with 722 additions and 192 deletions

View File

@ -167,26 +167,26 @@ print '<br>';
if ($conf->commande->enabled)
{
print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder",$servicename).':<br>';
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?amount=order&ref=<i>order_ref</i></b>'."<br>\n";
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?source=order&ref=<i>order_ref</i></b>'."<br>\n";
print '<br>';
}
if ($conf->facture->enabled)
{
print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice",$servicename).':<br>';
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?amount=invoice&ref=<i>invoice_ref</i></b>'."<br>\n";
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?source=invoice&ref=<i>invoice_ref</i></b>'."<br>\n";
// print $langs->trans("SetupPayBoxToHavePaymentCreatedAutomatically",$langs->transnoentitiesnoconv("FeatureNotYetAvailable"))."<br>\n";
print '<br>';
}
if ($conf->contrat->enabled)
{
print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine",$servicename).':<br>';
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?amount=contractline&ref=<i>contractline_ref</i></b>'."<br>\n";
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?source=contractline&ref=<i>contractline_ref</i></b>'."<br>\n";
print '<br>';
}
if ($conf->adherent->enabled)
{
print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription",$servicename).':<br>';
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?amount=membersubscription&ref=<i>member_ref</i></b>'."<br>\n";
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/newpayment.php?source=membersubscription&ref=<i>member_ref</i></b>'."<br>\n";
print '<br>';
}
print $langs->trans("YouCanAddTagOnUrl");

View File

@ -19,12 +19,10 @@
*/
/**
* \file htdocs/paybox/paybox.lib.php
* \file htdocs/paybox/lib/paybox.lib.php
* \brief Library for common paybox functions
* \version $Id$
*/
function llxHeaderPaybox($title, $head = "")
{
global $user, $conf, $langs;
@ -69,7 +67,7 @@ function print_paybox_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG)
{
global $conf, $langs, $db;
dol_syslog("Paypal.lib::print_paybox_redirect", LOG_DEBUG);
dol_syslog("Paybox.lib::print_paybox_redirect", LOG_DEBUG);
// Clean parameters
$PBX_IDENTIFIANT="2"; # Identifiant pour v2 test

View File

@ -38,17 +38,10 @@ if (!$user->admin)
if ($_POST["action"] == 'setvalue' && $user->admin)
{
//$result=dolibarr_set_const($db, "PAYPAL_IBS_DEVISE",$_POST["PAYPAL_IBS_DEVISE"],'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_CREDITOR",$_POST["PAYPAL_CREDITOR"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_CGI_URL_V1",$_POST["PAYPAL_CGI_URL_V1"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_CGI_URL_V2",$_POST["PAYPAL_CGI_URL_V2"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_IBS_SITE",$_POST["PAYPAL_IBS_SITE"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_IBS_RANG",$_POST["PAYPAL_IBS_RANG"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_PBX_IDENTIFIANT",$_POST["PAYPAL_PBX_IDENTIFIANT"],'chaine',0,'',$conf->entity);
*/
$result=dolibarr_set_const($db, "PAYPAL_API_SANDBOX",$_POST["PAYPAL_API_SANDBOX"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL",$_POST["PAYPAL_API_INTEGRAL"],'chaine',0,'',$conf->entity);
$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_API_USER",$_POST["PAYPAL_API_USER"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_API_PASSWORD",$_POST["PAYPAL_API_PASSWORD"],'chaine',0,'',$conf->entity);
$result=dolibarr_set_const($db, "PAYPAL_API_SIGNATURE",$_POST["PAYPAL_API_SIGNATURE"],'chaine',0,'',$conf->entity);
@ -161,26 +154,26 @@ print '<br>';
if ($conf->commande->enabled)
{
print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder",$servicename).':<br>';
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?amount=order&ref=<i>order_ref</i></b>'."<br>\n";
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?source=order&ref=<i>order_ref</i></b>'."<br>\n";
print '<br>';
}
if ($conf->facture->enabled)
{
print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice",$servicename).':<br>';
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?amount=invoice&ref=<i>invoice_ref</i></b>'."<br>\n";
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?source=invoice&ref=<i>invoice_ref</i></b>'."<br>\n";
// print $langs->trans("SetupPaypalToHavePaymentCreatedAutomatically",$langs->transnoentitiesnoconv("FeatureNotYetAvailable"))."<br>\n";
print '<br>';
}
if ($conf->contrat->enabled)
{
print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine",$servicename).':<br>';
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?amount=contractline&ref=<i>contractline_ref</i></b>'."<br>\n";
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?source=contractline&ref=<i>contractline_ref</i></b>'."<br>\n";
print '<br>';
}
if ($conf->adherent->enabled)
{
print img_picto('','puce.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription",$servicename).':<br>';
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?amount=membersubscription&ref=<i>member_ref</i></b>'."<br>\n";
print '<b>'.$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/newpayment.php?source=membersubscription&ref=<i>member_ref</i></b>'."<br>\n";
print '<br>';
}
print $langs->trans("YouCanAddTagOnUrl");

View File

@ -0,0 +1,82 @@
<?php
require_once ("paypalfunctions.php");
// ==================================
// PayPal Express Checkout Module
// ==================================
//'------------------------------------
//' The paymentAmount is the total value of
//' the shopping cart, that was set
//' earlier in a session variable
//' by the shopping cart page
//'------------------------------------
$paymentAmount = $_SESSION["Payment_Amount"];
//'------------------------------------
//' The currencyCodeType and paymentType
//' are set to the selections made on the Integration Assistant
//'------------------------------------
$currencyCodeType = "EUR";
$paymentType = "Sale";
//'------------------------------------
//' The returnURL is the location where buyers return to when a
//' payment has been succesfully authorized.
//'
//' This is set to the value entered on the Integration Assistant
//'------------------------------------
$returnURL = $PAYPAL_API_OK;
//'------------------------------------
//' The cancelURL is the location buyers are sent to when they hit the
//' cancel button during authorization of payment during the PayPal flow
//'
//' This is set to the value entered on the Integration Assistant
//'------------------------------------
$cancelURL = $PAYPAL_API_KO;
//'------------------------------------
//' Calls the SetExpressCheckout API call
//'
//'-------------------------------------------------
if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
// For payment with Paypal only
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
{
$resArray = CallShortcutExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL);
}
// For payment with Credit card or Paypal
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral')
{
$resArray = CallMarkExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL);
}
// For direct payment with credit card
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'cconly')
{
//$resArray = DirectPayment (...);
}
$ack = strtoupper($resArray["ACK"]);
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
RedirectToPayPal ( $resArray["TOKEN"] );
}
else
{
//Display a user friendly Error on the page using any of the following error information returned by PayPal
$ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
$ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
$ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
$ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
echo "SetExpressCheckout API call failed. ";
echo "Detailed Error Message: " . $ErrorLongMsg;
echo "Short Error Message: " . $ErrorShortMsg;
echo "Error Code: " . $ErrorCode;
echo "Error Severity Code: " . $ErrorSeverityCode;
}
?>

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2008-2009 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -19,12 +19,10 @@
*/
/**
* \file htdocs/paypal/paypal.lib.php
* \file htdocs/paypal/lib/paypal.lib.php
* \brief Library for common paypal functions
* \version $Id$
*/
function llxHeaderPaypal($title, $head = "")
{
global $user, $conf, $langs;
@ -68,90 +66,53 @@ function llxFooterPaypal()
function print_paypal_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG)
{
global $conf, $langs, $db;
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
global $PAYPAL_API_DEVISE, $PAYPAL_API_OK, $PAYPAL_API_KO;
global $PAYPAL_API_SANDBOX;
dol_syslog("Paypal.lib::print_paybox_redirect", LOG_DEBUG);
dol_syslog("Paypal.lib::print_paypal_redirect", LOG_DEBUG);
// Clean parameters
$PBX_IDENTIFIANT="2"; # Identifiant pour v2 test
if ($conf->global->PAYBOX_PBX_IDENTIFIANT) $PBX_IDENTIFIANT=$conf->global->PAYBOX_PBX_IDENTIFIANT;
$IBS_SITE="1999888"; # Site test
if ($conf->global->PAYBOX_IBS_SITE) $IBS_SITE=$conf->global->PAYBOX_IBS_SITE;
$IBS_RANG="99"; # Rang test
if ($conf->global->PAYBOX_IBS_RANG) $IBS_RANG=$conf->global->PAYBOX_IBS_RANG;
$IBS_DEVISE="840"; # Currency (Dollar US by default)
if ($CURRENCY == 'EUR') $IBS_DEVISE="978";
if ($CURRENCY == 'USD') $IBS_DEVISE="840";
$PAYPAL_API_USER="";
if ($conf->global->PAYPAL_API_USER) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
$PAYPAL_API_PASSWORD="";
if ($conf->global->PAYPAL_API_PASSWORD) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
$PAYPAL_API_SIGNATURE="";
if ($conf->global->PAYPAL_API_SIGNATURE) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
$PAYPAL_API_SANDBOX="";
if ($conf->global->PAYPAL_API_SANDBOX) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
$URLPAYBOX="";
if ($conf->global->PAYBOX_CGI_URL_V1) $URLPAYBOX=$conf->global->PAYBOX_CGI_URL_V1;
if ($conf->global->PAYBOX_CGI_URL_V2) $URLPAYBOX=$conf->global->PAYBOX_CGI_URL_V2;
if (empty($IBS_DEVISE))
if (empty($PAYPAL_API_USER))
{
dol_print_error('',"Paybox setup param PAYBOX_IBS_DEVISE not defined");
dol_print_error('',"Paypal setup param PAYPAL_API_USER not defined");
return -1;
}
if (empty($URLPAYBOX))
if (empty($PAYPAL_API_PASSWORD))
{
dol_print_error('',"Paybox setup param PAYBOX_CGI_URL_V1 and PAYBOX_CGI_URL_V2 undefined");
dol_print_error('',"Paypal setup param PAYPAL_API_PASSWORD not defined");
return -1;
}
if (empty($IBS_SITE))
if (empty($PAYPAL_API_SIGNATURE))
{
dol_print_error('',"Paybox setup param PAYBOX_IBS_SITE not defined");
return -1;
}
if (empty($IBS_RANG))
{
dol_print_error('',"Paybox setup param PAYBOX_IBS_RANG not defined");
dol_print_error('',"Paypal setup param PAYPAL_API_SIGNATURE not defined");
return -1;
}
// Definition des parametres vente produit pour paybox
$IBS_CMD=$TAG;
$IBS_TOTAL=$PRICE*100; # En centimes
$IBS_MODE=1; # Mode formulaire
$IBS_PORTEUR=$EMAIL;
$IBS_RETOUR="montant:M;ref:R;auto:A;trans:T"; # Format des parametres du get de validation en reponse (url a definir sous paybox)
//$IBS_TXT="<center><b>".$langsiso->trans("YouWillBeRedirectedOnPayBox")."</b><br><i>".$langsiso->trans("PleaseBePatient")."...</i><br></center>";
$IBS_TXT=' '; // Use a space
$IBS_BOUTPI=$langs->trans("Wait");
//$IBS_BOUTPI='';
$IBS_EFFECTUE=$urlok;
$IBS_ANNULE=$urlko;
$IBS_REFUSE=$urlko;
$IBS_BKGD="#FFFFFF";
$IBS_WAIT="2000";
$IBS_LANG="GBR"; // By default GBR=english (FRA, GBR, ESP, ITA et DEU...)
if (preg_match('/^FR/i',$langs->defaultlang)) $IBS_LANG="FRA";
if (preg_match('/^ES/i',$langs->defaultlang)) $IBS_LANG="ESP";
if (preg_match('/^IT/i',$langs->defaultlang)) $IBS_LANG="ITA";
if (preg_match('/^DE/i',$langs->defaultlang)) $IBS_LANG="DEU";
if (preg_match('/^NL/i',$langs->defaultlang)) $IBS_LANG="NLD";
if (preg_match('/^SE/i',$langs->defaultlang)) $IBS_LANG="SWE";
$IBS_OUTPUT='E';
$PBX_SOURCE='HTML';
$PBX_TYPEPAIEMENT='CARTE';
// Other
$PAYPAL_API_DEVISE="EUR";
if ($CURRENCY == 'EUR') $PAYPAL_API_DEVISE="EUR";
if ($CURRENCY == 'USD') $PAYPAL_API_DEVISE="USD";
$PAYPAL_API_OK=$urlok;
$PAYPAL_API_KO=$urlko;
dol_syslog("Soumission Paybox", LOG_DEBUG);
dol_syslog("IBS_MODE: $IBS_MODE", LOG_DEBUG);
dol_syslog("IBS_SITE: $IBS_SITE", LOG_DEBUG);
dol_syslog("IBS_RANG: $IBS_RANG", LOG_DEBUG);
dol_syslog("IBS_TOTAL: $IBS_TOTAL", LOG_DEBUG);
dol_syslog("IBS_DEVISE: $IBS_DEVISE", LOG_DEBUG);
dol_syslog("IBS_CMD: $IBS_CMD", LOG_DEBUG);
dol_syslog("IBS_PORTEUR: $IBS_PORTEUR", LOG_DEBUG);
dol_syslog("IBS_RETOUR: $IBS_RETOUR", LOG_DEBUG);
dol_syslog("IBS_EFFECTUE: $IBS_EFFECTUE", LOG_DEBUG);
dol_syslog("IBS_ANNULE: $IBS_ANNULE", LOG_DEBUG);
dol_syslog("IBS_REFUSE: $IBS_REFUSE", LOG_DEBUG);
dol_syslog("IBS_BKGD: $IBS_BKGD", LOG_DEBUG);
dol_syslog("IBS_WAIT: $IBS_WAIT", LOG_DEBUG);
dol_syslog("IBS_LANG: $IBS_LANG", LOG_DEBUG);
dol_syslog("IBS_OUTPUT: $IBS_OUTPUT", LOG_DEBUG);
dol_syslog("PBX_IDENTIFIANT: $PBX_IDENTITIANT", LOG_DEBUG);
dol_syslog("PBX_SOURCE: $PBX_SOURCE", LOG_DEBUG);
dol_syslog("PBX_TYPEPAIEMENT: $PBX_TYPEPAIEMENT", LOG_DEBUG);
dol_syslog("Soumission Paypal", LOG_DEBUG);
dol_syslog("PAYPAL_API_USER: $PAYPAL_API_USER", LOG_DEBUG);
dol_syslog("PAYPAL_API_PASSWORD: $PAYPAL_API_PASSWORD", LOG_DEBUG);
dol_syslog("PAYPAL_API_SIGNATURE: $PAYPAL_API_SIGNATURE", LOG_DEBUG);
dol_syslog("PAYPAL_API_DEVISE: $PAYPAL_API_DEVISE", LOG_DEBUG);
dol_syslog("PAYPAL_API_OK: $PAYPAL_API_OK", LOG_DEBUG);
dol_syslog("PAYPAL_API_KO: $PAYPAL_API_KO", LOG_DEBUG);
dol_syslog("PAYPAL_API_SANDBOX: $PAYPAL_API_SANDBOX", LOG_DEBUG);
header("Content-type: text/html; charset=".$conf->file->character_set_client);
@ -162,62 +123,26 @@ function print_paypal_redirect($PRICE,$CURRENCY,$EMAIL,$urlok,$urlko,$TAG)
print '<body>'."\n";
print "\n";
$_SESSION["Payment_Amount"]=$PRICE;
// A redirect is added if API call successfull
require_once(DOL_DOCUMENT_ROOT."/paypal/expresscheckout.php");
// Formulaire pour module Paybox
print '<form action="'.$URLPAYBOX.'" NAME="Submit" method="POST">'."\n";
// print '<form action="'.$URLPAYBOX.'" NAME="Submit" method="POST">'."\n";
//print "
//<form action='".DOL_URL_ROOT."/paypal/expresscheckout.php' METHOD='POST' NAME='Submit'>
//<input type='image' name='submit' src='https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif' border='0' align='top' alt='Check out with PayPal'/>
//</form>";
// print '</form>'."\n";
// For Paybox V1 (IBS_xxx)
/*
print '<!-- Param for Paybox v1 -->'."\n";
print '<input type="hidden" name="IBS_MODE" value="'.$IBS_MODE.'">'."\n";
print '<input type="hidden" name="IBS_SITE" value="'.$IBS_SITE.'">'."\n";
print '<input type="hidden" name="IBS_RANG" value="'.$IBS_RANG.'">'."\n";
print '<input type="hidden" name="IBS_TOTAL" value="'.$IBS_TOTAL.'">'."\n";
print '<input type="hidden" name="IBS_DEVISE" value="'.$IBS_DEVISE.'">'."\n";
print '<input type="hidden" name="IBS_CMD" value="'.$IBS_CMD.'">'."\n";
print '<input type="hidden" name="IBS_PORTEUR" value="'.$IBS_PORTEUR.'">'."\n";
print '<input type="hidden" name="IBS_RETOUR" value="'.$IBS_RETOUR.'">'."\n";
print '<input type="hidden" name="IBS_EFFECTUE" value="'.$IBS_EFFECTUE.'">'."\n";
print '<input type="hidden" name="IBS_ANNULE" value="'.$IBS_ANNULE.'">'."\n";
print '<input type="hidden" name="IBS_REFUSE" value="'.$IBS_REFUSE.'">'."\n";
print '<input type="hidden" name="IBS_TXT" value="'.$IBS_TXT.'">'."\n";
print '<input type="hidden" name="IBS_BKGD" value="'.$IBS_BKGD.'">'."\n";
print '<input type="hidden" name="IBS_WAIT" value="'.$IBS_WAIT.'">'."\n";
print '<input type="hidden" name="IBS_LANG" value="'.$IBS_LANG.'">'."\n";
print '<input type="hidden" name="IBS_OUTPUT" value="'.$IBS_OUTPUT.'">'."\n";
*/
// For Paybox V2 (PBX_xxx)
print '<!-- Param for Paybox v2 -->'."\n";
print '<input type="hidden" name="PBX_IDENTIFIANT" value="'.$PBX_IDENTIFIANT.'">'."\n";
print '<input type="hidden" name="PBX_MODE" value="'.$IBS_MODE.'">'."\n";
print '<input type="hidden" name="PBX_SITE" value="'.$IBS_SITE.'">'."\n";
print '<input type="hidden" name="PBX_RANG" value="'.$IBS_RANG.'">'."\n";
print '<input type="hidden" name="PBX_TOTAL" value="'.$IBS_TOTAL.'">'."\n";
print '<input type="hidden" name="PBX_DEVISE" value="'.$IBS_DEVISE.'">'."\n";
print '<input type="hidden" name="PBX_CMD" value="'.$IBS_CMD.'">'."\n";
print '<input type="hidden" name="PBX_PORTEUR" value="'.$IBS_PORTEUR.'">'."\n";
print '<input type="hidden" name="PBX_RETOUR" value="'.$IBS_RETOUR.'">'."\n";
print '<input type="hidden" name="PBX_EFFECTUE" value="'.$IBS_EFFECTUE.'">'."\n";
print '<input type="hidden" name="PBX_ANNULE" value="'.$IBS_ANNULE.'">'."\n";
print '<input type="hidden" name="PBX_REFUSE" value="'.$IBS_REFUSE.'">'."\n";
print '<input type="hidden" name="PBX_TXT" value="'.$IBS_TXT.'">'."\n";
print '<input type="hidden" name="PBX_BKGD" value="'.$IBS_BKGD.'">'."\n";
print '<input type="hidden" name="PBX_WAIT" value="'.$IBS_WAIT.'">'."\n";
print '<input type="hidden" name="PBX_LANG" value="'.$IBS_LANG.'">'."\n";
print '<input type="hidden" name="PBX_OUTPUT" value="'.$IBS_OUTPUT.'">'."\n";
print '<input type="hidden" name="PBX_SOURCE" value="'.$PBX_SOURCE.'">'."\n";
print '<input type="hidden" name="PBX_TYPEPAIEMENT" value="'.$PBX_TYPEPAIEMENT.'">'."\n";
print '</form>'."\n";
// Formulaire pour module Paybox v2 (PBX_xxx)
// print "\n";
// print '<script type="text/javascript" language="javascript">'."\n";
// print ' document.Submit.submit();'."\n";
// print '</script>'."\n";
// print "\n";
print "\n";
print '<script type="text/javascript" language="javascript">'."\n";
print ' document.Submit.submit();'."\n";
print '</script>'."\n";
print "\n";
print '</body></html>'."\n";
print "\n";

View File

@ -0,0 +1,414 @@
<?php
/********************************************
PayPal API Module
Defines all the global variables and the wrapper functions
********************************************/
$PROXY_HOST = '127.0.0.1';
$PROXY_PORT = '808';
$SandboxFlag = ($PAYPAL_API_SANDBOX?true:false);
//'------------------------------------
//' PayPal API Credentials
//' Replace <API_USERNAME> with your API Username
//' Replace <API_PASSWORD> with your API Password
//' Replace <API_SIGNATURE> with your Signature
//'------------------------------------
$API_UserName=$PAYPAL_API_USER;
$API_Password=$PAYPAL_API_PASSWORD;
$API_Signature=$PAYPAL_API_SIGNATURE;
// BN Code is only applicable for partners
$sBNCode = "PP-ECWizard";
/*
' Define the PayPal Redirect URLs.
' This is the URL that the buyer is first sent to do authorize payment with their paypal account
' change the URL depending if you are testing on the sandbox or the live PayPal site
'
' For the sandbox, the URL is https://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=
' For the live site, the URL is https://www.paypal.com/webscr&cmd=_express-checkout&token=
*/
if ($SandboxFlag == true)
{
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
$PAYPAL_URL = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
}
else
{
$API_Endpoint = "https://api-3t.paypal.com/nvp";
$PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
}
$USE_PROXY = false;
$version="2.3";
if (session_id() == "")
session_start();
/* An express checkout transaction starts with a token, that
identifies to PayPal your transaction
In this example, when the script sees a token, the script
knows that the buyer has already authorized payment through
paypal. If no token was found, the action is to send the buyer
to PayPal to first authorize payment
*/
/*
'-------------------------------------------------------------------------------------------------------------------------------------------
' Purpose: Prepares the parameters for the SetExpressCheckout API Call.
' Inputs:
' paymentAmount: Total value of the shopping cart
' currencyCodeType: Currency code value the PayPal API
' paymentType: paymentType has to be one of the following values: Sale or Order or Authorization
' returnURL: the page where buyers return to after they are done with the payment review on PayPal
' cancelURL: the page where buyers return to when they cancel the payment review on PayPal
'--------------------------------------------------------------------------------------------------------------------------------------------
*/
function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL)
{
//------------------------------------------------------------------------------------------------------------------------------------
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
$nvpstr="&Amt=". $paymentAmount;
$nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType;
$nvpstr = $nvpstr . "&ReturnUrl=" . $returnURL;
$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
$nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCodeType;
$_SESSION["currencyCodeType"] = $currencyCodeType;
$_SESSION["PaymentType"] = $paymentType;
//'---------------------------------------------------------------------------------------------------------------
//' Make the API call to PayPal
//' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
//' If an error occured, show the resulting errors
//'---------------------------------------------------------------------------------------------------------------
$resArray=hash_call("SetExpressCheckout", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
$token = urldecode($resArray["TOKEN"]);
$_SESSION['TOKEN']=$token;
}
return $resArray;
}
/*
'-------------------------------------------------------------------------------------------------------------------------------------------
' Purpose: Prepares the parameters for the SetExpressCheckout API Call.
' Inputs:
' paymentAmount: Total value of the shopping cart
' currencyCodeType: Currency code value the PayPal API
' paymentType: paymentType has to be one of the following values: Sale or Order or Authorization
' returnURL: the page where buyers return to after they are done with the payment review on PayPal
' cancelURL: the page where buyers return to when they cancel the payment review on PayPal
' shipToName: the Ship to name entered on the merchant's site
' shipToStreet: the Ship to Street entered on the merchant's site
' shipToCity: the Ship to City entered on the merchant's site
' shipToState: the Ship to State entered on the merchant's site
' shipToCountryCode: the Code for Ship to Country entered on the merchant's site
' shipToZip: the Ship to ZipCode entered on the merchant's site
' shipToStreet2: the Ship to Street2 entered on the merchant's site
' phoneNum: the phoneNum entered on the merchant's site
'--------------------------------------------------------------------------------------------------------------------------------------------
*/
function CallMarkExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL,
$cancelURL, $shipToName, $shipToStreet, $shipToCity, $shipToState,
$shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum
)
{
//------------------------------------------------------------------------------------------------------------------------------------
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
$nvpstr="&Amt=". $paymentAmount;
$nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType;
$nvpstr = $nvpstr . "&ReturnUrl=" . $returnURL;
$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
$nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCodeType;
$nvpstr = $nvpstr . "&ADDROVERRIDE=1";
$nvpstr = $nvpstr . "&SHIPTONAME=" . $shipToName;
$nvpstr = $nvpstr . "&SHIPTOSTREET=" . $shipToStreet;
$nvpstr = $nvpstr . "&SHIPTOSTREET2=" . $shipToStreet2;
$nvpstr = $nvpstr . "&SHIPTOCITY=" . $shipToCity;
$nvpstr = $nvpstr . "&SHIPTOSTATE=" . $shipToState;
$nvpstr = $nvpstr . "&SHIPTOCOUNTRYCODE=" . $shipToCountryCode;
$nvpstr = $nvpstr . "&SHIPTOZIP=" . $shipToZip;
$nvpstr = $nvpstr . "&PHONENUM=" . $phoneNum;
$_SESSION["currencyCodeType"] = $currencyCodeType;
$_SESSION["PaymentType"] = $paymentType;
//'---------------------------------------------------------------------------------------------------------------
//' Make the API call to PayPal
//' If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment.
//' If an error occured, show the resulting errors
//'---------------------------------------------------------------------------------------------------------------
$resArray=hash_call("SetExpressCheckout", $nvpstr);
$ack = strtoupper($resArray["ACK"]);
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
$token = urldecode($resArray["TOKEN"]);
$_SESSION['TOKEN']=$token;
}
return $resArray;
}
/*
'-------------------------------------------------------------------------------------------
' Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call.
'
' Inputs:
' None
' Returns:
' The NVP Collection object of the GetExpressCheckoutDetails Call Response.
'-------------------------------------------------------------------------------------------
*/
function GetShippingDetails( $token )
{
//'--------------------------------------------------------------
//' At this point, the buyer has completed authorizing the payment
//' at PayPal. The function will call PayPal to obtain the details
//' of the authorization, incuding any shipping information of the
//' buyer. Remember, the authorization is not a completed transaction
//' at this state - the buyer still needs an additional step to finalize
//' the transaction
//'--------------------------------------------------------------
//'---------------------------------------------------------------------------
//' Build a second API request to PayPal, using the token as the
//' ID to get the details on the payment authorization
//'---------------------------------------------------------------------------
$nvpstr="&TOKEN=" . $token;
//'---------------------------------------------------------------------------
//' Make the API call and store the results in an array.
//' If the call was a success, show the authorization details, and provide
//' an action to complete the payment.
//' If failed, show the error
//'---------------------------------------------------------------------------
$resArray=hash_call("GetExpressCheckoutDetails",$nvpstr);
$ack = strtoupper($resArray["ACK"]);
if($ack == "SUCCESS" || $ack=="SUCCESSWITHWARNING")
{
$_SESSION['payer_id'] = $resArray['PAYERID'];
}
return $resArray;
}
/*
'-------------------------------------------------------------------------------------------------------------------------------------------
' Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call.
'
' Inputs:
' sBNCode: The BN code used by PayPal to track the transactions from a given shopping cart.
' Returns:
' The NVP Collection object of the GetExpressCheckoutDetails Call Response.
'--------------------------------------------------------------------------------------------------------------------------------------------
*/
function ConfirmPayment( $FinalPaymentAmt )
{
/* Gather the information to make the final call to
finalize the PayPal payment. The variable nvpstr
holds the name value pairs
*/
//Format the other parameters that were stored in the session from the previous calls
$token = urlencode($_SESSION['TOKEN']);
$paymentType = urlencode($_SESSION['PaymentType']);
$currencyCodeType = urlencode($_SESSION['currencyCodeType']);
$payerID = urlencode($_SESSION['payer_id']);
$serverName = urlencode($_SERVER['SERVER_NAME']);
$nvpstr = '&TOKEN=' . $token . '&PAYERID=' . $payerID . '&PAYMENTACTION=' . $paymentType . '&AMT=' . $FinalPaymentAmt;
$nvpstr .= '&CURRENCYCODE=' . $currencyCodeType . '&IPADDRESS=' . $serverName;
/* Make the call to PayPal to finalize payment
If an error occured, show the resulting errors
*/
$resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);
/* Display the API response back to the browser.
If the response from PayPal was a success, display the response parameters'
If the response was an error, display the errors received using APIError.php.
*/
$ack = strtoupper($resArray["ACK"]);
return $resArray;
}
/*
'-------------------------------------------------------------------------------------------------------------------------------------------
' Purpose: This function makes a DoDirectPayment API call
'
' Inputs:
' paymentType: paymentType has to be one of the following values: Sale or Order or Authorization
' paymentAmount: total value of the shopping cart
' currencyCode: currency code value the PayPal API
' firstName: first name as it appears on credit card
' lastName: last name as it appears on credit card
' street: buyer's street address line as it appears on credit card
' city: buyer's city
' state: buyer's state
' countryCode: buyer's country code
' zip: buyer's zip
' creditCardType: buyer's credit card type (i.e. Visa, MasterCard ... )
' creditCardNumber: buyers credit card number without any spaces, dashes or any other characters
' expDate: credit card expiration date
' cvv2: Card Verification Value
'
'-------------------------------------------------------------------------------------------
'
' Returns:
' The NVP Collection object of the DoDirectPayment Call Response.
'--------------------------------------------------------------------------------------------------------------------------------------------
*/
function DirectPayment( $paymentType, $paymentAmount, $creditCardType, $creditCardNumber,
$expDate, $cvv2, $firstName, $lastName, $street, $city, $state, $zip,
$countryCode, $currencyCode )
{
//Construct the parameter string that describes DoDirectPayment
$nvpstr = "&AMT=" . $paymentAmount;
$nvpstr = $nvpstr . "&CURRENCYCODE=" . $currencyCode;
$nvpstr = $nvpstr . "&PAYMENTACTION=" . $paymentType;
$nvpstr = $nvpstr . "&CREDITCARDTYPE=" . $creditCardType;
$nvpstr = $nvpstr . "&ACCT=" . $creditCardNumber;
$nvpstr = $nvpstr . "&EXPDATE=" . $expDate;
$nvpstr = $nvpstr . "&CVV2=" . $cvv2;
$nvpstr = $nvpstr . "&FIRSTNAME=" . $firstName;
$nvpstr = $nvpstr . "&LASTNAME=" . $lastName;
$nvpstr = $nvpstr . "&STREET=" . $street;
$nvpstr = $nvpstr . "&CITY=" . $city;
$nvpstr = $nvpstr . "&STATE=" . $state;
$nvpstr = $nvpstr . "&COUNTRYCODE=" . $countryCode;
$nvpstr = $nvpstr . "&IPADDRESS=" . $_SERVER['REMOTE_ADDR'];
$resArray=hash_call("DoDirectPayment", $nvpstr);
return $resArray;
}
/**
'-------------------------------------------------------------------------------------------------------------------------------------------
* hash_call: Function to perform the API call to PayPal using API signature
* @methodName is name of API method.
* @nvpStr is nvp string.
* returns an associtive array containing the response from the server.
'-------------------------------------------------------------------------------------------------------------------------------------------
*/
function hash_call($methodName,$nvpStr)
{
//declaring of global variables
global $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature;
global $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
global $gv_ApiErrorURL;
global $sBNCode;
//setting the curl parameters.
$ch = curl_init();
/*print $API_Endpoint."-".$version."-".$API_UserName."-".$API_Password."-".$API_Signature."<br>";
print $USE_PROXY."-".$gv_ApiErrorURL."-".$sBNCode."<br>";
print $nvpStr;
exit;*/
curl_setopt($ch, CURLOPT_URL,$API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//turning off the server and peer verification(TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
//if USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
//Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php
if($USE_PROXY)
curl_setopt ($ch, CURLOPT_PROXY, $PROXY_HOST. ":" . $PROXY_PORT);
//NVPRequest for submitting to server
$nvpreq="METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($version) . "&PWD=" . urlencode($API_Password) . "&USER=" . urlencode($API_UserName) . "&SIGNATURE=" . urlencode($API_Signature) . $nvpStr . "&BUTTONSOURCE=" . urlencode($sBNCode);
//setting the nvpreq as POST FIELD to curl
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
//getting response from server
$response = curl_exec($ch);
//convrting NVPResponse to an Associative Array
$nvpResArray=deformatNVP($response);
$nvpReqArray=deformatNVP($nvpreq);
$_SESSION['nvpReqArray']=$nvpReqArray;
if (curl_errno($ch))
{
// moving to display page to display curl errors
$_SESSION['curl_error_no']=curl_errno($ch) ;
$_SESSION['curl_error_msg']=curl_error($ch);
//Execute the Error handling module to display errors.
}
else
{
//closing the curl
curl_close($ch);
}
return $nvpResArray;
}
/*'----------------------------------------------------------------------------------
Purpose: Redirects to PayPal.com site.
Inputs: NVP string.
Returns:
----------------------------------------------------------------------------------
*/
function RedirectToPayPal ( $token )
{
global $PAYPAL_URL;
// Redirect to paypal.com here
$payPalURL = $PAYPAL_URL . $token;
header("Location: ".$payPalURL);
}
/*'----------------------------------------------------------------------------------
* This function will take NVPString and convert it to an Associative Array and it will decode the response.
* It is usefull to search for a particular key and displaying arrays.
* @nvpstr is NVPString.
* @nvpArray is Associative Array.
----------------------------------------------------------------------------------
*/
function deformatNVP($nvpstr)
{
$intial=0;
$nvpArray = array();
while(strlen($nvpstr))
{
//postion of Key
$keypos= strpos($nvpstr,'=');
//position of value
$valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);
/*getting the Key and Value values and storing in a Associative Array*/
$keyval=substr($nvpstr,$intial,$keypos);
$valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1);
//decoding the respose
$nvpArray[urldecode($keyval)] =urldecode( $valval);
$nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
}
return $nvpArray;
}
?>

View File

@ -70,20 +70,20 @@ $langs->load("errors");
if (empty($_REQUEST["currency"])) $currency=$conf->global->MAIN_MONNAIE;
else $currency=$_REQUEST["currency"];
if (empty($_REQUEST["amount"]))
if (empty($_REQUEST["amount"]) && empty($_REQUEST["source"]))
{
dol_print_error('','ErrorBadParameters');
session_destroy();
exit;
}
$amount=$_REQUEST["amount"];
if (is_numeric($amount) && empty($_REQUEST["tag"]))
if (is_numeric($amount) && empty($_REQUEST["tag"]) && empty($_REQUEST["source"]))
{
dol_print_error('','ErrorBadParameters');
session_destroy();
exit;
}
if (! is_numeric($amount) && empty($_REQUEST["ref"]))
if (! empty($REQUEST["source"]) && empty($_REQUEST["ref"]))
{
dol_print_error('','ErrorBadParameters');
session_destroy();
@ -98,10 +98,12 @@ $suffix=$_REQUEST["suffix"];
*/
if ($_REQUEST["action"] == 'dopayment')
{
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$dolibarr_main_url_root);
$PRICE=$_REQUEST["newamount"];
$EMAIL=$_REQUEST["EMAIL"];
$urlok='';
$urlko='';
$urlok=$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/paymentok.php';
$urlko=$urlwithouturlroot.DOL_URL_ROOT.'/public/paybox/paymentko.php';
$TAG=$_REQUEST["newtag"];
$ID=$_REQUEST["id"];
@ -190,7 +192,7 @@ $var=false;
// Free payment
if (is_numeric($_REQUEST["amount"]))
if (empty($_REQUEST["source"]))
{
$found=true;
$tag=$_REQUEST["tag"];
@ -211,8 +213,9 @@ if (is_numeric($_REQUEST["amount"]))
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
@ -232,7 +235,7 @@ if (is_numeric($_REQUEST["amount"]))
// Payment on customer order
if ($_REQUEST["amount"] == 'order')
if ($_REQUEST["source"] == 'order')
{
$found=true;
$langs->load("orders");
@ -252,6 +255,7 @@ if ($_REQUEST["amount"] == 'order')
}
$amount=$order->total_ttc;
if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"];
$newtag='IR='.$order->ref.'.TPID='.$order->client->id.'.TP='.strtr($order->client->nom,"-"," ");
if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; }
@ -285,8 +289,9 @@ if ($_REQUEST["amount"] == 'order')
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
@ -306,7 +311,7 @@ if ($_REQUEST["amount"] == 'order')
// Payment on customer invoice
if ($_REQUEST["amount"] == 'invoice')
if ($_REQUEST["source"] == 'invoice')
{
$found=true;
$langs->load("bills");
@ -326,6 +331,7 @@ if ($_REQUEST["amount"] == 'invoice')
}
$amount=$invoice->total_ttc - $invoice->getSommePaiement();
if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"];
$newtag='IR='.$invoice->ref.'.TPID='.$invoice->client->id.'.TP='.strtr($invoice->client->nom,"-"," ");
if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; }
@ -359,8 +365,9 @@ if ($_REQUEST["amount"] == 'invoice')
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
@ -379,7 +386,7 @@ if ($_REQUEST["amount"] == 'invoice')
}
// Payment on contract line
if ($_REQUEST["amount"] == 'contractline')
if ($_REQUEST["source"] == 'contractline')
{
$found=true;
$langs->load("contracts");
@ -443,6 +450,7 @@ if ($_REQUEST["amount"] == 'contractline')
exit;
}
}
if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"];
$newtag='CLR='.$contractline->ref.'.CR='.$contract->ref.'.TPID='.$contract->client->id.'.TP='.strtr($contract->client->nom,"-"," ");
if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; }
@ -521,8 +529,9 @@ if ($_REQUEST["amount"] == 'contractline')
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
@ -542,7 +551,7 @@ if ($_REQUEST["amount"] == 'contractline')
}
// Payment on member subscription
if ($_REQUEST["amount"] == 'membersubscription')
if ($_REQUEST["source"] == 'membersubscription')
{
$found=true;
$langs->load("members");
@ -563,6 +572,7 @@ if ($_REQUEST["amount"] == 'membersubscription')
}
$amount=$subscription->total_ttc;
if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"];
$newtag='MID='.$member->id.'.M='.strtr($member->getFullName($langs),"-"," ");
if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; }
@ -596,8 +606,9 @@ if ($_REQUEST["amount"] == 'membersubscription')
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag

View File

@ -71,20 +71,20 @@ $langs->load("paypal");
if (empty($_REQUEST["currency"])) $currency=$conf->global->MAIN_MONNAIE;
else $currency=$_REQUEST["currency"];
if (empty($_REQUEST["amount"]))
if (empty($_REQUEST["amount"]) && empty($_REQUEST["source"]))
{
dol_print_error('','ErrorBadParameters');
session_destroy();
exit;
}
$amount=$_REQUEST["amount"];
if (is_numeric($amount) && empty($_REQUEST["tag"]))
if (is_numeric($amount) && empty($_REQUEST["tag"]) && empty($_REQUEST["source"]))
{
dol_print_error('','ErrorBadParameters');
session_destroy();
exit;
}
if (! is_numeric($amount) && empty($_REQUEST["ref"]))
if (! empty($REQUEST["source"]) && empty($_REQUEST["ref"]))
{
dol_print_error('','ErrorBadParameters');
session_destroy();
@ -99,23 +99,113 @@ $suffix=$_REQUEST["suffix"];
*/
if ($_REQUEST["action"] == 'dopayment')
{
$PRICE=$_REQUEST["newamount"];
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',$dolibarr_main_url_root);
$PAYPAL_API_PRICE=$_REQUEST["newamount"];
$EMAIL=$_REQUEST["EMAIL"];
$urlok='';
$urlko='';
$urlok=$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/paymentok.php';
$urlko=$urlwithouturlroot.DOL_URL_ROOT.'/public/paypal/paymentko.php';
$TAG=$_REQUEST["newtag"];
$ID=$_REQUEST["id"];
$mesg='';
if (empty($PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount"));
if (empty($PAYPAL_API_PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount"));
elseif (empty($EMAIL)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail"));
elseif (! isValidEMail($EMAIL)) $mesg=$langs->trans("ErrorBadEMail",$EMAIL);
elseif (empty($TAG)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode"));
if (empty($mesg))
{
print_paypal_redirect($PRICE, $conf->monnaie, $EMAIL, $urlok, $urlko, $TAG, $ID);
session_destroy();
//print_paypal_redirect($PAYPAL_API_PRICE, $conf->monnaie, $EMAIL, $urlok, $urlko, $TAG, $ID);
/*global $conf, $langs, $db;
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
global $PAYPAL_API_DEVISE, $PAYPAL_API_OK, $PAYPAL_API_KO;
global $PAYPAL_API_SANDBOX;
*/
dol_syslog("newpayment.php call paypal api and do redirect", LOG_DEBUG);
// Clean parameters
$PAYPAL_API_USER="";
if ($conf->global->PAYPAL_API_USER) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
$PAYPAL_API_PASSWORD="";
if ($conf->global->PAYPAL_API_PASSWORD) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
$PAYPAL_API_SIGNATURE="";
if ($conf->global->PAYPAL_API_SIGNATURE) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
$PAYPAL_API_SANDBOX="";
if ($conf->global->PAYPAL_API_SANDBOX) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
$PAYPAL_API_OK="";
if ($urlok) $PAYPAL_API_OK=$urlok;
$PAYPAL_API_KO="";
if ($urlko) $PAYPAL_API_KO=$urlko;
if (empty($PAYPAL_API_USER))
{
dol_print_error('',"Paypal setup param PAYPAL_API_USER not defined");
return -1;
}
if (empty($PAYPAL_API_PASSWORD))
{
dol_print_error('',"Paypal setup param PAYPAL_API_PASSWORD not defined");
return -1;
}
if (empty($PAYPAL_API_SIGNATURE))
{
dol_print_error('',"Paypal setup param PAYPAL_API_SIGNATURE not defined");
return -1;
}
// Other
$PAYPAL_API_DEVISE="EUR";
if ($CURRENCY == 'EUR') $PAYPAL_API_DEVISE="EUR";
if ($CURRENCY == 'USD') $PAYPAL_API_DEVISE="USD";
dol_syslog("Soumission Paypal", LOG_DEBUG);
dol_syslog("PAYPAL_API_USER: $PAYPAL_API_USER", LOG_DEBUG);
dol_syslog("PAYPAL_API_PASSWORD: $PAYPAL_API_PASSWORD", LOG_DEBUG);
dol_syslog("PAYPAL_API_SIGNATURE: $PAYPAL_API_SIGNATURE", LOG_DEBUG);
dol_syslog("PAYPAL_API_SANDBOX: $PAYPAL_API_SANDBOX", LOG_DEBUG);
dol_syslog("PAYPAL_API_OK: $PAYPAL_API_OK", LOG_DEBUG);
dol_syslog("PAYPAL_API_KO: $PAYPAL_API_KO", LOG_DEBUG);
dol_syslog("PAYPAL_API_PRICE: $PAYPAL_API_PRICE", LOG_DEBUG);
dol_syslog("PAYPAL_API_DEVISE: $PAYPAL_API_DEVISE", LOG_DEBUG);
header("Content-type: text/html; charset=".$conf->file->character_set_client);
print '<html>'."\n";
print '<head>'."\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=".$conf->file->character_set_client."\">\n";
print '</head>'."\n";
print '<body>'."\n";
print "\n";
$_SESSION["Payment_Amount"]=$PAYPAL_API_PRICE;
// A redirect is added if API call successfull
require_once(DOL_DOCUMENT_ROOT."/paypal/expresscheckout.php");
// Formulaire pour module Paybox
// print '<form action="'.$URLPAYBOX.'" NAME="Submit" method="POST">'."\n";
//print "
//<form action='".DOL_URL_ROOT."/paypal/expresscheckout.php' METHOD='POST' NAME='Submit'>
//<input type='image' name='submit' src='https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif' border='0' align='top' alt='Check out with PayPal'/>
//</form>";
// print '</form>'."\n";
// print "\n";
// print '<script type="text/javascript" language="javascript">'."\n";
// print ' document.Submit.submit();'."\n";
// print '</script>'."\n";
// print "\n";
print '</body></html>'."\n";
print "\n";
exit;
}
}
@ -191,7 +281,7 @@ $var=false;
// Free payment
if (is_numeric($_REQUEST["amount"]))
if (empty($_REQUEST["source"]))
{
$found=true;
$tag=$_REQUEST["tag"];
@ -212,8 +302,9 @@ if (is_numeric($_REQUEST["amount"]))
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
@ -233,7 +324,7 @@ if (is_numeric($_REQUEST["amount"]))
// Payment on customer order
if ($_REQUEST["amount"] == 'order')
if ($_REQUEST["source"] == 'order')
{
$found=true;
$langs->load("orders");
@ -253,6 +344,7 @@ if ($_REQUEST["amount"] == 'order')
}
$amount=$order->total_ttc;
if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"];
$newtag='IR='.$order->ref.'.TPID='.$order->client->id.'.TP='.strtr($order->client->nom,"-"," ");
if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; }
@ -286,8 +378,9 @@ if ($_REQUEST["amount"] == 'order')
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
@ -307,7 +400,7 @@ if ($_REQUEST["amount"] == 'order')
// Payment on customer invoice
if ($_REQUEST["amount"] == 'invoice')
if ($_REQUEST["source"] == 'invoice')
{
$found=true;
$langs->load("bills");
@ -327,6 +420,7 @@ if ($_REQUEST["amount"] == 'invoice')
}
$amount=$invoice->total_ttc - $invoice->getSommePaiement();
if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"];
$newtag='IR='.$invoice->ref.'.TPID='.$invoice->client->id.'.TP='.strtr($invoice->client->nom,"-"," ");
if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; }
@ -360,8 +454,9 @@ if ($_REQUEST["amount"] == 'invoice')
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
@ -380,7 +475,7 @@ if ($_REQUEST["amount"] == 'invoice')
}
// Payment on contract line
if ($_REQUEST["amount"] == 'contractline')
if ($_REQUEST["source"] == 'contractline')
{
$found=true;
$langs->load("contracts");
@ -444,6 +539,7 @@ if ($_REQUEST["amount"] == 'contractline')
exit;
}
}
if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"];
$newtag='CLR='.$contractline->ref.'.CR='.$contract->ref.'.TPID='.$contract->client->id.'.TP='.strtr($contract->client->nom,"-"," ");
if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; }
@ -522,8 +618,9 @@ if ($_REQUEST["amount"] == 'contractline')
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
@ -543,7 +640,7 @@ if ($_REQUEST["amount"] == 'contractline')
}
// Payment on member subscription
if ($_REQUEST["amount"] == 'membersubscription')
if ($_REQUEST["source"] == 'membersubscription')
{
$found=true;
$langs->load("members");
@ -564,6 +661,7 @@ if ($_REQUEST["amount"] == 'membersubscription')
}
$amount=$subscription->total_ttc;
if ($_REQUEST["amount"]) $amount=$_REQUEST["amount"];
$newtag='MID='.$member->id.'.M='.strtr($member->getFullName($langs),"-"," ");
if (! empty($_REQUEST["tag"])) { $tag=$_REQUEST["tag"]; $newtag.='.TAG='.$_REQUEST["tag"]; }
@ -597,8 +695,9 @@ if ($_REQUEST["amount"] == 'membersubscription')
print '<b>'.price($amount).'</b>';
print '<input type="hidden" name="newamount" value="'.$amount.'">';
}
print ' <b>'.$langs->trans("Currency".$conf->monnaie).'</b>';
print '<input type="hidden" name="currency" value="'.$conf->monnaie.'">';
// Currency
print ' <b>'.$langs->trans("Currency".$currency).'</b>';
print '<input type="hidden" name="currency" value="'.$currency.'">';
print '</td></tr>'."\n";
// Tag
@ -627,8 +726,16 @@ print '</table>';
if ($found && ! $error) // We are in a management option and no error
{
print '<br><input class="button" type="submit" name="dopayment" value="'.$langs->trans("PayBoxDoPayment").'">';
//print '<tr><td align="center" colspan="2">'.$langs->trans("YouWillBeRedirectedOnPayBox").'...</td></tr>';
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" value="'.$langs->trans("PaypalOrCBDoPayment").'">';
}
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
{
print '<br><input class="button" type="submit" name="dopayment" value="'.$langs->trans("PaypalDoPayment").'">';
}
}
else
{