2011-12-16 9 views
0

私は自分のカートを処理するために私のウェブサイトのためにPaypalのNVPインターフェースを使って立ち上げようとしています。私はサンプルコード(here)をダウンロードし、成功していても変更なしで実行しようとしました。 エラー番号:3エラーメッセージ:URLが設定されていません!私はlocalhostと私のホストされたサイトの両方でこれを試しました。Paypal NVP with PHP error

hash_call()は、Paypalへの呼び出しを処理する関数です。 hash_callを呼び出すコードは()もURLを設定しますbelow.Theirコードが含まれます:

$にreturnurl =でurlencode($のURL '/ ReviewOrder.php currencyCodeType =?' $ currencyCodeType '& paymentType ='。。。。 $ paymentType);

$ cancelURL = urlencode( "$ url/SetExpressCheckout.php?paymentType = $ paymentType");

私はcancelURLラインがオフに見て、それを修正考えた:

$ cancelURL =でurlencode(。。$ URL '?/ SetExpressCheckout.php paymentType =' $ paymentType)。

いずれも機能しませんでした。どんな助けもありがとう。私はカールで働いたことがない。

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.'&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 = "&SHIPTONAME=$personName&SHIPTOSTREET=$SHIPTOSTREET&SHIPTOCITY=$SHIPTOCITY&SHIPTOSTATE=$SHIPTOSTATE&SHIPTOCOUNTRYCODE=$SHIPTOCOUNTRYCODE&SHIPTOZIP=$SHIPTOZIP"; 

       $nvpstr="&ADDRESSOVERRIDE=1$shiptoAddress&L_NAME0=".$L_NAME0."&L_NAME1=".$L_NAME1."&L_AMT0=".$L_AMT0."&L_AMT1=".$L_AMT1."&L_QTY0=".$L_QTY0."&L_QTY1=".$L_QTY1."&MAXAMT=".(string)$maxamt."&AMT=".(string)$amt."&ITEMAMT=".(string)$itemamt."&CALLBACKTIMEOUT=4&L_SHIPPINGOPTIONAMOUNT1=8.00&L_SHIPPINGOPTIONlABEL1=UPS Next Day Air&L_SHIPPINGOPTIONNAME1=UPS Air&L_SHIPPINGOPTIONISDEFAULT1=true&L_SHIPPINGOPTIONAMOUNT0=3.00&L_SHIPPINGOPTIONLABEL0=UPS Ground 7 Days&L_SHIPPINGOPTIONNAME0=Ground&L_SHIPPINGOPTIONISDEFAULT0=false&INSURANCEAMT=1.00&INSURANCEOPTIONOFFERED=true&CALLBACK=https://www.ppcallback.com/callback.pl&SHIPPINGAMT=8.00&SHIPDISCAMT=-3.00&TAXAMT=2.00&L_NUMBER0=1000&L_DESC0=Size: 8.8-oz&L_NUMBER1=10001&L_DESC1=Size: Two 24-piece boxes&L_ITEMWEIGHTVALUE1=0.5&L_ITEMWEIGHTUNIT1=lbs&ReturnUrl=".$returnURL."&CANCELURL=".$cancelURL ."&CURRENCYCODE=".$currencyCodeType."&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) && !empty($AUTH_signature) && !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 = "&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; 
     } 

答えて

-2

、このクラスを試してみてください

<?php 
class ZC_Paypal 
{  

     public $API_USERNAME; 
    public $API_PASSWORD;  
    public $API_SIGNATURE='xxxxxxxxxxxxxxxxxxxxxxxxxxxx'; 
    public $API_ENDPOINT; 
    public $USE_PROXY; 
    public $PROXY_HOST; 
    public $PROXY_PORT; 
    public $PAYPAL_URL; 
    public $VERSION; 
    public $NVP_HEADER; 

     public $SSLCERTPATH; 
    function __construct($PROXY_HOST, $PROXY_PORT, $IS_ONLINE = FALSE, $USE_PROXY = FALSE, $VERSION = '51.0', $api_url) 
    { 
     /*$this->API_USERNAME = $API_USERNAME; 
     $this->API_PASSWORD = $API_PASSWORD; 
     $this->API_SIGNATURE = $API_SIGNATURE;*/ 

       //$this->API_ENDPOINT = 'https://api-3t.sandbox.paypal.com/nvp'; 
       $this->API_ENDPOINT = $api_url; 
     $this->USE_PROXY = $USE_PROXY; 
     if($this->USE_PROXY == true) 
     { 
      $this->PROXY_HOST = $PROXY_HOST; 
      $this->PROXY_PORT = $PROXY_PORT; 
     } 
     else 
     { 
      $this->PROXY_HOST = '127.0.0.1'; 
      $this->PROXY_PORT = '808'; 
     } 
     if($IS_ONLINE == FALSE) 
     { 
      $this->PAYPAL_URL = 'https://api-3t.sandbox.paypal.com/nvp'; 
     } 
     else 
     { 
      $this->PAYPAL_URL = 'https://api-3t.paypal.com/nvp'; 
     } 
     $this->VERSION = $VERSION; 
    } 

