是否是有效的PayPal电子邮件地址(PHP)

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了是否是有效的PayPal电子邮件地址(PHP)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用paypal自适应支付,我需要验证商店/卖家给出的paypal api的邮件地址,以便付款可以直接由客户提供给商店.

我想检查一下,如果商店给出的电子邮件是有效的PayPal电子邮件地址,并且他/她已经注册了paypal.

告诉我PayPal是否支持并允许应用程序访问.

并在PHP中给我示例代码

解决方法

是的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("&amp;",$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>";  
?>

脚本宝典总结

以上是脚本宝典为你收集整理的是否是有效的PayPal电子邮件地址(PHP)全部内容,希望文章能够帮你解决是否是有效的PayPal电子邮件地址(PHP)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。