Qual: Removed dead code
This commit is contained in:
parent
15638b5758
commit
3b0b8b4559
@ -60,96 +60,6 @@ function llxFooterPaypal()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Create a redirect form to paypal form
|
||||
* \return int 1 if OK, -1 if ERROR
|
||||
*/
|
||||
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_paypal_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;
|
||||
|
||||
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";
|
||||
$PAYPAL_API_OK=$urlok;
|
||||
$PAYPAL_API_KO=$urlko;
|
||||
|
||||
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);
|
||||
|
||||
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"]=$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";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show footer of company in HTML pages
|
||||
@ -217,4 +127,416 @@ function html_print_paypal_footer($fromcompany,$langs)
|
||||
print '</font></center>'."\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Send redirect to paypal to browser
|
||||
* @param $paymentAmount
|
||||
* @param $currencyCodeType
|
||||
* @param $paymentType
|
||||
* @param $returnURL
|
||||
* @param $cancelURL
|
||||
* @param $tag
|
||||
*/
|
||||
function print_paypal_redirect($paymentAmount,$currencyCodeType,$paymentType,$returnURL,$cancelURL,$tag)
|
||||
{
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
global $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum;
|
||||
|
||||
//'------------------------------------
|
||||
//' Calls the SetExpressCheckout API call
|
||||
//'
|
||||
//'-------------------------------------------------
|
||||
|
||||
if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
|
||||
|
||||
$solutionType='Sole';
|
||||
$landingPage='Billing';
|
||||
// For payment with Paypal only
|
||||
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
|
||||
{
|
||||
$solutionType='Mark';
|
||||
$landingPage='Login';
|
||||
}
|
||||
// For payment with Credit card or Paypal
|
||||
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral')
|
||||
{
|
||||
$solutionType='Sole';
|
||||
$landingPage='Billing';
|
||||
}
|
||||
// For payment with Credit card
|
||||
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'cconly')
|
||||
{
|
||||
$solutionType='Sole';
|
||||
$landingPage='Billing';
|
||||
}
|
||||
|
||||
dol_syslog("expresscheckout redirect with CallSetExpressCheckout $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $landingPage, $solutionType, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum");
|
||||
$resArray = CallSetExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage,
|
||||
$shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum);
|
||||
/* For direct payment with credit card
|
||||
{
|
||||
//$resArray = DirectPayment (...);
|
||||
}
|
||||
*/
|
||||
|
||||
$ack = strtoupper($resArray["ACK"]);
|
||||
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
|
||||
{
|
||||
$token=$resArray["TOKEN"];
|
||||
|
||||
// Redirect to paypal.com here
|
||||
$payPalURL = $API_Url . $token;
|
||||
header("Location: ".$payPalURL);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
'-------------------------------------------------------------------------------------------------------------------------------------------
|
||||
' 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 CallSetExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage,
|
||||
$shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum)
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
|
||||
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
$nvpstr="&AMT=". urlencode($paymentAmount);
|
||||
$nvpstr = $nvpstr . "&PAYMENTACTION=" . urlencode($paymentType);
|
||||
$nvpstr = $nvpstr . "&RETURNURL=" . urlencode($returnURL);
|
||||
$nvpstr = $nvpstr . "&CANCELURL=" . urlencode($cancelURL);
|
||||
$nvpstr = $nvpstr . "&CURRENCYCODE=" . urlencode($currencyCodeType);
|
||||
$nvpstr = $nvpstr . "&ADDROVERRIDE=1";
|
||||
//$nvpstr = $nvpstr . "&ALLOWNOTE=0";
|
||||
$nvpstr = $nvpstr . "&SHIPTONAME=" . urlencode($shipToName);
|
||||
$nvpstr = $nvpstr . "&SHIPTOSTREET=" . urlencode($shipToStreet);
|
||||
$nvpstr = $nvpstr . "&SHIPTOSTREET2=" . urlencode($shipToStreet2);
|
||||
$nvpstr = $nvpstr . "&SHIPTOCITY=" . urlencode($shipToCity);
|
||||
$nvpstr = $nvpstr . "&SHIPTOSTATE=" . urlencode($shipToState);
|
||||
$nvpstr = $nvpstr . "&SHIPTOCOUNTRYCODE=" . urlencode($shipToCountryCode);
|
||||
$nvpstr = $nvpstr . "&SHIPTOZIP=" . urlencode($shipToZip);
|
||||
$nvpstr = $nvpstr . "&PHONENUM=" . urlencode($phoneNum);
|
||||
$nvpstr = $nvpstr . "&SOLUTIONTYPE=" . urlencode($solutionType);
|
||||
$nvpstr = $nvpstr . "&LANDINGPAGE=" . urlencode($landingPage);
|
||||
//$nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($tag);
|
||||
$nvpstr = $nvpstr . "&INVNUM=" . urlencode($tag);
|
||||
|
||||
|
||||
|
||||
$_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;
|
||||
$_SESSION['ipaddress']=$_SERVER['REMOTE_ADDR ']; // Payer ip
|
||||
}
|
||||
|
||||
return $resArray;
|
||||
}
|
||||
|
||||
/*
|
||||
'-------------------------------------------------------------------------------------------
|
||||
' Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call.
|
||||
'
|
||||
' Inputs:
|
||||
' None
|
||||
' Returns:
|
||||
' The NVP Collection object of the GetExpressCheckoutDetails Call Response.
|
||||
'-------------------------------------------------------------------------------------------
|
||||
*/
|
||||
function GetDetails( $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
|
||||
//'--------------------------------------------------------------
|
||||
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
//'---------------------------------------------------------------------------
|
||||
//' 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: Validate payment
|
||||
'--------------------------------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
function ConfirmPayment( $token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag )
|
||||
{
|
||||
/* Gather the information to make the final call to
|
||||
finalize the PayPal payment. The variable nvpstr
|
||||
holds the name value pairs
|
||||
*/
|
||||
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
$nvpstr = '&TOKEN=' . urlencode($token) . '&PAYERID=' . urlencode($payerID) . '&PAYMENTACTION=' . urlencode($paymentType) . '&AMT=' . urlencode($FinalPaymentAmt);
|
||||
$nvpstr .= '&CURRENCYCODE=' . urlencode($currencyCodeType) . '&IPADDRESS=' . urlencode($ipaddress);
|
||||
//$nvpstr .= '&CUSTOM=' . urlencode($tag);
|
||||
$nvpstr .= '&INVNUM=' . urlencode($tag);
|
||||
|
||||
/* 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, $tag )
|
||||
{
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
//Construct the parameter string that describes DoDirectPayment
|
||||
$nvpstr = "&AMT=" . urlencode($paymentAmount);
|
||||
$nvpstr = $nvpstr . "&CURRENCYCODE=" . urlencode($currencyCode);
|
||||
$nvpstr = $nvpstr . "&PAYMENTACTION=" . urlencode($paymentType);
|
||||
$nvpstr = $nvpstr . "&CREDITCARDTYPE=" . urlencode($creditCardType);
|
||||
$nvpstr = $nvpstr . "&ACCT=" . urlencode($creditCardNumber);
|
||||
$nvpstr = $nvpstr . "&EXPDATE=" . urlencode($expDate);
|
||||
$nvpstr = $nvpstr . "&CVV2=" . urlencode($cvv2);
|
||||
$nvpstr = $nvpstr . "&FIRSTNAME=" . urlencode($firstName);
|
||||
$nvpstr = $nvpstr . "&LASTNAME=" . urlencode($lastName);
|
||||
$nvpstr = $nvpstr . "&STREET=" . urlencode($street);
|
||||
$nvpstr = $nvpstr . "&CITY=" . urlencode($city);
|
||||
$nvpstr = $nvpstr . "&STATE=" . urlencode($state);
|
||||
$nvpstr = $nvpstr . "&COUNTRYCODE=" . urlencode($countryCode);
|
||||
$nvpstr = $nvpstr . "&IPADDRESS=" . $_SERVER['REMOTE_ADDR'];
|
||||
$nvpstr = $nvpstr . "&INVNUM=" . urlencode($tag);
|
||||
|
||||
$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 $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
dol_syslog("Paypal API endpoint ".$API_Endpoint);
|
||||
|
||||
//setting the curl parameters.
|
||||
$ch = curl_init();
|
||||
|
||||
/*print $API_Endpoint."-".$API_version."-".$PAYPAL_API_USER."-".$PAYPAL_API_PASSWORD."-".$PAYPAL_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($API_version) . "&PWD=" . urlencode($PAYPAL_API_PASSWORD) . "&USER=" . urlencode($PAYPAL_API_USER) . "&SIGNATURE=" . urlencode($PAYPAL_API_SIGNATURE) . $nvpStr . "&BUTTONSOURCE=" . urlencode($sBNCode);
|
||||
$nvpreq.="&LOCALE=".strtoupper($langs->getDefaultLang(1));
|
||||
//$nvpreq.="&BRANDNAME=".urlencode(); // Override merchant name
|
||||
//$nvpreq.="&NOTIFYURL=".urlencode(); // For Instant Payment Notification url
|
||||
|
||||
|
||||
dol_syslog("Paypal API Request nvpreq=".$nvpreq);
|
||||
|
||||
//setting the nvpreq as POST FIELD to curl
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
|
||||
|
||||
//getting response from server
|
||||
$response = curl_exec($ch);
|
||||
|
||||
$nvpReqArray=deformatNVP($nvpreq);
|
||||
$_SESSION['nvpReqArray']=$nvpReqArray;
|
||||
|
||||
//convrting NVPResponse to an Associative Array
|
||||
dol_syslog("Paypal API Response nvpresp=".$response);
|
||||
$nvpResArray=deformatNVP($response);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*'----------------------------------------------------------------------------------
|
||||
* 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;
|
||||
}
|
||||
|
||||
?>
|
||||
@ -18,16 +18,7 @@
|
||||
|
||||
/** \file htdocs/paypal/lib/paypalfunctions.lib.php
|
||||
* \ingroup paypal
|
||||
* \brief Page with Paypal functions.
|
||||
* Must be included where global variables are set:
|
||||
* $PAYPAL_API_SANDBOX
|
||||
* $PAYPAL_API_USER
|
||||
* $PAYPAL_API_PASSWORD
|
||||
* $PAYPAL_API_SIGNATURE
|
||||
* $PAYPAL_AMT
|
||||
* $PAYPAL_API_DEVISE
|
||||
* $PAYPAL_API_OK
|
||||
* $PAYPAL_API_KO
|
||||
* \brief Page with Paypal init var.
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
@ -67,410 +58,4 @@ $USE_PROXY = false;
|
||||
// BN Code is only applicable for partners
|
||||
$sBNCode = "PP-ECWizard";
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Send redirect to paypal to browser
|
||||
*/
|
||||
function RedirectToPaypal($paymentAmount,$currencyCodeType,$paymentType,$returnURL,$cancelURL,$tag)
|
||||
{
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
global $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum;
|
||||
|
||||
//'------------------------------------
|
||||
//' Calls the SetExpressCheckout API call
|
||||
//'
|
||||
//'-------------------------------------------------
|
||||
|
||||
if (empty($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY)) $conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY='integral';
|
||||
|
||||
$solutionType='Sole';
|
||||
$landingPage='Billing';
|
||||
// For payment with Paypal only
|
||||
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'paypalonly')
|
||||
{
|
||||
$solutionType='Mark';
|
||||
$landingPage='Login';
|
||||
}
|
||||
// For payment with Credit card or Paypal
|
||||
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'integral')
|
||||
{
|
||||
$solutionType='Sole';
|
||||
$landingPage='Billing';
|
||||
}
|
||||
// For payment with Credit card
|
||||
if ($conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY == 'cconly')
|
||||
{
|
||||
$solutionType='Sole';
|
||||
$landingPage='Billing';
|
||||
}
|
||||
|
||||
dol_syslog("expresscheckout redirect with CallSetExpressCheckout $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $landingPage, $solutionType, $shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum");
|
||||
$resArray = CallSetExpressCheckout ($paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage,
|
||||
$shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum);
|
||||
/* For direct payment with credit card
|
||||
{
|
||||
//$resArray = DirectPayment (...);
|
||||
}
|
||||
*/
|
||||
|
||||
$ack = strtoupper($resArray["ACK"]);
|
||||
if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
|
||||
{
|
||||
$token=$resArray["TOKEN"];
|
||||
|
||||
// Redirect to paypal.com here
|
||||
$payPalURL = $API_Url . $token;
|
||||
header("Location: ".$payPalURL);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
'-------------------------------------------------------------------------------------------------------------------------------------------
|
||||
' 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 CallSetExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL, $tag, $solutionType, $landingPage,
|
||||
$shipToName, $shipToStreet, $shipToCity, $shipToState, $shipToCountryCode, $shipToZip, $shipToStreet2, $phoneNum)
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Construct the parameter string that describes the SetExpressCheckout API call in the shortcut implementation
|
||||
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
$nvpstr="&AMT=". urlencode($paymentAmount);
|
||||
$nvpstr = $nvpstr . "&PAYMENTACTION=" . urlencode($paymentType);
|
||||
$nvpstr = $nvpstr . "&RETURNURL=" . urlencode($returnURL);
|
||||
$nvpstr = $nvpstr . "&CANCELURL=" . urlencode($cancelURL);
|
||||
$nvpstr = $nvpstr . "&CURRENCYCODE=" . urlencode($currencyCodeType);
|
||||
$nvpstr = $nvpstr . "&ADDROVERRIDE=1";
|
||||
//$nvpstr = $nvpstr . "&ALLOWNOTE=0";
|
||||
$nvpstr = $nvpstr . "&SHIPTONAME=" . urlencode($shipToName);
|
||||
$nvpstr = $nvpstr . "&SHIPTOSTREET=" . urlencode($shipToStreet);
|
||||
$nvpstr = $nvpstr . "&SHIPTOSTREET2=" . urlencode($shipToStreet2);
|
||||
$nvpstr = $nvpstr . "&SHIPTOCITY=" . urlencode($shipToCity);
|
||||
$nvpstr = $nvpstr . "&SHIPTOSTATE=" . urlencode($shipToState);
|
||||
$nvpstr = $nvpstr . "&SHIPTOCOUNTRYCODE=" . urlencode($shipToCountryCode);
|
||||
$nvpstr = $nvpstr . "&SHIPTOZIP=" . urlencode($shipToZip);
|
||||
$nvpstr = $nvpstr . "&PHONENUM=" . urlencode($phoneNum);
|
||||
$nvpstr = $nvpstr . "&SOLUTIONTYPE=" . urlencode($solutionType);
|
||||
$nvpstr = $nvpstr . "&LANDINGPAGE=" . urlencode($landingPage);
|
||||
//$nvpstr = $nvpstr . "&CUSTOMERSERVICENUMBER=" . urlencode($tag);
|
||||
$nvpstr = $nvpstr . "&INVNUM=" . urlencode($tag);
|
||||
|
||||
|
||||
|
||||
$_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;
|
||||
$_SESSION['ipaddress']=$_SERVER['REMOTE_ADDR ']; // Payer ip
|
||||
}
|
||||
|
||||
return $resArray;
|
||||
}
|
||||
|
||||
/*
|
||||
'-------------------------------------------------------------------------------------------
|
||||
' Purpose: Prepares the parameters for the GetExpressCheckoutDetails API Call.
|
||||
'
|
||||
' Inputs:
|
||||
' None
|
||||
' Returns:
|
||||
' The NVP Collection object of the GetExpressCheckoutDetails Call Response.
|
||||
'-------------------------------------------------------------------------------------------
|
||||
*/
|
||||
function GetDetails( $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
|
||||
//'--------------------------------------------------------------
|
||||
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
//'---------------------------------------------------------------------------
|
||||
//' 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: Validate payment
|
||||
'--------------------------------------------------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
function ConfirmPayment( $token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $tag )
|
||||
{
|
||||
/* Gather the information to make the final call to
|
||||
finalize the PayPal payment. The variable nvpstr
|
||||
holds the name value pairs
|
||||
*/
|
||||
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
$nvpstr = '&TOKEN=' . urlencode($token) . '&PAYERID=' . urlencode($payerID) . '&PAYMENTACTION=' . urlencode($paymentType) . '&AMT=' . urlencode($FinalPaymentAmt);
|
||||
$nvpstr .= '&CURRENCYCODE=' . urlencode($currencyCodeType) . '&IPADDRESS=' . urlencode($ipaddress);
|
||||
//$nvpstr .= '&CUSTOM=' . urlencode($tag);
|
||||
$nvpstr .= '&INVNUM=' . urlencode($tag);
|
||||
|
||||
/* 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, $tag )
|
||||
{
|
||||
//declaring of global variables
|
||||
global $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
//Construct the parameter string that describes DoDirectPayment
|
||||
$nvpstr = "&AMT=" . urlencode($paymentAmount);
|
||||
$nvpstr = $nvpstr . "&CURRENCYCODE=" . urlencode($currencyCode);
|
||||
$nvpstr = $nvpstr . "&PAYMENTACTION=" . urlencode($paymentType);
|
||||
$nvpstr = $nvpstr . "&CREDITCARDTYPE=" . urlencode($creditCardType);
|
||||
$nvpstr = $nvpstr . "&ACCT=" . urlencode($creditCardNumber);
|
||||
$nvpstr = $nvpstr . "&EXPDATE=" . urlencode($expDate);
|
||||
$nvpstr = $nvpstr . "&CVV2=" . urlencode($cvv2);
|
||||
$nvpstr = $nvpstr . "&FIRSTNAME=" . urlencode($firstName);
|
||||
$nvpstr = $nvpstr . "&LASTNAME=" . urlencode($lastName);
|
||||
$nvpstr = $nvpstr . "&STREET=" . urlencode($street);
|
||||
$nvpstr = $nvpstr . "&CITY=" . urlencode($city);
|
||||
$nvpstr = $nvpstr . "&STATE=" . urlencode($state);
|
||||
$nvpstr = $nvpstr . "&COUNTRYCODE=" . urlencode($countryCode);
|
||||
$nvpstr = $nvpstr . "&IPADDRESS=" . $_SERVER['REMOTE_ADDR'];
|
||||
$nvpstr = $nvpstr . "&INVNUM=" . urlencode($tag);
|
||||
|
||||
$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 $conf, $langs;
|
||||
global $API_Endpoint, $API_Url, $API_version, $USE_PROXY, $PROXY_HOST, $PROXY_PORT;
|
||||
global $PAYPAL_API_USER, $PAYPAL_API_PASSWORD, $PAYPAL_API_SIGNATURE;
|
||||
global $sBNCode;
|
||||
|
||||
dol_syslog("Paypal API endpoint ".$API_Endpoint);
|
||||
|
||||
//setting the curl parameters.
|
||||
$ch = curl_init();
|
||||
|
||||
/*print $API_Endpoint."-".$API_version."-".$PAYPAL_API_USER."-".$PAYPAL_API_PASSWORD."-".$PAYPAL_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($API_version) . "&PWD=" . urlencode($PAYPAL_API_PASSWORD) . "&USER=" . urlencode($PAYPAL_API_USER) . "&SIGNATURE=" . urlencode($PAYPAL_API_SIGNATURE) . $nvpStr . "&BUTTONSOURCE=" . urlencode($sBNCode);
|
||||
$nvpreq.="&LOCALE=".strtoupper($langs->getDefaultLang(1));
|
||||
//$nvpreq.="&BRANDNAME=".urlencode(); // Override merchant name
|
||||
//$nvpreq.="&NOTIFYURL=".urlencode(); // For Instant Payment Notification url
|
||||
|
||||
|
||||
dol_syslog("Paypal API Request nvpreq=".$nvpreq);
|
||||
|
||||
//setting the nvpreq as POST FIELD to curl
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
|
||||
|
||||
//getting response from server
|
||||
$response = curl_exec($ch);
|
||||
|
||||
$nvpReqArray=deformatNVP($nvpreq);
|
||||
$_SESSION['nvpReqArray']=$nvpReqArray;
|
||||
|
||||
//convrting NVPResponse to an Associative Array
|
||||
dol_syslog("Paypal API Response nvpresp=".$response);
|
||||
$nvpResArray=deformatNVP($response);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*'----------------------------------------------------------------------------------
|
||||
* 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;
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user