paypal快速结帐问题

发布于 2024-10-09 00:30:11 字数 4920 浏览 0 评论 0原文

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

,我无法理解发生了什么问题。请帮忙。

Hi I am integrating paypal with my website. I want that user enter their all information on my site (creditcard information and personal information).

I have down loded paypalfunctions.php from paypal developer website.

My code is :-

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 method is in paypalFunctions.php and this is

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;
 }


    }
    ?>

it gives error

         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
)

i cant understand what is problem is going on.Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水晶透心 2024-10-16 00:30:11

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

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

  2. 转到应用程序

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

如果没有,您应该能够使用“创建帐户”按钮创建一种类型的业务。

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

如果您在使用沙盒 URL 时不使用沙盒帐户的凭据,则可能会收到此 10002 安全错误,代码无效。

Here are a few things to need to worry about as well:

  1. Login to the developer site:
    https://developer.paypal.com/

  2. Go to Applications

  3. On the left side, hit "Sandbox Accounts"

You should be able to create one of type BUSINESS right there with the "Create Account" button if there isn't one.

  1. Click on the account, choose "Profile", make sure the account is the BUSINESS kind.
  2. The API Credentials tab will the display the username/password/signature you want to use.

If you don't use the credentials of a sandbox account when using the sandbox url, you are likely to get this 10002 Security error not valid code.

感情旳空白 2024-10-16 00:30:11

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

如果您正在进行沙箱测试,
确保调用的端点为: https://api-3t.sandbox.paypal.com/ NVP
-- 指向“沙盒”

Have configure your API credentials correctly?
you can dump the hash_call out if needed.

If you are doing sandbox testing,
Make sure the endpoint of the call is: https://api-3t.sandbox.paypal.com/nvp
-- pointed to the 'SANDBOX'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文