如何在 Laravel 中验证电子邮件地址是否有效 PayPal 电子邮件地址

时间:2021-04-08 05:41:14

标签: php laravel paypal

我需要验证正确的 PayPal 电子邮件地址。因为我需要向那个 PayPal 电子邮件地址汇款。

此代码以前有效。但现在它没有经过验证。

我的代码是

 $ch = curl_init();
    //parameters of requests
    $nvpStr = 'emailAddress=' . $request->email . '&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:" . env('PAYPAL_USERNAME'),
        "X-PAYPAL-SECURITY-PASSWORD:" . env('PAYPAL_PASSWORD'),
        "X-PAYPAL-SECURITY-SIGNATURE:" . env('PAYPAL_SIGNATURE'),
        "X-PAYPAL-REQUEST-DATA-FORMAT:JSON",
        "X-PAYPAL-RESPONSE-DATA-FORMAT:JSON",
        "X-PAYPAL-APPLICATION-ID:" . env('PAYPAL_APP_ID') //,
        //"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);

    $data = json_decode($paypalResponse);

    if ($data->responseEnvelope->ack == 'Success')
        return true;
    else
        return false;

我收到了这个回应 enter image description here

我正在研究 PHP laravel。

如果有人有任何想法,请帮忙。

1 个答案:

答案 0 :(得分:0)

错误 ID 和相关 ID 在问题的屏幕截图中被涂掉。使任何人都无法准确回答问题所在的方法。

一个可能的问题是 GetVerifiedStatus 不支持 &matchCriteria=NONE。相反,传递诸如 &matchCriteria=NAME 以及 &FirstName=xxxxx&LastName=xxxxx 之类的东西。

如果您不想提示用户输入匹配条件,另一种不同的解决方案是使用 Connect with PayPal 按钮让他们登录。