【问题标题】:Paypal IPN hook not workingPaypal IPN 挂钩不起作用
【发布时间】:2017-02-02 07:26:27
【问题描述】:

我创建了一个插件,可以在用户使用贝宝捐款后向他们发送电子邮件。但问题是用户没有收到任何电子邮件。请在下面检查我的代码。我也在使用名为“PayPal IPN for WordPress”的插件来获取捐赠信息。

<?php
/*
Plugin Name: PayPal IPN Send Email
Plugin URI: http://www.trustedwebsolution.com/
Description: Hook tester for PayPal IPN for WordPress plugin.
Author: Jhishu Singha
Version: 1.0.0
*/


add_action('paypal_ipn_for_wordpress_payment_status_processed', 'paypal_ipn_for_wordpress_payment_email', 10, 1);
function paypal_ipn_for_wordpress_payment_email($posted) {
    // Parse data from IPN $posted array

    $dir = plugin_dir_url( __FILE__ );
    $item_name = isset($posted['item_name']) ? $posted['item_name'] : '';
    $payment_gross = isset($posted['payment_gross']) ? $posted['payment_gross'] : '';
    $first_name = isset($posted['first_name']) ? $posted['first_name'] : '';
    $last_name = isset($posted['last_name']) ? $posted['last_name'] : '';
    $payer_email = isset($posted['payer_email']) ? $posted['payer_email'] : '';
    $subscr_date = isset($posted['subscr_date']) ? $posted['subscr_date'] : '';

    /**
     * At this point you can use the data to generate email notifications,
     * update your local database, hit 3rd party web services, or anything
     * else you might want to automate based on this type of IPN.
     */
    if($item_name == 'ATF Donation') { 
    $to = $payer_email;
    $subject = 'Email from Adaptive Training Foundation';
    $message = 'Thanks for donation';
    $headers = array('Content-Type: text/html; charset=UTF-8');
    wp_mail( $to, $subject, $message, $headers );
    } else {
        // No email
    }
}
?>

我试图解决它几天。但没有运气。提前感谢您的帮助。

【问题讨论】:

    标签: php wordpress email paypal paypal-ipn


    【解决方案1】:

    我认为你应该使用不同的钩子。而不是paypal_ipn_for_wordpress_payment_status_processed 使用paypal_ipn_for_wordpress_payment_status_completed 看看是否有帮助。

    另外,出于测试目的,我会在您声明的 else 部分中添加一封给您自己的电子邮件,以便您在代码落入那里时得到一些东西,并且您不会认为 IPN 根本就没有运行过。

    【讨论】:

    • 感谢您的回复。首先我使用了“paypal_ipn_for_wordpress_payment_status_completed”钩子。当这个钩子不起作用时,我使用了这个“paypal_ipn_for_wordpress_payment_status_processed”。这也行不通。我还添加了我的电子邮件地址以进行测试。
    • 您是否在 PayPal 中获取 IPN 记录 -> WP 管理面板中的 IPN 列表?
    • 是的。我正在获取 IPN 记录。
    最近更新 更多