Thank you for your code snippet Aaron, but I’d really like to try and get what I had working rather than starting over again. I figured maybe I just couldn’t execute the curl from an file that I’m requiring like that, so I took all three files I’m using for the PayPal processing and combined them into one. Then, I put it into a code snippet which I call from the site and I’m still hitting the ’OR die’ on the curl_exec you’ll see below. Here is my entire code snippet:
<?php
#########################################
## BEGIN CONTENTS FROM constants.php ##
#########################################
/****************************************************
constants.php
This is the configuration file for the samples.This file
defines the parameters needed to make an API call.
PayPal includes the following API Signature for making API
calls to the PayPal sandbox:
API Username sdk-three_api1.sdk.com
API Password QFZCWN5HZM8VBG7Q
API Signature A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU
Called by CallerService.php.
****************************************************/
/**
# API user: The user that is identified as making the call. you can
# also use your own API username that you created on PayPalís sandbox
# or the PayPal live site
*/
define('API_USERNAME', '* PRIVATE *');
/**
# API_password: The password associated with the API user
# If you are using your own API username, enter the API password that
# was generated by PayPal below
# IMPORTANT - HAVING YOUR API PASSWORD INCLUDED IN THE MANNER IS NOT
# SECURE, AND ITS ONLY BEING SHOWN THIS WAY FOR TESTING PURPOSES
*/
define('API_PASSWORD', '* PRIVATE *');
/**
# API_Signature:The Signature associated with the API user. which is generated by paypal.
*/
define('API_SIGNATURE', '* PRIVATE *');
/**
# Endpoint: this is the server URL which you have to connect for submitting your API request.
*/
define('API_ENDPOINT', 'https://api-3t.paypal.com/nvp');
/**
USE_PROXY: Set this variable to TRUE to route all the API requests through proxy.
like define('USE_PROXY',TRUE);
*/
define('USE_PROXY',FALSE);
/**
PROXY_HOST: Set the host name or the IP address of proxy server.
PROXY_PORT: Set proxy port.
PROXY_HOST and PROXY_PORT will be read only if USE_PROXY is set to TRUE
*/
define('PROXY_HOST', '127.0.0.1');
define('PROXY_PORT', '808');
/* Define the PayPal URL. This is the URL that the buyer is
first sent to to authorize payment with their paypal account
change the URL depending if you are testing on the sandbox
or going to 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=
*/
define('PAYPAL_URL', 'https://www.paypal.com/webscr&cmd=_express-checkout&token=');
/**
# Version: this is the API version in the request.
# It is a mandatory parameter for each API request.
# The only supported value at this time is 2.3
*/
define('VERSION', '53.0');
#######################################
## END CONTENTS FROM constants.php ##
#######################################
#############################################
## BEGIN CONTENTS FROM CallerService.php ##
#############################################
/****************************************************
CallerService.php
This file uses the constants.php to get parameters needed
to make an API call and calls the server.if you want use your
own credentials, you have to change the constants.php
Called by TransactionDetails.php, ReviewOrder.php,
DoDirectPaymentReceipt.php and DoExpressCheckoutPayment.php.
****************************************************/
$API_UserName=API_USERNAME;
$API_Password=API_PASSWORD;
$API_Signature=API_SIGNATURE;
$API_Endpoint =API_ENDPOINT;
$version=VERSION;
//session_start();
/**
* 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,$nvp_Header;
//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;
//setting the nvpreq as POST FIELD to curl
curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);
//getting response from server
$response = curl_exec($ch) OR die ('Curl did not work... even from the snippet!');
//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);
$location = "/paypal/APIError.php";
header("Location: $location");
} 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;
}
###########################################
## END CONTENTS FROM CallerService.php ##
###########################################
/**
* Get required parameters from the web form for the request
*/
$paymentType = 'Sale';
$firstName =urlencode( $_SESSION['reg_first_name']);
$lastName =urlencode( $_SESSION['reg_last_name']);
$creditCardType =urlencode(decrypt($_SESSION['reg_cc_type'], $_SESSION['encryption_key']));
$creditCardNumber = urlencode(decrypt($_SESSION['reg_cc_number'], $_SESSION['encryption_key']));
$expDateMonth =urlencode(decrypt($_SESSION['reg_cc_exp_m'], $_SESSION['encryption_key']));
// Month must be padded with leading zero
$padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
$expDateYear =urlencode(decrypt($_SESSION['reg_cc_exp_y'], $_SESSION['encryption_key']));
$cvv2Number = urlencode(decrypt($_SESSION['reg_cc_cvv2'], $_SESSION['encryption_key']));
$address1 = urlencode($_SESSION['reg_address']);
$address2 = urlencode($_SESSION['reg_address_2']);
$city = urlencode($_SESSION['reg_city']);
$state =urlencode( $_SESSION['reg_state']);
$zip = urlencode($_SESSION['reg_zip']);
$email = urlencode($_SESSION['reg_email']);
$phone = urlencode($_SESSION['reg_phone']);
$amount = urlencode($_SESSION['reg_total_price']);
//$currencyCode=urlencode($_SESSION['currency']);
$currencyCode="USD";
/* Construct the request string that will be sent to PayPal.
The variable $nvpstr contains all the variables and is a
name value pair string with & as a delimiter */
$nvpstr="&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber&EXPDATE=". $padDateMonth.$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName&STREET=$address1&STREET2=$address2&CITY=$city&STATE=$state".
"&ZIP=$zip&COUNTRYCODE=US&CURRENCYCODE=$currencyCode&EMAIL=$email&PHONENUM=$phone";
/* Make the API call to PayPal, using API signature.
The API response is stored in an associative array called $resArray */
$resArray=hash_call("doDirectPayment",$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"]);
?>
Any ideas what I’m doing wrong??