【问题标题】:paypal express checkout problempaypal express 结账问题
【发布时间】:2011-05-28 15:49:57
【问题描述】:

您好,我正在将 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
)

我不明白发生了什么问题。请帮忙。

【问题讨论】:

标签: paypal


【解决方案1】:

还有一些需要担心的事情:

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

  2. 转到应用程序

  3. 在左侧,点击“沙盒帐户”

如果没有,您应该可以使用“创建帐户”按钮在此处创建一个 BUSINESS 类型。

  1. 点击帐号,选择“个人资料”,确保帐号为 BUSINESS 类型。
  2. API 凭据选项卡将显示您要使用的用户名/密码/签名。

如果您在使用沙盒 url 时未使用沙盒帐户的凭据,则可能会收到此 10002 Security error not valid code。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 你还必须配置全局 $API_Endpoint, $version, $API_UserName, $API_Password, $API_Signature;
    猜你喜欢
    • 2011-11-26
    • 2012-09-23
    • 2016-12-02
    • 2016-03-11
    • 2017-09-07
    • 2016-03-10
    • 2014-09-27
    • 2018-09-24
    • 2014-03-03
    相关资源
    最近更新 更多