PayPal IPN验证回发到HTTPS升级特定类

时间:2017-12-22 22:20:56

标签: php paypal https postback paypal-ipn

我已成功使用以下PayPal网站付款专业版多年。我正在尝试升级它,以满足PayPal的IPN验证回传到HTTPS要求,但没有成功。这是班级:

class paypal_website_payment_pro
{
public $API_USERNAME;
public $API_PASSWORD;
public $API_SIGNATURE;
public $API_ENDPOINT;
public $USE_PROXY;
public $PROXY_HOST;
public $PROXY_PORT;
public $PAYPAL_URL;
public $VERSION;
public $NVP_HEADER;

function __construct($API_USERNAME, $API_PASSWORD, $API_SIGNATURE, $PROXY_HOST, $PROXY_PORT, $IS_ONLINE = TRUE, $USE_PROXY = FALSE, $VERSION = '57.0')
{
$this->API_USERNAME = $API_USERNAME;
$this->API_PASSWORD = $API_PASSWORD;
$this->API_SIGNATURE = $API_SIGNATURE;      
$this->API_ENDPOINT = 'https://api-3t.paypal.com/nvp';
$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://www.sandbox.paypal.com/webscr&cmd=_express-checkout&token=';
}
else
{
$this->PAYPAL_URL = 'https://www.paypal.com/webscr&cmd=_express-checkout&token=';
}
$this->VERSION = $VERSION;
}

function hash_call($methodName,$nvpStr)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$this->API_ENDPOINT);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
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);
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() 
{

}
}

以下是实际上的课程:

require_once("paypalprocess.php");
$nvpstr='&PAYMENTACTION='.$paymentAction.'&IPADDRESS='.$ip_address.'&DESC='.$item_name.'&AMT='.$amount.'&CREDITCARDTYPE='.$creditCardType.'&ACCT='.$creditCardNumber.'&EXPDATE='.         $padDateMonth.$expDateYear.'&CVV2='.$cvv2Number.'&FIRSTNAME='.$firstName.'&LASTNAME='.$lastName.'&STREET='.$address1.'&STREET2='.$address2.'&CITY='.$city.'&STATE='.$state.'&ZIP='.$zip.'&COUNTRYCODE='.$countrycode.'&INVNUM='.$app_idpp.'&CUSTOM=Credit Card&CURRENCYCODE='.$currencyCode.$nvpRecurring;

$paypal_website_payment_pro = new paypal_website_payment_pro(USERNAME, PASSWORD, PAYPALKEY, '', '', TRUE, FALSE );

$resArray = $paypal_website_payment_pro->hash_call($methodToCall,$nvpstr);

$ack = strtoupper($resArray["ACK"]);

if($ack!="SUCCESS")
{
// error stuff
}
else
{
// success stuff
}

我尝试将API_ENDPOINT更改为:https://ipnpb.paypal.com/cgi-bin/webscr并添加了必要的curl_setopt参数(参见下文)。 PayPal说我还需要回发到HTTPS。你能告诉我我做错了什么吗?

更新了课程:

<?php
class paypal_website_payment_pro
{
public $API_USERNAME;
public $API_PASSWORD;
public $API_SIGNATURE;
public $API_ENDPOINT;
public $USE_PROXY;
public $PROXY_HOST;
public $PROXY_PORT;
public $PAYPAL_URL;
public $VERSION;
public $NVP_HEADER;

function __construct($API_USERNAME, $API_PASSWORD, $API_SIGNATURE, $PROXY_HOST, $PROXY_PORT, $IS_ONLINE = TRUE, $USE_PROXY = FALSE, $VERSION = '57.0')
{
$this->API_USERNAME = $API_USERNAME;
$this->API_PASSWORD = $API_PASSWORD;
$this->API_SIGNATURE = $API_SIGNATURE;      
$this->API_ENDPOINT = 'https://ipnpb.paypal.com/cgi-bin/webscr';
$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://ipnpb.sandbox.paypal.com/cgi-bin/webscr&cmd=_express-checkout&token=';
}
else
{
$this->PAYPAL_URL = 'https://ipnpb.paypal.com/cgi-bin/webscr&cmd=_express-checkout&token=';
}
$this->VERSION = $VERSION;
}

function hash_call($methodName,$nvpStr)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_URL,$this->API_ENDPOINT);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
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);
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() 
{

}
}

0 个答案:

没有答案