Developer Hooks

Issue #3 closed
Drew Angell repo owner created an issue

Provide hooks for developers to trigger their own functions based on different txn_type values received by PayPal IPN's.

Comments (20)

  1. jignesh kaila

    I have provided hook name like "paypal_ipn_for_wordpress_txn_type_" + txn_type and "paypal_ipn_for_wordpress_payment_status_" + payment_status.

    below are example:

    1. paypal_ipn_for_wordpress_txn_type_web_accept
    2. paypal_ipn_for_wordpress_payment_status_canceled_reversal

    So I think txn_type and payment_status wise hook create dynamically is it fine for you? Please let me know your thoughts for the same.

  2. jignesh kaila

    Can you please merge issue-2 branch to development branch, so I can get pull from development branch to this branch and push this branch for your review.

  3. Drew Angell reporter

    I left some details about the comments in the classes getting duplicated for #2. I'd rather not merge until that's resolved. Should be real quick, and I'll be around tonight, so just let me know once that other deal is fixed and I'll get everything merged up. Thanks!

  4. jignesh kaila

    I have remove duplicate comments and put class and function comments which are I left during development.

    I get pull from development branch to this branch and push on issue-3 branch.

    Please review it and let me know if any.

  5. Drew Angell reporter

    I went ahead and merged this into the dev branch so it's caught up. I would appreciate it if you can provide a quick sample for me here, though, of how a developer would utilize these hooks to automate a task. Just a quick sample of how one would go about triggering one of these hooks from within their own plugin would be great. Thanks!

  6. Drew Angell reporter

    I'm assuming it would be done with something like this..??

    add_action('paypal_ipn_for_wordpress_txy_type_recurring_payment', 'process_recurring_payment');
    
    function process_recurring_payment()
    {
        // Handle the data here
        $first_name = isset($posted['first_name']) ? $posted['first_name'] : ''; // Is this a proper example?
    }
    

    What I'm curious about, though, is how the actual IPN data will be available to the developer within that function..?? Is what I did here correct? Seems like I must need to load $posted into my function somehow to make it available..??

  7. jignesh kaila

    below is example

    add_action('paypal_ipn_for_wordpress_txy_type_recurring_payment', 'process_recurring_payment', 10, 1);
    
    function process_recurring_payment( $posted )
    {
        // Handle the data here
        $first_name = isset($posted['first_name']) ? $posted['first_name'] : ''; // Is this a proper example?
    }
    

    Using this example IPN data will be available to the developer within that function.

    Please let me know if any query.

  8. Drew Angell reporter

    Do we have a hook that covers any and all IPN's? For example, if I wanted to create a basic extension that emails the site admin with the IPN data for any IPN, do we have a hook for that? Like a paypal_ipn_for_wordpress_catch_all hook that would be triggered for every IPN regardless of type or status.

  9. jignesh kaila

    I have created one more hook like "paypal_ipn_for_wordpress_ipn_response_handler", that allow developer to trigger for every IPN response.

    I have push Issue-3 branch to development branch for your review.

  10. Drew Angell reporter
    • changed status to open

    I have another question now that I'm writing documentation for this.

    I see that the do_action() functions are to create the dynamic hook names is within an if statement...

            // Custom holds post ID
            if (!empty($posted['invoice']) && !empty($posted['custom'])) {
    
                // Lowercase returned variables
                $posted['payment_status'] = strtolower($posted['payment_status']);
                $posted['txn_type'] = strtolower($posted['txn_type']);
    
                if ('yes' == $this->debug) {
                    $this->log->add('paypal', 'Payment status: ' . $posted['payment_status']);
                }
    
                /* developers to trigger their own functions based on different txn_type values received by PayPal IPN's.
                 * $posted array contain all the response variable from received by PayPal IPN's
                 */
    
                do_action('paypal_ipn_for_wordpress_txn_type_' . $posted['txn_type'], $posted);
    
                /* developers to trigger their own functions based on different txn_type values received by PayPal IPN's.
                 * $posted array contain all the response variable from received by PayPal IPN's
                 */
    
                do_action('paypal_ipn_for_wordpress_payment_status_' . $posted['payment_status'], $posted);
    
                if ('yes' == $this->debug) {
                    $this->log->add('paypal', 'Payment txn_type: ' . $posted['txn_type']);
                }
            }
    

    The thing is, not every IPN will have these parameters at all, and sometimes they will have these parameters, but the value would indeed be empty. As such, when an IPN comes through without any invoice or custom value, the action hook would not get set, and people attempting to use the hook would not have their function triggered.

    For example, here is an IPN that doesn't include the invoice parameter at all, but it does include an empty custom parameter.

    Array
    (
        [mc_gross] => 77.64
        [protection_eligibility] => Eligible
        [address_status] => confirmed
        [item_number1] => 
        [payer_id] => YW66KXBKJRRES
        [tax] => 4.74
        [address_street] => 123 Test Ave
        [payment_date] => 17:15:02 Jan 14, 2015 PST
        [payment_status] => Completed
        [charset] => windows-1252
        [address_zip] => 64030
        [mc_shipping] => 0.00
        [mc_handling] => 0.00
        [first_name] => Tester
        [mc_fee] => 2.55
        [address_country_code] => US
        [address_name] => Testers, Llc
        [notify_version] => 3.8
        [custom] => 
        [payer_status] => verified
        [address_country] => United States
        [num_cart_items] => 1
        [mc_handling1] => 0.00
        [address_city] => Grandview
        [verify_sign] => ACJ.OlgcXB2UnaGy41m36nWibbhOABEI8W8rYa4c.Q.bsQuQ0EUix1.1
        [payer_email] => drew@angelleye.com
        [mc_shipping1] => 0.00
        [tax1] => 0.00
        [contact_phone] => 816-256-3419
        [txn_id] => 23888088EX5277921
        [payment_type] => instant
        [payer_business_name] => Testers, LLC
        [last_name] => Testerson
        [address_state] => MO
        [item_name1] => Woo Album #3
        [receiver_email] => sandbo_1215254764_biz@angelleye.com
        [payment_fee] => 2.55
        [quantity1] => 9
        [receiver_id] => ATSCG2QMC9KAU
        [txn_type] => cart
        [mc_gross_1] => 72.90
        [mc_currency] => USD
        [residence_country] => US
        [test_ipn] => 1
        [transaction_subject] => 
        [payment_gross] => 77.64
        [ipn_track_id] => fa75d0bcf263
    )
    

    If somebody had a hook setup for "paypal_ipn_for_wordpress_txn_type_cart" it wouldn't get triggered in this case, would it? Am I missing something?

    I'm also curious about that comment you made, "Custom holds post ID", as if the custom parameter should always have the post ID..?? This would not be the case. People could have their own custom value(s) in this parameter, and the IPN wouldn't know the post ID of the IPN in our system until it was already POSTed, so I'm a little confused here.

  11. Drew Angell reporter

    I did make a small change here, too, so that the hook name will always be all lowercase. I adjusted your do_action() lines like this...

    do_action('paypal_ipn_for_wordpress_txn_type_' . strtolower($posted['txn_type']), $posted);
    
    do_action('paypal_ipn_for_wordpress_payment_status_' . strtolower($posted['payment_status']), $posted);
    

    These updates have been pushed to the dev branch.

  12. Log in to comment