我正在使用paypal自适应付款,我需要验证商店/卖家给出的paypal api的电子邮件地址,以便付款可以直接由客户存储。
我想检查一下,如果商店提供的电子邮件是有效的PayPal电子邮件地址,并且他/她已经注册了PayPal。
告诉我PayPal是否支持并允许应用程序访问。
并在php中给我示例代码
答案 0 :(得分:6)
是的,PayPal通过使用“GetVerifiedStatus”API支持此功能,您必须输入电子邮件地址,名字和姓氏作为必需参数,它将返回如下所示的响应:
Response:
responseEnvelope.timestamp: 2014-10-01T01%3A17%3A10.081-07%3A00
responseEnvelope.ack: Success
responseEnvelope.correlationId: ce5a28138ca78
responseEnvelope.build: 13068405
accountStatus: VERIFIED
userInfo.emailAddress: XXXXXXX
userInfo.accountType: BUSINESS
userInfo.accountId: XXXXXXXX
userInfo.name.salutation:
userInfo.name.firstName: Eshan+Business+Test
userInfo.name.middleName:
userInfo.name.lastName: Account
userInfo.name.suffix:
userInfo.businessName: Eshan+New+Business+Name
您可以使用以下php代码:
<?php
$url = trim("https://svcs.sandbox.paypal.com/AdaptiveAccounts/GetVerifiedStatus"); //set PayPal Endpoint to sandbox
//$url = trim("https://svcs.paypal.com/AdaptiveAccounts/GetVerifiedStatus"); //set PayPal Endpoint to Live
$API_UserName = "XXXXXXXXXXXXXXXXXXX"; //PayPal Test API Credentials, Replace it with live if in live mode
$API_Password = "XXXXXXXXXXXXXXXXXXX";
$API_Signature = "XXXXXXXXXXXXXXXXXX";
$API_AppID = "APP-80W284485P519543T"; //Default App ID for Sandbox, replace it with live id if in live mode
$API_RequestFormat = "NV";
$API_ResponseFormat = "NV";
//Create request payload
$bodyparams = array ( "requestEnvelope.errorLanguage" => "en_US",
"emailAddress" =>"put email address to check ",
"firstName" =>"XXXXX",
"lastName" =>"XXXXXX",
"matchCriteria" => "NAME"
);
// convert payload array into url encoded query string
$body_data = http_build_query($bodyparams, "", chr(38));
try
{
//create request and add headers
$params = array("http" => array(
"method" => "POST",
"content" => $body_data,
"header" => "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" .
"X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" .
"X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" .
"X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" .
"X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" .
"X-PAYPAL-RESPONSE-DATA-FORMAT:" . $API_ResponseFormat . "\r\n"
));
$ctx = stream_context_create($params); //create stream context
$fp = @fopen($url, "r", false, $ctx); //open the stream and send request
$response = stream_get_contents($fp); //get response
//check to see if stream is open
if ($response === false)
{
throw new Exception("php error message = " . "$php_errormsg");
}
fclose($fp); //close the stream
//parse the ap key from the response
$keyArray = explode("&", $response);
foreach ($keyArray as $rVal)
{
list($qKey, $qVal) = explode ("=", $rVal);
$kArray[$qKey] = $qVal;
}
//print the request to screen for testing purposes
echo "Header info:" . "<br>";
print_r($params['http']['header']);
echo "<br><br>" . "Request Info:" . "<br>";
print_r(urldecode($params['http']['content']));
echo "<br><br>" . "Response:" . "<br>";
//print the response to screen for testing purposes
If ( $kArray["responseEnvelope.ack"] == "Success")
{
foreach ($kArray as $key =>$value)
{
echo $key . ": " .$value . "<br/>";
}
}
else
{
foreach ($kArray as $key =>$value)
{
echo $key . ": " .$value . "<br/>";
}
}
}
catch(Exception $e)
{
echo "Message: ||" .$e->getMessage()."||";
}
echo "<br>";
?>
答案 1 :(得分:1)
结帐Paypay Adaptive Accounts并查找GetVerifiedStatus
答案 2 :(得分:0)
$email_pay=json_decode($this->config->item('paypal_payment'));
$paypal_email=$email_pay->email;
$paypal_username=$email_pay->username;
$paypal_password=$email_pay->password;
$paypal_appid=$email_pay->appid;
$paypal_signature=$email_pay->signature;
$mode=$email_pay->mode;
if($mode==0)
{
$API_Endpoint = "https://svcs.sandbox.paypal.com/AdaptiveAccounts/GetVerifiedStatus";
}
else
{
$API_Endpoint = "https://svcs.paypal.com/AdaptiveAccounts/GetVerifiedStatus";
}
$ret['error_new']='';
$payLoad["emailAddress"]=$_POST['paypal_email'];
$payLoad["matchCriteria"]="NONE"; $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
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);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-PAYPAL-REQUEST-DATA-FORMAT: JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT: JSON',
'X-PAYPAL-SECURITY-USERID: '. $paypal_username,
'X-PAYPAL-SECURITY-PASSWORD: '. $paypal_password,
'X-PAYPAL-SECURITY-SIGNATURE: '. $paypal_signature,
'X-PAYPAL-APPLICATION-ID: '. $paypal_appid
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payLoad));
$response = curl_exec($ch);
$response = json_decode($response, 1);
if(empty($response['error'])){
//valid account
}
else{
$ret['error_new']='Please enter valid paypal email id.';
}
}
else
{
$ret['status']=0;
}
echo json_encode($ret);