【问题标题】:Configure Wordpress to receive Paypal IPN notifications配置 Wordpress 以接收 Paypal IPN 通知
【发布时间】:2017-07-04 22:39:32
【问题描述】:

我在我的网站中使用 Wordpress。我在我的网站上附加了一些用于处理购买内容的插件。我使用 Easy Digital Downloads (https://wordpress.org/plugins/easy-digital-downloads) 插件来管理数字内容的销售,并使用 Paypal IPN for WordPress (https://wordpress.org/plugins/paypal-ipn/) 从我的 Paypal 帐户中获取交易详情。

我必须在 sandbox.paypal.com 上创建一个帐户来测试所有功能是否正常运行。对于插件 Easy Digital Downloads 的管理,当前帐户和正确记录。但是我没有收到关于 Paypal IPN for WordPress 插件的报告。交易报告时,我已将插件中的 URL 作为地址输入到我的 Paypal 帐户中。但是我完全没有从贝宝收到报告。

所以我想在没有 wordpress 插件的情况下从头开始创建自己的网页,并在 PHP 脚本之上运行所有功能。那么,我最好继续使用 Wordpress 还是通过编写自己的脚本从头开始重建网站。

如果您对wordpress插件的使用有参考,请在cmets中分享。感谢您的帮助。

【问题讨论】:

    标签: php wordpress plugins paypal


    【解决方案1】:

    首先,您需要创建一个custom WordPress page 并配置 Paypal IPN 脚本以发布和获取数据。在这样的页面上,您还可以添加功能以将数据存储在数据库中、通过邮件发送、添加 cron 作业或其他任何 IPN scripts ...

    另外,您需要访问paypal网站和set the ipn link,然后将您网站的数据发布到那里,并将其配置为回传到wordpress网站的url,并带有接收paypal ipn post数据的页面...

    这是一个页面example

    <?php
    class PayPal_IPN{
    function infotuts_ipn($im_debut_ipn) {
    
    define('SSL_P_URL', 'https://www.paypal.com/cgi-bin/webscr');
     define('SSL_SAND_URL', 'https://www.sandbox.paypal.com/cgi-bin/webscr');
     $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
     if (!preg_match('/paypal\.com$/', $hostname)) {
     $ipn_status = 'Validation post isn\'t from PayPal';
     if ($im_debut_ipn == true) {
     // mail test
     }
    
    return false;
     }
    
    // parse the paypal URL
     $paypal_url = ($_REQUEST['test_ipn'] == 1) ? SSL_SAND_URL : SSL_P_URL;
     $url_parsed = parse_url($paypal_url);
    
     $post_string = '';
     foreach ($_REQUEST as $field => $value) {
     $post_string .= $field . '=' . urlencode(stripslashes($value)) . '&';
     }
     $post_string.="cmd=_notify-validate"; // append ipn command
     // get the correct paypal url to post request to
     $paypal_mode_status = $im_debut_ipn; //get_option('im_sabdbox_mode');
     if ($paypal_mode_status == true)
     $fp = fsockopen('ssl://www.sandbox.paypal.com', "443", $err_num, $err_str, 60);
     else
     $fp = fsockopen('ssl://www.paypal.com', "443", $err_num, $err_str, 60);
    
    $ipn_response = '';
    
    if (!$fp) {
    // could not open the connection. If loggin is on, the error message
    // will be in the log.
     $ipn_status = "fsockopen error no. $err_num: $err_str";
     if ($im_debut_ipn == true) {
     echo 'fsockopen fail';
     }
     return false;
     } else {
    // Post the data back to paypal
     fputs($fp, "POST $url_parsed[path] HTTP/1.1\r\n");
     fputs($fp, "Host: $url_parsed[host]\r\n");
     fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
     fputs($fp, "Content-length: " . strlen($post_string) . "\r\n");
     fputs($fp, "Connection: close\r\n\r\n");
     fputs($fp, $post_string . "\r\n\r\n");
    
    // loop through the response from the server and append to variable
     while (!feof($fp)) {
     $ipn_response .= fgets($fp, 1024);
     }
     fclose($fp); // close connection
     }
    
    // Invalid IPN transaction. Check the $ipn_status and log for details.
     if (!preg_match("/VERIFIED/s", $ipn_response)) {
     $ipn_status = 'IPN Validation Failed';
    
    if ($im_debut_ipn == true) {
     echo 'Validation fail';
     print_r($_REQUEST);
     }
     return false;
     } else {
     $ipn_status = "IPN VERIFIED";
     if ($im_debut_ipn == true) {
     echo 'SUCCESS';
    
     }
    
    return true;
     }
     }
     function ipn_response($request){
     mail("sanjeev00733@gmail.com","My subject",print_r($request,true));
     $im_debut_ipn=true;
     if ($this->infotuts_ipn($im_debut_ipn)) {
    
     // if paypal sends a response code back let's handle it
     if ($im_debut_ipn == true) {
     $sub = 'PayPal IPN Debug Email Main';
     $msg = print_r($request, true);
     $aname = 'infotuts';
     //mail send
     }
    
    // process the membership since paypal gave us a valid +
     $this->insert_data($request);
     }
     }
    function issetCheck($post,$key){
    if(isset($post[$key])){
    $return=$post[$key];
    }
    else{
    $return='';
    }
    return $return;
    }
     function insert_data($request){
     require_once('dbconnect.php');
    
    $post=$request;
    $item_name=$this->issetCheck($post,'item_name');
    $amount=$this->issetCheck($post,'mc_gross');
    $currency=$this->issetCheck($post,'mc_currency');
    $payer_email=$this->issetCheck($post,'payer_email');
    $first_name=$this->issetCheck($post,'first_name');
    $last_name=$this->issetCheck($post,'last_name');
    $country=$this->issetCheck($post,'residence_country');
    $txn_id=$this->issetCheck($post,'txn_id');
    $txn_type=$this->issetCheck($post,'txn_type');
    $payment_status=$this->issetCheck($post,'payment_status');
    $payment_type=$this->issetCheck($post,'payment_type');
    $payer_id=$this->issetCheck($post,'payer_id');
    $create_date=date('Y-m-d H:i:s');
    $payment_date=date('Y-m-d H:i:s');
    
    mysqli_query($con,"INSERT INTO infotuts_transection_tbl (item_name,payer_email,first_name,last_name,amount,currency,country,txn_id,txn_type,payer_id,payment_status,payment_type,create_date,payment_date)
    VALUES ('$item_name','$payer_email','$first_name','$last_name','$amount','$currency','$country','$txn_id','$txn_type','$payer_id','$payment_status','$payment_type','$create_date','$payment_date')");
    mysqli_close($con);
    
     }
     }
     $obj = New PayPal_IPN();
     $obj->ipn_response($_REQUEST);
    
     ?>
    

    【讨论】:

    • 感谢您的回答。所以通过使用上面的脚本我不再需要安装插件“Paypal IPN for Wordpress”?我现在正在使用它,
    • 插件必须使用这样的东西,在没有插件的情况下使用它,或者,您可以根据 WordPress codex 的设置编辑插件源文件。首先通过PayPal设置IPN url,然后尝试...
    猜你喜欢
    • 2010-11-10
    • 1970-01-01
    • 2019-05-04
    • 2015-02-08
    • 2014-02-05
    • 1970-01-01
    • 2016-02-19
    • 2014-05-02
    • 1970-01-01
    相关资源
    最近更新 更多