Provide hook function snippets in the IPN detail page.

Issue #44 closed
Drew Angell repo owner created an issue

Right now our IPN details page simply lists the parameters and the raw IPN dump that were included in that particular IPN. There isn't really any instruction on what to do with that here, and it leaves people a little bit confused.

In my basic developer documentation that I put together I provide the following sample...

add_action('paypal_ipn_for_wordpress_txn_type_recurring_payment', 'process_recurring_payment', 10, 1);

function process_recurring_payment( $posted )
{
    // Parse data from IPN $posted[] array
    $first_name = isset($posted['first_name']) ? $posted['first_name'] : '';
    $last_name = isset($posted['last_name']) ? $posted['last_name'] : '';
    $mc_gross = isset($posted['mc_gross']) ? $posted['mc_gross'] : '';
    $recurring_payment_id = isset($posted['recurring_payment_id']) ? $posted['recurring_payment_id'] : '';
    $payer_email = isset($posted['payer_email']) ? $posted['payer_email'] : '';
    $txn_id = isset($posted['txn_id']) ? $posted['txn_id'] : '';

    /**
     * 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.
     */
}

What I would like to do is add some very basic instructions within the IPN details and also provide a sample just like this using the parameters that were sent in that particular IPN.

This way, every IPN will have a nice snippet that you can copy/paste to use for your own hooks.

So we would just provide some general instruction and maybe a link to all of the different hooks that can be used to trigger your own function, and then we'll also provide a snippet of the function itself as a starting point for people to get going quickly.

Comments (11)

  1. jignesh kaila

    I am still working on this ticket, once I am done with this ticket I will let you know for the same.

  2. jignesh kaila

    I am done with this task and push to development branch.

    Please review the screenshot for more information:

    44.png

  3. Drew Angell reporter

    This looks good, but I'd like to make an adjustment. Right now we're basically outputting the same function two times because you're showing that you can do it based on status or transaction type. The process is the same either way, though, and with only a single hook used in the sample they'd still have to change it to what they want to use in most cases.

    As such, what I would like to do is continue to prepare all of the variables that the IPN contained like you are in the function, but we would just show a single function with generic placeholder names for the function/hook. For example, we might show something like this...

    add_action('hook_name', 'function_name', 10, 1);
            function function_name($posted) {
    
                  // Parse data from IPN $posted array
    
                  $mc_gross = isset($posted['mc_gross']) ? $posted['mc_gross'] : '';
                  $invoice = isset($posted['invoice']) ? $posted['invoice'] : '';
                  $protection_eligibility = isset($posted['protection_eligibility']) ? $posted['protection_eligibility'] : '';
                  $payer_id = isset($posted['payer_id']) ? $posted['payer_id'] : '';
                  $tax = isset($posted['tax']) ? $posted['tax'] : '';
                  $payment_date = isset($posted['payment_date']) ? $posted['payment_date'] : '';
                  $payment_status = isset($posted['payment_status']) ? $posted['payment_status'] : '';
                  $charset = isset($posted['charset']) ? $posted['charset'] : '';
                  $first_name = isset($posted['first_name']) ? $posted['first_name'] : '';
                  $mc_fee = isset($posted['mc_fee']) ? $posted['mc_fee'] : '';
                  $notify_version = isset($posted['notify_version']) ? $posted['notify_version'] : '';
                  $payer_status = isset($posted['payer_status']) ? $posted['payer_status'] : '';
                  $business = isset($posted['business']) ? $posted['business'] : '';
                  $quantity = isset($posted['quantity']) ? $posted['quantity'] : '';
                  $verify_sign = isset($posted['verify_sign']) ? $posted['verify_sign'] : '';
                  $payer_email = isset($posted['payer_email']) ? $posted['payer_email'] : '';
                  $txn_id = isset($posted['txn_id']) ? $posted['txn_id'] : '';
                  $payment_type = isset($posted['payment_type']) ? $posted['payment_type'] : '';
                  $last_name = isset($posted['last_name']) ? $posted['last_name'] : '';
                  $receiver_email = isset($posted['receiver_email']) ? $posted['receiver_email'] : '';
                  $payment_fee = isset($posted['payment_fee']) ? $posted['payment_fee'] : '';
                  $receiver_id = isset($posted['receiver_id']) ? $posted['receiver_id'] : '';
                  $txn_type = isset($posted['txn_type']) ? $posted['txn_type'] : '';
                  $item_name = isset($posted['item_name']) ? $posted['item_name'] : '';
                  $mc_currency = isset($posted['mc_currency']) ? $posted['mc_currency'] : '';
                  $residence_country = isset($posted['residence_country']) ? $posted['residence_country'] : '';
                  $test_ipn = isset($posted['test_ipn']) ? $posted['test_ipn'] : '';
                  $receipt_id = isset($posted['receipt_id']) ? $posted['receipt_id'] : '';
                  $handling_amount = isset($posted['handling_amount']) ? $posted['handling_amount'] : '';
                  $payment_gross = isset($posted['payment_gross']) ? $posted['payment_gross'] : '';
                  $shipping = isset($posted['shipping']) ? $posted['shipping'] : '';
                  $ipn_track_id = isset($posted['ipn_track_id']) ? $posted['ipn_track_id'] : '';
                  $IPN_status = isset($posted['IPN_status']) ? $posted['IPN_status'] : '';
    
                /**
                * 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.
                */
            }
    

    And then we would just explain that they need to set the "hook_name" to the hook they want to use, and the "function_name" to whatever they want to call it. We would also include a link to the documentation that shows all of the hooks that are available.

    So then I could look at an IPN, grab the snippet, update the hook and function name, and then add whatever logic I want to process the available data.

    Make sense?

  4. Drew Angell reporter

    Also, I just noticed that if I have both the "PayPal IPN Fields" and "Hook Function Snippets" accordion items minimized, then I can't open up the Hook Function Snippets section. Not sure if my theme's settings box is conflicting and getting in the way..?? Here's a video of what I'm experiencing.

    http://fiber.angelleye.com/temp/accordion.mp4

  5. jignesh kaila

    I am done with accordion issue and add some more detail for hook, please check review it and let me know your suggestion/changes regarding hook - function content details.

    I have also attached screenshot for your review:

    issue44a.png

  6. Drew Angell reporter

    I've made a few adjustments to the layout and the verbiage, but there's one more think I'd like you to do please.

    I would like to be able to select the whole code snippet with one click, so using an "onclick" on that div or something like that would select the entire snippet of code so I don't have to click and drag to select it.

  7. Log in to comment