Online Book Reader

Home Category

PayPal APIs_ Up and Running_ A Developer's Guide - Michael Balderas [16]

By Root 166 0
$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 associative 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();

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);

//converting 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

* then will decode the response.

* It is useful to search for a particular key and display the arrays.

* @nvpstr is NVPString.

* @nvpArray is Associative Array.

----------------------------------------------------------------------------------

*/

function deformatNVP($nvpstr)

{

$intial=0;

$nvpArray = array();

while(strlen($nvpstr))

Return Main Page Previous Page Next Page

®Online Book Reader