是有效的贝宝电子邮件地址(PHP) [英] Is a valid paypal email address or not (PHP)

查看:104
本文介绍了是有效的贝宝电子邮件地址(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用贝宝(Paypal)自适应付款,并且我需要验证商店/卖家提供的贝宝(Paypal)api的电子邮件地址,以便客户可以直接将其付款给商店.

I am using paypal adaptive payments and i need to verify email address from paypal api given by the store/seller, so that the payment can be directly given to store by customers.

我想检查商店的给定电子邮件是否是有效的贝宝电子邮件地址,并且他/她是否已注册贝宝.

i want to check that if store's given email is a valid paypal email address and he/she has signed up for paypal or not.

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

tell me if PayPal supports and allows Application to access or not.

,还请在php中给我示例代码

and also give me sample code please in php

推荐答案

是的,PayPal通过使用"GetVerifiedStatus" API来支持此功能,在该API中,您必须输入电子邮件地址,名字和姓氏作为必需参数,并且它将返回如下响应:

Yes PayPal supports this feature via the use of "GetVerifiedStatus" API where you have to input the email address , first name and the last name as the required parameter and it will return the response like below :

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代码:

You can use the below php code for this :

<?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>";  
?>

这篇关于是有效的贝宝电子邮件地址(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