paypal快速结账问题

时间:2010-12-21 06:20:39

标签: paypal

您好我正在将paypal与我的网站集成。我希望该用户在我的网站上输入他们的所有信息(信用卡信息和个人信息)。

我已经从paypal开发者网站上下载了自己的paypalfunctions.php。

我的代码是: -

if(isset($_POST['submitCard']))
{
 $firstName  =trim($_POST['firstName']);
 $lastName  =trim($_POST['lastName']);
 $street   =trim($_POST['street']);
 $city   =trim($_POST['city']);
 $state   =trim($_POST['state']);
 $zip   =trim($_POST['zip']);
 $countryCode =$_POST['country'];
 $currencyCode ='USD';
 $paymentType ='Sale';
 $paymentAmount =$_POST['productPrice'];
 $creditCardType =$_POST['cardType'];
 $creditCardNumber=$_POST['cardNo'];
 $expDate  ='122015';
 $cvv2   =$_POST['cvv'];
 $returnResult=DirectPayment( $paymentType, $paymentAmount, $creditCardType, $creditCardNumber,
        $expDate, $cvv2, $firstName, $lastName, $street, $city, $state, $zip, 
        $countryCode, $currencyCode );
 echo '<pre>';
     print_r($returnResult);

DirectPayment方法在paypalFunctions.php中,这是

function DirectPayment( $paymentType, $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 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;
  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);

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

     //Execute the Error handling module to display errors. 
  } 
  else 
  {
    //closing the curl
     curl_close($ch);
  }

  return $nvpResArray;
 }


    }
    ?>

它给出了错误

         Array
(
    [TIMESTAMP] => 2010-12-21T06:06:54Z
    [CORRELATIONID] => 1cafc53222e76
    [ACK] => Failure
    [VERSION] => 64
    [BUILD] => 1620725
    [L_ERRORCODE0] => 10002
    [L_SHORTMESSAGE0] => Security error
    [L_LONGMESSAGE0] => Security header is not valid
    [L_SEVERITYCODE0] => Error
)

我无法理解正在发生什么问题。请帮助。

2 个答案:

答案 0 :(得分:1)

以下是一些需要担心的事情:

  1. 登录开发者网站: https://developer.paypal.com/

  2. 转到应用程序

  3. 在左侧,点击“沙盒帐户”
  4. 如果没有“创建帐户”按钮,您应该可以在那里创建一种类型的商家。

    1. 点击该帐户,选择“个人资料”,确保该帐户为商家类型。
    2. “API凭据”选项卡将显示您要使用的用户名/密码/签名。
    3. 如果您在使用沙盒网址时未使用沙盒帐户的凭据,则可能会出现此10002安全错误无效的代码。

答案 1 :(得分:0)

是否正确配置了您的API凭据? 如果需要,你可以将hash_call转储出来。

如果您正在进行沙盒测试, 确保呼叫的端点是:https://api-3t.sandbox.paypal.com/nvp - 指向'SANDBOX'