    function hash_call($methodName,$nvpStr,$uname,$pwd,$api_url,$sslcerpath) 
    { 
       $this->API_ENDPOINT = $api_url; 
       $this->API_PASSWORD = $pwd; 
       $this->API_USERNAME = $uname; 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL,$this->API_ENDPOINT); 
       //curl_setopt($ch, CURLOPT_SSLCERT, $sslcerpath); 
     curl_setopt($ch, CURLOPT_VERBOSE, 1); 
     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($this->USE_PROXY) 
     { 
      curl_setopt ($ch, CURLOPT_PROXY, $this->PROXY_HOST.":".$this->PROXY_PORT); 
     } 

     $nvpreq="METHOD=".urlencode($methodName)."&VERSION=".urlencode($this->VERSION)."&PWD=".urlencode($this->API_PASSWORD)."&USER=".urlencode($this->API_USERNAME)."&SIGNATURE=".urlencode($this->API_SIGNATURE).$nvpStr; 
     curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq); 
     $response = curl_exec($ch); 
     $nvpResArray=$this->deformatNVP($response); 
     $nvpReqArray=$this->deformatNVP($nvpreq); 
     $_SESSION['nvpReqArray']=$nvpReqArray; 
     if (curl_errno($ch)) 
     { 
      die("CURL send a error during perform operation: ".curl_errno($ch)); 
     } 
     else 
     { 
      curl_close($ch); 
     } 

    return $nvpResArray; 
    } 

    function deformatNVP($nvpstr) 
    { 

     $intial=0; 
     $nvpArray = array(); 
     while(strlen($nvpstr)) 
     { 
      $keypos= strpos($nvpstr,'='); 
      $valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr); 
      $keyval=substr($nvpstr,$intial,$keypos); 
      $valval=substr($nvpstr,$keypos+1,$valuepos-$keypos-1); 
      $nvpArray[urldecode($keyval)] =urldecode($valval); 
      $nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr)); 
     } 
     return $nvpArray; 
    } 

    function __destruct() 
    { 

    } 
} 

とそれぞれの変数にパス資格、のようなクラスの上

.... 
     $currencyCode="USD"; 
     //$paymentAction = urlencode("Sale"); 
       $paymentAction = urlencode("Authorization"); 
     $nvpRecurring = ''; 
     $methodToCall = 'doDirectPayment'; 
         $nvpstr='&PAYMENTACTION='.$paymentAction.'&AMT='.$amount.'&CREDITCARDTYPE='.$creditCardType.'&ACCT='.$creditCardNumber.'&EXPDATE='.$padDateMonth.$expDateYear.'&CVV2='.$cvv2Number.'&FIRSTNAME='.$firstName.'&LASTNAME='.$lastName.'&STREET='.$address1.'&CITY='.$city.'&STATE='.$state.'&ZIP='.$zip.'&COUNTRYCODE='.$country.'&CURRENCYCODE='.$currencyCode.$nvpRecurring; 
     $paypalPro = new ZC_Paypal('', '', FALSE, FALSE,'51.0',Zend_Registry::get("admin_paypal_pro_url")); 
       $resArray = $paypalPro->hash_call($methodToCall,$nvpstr,Zend_Registry::get("admin_paypal_user_name"), Zend_Registry::get("admin_paypal_password"),Zend_Registry::get("admin_paypal_pro_url"),Zend_Registry::get("admin_paypal_ssl_path")); 
     $ack = strtoupper($resArray["ACK"]); 

     //echo '<pre>'; print_r($resArray); exit; 
     if($ack!="SUCCESS") 
     { 
      if(!in_array($resArray["L_LONGMESSAGE0"], array('Internal Error', 'CURL send a error during perform operation: 6'))) 
       echo $resArray["L_LONGMESSAGE0"]; 
      else 
       echo 'Transaction Failed, Try again later.'; 
     } 
     else{ 
// if success ..... 
} 

を呼び出して、私はZendのを使用していますので、ここでコアPHPを使用してみてください。 ..

+0

金融アプリケーションのために 'CURLOPT_SSL_VERIFYPEER'や' CURLOPT_SSL_VERIFYHOST'を無効にすることさえ考えないでください。トランザクションはMITM攻撃に対して広く開いています。 – simpleigh

関連する問題