Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a plugin which will involve accepting PayPal Instant Payment Notifications. IPNs are a web-hook which gets called when a payment is processed. Currently I have a script to handle the IPNs within the plugin e.g.

http://mywordpressinstall.com/wp-content/plugins/paypalplugin/IPNHandler.php

I then paste this URL into the PayPal developer settings area.

I'd like to use a more customizable location for the IPN handler (with a friendlier URL).

I was thinking maybe a shortcode could be used to give 'handler' functionality to any page it's inserted in. Is this a sensible idea? Does anyone have any suggestion on how I can make the URL of the handler shorter?

Thanks!

share|improve this question
add comment

1 Answer

You can hook to the init action and then check for the query variable, you can use the PayPal provided query var or you can use your own custom query var.

I will give you example of your own custom query var i.e MYIPN_LISTENER

The Code:

function wpse58656_paypal_ipn_listener() {
    // check for your custom query var
    // If you are paranoid you can also check the value of the var
    if ( ! isset( $_GET['MYIPN_LISTENER'] ) ) {
        // if query var is not present just return
        return;
    }

    // do the processsing here

    // don't forget to exit when you are done
    exit;
}
add_action( 'init', 'wpse58656_paypal_ipn_listener' );

Now you can use any URL but it should have MYIPN_LISTENER as a query var e.g: http://mywordpressinstall.com/?MYIPN_LISTENER=1

share|improve this answer
    
I was going to ask exactly the same question pertaining to another event notifier. +1 for saving me the trouble. –  helgatheviking Nov 10 '12 at 18:00
    
@hameedulllah-khan can I just ask why you have to exit? –  helgatheviking Nov 10 '12 at 18:35
    
You have to exit because your hooking into WordPress init function, init is run before WordPress sends any headers back. If you will not exit than WordPress will start sending headers and content which is not required in this case. –  Hameedullah Khan Nov 11 '12 at 9:13
    
ok. makes sense. thank you for the additional explanation. –  helgatheviking Nov 11 '12 at 15:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.