Test File for Developer Hooks

Issue #26 closed
Drew Angell repo owner created an issue

I'd like to create a very basic extension plugin that uses each of the IPN hooks the plugin supports so that we can ensure they're working as expected.

Each hook can do nothing but save a log file with the IPN data, just so we can see that the hook was indeed triggered.

I tried to start this on my own, so I put together a very basic sample that I was just going to email myself the data with.

/**
 * @package PayPal IPN for WordPress - Hook Tester
 * @version 1.0.0
 */
/*
Plugin Name: PayPal IPN for WordPress - Hook Tester
Plugin URI: http://www.angelleye.com/
Description: Hook tester for PayPal IPN for WordPress plugin.
Author: angelleye
Version: 1.0.0
*/

add_action('paypal_ipn_for_wordpress_payment_status_refunded', 'process_refund', 10, 1);

function process_refund( $posted )
{
    $mailbody = '';

    // Parse data from IPN $posted[] array
    foreach($posted as $var => $val)
    {
        $mailbody .= "$var: $val <br />";
    }

    wp_mail('andrew@angelleye.com','PayPal IPN for WordPress - Hook Tester - ' . $posted['txn_type'], $mailbody);
}

For some reason I'm not getting an email, though, so I'm assuming I've done something wrong in my plugin hook..??

Comments (8)

  1. Drew Angell reporter

    I adjusted my plugin to simplify things a little bit. Here's what I'm working with...

    /**
     * @package PayPal IPN for WordPress - Hook Tester
     * @version 1.0.0
     */
    /*
    Plugin Name: PayPal IPN for WordPress - Hook Tester
    Plugin URI: http://www.angelleye.com/
    Description: Hook tester for PayPal IPN for WordPress plugin.
    Author: angelleye
    Version: 1.0.0
    */
    
    add_action('paypal_ipn_for_wordpress_payment_status_refunded', 'send_test_email', 10, 1);
    add_action('paypal_ipn_for_wordpress_payment_status_completed', 'send_test_email', 10, 1);
    add_action('paypal_ipn_for_wordpress_txn_type_express_checkout', 'send_test_email', 10, 1);
    add_action('paypal_ipn_for_wordpress_txn_type_cart', 'send_test_email', 10, 1);
    add_action('paypal_ipn_for_wordpress_txn_type_masspay', 'send_test_email', 10, 1);
    
    function send_test_email( $posted )
    {
        $mailbody = '';
    
        // Parse data from IPN $posted[] array
        foreach($posted as $var => $val)
        {
            $mailbody .= "$var: $val".chr(13);
        }
    
        wp_mail('andrew@angelleye.com','PayPal IPN for WordPress - Hook Tester - ' . $posted['txn_type'], $mailbody);
    }
    

    When I run tests with this plugin enabled I am getting the emails I expect for the txn_type hooks, but not for the payment_status hooks.

  2. Drew Angell reporter

    I add the paypal_ipn_for_wordpress_txn_type_masspay hook to the tester plugin and ran another MassPay transaction. This time both the txn_type and the payment_status hooks seemed to have worked. I had 2 payments on the MassPay request, and I wound up with 4 emails, which would be expected since each IPN was a masspay transaction that was completed, so both hooks were triggered both times.

    Still, though, the payment_status_refunded hook did not trigger as expected.

  3. Drew Angell reporter

    Well, I think I see the problem, but now I'm not so sure any of my payment_status hooks were ever getting triggered.

    In the helper class on line 163 is where I see we're creating the hook based on payment_status, however, the prefix for it there is paypal_ipn_for_wordpress_txn_type_ instead of paypal_ipn_for_wordpress_payment_status_

  4. Drew Angell reporter

    Yup, that was the problem. I updated that and now the hooks based on payment_status are working as expected so far.

  5. Drew Angell reporter

    You don't need to do anything with this one at this point. I'm going to play with some more hooks in my test file, but I'll update again if you need to address anything here.

  6. Log in to comment