且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PayPal API - 验证帐户是否有效/存在/已验证

更新时间:2023-11-26 21:00:58

<?php
// create a new cURL resource
$ch = curl_init();

$ppUserID = "******************"; //Take it from   sandbox dashboard for test mode or take it from paypal.com account in production mode, help: https://developer.paypal.com/docs/classic/api/apiCredentials/
$ppPass = "*************"; //Take it from sandbox dashboard for test mode or take it from paypal.com account in production mode, help: https://developer.paypal.com/docs/classic/api/apiCredentials/
$ppSign = "********************"; //Take it from sandbox dashboard for test mode or take it from paypal.com account in production mode, help: https://developer.paypal.com/docs/classic/api/apiCredentials/
$ppAppID = "***********"; //if it is sandbox then app id is always: APP-80W284485P519543T
$sandboxEmail = "********************"; //comment this line if you want to use it in production mode.It is just for sandbox mode

$emailAddress = "sunil@rudrainnovatives.com"; //The email address you wana verify

//parameters of requests
$nvpStr = 'emailAddress='.$emailAddress.'&matchCriteria=NONE';

// RequestEnvelope fields
$detailLevel    = urlencode("ReturnAll");
$errorLanguage  = urlencode("en_US");
$nvpreq = "requestEnvelope.errorLanguage=$errorLanguage&requestEnvelope.detailLevel=$detailLevel&";
$nvpreq .= "&$nvpStr";
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

$headerArray = array(
"X-PAYPAL-SECURITY-USERID:$ppUserID",
"X-PAYPAL-SECURITY-PASSWORD:$ppPass",
"X-PAYPAL-SECURITY-SIGNATURE:$ppSign",
"X-PAYPAL-REQUEST-DATA-FORMAT:NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT:JSON",
"X-PAYPAL-APPLICATION-ID:$ppAppID",
"X-PAYPAL-SANDBOX-EMAIL-ADDRESS:$sandboxEmail" //comment this line in production mode. IT IS JUST FOR SANDBOX TEST 
);

$url="https://svcs.sandbox.paypal.com/AdaptiveAccounts/GetVerifiedStatus";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
$paypalResponse = curl_exec($ch);
//echo $paypalResponse;   //if you want to see whole PayPal response then uncomment it.
curl_close($ch);

echo $data = json_decode($paypalResponse);



?>