title: Paypal NVP with php error
body: <p>I am trying to get up and running using Paypal's NVP interface for my website to process my custom cart. I've downloaded their sample code (<a href="https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&amp;content_ID=developer/library_download_sdks" rel="nofollow">here</a>) and have tried to run unaltered  without success. Any function I choose (e.g. express checkout sale) gives the curl_errno() error: <strong>Error Number: 3 Error Message: No URL set!</strong>  I have tried this both on localhost and on my hosted site.</p>
  
  <p>hash_call() is the function processing the call to Paypal. The code which calls hash_call() is also included below.Their code that sets urls is:</p>
  
  <p>$returnURL =urlencode($url.'/ReviewOrder.php?currencyCodeType='.$currencyCodeType.'&amp;paymentType='.$paymentType);</p>
  
  <p>$cancelURL =urlencode("$url/SetExpressCheckout.php?paymentType=$paymentType" );</p>
  
  <p>I thought the cancelURL line looked off and modified it to:</p>
  
  <p>$cancelURL =urlencode($url.'/SetExpressCheckout.php?paymentType='.$paymentType );</p>
  
  <p>Neither have worked. Any help would be appreciated. I've never worked with curl.</p>
  
  <pre><code>require_once 'CallerService.php';
  session_start();
      if(! isset($_REQUEST['token'])) {
  
              /* The servername and serverport tells PayPal where the buyer
                 should be directed back to after authorizing payment.
                 In this case, its the local webserver that is running this script
                 Using the servername and serverport, the return URL is the first
                 portion of the URL that buyers will return to after authorizing payment
                 */
                 $serverName = $_SERVER['SERVER_NAME'];
                 $serverPort = $_SERVER['SERVER_PORT'];
                 $url=dirname('http://'.$serverName.':'.$serverPort.$_SERVER['REQUEST_URI']);
  
  
                 $currencyCodeType=$_REQUEST['currencyCodeType'];
                 $paymentType=$_REQUEST['paymentType'];
  
  
                 $personName        = $_REQUEST['PERSONNAME'];
                 $SHIPTOSTREET      = $_REQUEST['SHIPTOSTREET'];
                 $SHIPTOCITY        = $_REQUEST['SHIPTOCITY'];
                 $SHIPTOSTATE       = $_REQUEST['SHIPTOSTATE'];
                 $SHIPTOCOUNTRYCODE = $_REQUEST['SHIPTOCOUNTRYCODE'];
                 $SHIPTOZIP         = $_REQUEST['SHIPTOZIP'];
                 $L_NAME0           = $_REQUEST['L_NAME0'];
                 $L_AMT0            = $_REQUEST['L_AMT0'];
                 $L_QTY0            = $_REQUEST['L_QTY0'];
                 $L_NAME1           = $_REQUEST['L_NAME1'];
                 $L_AMT1            = $_REQUEST['L_AMT1'];
                 $L_QTY1            = $_REQUEST['L_QTY1'];
  
  
  
               /* The returnURL is the location where buyers return when a
                  payment has been succesfully authorized.
                  The cancelURL is the location buyers are sent to when they hit the
                  cancel button during authorization of payment during the PayPal flow
                  */
  
                 $returnURL =urlencode($url.'/ReviewOrder.php?currencyCodeType='.$currencyCodeType.'&amp;paymentType='.$paymentType);
                 $cancelURL =urlencode($url.'/SetExpressCheckout.php?paymentType='.$paymentType );
  
               /* Construct the parameter string that describes the PayPal payment
                  the varialbes were set in the web form, and the resulting string
                  is stored in $nvpstr
                  */
                 $itemamt = 0.00;
                 $itemamt = $L_QTY0*$L_AMT0+$L_AMT1*$L_QTY1;
                 $amt = 5.00+2.00+1.00+$itemamt;
                 $maxamt= $amt+25.00;
                 $nvpstr="";
  
                 /*
                  * Setting up the Shipping address details
                  */
                 $shiptoAddress = "&amp;SHIPTONAME=$personName&amp;SHIPTOSTREET=$SHIPTOSTREET&amp;SHIPTOCITY=$SHIPTOCITY&amp;SHIPTOSTATE=$SHIPTOSTATE&amp;SHIPTOCOUNTRYCODE=$SHIPTOCOUNTRYCODE&amp;SHIPTOZIP=$SHIPTOZIP";
  
                 $nvpstr="&amp;ADDRESSOVERRIDE=1$shiptoAddress&amp;L_NAME0=".$L_NAME0."&amp;L_NAME1=".$L_NAME1."&amp;L_AMT0=".$L_AMT0."&amp;L_AMT1=".$L_AMT1."&amp;L_QTY0=".$L_QTY0."&amp;L_QTY1=".$L_QTY1."&amp;MAXAMT=".(string)$maxamt."&amp;AMT=".(string)$amt."&amp;ITEMAMT=".(string)$itemamt."&amp;CALLBACKTIMEOUT=4&amp;L_SHIPPINGOPTIONAMOUNT1=8.00&amp;L_SHIPPINGOPTIONlABEL1=UPS Next Day Air&amp;L_SHIPPINGOPTIONNAME1=UPS Air&amp;L_SHIPPINGOPTIONISDEFAULT1=true&amp;L_SHIPPINGOPTIONAMOUNT0=3.00&amp;L_SHIPPINGOPTIONLABEL0=UPS Ground 7 Days&amp;L_SHIPPINGOPTIONNAME0=Ground&amp;L_SHIPPINGOPTIONISDEFAULT0=false&amp;INSURANCEAMT=1.00&amp;INSURANCEOPTIONOFFERED=true&amp;CALLBACK=https://www.ppcallback.com/callback.pl&amp;SHIPPINGAMT=8.00&amp;SHIPDISCAMT=-3.00&amp;TAXAMT=2.00&amp;L_NUMBER0=1000&amp;L_DESC0=Size: 8.8-oz&amp;L_NUMBER1=10001&amp;L_DESC1=Size: Two 24-piece boxes&amp;L_ITEMWEIGHTVALUE1=0.5&amp;L_ITEMWEIGHTUNIT1=lbs&amp;ReturnUrl=".$returnURL."&amp;CANCELURL=".$cancelURL ."&amp;CURRENCYCODE=".$currencyCodeType."&amp;PAYMENTACTION=".$paymentType;
  
  
  
                  /* Make the call to PayPal to set the Express Checkout token
                  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);
  
  ********************************************************************************* 
  
  
         /**
            * 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, $subject, $AUTH_token,$AUTH_signature,$AUTH_timestamp;
              // form header string
              $nvpheader=nvpHeader();
              //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, TRUE);
              curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, TRUE);
  
              curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
              curl_setopt($ch, CURLOPT_POST, 1);
  
  
  
          //WARNING: this would prevent curl from detecting a 'man in the middle' attack
              $ch = curl_init();
          //curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
          //curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
  
  
  
          curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
          curl_setopt ($ch, CURLOPT_CAINFO, "c:/xampp/apache/cacert.pem");        
  
  
              //in case of permission APIs send headers as HTTPheders
              if(!empty($AUTH_token) &amp;&amp; !empty($AUTH_signature) &amp;&amp; !empty($AUTH_timestamp))
               {
                  $headers_array[] = "X-PP-AUTHORIZATION: ".$nvpheader;
  
              curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_array);
              curl_setopt($ch, CURLOPT_HEADER, false);
              }
              else 
              {
                  $nvpStr=$nvpheader.$nvpStr;
              }
              //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); 
  
              //check if version is included in $nvpStr else include the version.
              if(strlen(str_replace('VERSION=', '', strtoupper($nvpStr))) == strlen($nvpStr)) {
                  $nvpStr = "&amp;VERSION=" . urlencode($version) . $nvpStr;  
              }
  
              $nvpreq="METHOD=".urlencode($methodName).$nvpStr;
  
              //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);
                    $location = "APIError.php";
                    header("Location: $location");
               } else {
                   //closing the curl
                      curl_close($ch);
                }
  
          return $nvpResArray;
          }
  </code></pre>